blob: 57a68ed04b9e05ce3d02b5f0536efe5ad309aa7c [file] [log] [blame]
Benjamin Chan59a06052017-01-12 18:06:03 -05001/* Copyright (c) 2015-2017, The Linux Foundation. All rights reserved.
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -07002 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 */
13
14#ifndef SDE_ROTATOR_CORE_H
15#define SDE_ROTATOR_CORE_H
16
17#include <linux/list.h>
18#include <linux/file.h>
19#include <linux/ktime.h>
20#include <linux/mutex.h>
21#include <linux/types.h>
22#include <linux/cdev.h>
23#include <linux/pm_runtime.h>
Benjamin Chanf8d9a462016-11-08 21:38:10 -050024#include <linux/kthread.h>
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -070025
26#include "sde_rotator_base.h"
27#include "sde_rotator_util.h"
28#include "sde_rotator_sync.h"
29
30/**********************************************************************
31 * Rotation request flag
32 **********************************************************************/
33/* no rotation flag */
34#define SDE_ROTATION_NOP 0x01
35
36/* left/right flip */
37#define SDE_ROTATION_FLIP_LR 0x02
38
39/* up/down flip */
40#define SDE_ROTATION_FLIP_UD 0x04
41
42/* rotate 90 degree */
43#define SDE_ROTATION_90 0x08
44
45/* rotate 180 degre */
46#define SDE_ROTATION_180 (SDE_ROTATION_FLIP_LR | SDE_ROTATION_FLIP_UD)
47
48/* rotate 270 degree */
49#define SDE_ROTATION_270 (SDE_ROTATION_90 | SDE_ROTATION_180)
50
51/* format is interlaced */
52#define SDE_ROTATION_DEINTERLACE 0x10
53
54/* secure data */
55#define SDE_ROTATION_SECURE 0x80
56
57/* verify input configuration only */
58#define SDE_ROTATION_VERIFY_INPUT_ONLY 0x10000
59
60/* use client provided dma buf instead of ion fd */
61#define SDE_ROTATION_EXT_DMA_BUF 0x20000
62
Abhijit Kulkarni298c8232016-09-26 22:32:10 -070063/* secure camera operation*/
64#define SDE_ROTATION_SECURE_CAMERA 0x40000
65
Alan Kwong6bc64622017-02-04 17:36:03 -080066/* use client mapped i/o virtual address */
67#define SDE_ROTATION_EXT_IOVA 0x80000
68
Alan Kwongf366a012017-02-10 20:54:46 -080069/* use client provided clock/bandwidth parameters */
70#define SDE_ROTATION_EXT_PERF 0x100000
71
Alan Kwonga94684f2016-01-16 22:06:36 -050072/**********************************************************************
73 * configuration structures
74 **********************************************************************/
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -070075
Alan Kwongf94a2552016-12-28 09:41:22 -080076/*
77 * struct sde_rotation_buf_info - input/output buffer configuration
78 * @width: width of buffer region to be processed
79 * @height: height of buffer region to be processed
80 * @format: pixel format of buffer
81 * @comp_ratio: compression ratio for the session
Alan Kwong6bc64622017-02-04 17:36:03 -080082 * @sbuf: true if buffer is streaming buffer
Alan Kwongf94a2552016-12-28 09:41:22 -080083 */
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -070084struct sde_rotation_buf_info {
85 uint32_t width;
86 uint32_t height;
87 uint32_t format;
88 struct sde_mult_factor comp_ratio;
Alan Kwong6bc64622017-02-04 17:36:03 -080089 bool sbuf;
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -070090};
91
Alan Kwongf94a2552016-12-28 09:41:22 -080092/*
93 * struct sde_rotation_config - rotation configuration for given session
94 * @session_id: identifier of the given session
95 * @input: input buffer information
96 * @output: output buffer information
97 * @frame_rate: session frame rate in fps
Alan Kwongf366a012017-02-10 20:54:46 -080098 * @clk_rate: requested rotator clock rate if SDE_ROTATION_EXT_PERF is set
99 * @data_bw: requested data bus bandwidth if SDE_ROTATION_EXT_PERF is set
Alan Kwongf94a2552016-12-28 09:41:22 -0800100 * @flags: configuration flags, e.g. rotation angle, flip, etc...
101 */
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -0700102struct sde_rotation_config {
103 uint32_t session_id;
104 struct sde_rotation_buf_info input;
105 struct sde_rotation_buf_info output;
106 uint32_t frame_rate;
Alan Kwongf366a012017-02-10 20:54:46 -0800107 uint64_t clk_rate;
108 uint64_t data_bw;
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -0700109 uint32_t flags;
110};
111
112enum sde_rotator_ts {
113 SDE_ROTATOR_TS_SRCQB, /* enqueue source buffer */
114 SDE_ROTATOR_TS_DSTQB, /* enqueue destination buffer */
115 SDE_ROTATOR_TS_FENCE, /* wait for source buffer fence */
116 SDE_ROTATOR_TS_QUEUE, /* wait for h/w resource */
117 SDE_ROTATOR_TS_COMMIT, /* prepare h/w command */
Clarence Ip3ce07c02017-08-11 16:21:45 -0400118 SDE_ROTATOR_TS_START, /* wait for h/w kickoff rdy (inline) */
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -0700119 SDE_ROTATOR_TS_FLUSH, /* initiate h/w processing */
120 SDE_ROTATOR_TS_DONE, /* receive h/w completion */
121 SDE_ROTATOR_TS_RETIRE, /* signal destination buffer fence */
122 SDE_ROTATOR_TS_SRCDQB, /* dequeue source buffer */
123 SDE_ROTATOR_TS_DSTDQB, /* dequeue destination buffer */
124 SDE_ROTATOR_TS_MAX
125};
126
Benjamin Chan77aed192016-10-17 17:49:41 -0400127enum sde_rotator_clk_type {
128 SDE_ROTATOR_CLK_MDSS_AHB,
129 SDE_ROTATOR_CLK_MDSS_AXI,
Clarence Ip77c053d2017-04-24 19:26:37 -0700130 SDE_ROTATOR_CLK_MDSS_ROT_SUB,
Benjamin Chan77aed192016-10-17 17:49:41 -0400131 SDE_ROTATOR_CLK_MDSS_ROT,
132 SDE_ROTATOR_CLK_MNOC_AHB,
Alan Kwonge1947ab2016-11-26 13:32:25 -0800133 SDE_ROTATOR_CLK_GCC_AHB,
134 SDE_ROTATOR_CLK_GCC_AXI,
Benjamin Chan77aed192016-10-17 17:49:41 -0400135 SDE_ROTATOR_CLK_MAX
136};
137
Alan Kwong6bc64622017-02-04 17:36:03 -0800138enum sde_rotator_trigger {
139 SDE_ROTATOR_TRIGGER_IMMEDIATE,
140 SDE_ROTATOR_TRIGGER_VIDEO,
141 SDE_ROTATOR_TRIGGER_COMMAND,
142};
143
Alan Kwong4b416162017-08-11 21:03:10 -0400144enum sde_rotator_mode {
145 SDE_ROTATOR_MODE_OFFLINE,
146 SDE_ROTATOR_MODE_SBUF,
147 SDE_ROTATOR_MODE_MAX,
148};
149
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -0700150struct sde_rotation_item {
151 /* rotation request flag */
152 uint32_t flags;
153
Alan Kwong6bc64622017-02-04 17:36:03 -0800154 /* rotation trigger mode */
155 uint32_t trigger;
156
Alan Kwong498d59f2017-02-11 18:56:34 -0800157 /* prefill bandwidth in Bps */
158 uint64_t prefill_bw;
159
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -0700160 /* Source crop rectangle */
161 struct sde_rect src_rect;
162
163 /* Destination rectangle */
164 struct sde_rect dst_rect;
165
166 /* Input buffer for the request */
167 struct sde_layer_buffer input;
168
169 /* The output buffer for the request */
170 struct sde_layer_buffer output;
171
Alan Kwonga94684f2016-01-16 22:06:36 -0500172 /*
173 * DMA pipe selection for this request by client:
174 * 0: DMA pipe 0
175 * 1: DMA pipe 1
176 * or SDE_ROTATION_HW_ANY if client wants
177 * driver to allocate any that is available
178 *
179 * OR
180 *
181 * Reserved
182 */
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -0700183 uint32_t pipe_idx;
184
Alan Kwonga94684f2016-01-16 22:06:36 -0500185 /*
186 * Write-back block selection for this request by client:
187 * 0: Write-back block 0
188 * 1: Write-back block 1
189 * or SDE_ROTATION_HW_ANY if client wants
190 * driver to allocate any that is available
191 *
192 * OR
193 *
194 * Priority selection for this request by client:
195 * 0: Highest
196 * 1..n: Limited by the lowest available priority
197 */
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -0700198 uint32_t wb_idx;
199
Alan Kwonga94684f2016-01-16 22:06:36 -0500200 /*
201 * Sequence ID of this request within the session
202 */
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -0700203 uint32_t sequence_id;
204
205 /* Which session ID is this request scheduled on */
206 uint32_t session_id;
207
208 /* Time stamp for profiling purposes */
209 ktime_t *ts;
Clarence Ipb25c65c2017-05-17 12:09:23 -0400210
211 /* Completion structure for inline rotation */
212 struct completion inline_start;
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -0700213};
214
215/*
216 * Defining characteristics about rotation work, that has corresponding
217 * fmt and roi checks in open session
218 */
219#define SDE_ROT_DEFINING_FLAG_BITS SDE_ROTATION_90
220
221struct sde_rot_entry;
222struct sde_rot_perf;
223
224struct sde_rot_clk {
225 struct clk *clk;
226 char clk_name[32];
227 unsigned long rate;
228};
229
230struct sde_rot_hw_resource {
231 u32 wb_id;
232 u32 pending_count;
233 atomic_t num_active;
234 int max_active;
235 wait_queue_head_t wait_queue;
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -0700236};
237
238struct sde_rot_queue {
Benjamin Chanf8d9a462016-11-08 21:38:10 -0500239 struct kthread_worker rot_kw;
240 struct task_struct *rot_thread;
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -0700241 struct sde_rot_timeline *timeline;
242 struct sde_rot_hw_resource *hw;
243};
244
Alan Kwongf94a2552016-12-28 09:41:22 -0800245/*
246 * struct sde_rot_entry_container - rotation request
247 * @list: list of active requests managed by rotator manager
248 * @flags: reserved
249 * @count: size of rotation entries
250 * @pending_count: count of entries pending completion
251 * @failed_count: count of entries failed completion
252 * @finished: true if client is finished with the request
253 * @retireq: workqueue to post completion notification
254 * @retire_work: work for completion notification
255 * @entries: array of rotation entries
256 */
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -0700257struct sde_rot_entry_container {
258 struct list_head list;
259 u32 flags;
260 u32 count;
261 atomic_t pending_count;
262 atomic_t failed_count;
Benjamin Chanf8d9a462016-11-08 21:38:10 -0500263 struct kthread_worker *retire_kw;
264 struct kthread_work *retire_work;
Alan Kwongf94a2552016-12-28 09:41:22 -0800265 bool finished;
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -0700266 struct sde_rot_entry *entries;
267};
268
269struct sde_rot_mgr;
270struct sde_rot_file_private;
271
Alan Kwong6bc64622017-02-04 17:36:03 -0800272/*
273 * struct sde_rot_entry - rotation entry
274 * @item: rotation item
275 * @commit_work: work descriptor for commit handler
276 * @done_work: work descriptor for done handler
277 * @commitq: pointer to commit handler rotator queue
278 * @fenceq: pointer to fence signaling rotator queue
279 * @doneq: pointer to done handler rotator queue
280 * @request: pointer to containing request
281 * @src_buf: descriptor of source buffer
282 * @dst_buf: descriptor of destination buffer
283 * @input_fence: pointer to input fence for when input content is available
284 * @output_fence: pointer to output fence for when output content is available
285 * @output_signaled: true if output fence of this entry has been signaled
286 * @dnsc_factor_w: calculated width downscale factor for this entry
287 * @dnsc_factor_w: calculated height downscale factor for this entry
288 * @perf: pointer to performance configuration associated with this entry
289 * @work_assigned: true if this item is assigned to h/w queue/unit
290 * @private: pointer to controlling session context
291 */
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -0700292struct sde_rot_entry {
293 struct sde_rotation_item item;
Benjamin Chanf8d9a462016-11-08 21:38:10 -0500294 struct kthread_work commit_work;
295 struct kthread_work done_work;
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -0700296 struct sde_rot_queue *commitq;
297 struct sde_rot_queue *fenceq;
298 struct sde_rot_queue *doneq;
299 struct sde_rot_entry_container *request;
300
301 struct sde_mdp_data src_buf;
302 struct sde_mdp_data dst_buf;
303
304 struct sde_rot_sync_fence *input_fence;
305
306 struct sde_rot_sync_fence *output_fence;
307 bool output_signaled;
308
309 u32 dnsc_factor_w;
310 u32 dnsc_factor_h;
311
312 struct sde_rot_perf *perf;
313 bool work_assigned; /* Used when cleaning up work_distribution */
314 struct sde_rot_file_private *private;
315};
316
Alan Kwong6bc64622017-02-04 17:36:03 -0800317/*
318 * struct sde_rot_perf - rotator session performance configuration
319 * @list: list of performance configuration under one session
320 * @config: current rotation configuration
321 * @clk_rate: current clock rate in Hz
322 * @bw: current bandwidth in byte per second
323 * @work_dis_lock: serialization lock for updating work distribution (not used)
324 * @work_distribution: work distribution among multiple hardware queue/unit
325 * @last_wb_idx: last queue/unit index, used to account for pre-distributed work
326 * @rdot_limit: read OT limit of this session
327 * @wrot_limit: write OT limit of this session
328 */
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -0700329struct sde_rot_perf {
330 struct list_head list;
331 struct sde_rotation_config config;
332 unsigned long clk_rate;
333 u64 bw;
334 struct mutex work_dis_lock;
335 u32 *work_distribution;
336 int last_wb_idx; /* last known wb index, used when above count is 0 */
Alan Kwongeffb5ee2016-03-12 19:47:45 -0500337 u32 rdot_limit;
338 u32 wrot_limit;
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -0700339};
340
Alan Kwong6bc64622017-02-04 17:36:03 -0800341/*
342 * struct sde_rot_file_private - rotator manager per session context
343 * @list: list of all session context
344 * @req_list: list of rotation request for this session
345 * @perf_list: list of performance configuration for this session (only one)
346 * @mgr: pointer to the controlling rotator manager
347 * @fenceq: pointer to rotator queue to signal when entry is done
348 */
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -0700349struct sde_rot_file_private {
350 struct list_head list;
351 struct list_head req_list;
352 struct list_head perf_list;
353 struct sde_rot_mgr *mgr;
354 struct sde_rot_queue *fenceq;
355};
356
Alan Kwong6bc64622017-02-04 17:36:03 -0800357/*
358 * struct sde_rot_bus_data_type - rotator bus scaling configuration
359 * @bus_cale_pdata: pointer to bus scaling configuration table
360 * @bus_hdl: msm bus scaling handle
361 * @curr_bw_uc_idx; current usecase index into configuration table
362 * @curr_quota_val: current bandwidth request in byte per second
363 */
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -0700364struct sde_rot_bus_data_type {
365 struct msm_bus_scale_pdata *bus_scale_pdata;
366 u32 bus_hdl;
367 u32 curr_bw_uc_idx;
368 u64 curr_quota_val;
369};
370
Alan Kwong6bc64622017-02-04 17:36:03 -0800371/*
372 * struct sde_rot_mgr - core rotator manager
373 * @lock: serialization lock to rotator manager functions
374 * @device_suspended: 0 if device is not suspended; non-zero suspended
375 * @pdev: pointer to controlling platform device
376 * @device: pointer to controlling device
377 * @queue_count: number of hardware queue/unit available
378 * @commitq: array of rotator commit queue corresponding to hardware queue
379 * @doneq: array of rotator done queue corresponding to hardware queue
380 * @file_list: list of all sessions managed by rotator manager
381 * @pending_close_bw_vote: bandwidth of closed sessions with pending work
Alan Kwong30ab1ce2017-03-03 12:09:32 -0800382 * @minimum_bw_vote: minimum bandwidth required for current use case
383 * @enable_bw_vote: minimum bandwidth required for power enable
Alan Kwong6bc64622017-02-04 17:36:03 -0800384 * @data_bus: data bus configuration state
385 * @reg_bus: register bus configuration state
386 * @module_power: power/clock configuration state
387 * @regulator_enable: true if foot switch is enabled; false otherwise
388 * @res_ref_cnt: reference count of how many times resource is requested
389 * @rot_enable_clk_cnt: reference count of how many times clock is requested
390 * @rot_clk: array of rotator and periphery clocks
391 * @num_rot_clk: size of the rotator clock array
392 * @rdot_limit: current read OT limit
393 * @wrot_limit: current write OT limit
394 * @hwacquire_timeout: maximum wait time for hardware availability in msec
395 * @pixel_per_clk: rotator hardware performance in pixel for clock
396 * @fudge_factor: fudge factor for clock calculation
397 * @overhead: software overhead for offline rotation in msec
Lloyd Atkinson17e37232017-08-30 13:45:29 -0400398 * @min_rot_clk: minimum rotator clock rate
Alan Kwong6bc64622017-02-04 17:36:03 -0800399 * @sbuf_ctx: pointer to sbuf session context
400 * @ops_xxx: function pointers of rotator HAL layer
401 * @hw_data: private handle of rotator HAL layer
402 */
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -0700403struct sde_rot_mgr {
404 struct mutex lock;
405 atomic_t device_suspended;
406 struct platform_device *pdev;
407 struct device *device;
408
409 /*
410 * Managing rotation queues, depends on
411 * how many hw pipes available on the system
412 */
413 int queue_count;
414 struct sde_rot_queue *commitq;
415 struct sde_rot_queue *doneq;
416
417 /*
418 * managing all the open file sessions to bw calculations,
419 * and resource clean up during suspend
420 */
421 struct list_head file_list;
422
423 u64 pending_close_bw_vote;
Alan Kwong30ab1ce2017-03-03 12:09:32 -0800424 u64 minimum_bw_vote;
425 u64 enable_bw_vote;
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -0700426 struct sde_rot_bus_data_type data_bus;
427 struct sde_rot_bus_data_type reg_bus;
428
429 /* Module power is only used for regulator management */
430 struct sde_module_power module_power;
431 bool regulator_enable;
432
433 int res_ref_cnt;
434 int rot_enable_clk_cnt;
435 struct sde_rot_clk *rot_clk;
436 int num_rot_clk;
Alan Kwongeffb5ee2016-03-12 19:47:45 -0500437 u32 rdot_limit;
438 u32 wrot_limit;
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -0700439
440 u32 hwacquire_timeout;
441 struct sde_mult_factor pixel_per_clk;
Benjamin Chandbe13112016-09-26 12:10:06 -0400442 struct sde_mult_factor fudge_factor;
443 struct sde_mult_factor overhead;
Lloyd Atkinson17e37232017-08-30 13:45:29 -0400444 unsigned long min_rot_clk;
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -0700445
Alan Kwong6bc64622017-02-04 17:36:03 -0800446 struct sde_rot_file_private *sbuf_ctx;
447
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -0700448 int (*ops_config_hw)(struct sde_rot_hw_resource *hw,
449 struct sde_rot_entry *entry);
Clarence Ip3ce07c02017-08-11 16:21:45 -0400450 int (*ops_cancel_hw)(struct sde_rot_hw_resource *hw,
451 struct sde_rot_entry *entry);
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -0700452 int (*ops_kickoff_entry)(struct sde_rot_hw_resource *hw,
453 struct sde_rot_entry *entry);
454 int (*ops_wait_for_entry)(struct sde_rot_hw_resource *hw,
455 struct sde_rot_entry *entry);
456 struct sde_rot_hw_resource *(*ops_hw_alloc)(struct sde_rot_mgr *mgr,
457 u32 pipe_id, u32 wb_id);
458 void (*ops_hw_free)(struct sde_rot_mgr *mgr,
459 struct sde_rot_hw_resource *hw);
460 int (*ops_hw_init)(struct sde_rot_mgr *mgr);
Benjamin Chan0f9e61d2016-09-16 16:01:09 -0400461 void (*ops_hw_pre_pmevent)(struct sde_rot_mgr *mgr, bool pmon);
462 void (*ops_hw_post_pmevent)(struct sde_rot_mgr *mgr, bool pmon);
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -0700463 void (*ops_hw_destroy)(struct sde_rot_mgr *mgr);
464 ssize_t (*ops_hw_show_caps)(struct sde_rot_mgr *mgr,
465 struct device_attribute *attr, char *buf, ssize_t len);
466 ssize_t (*ops_hw_show_state)(struct sde_rot_mgr *mgr,
467 struct device_attribute *attr, char *buf, ssize_t len);
468 int (*ops_hw_create_debugfs)(struct sde_rot_mgr *mgr,
469 struct dentry *debugfs_root);
470 int (*ops_hw_validate_entry)(struct sde_rot_mgr *mgr,
471 struct sde_rot_entry *entry);
Alan Kwongda16e442016-08-14 20:47:18 -0400472 u32 (*ops_hw_get_pixfmt)(struct sde_rot_mgr *mgr, int index,
Alan Kwong4b416162017-08-11 21:03:10 -0400473 bool input, u32 mode);
Alan Kwongda16e442016-08-14 20:47:18 -0400474 int (*ops_hw_is_valid_pixfmt)(struct sde_rot_mgr *mgr, u32 pixfmt,
Alan Kwong4b416162017-08-11 21:03:10 -0400475 bool input, u32 mode);
Alan Kwong6bc64622017-02-04 17:36:03 -0800476 int (*ops_hw_get_downscale_caps)(struct sde_rot_mgr *mgr, char *caps,
477 int len);
Alan Kwongb6c049c2017-03-31 12:50:27 -0700478 int (*ops_hw_get_maxlinewidth)(struct sde_rot_mgr *mgr);
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -0700479
480 void *hw_data;
481};
482
Alan Kwongda16e442016-08-14 20:47:18 -0400483static inline int sde_rotator_is_valid_pixfmt(struct sde_rot_mgr *mgr,
Alan Kwong4b416162017-08-11 21:03:10 -0400484 u32 pixfmt, bool input, u32 mode)
Alan Kwongda16e442016-08-14 20:47:18 -0400485{
486 if (mgr && mgr->ops_hw_is_valid_pixfmt)
Alan Kwong4b416162017-08-11 21:03:10 -0400487 return mgr->ops_hw_is_valid_pixfmt(mgr, pixfmt, input, mode);
Alan Kwongda16e442016-08-14 20:47:18 -0400488
489 return false;
490}
491
492static inline u32 sde_rotator_get_pixfmt(struct sde_rot_mgr *mgr,
Alan Kwong4b416162017-08-11 21:03:10 -0400493 int index, bool input, u32 mode)
Alan Kwongda16e442016-08-14 20:47:18 -0400494{
495 if (mgr && mgr->ops_hw_get_pixfmt)
Alan Kwong4b416162017-08-11 21:03:10 -0400496 return mgr->ops_hw_get_pixfmt(mgr, index, input, mode);
Alan Kwongda16e442016-08-14 20:47:18 -0400497
498 return 0;
499}
500
Alan Kwong6bc64622017-02-04 17:36:03 -0800501static inline int sde_rotator_get_downscale_caps(struct sde_rot_mgr *mgr,
502 char *caps, int len)
503{
504 if (mgr && mgr->ops_hw_get_downscale_caps)
505 return mgr->ops_hw_get_downscale_caps(mgr, caps, len);
506
507 return 0;
508}
509
Alan Kwongb6c049c2017-03-31 12:50:27 -0700510static inline int sde_rotator_get_maxlinewidth(struct sde_rot_mgr *mgr)
511{
512 if (mgr && mgr->ops_hw_get_maxlinewidth)
513 return mgr->ops_hw_get_maxlinewidth(mgr);
514
515 return 2048;
516}
517
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -0700518static inline int __compare_session_item_rect(
519 struct sde_rotation_buf_info *s_rect,
520 struct sde_rect *i_rect, uint32_t i_fmt, bool src)
521{
522 if ((s_rect->width != i_rect->w) || (s_rect->height != i_rect->h) ||
523 (s_rect->format != i_fmt)) {
524 SDEROT_DBG(
525 "%s: session{%u,%u}f:%u mismatch from item{%u,%u}f:%u\n",
526 (src ? "src":"dst"), s_rect->width, s_rect->height,
527 s_rect->format, i_rect->w, i_rect->h, i_fmt);
528 return -EINVAL;
529 }
530 return 0;
531}
532
533/*
534 * Compare all important flag bits associated with rotation between session
535 * config and item request. Format and roi validation is done during open
536 * session and is based certain defining bits. If these defining bits are
537 * different in item request, there is a possibility that rotation item
538 * is not a valid configuration.
539 */
540static inline int __compare_session_rotations(uint32_t cfg_flag,
541 uint32_t item_flag)
542{
543 cfg_flag &= SDE_ROT_DEFINING_FLAG_BITS;
544 item_flag &= SDE_ROT_DEFINING_FLAG_BITS;
545 if (cfg_flag != item_flag) {
546 SDEROT_DBG(
547 "Rotation degree request different from open session\n");
548 return -EINVAL;
549 }
550 return 0;
551}
552
Alan Kwongf94a2552016-12-28 09:41:22 -0800553/*
554 * sde_rotator_core_init - initialize rotator manager for the given platform
555 * device
556 * @pmgr: Pointer to pointer of the newly initialized rotator manager
557 * @pdev: Pointer to platform device
558 * return: 0 if success; error code otherwise
559 */
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -0700560int sde_rotator_core_init(struct sde_rot_mgr **pmgr,
561 struct platform_device *pdev);
562
Alan Kwongf94a2552016-12-28 09:41:22 -0800563/*
564 * sde_rotator_core_destroy - destroy given rotator manager
565 * @mgr: Pointer to rotator manager
566 * return: none
567 */
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -0700568void sde_rotator_core_destroy(struct sde_rot_mgr *mgr);
569
Alan Kwongf94a2552016-12-28 09:41:22 -0800570/*
571 * sde_rotator_session_open - open a new rotator per file session
572 * @mgr: Pointer to rotator manager
573 * @pprivate: Pointer to pointer of the newly initialized per file session
574 * @session_id: identifier of the newly created session
575 * @queue: Pointer to fence queue of the new session
576 * return: 0 if success; error code otherwise
577 */
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -0700578int sde_rotator_session_open(struct sde_rot_mgr *mgr,
579 struct sde_rot_file_private **pprivate, int session_id,
580 struct sde_rot_queue *queue);
581
Alan Kwongf94a2552016-12-28 09:41:22 -0800582/*
583 * sde_rotator_session_close - close the given rotator per file session
584 * @mgr: Pointer to rotator manager
585 * @private: Pointer to per file session
586 * @session_id: identifier of the session
587 * return: none
588 */
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -0700589void sde_rotator_session_close(struct sde_rot_mgr *mgr,
590 struct sde_rot_file_private *private, int session_id);
591
Alan Kwongf94a2552016-12-28 09:41:22 -0800592/*
593 * sde_rotator_session_config - configure the given rotator per file session
594 * @mgr: Pointer to rotator manager
595 * @private: Pointer to per file session
596 * @config: Pointer to rotator configuration
597 * return: 0 if success; error code otherwise
598 */
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -0700599int sde_rotator_session_config(struct sde_rot_mgr *mgr,
600 struct sde_rot_file_private *private,
601 struct sde_rotation_config *config);
602
Alan Kwongf94a2552016-12-28 09:41:22 -0800603/*
Alan Kwong871fc482017-09-20 11:17:28 -0400604 * sde_rotator_session_validate - validate session configuration
605 * @mgr: Pointer to rotator manager
606 * @private: Pointer to per file session
607 * @config: Pointer to rotator configuration
608 * return: 0 if success; error code otherwise
609 */
610int sde_rotator_session_validate(struct sde_rot_mgr *mgr,
611 struct sde_rot_file_private *private,
612 struct sde_rotation_config *config);
613
614/*
Alan Kwongf94a2552016-12-28 09:41:22 -0800615 * sde_rotator_req_init - allocate a new request and initialzie with given
616 * array of rotation items
617 * @rot_dev: Pointer to rotator device
618 * @private: Pointer to rotator manager per file context
619 * @items: Pointer to array of rotation item
620 * @count: size of rotation item array
621 * @flags: rotation request flags
622 * return: Pointer to new rotation request if success; ERR_PTR otherwise
623 */
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -0700624struct sde_rot_entry_container *sde_rotator_req_init(
625 struct sde_rot_mgr *rot_dev,
626 struct sde_rot_file_private *private,
627 struct sde_rotation_item *items,
628 u32 count, u32 flags);
629
Alan Kwongf94a2552016-12-28 09:41:22 -0800630/*
Clarence Ipb25c65c2017-05-17 12:09:23 -0400631 * sde_rotator_req_reset_start - reset inline h/w 'start' indicator
632 * For inline rotations, the time of rotation start is not controlled
633 * by the rotator driver. This function resets an internal 'start'
634 * indicator that allows the rotator to delay its rotator
635 * timeout waiting until such time as the inline rotation has
636 * really started.
Clarence Ip3ce07c02017-08-11 16:21:45 -0400637 * @mgr: Pointer to rotator manager
Clarence Ipb25c65c2017-05-17 12:09:23 -0400638 * @req: Pointer to rotation request
639 */
Clarence Ip3ce07c02017-08-11 16:21:45 -0400640void sde_rotator_req_reset_start(struct sde_rot_mgr *mgr,
641 struct sde_rot_entry_container *req);
Clarence Ipb25c65c2017-05-17 12:09:23 -0400642
643/*
644 * sde_rotator_req_set_start - set inline h/w 'start' indicator
Clarence Ip3ce07c02017-08-11 16:21:45 -0400645 * @mgr: Pointer to rotator manager
Clarence Ipb25c65c2017-05-17 12:09:23 -0400646 * @req: Pointer to rotation request
647 */
Clarence Ip3ce07c02017-08-11 16:21:45 -0400648void sde_rotator_req_set_start(struct sde_rot_mgr *mgr,
649 struct sde_rot_entry_container *req);
650
651/*
652 * sde_rotator_req_wait_start - wait for inline h/w 'start' indicator
653 * @mgr: Pointer to rotator manager
654 * @req: Pointer to rotation request
655 * return: Zero on success
656 */
657int sde_rotator_req_wait_start(struct sde_rot_mgr *mgr,
658 struct sde_rot_entry_container *req);
Clarence Ipb25c65c2017-05-17 12:09:23 -0400659
660/*
Alan Kwongf94a2552016-12-28 09:41:22 -0800661 * sde_rotator_req_finish - notify manager that client is finished with the
662 * given request and manager can release the request as required
Clarence Ip3ce07c02017-08-11 16:21:45 -0400663 * @mgr: Pointer to rotator manager
Alan Kwongf94a2552016-12-28 09:41:22 -0800664 * @private: Pointer to rotator manager per file context
665 * @req: Pointer to rotation request
666 * return: none
667 */
668void sde_rotator_req_finish(struct sde_rot_mgr *mgr,
669 struct sde_rot_file_private *private,
670 struct sde_rot_entry_container *req);
671
672/*
673 * sde_rotator_handle_request_common - add the given request to rotator
674 * manager and clean up completed requests
675 * @rot_dev: Pointer to rotator device
676 * @private: Pointer to rotator manager per file context
677 * @req: Pointer to rotation request
678 * return: 0 if success; error code otherwise
679 */
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -0700680int sde_rotator_handle_request_common(struct sde_rot_mgr *rot_dev,
681 struct sde_rot_file_private *ctx,
Alan Kwongf94a2552016-12-28 09:41:22 -0800682 struct sde_rot_entry_container *req);
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -0700683
Alan Kwongf94a2552016-12-28 09:41:22 -0800684/*
685 * sde_rotator_queue_request - queue/schedule the given request for h/w commit
686 * @rot_dev: Pointer to rotator device
687 * @private: Pointer to rotator manager per file context
688 * @req: Pointer to rotation request
689 * return: 0 if success; error code otherwise
690 */
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -0700691void sde_rotator_queue_request(struct sde_rot_mgr *rot_dev,
692 struct sde_rot_file_private *ctx,
693 struct sde_rot_entry_container *req);
694
Alan Kwongf94a2552016-12-28 09:41:22 -0800695/*
696 * sde_rotator_verify_config_all - verify given rotation configuration
697 * @rot_dev: Pointer to rotator device
698 * @config: Pointer to rotator configuration
699 * return: 0 if success; error code otherwise
700 */
Benjamin Chan59a06052017-01-12 18:06:03 -0500701int sde_rotator_verify_config_all(struct sde_rot_mgr *rot_dev,
702 struct sde_rotation_config *config);
703
Alan Kwongf94a2552016-12-28 09:41:22 -0800704/*
705 * sde_rotator_verify_config_input - verify rotation input configuration
706 * @rot_dev: Pointer to rotator device
707 * @config: Pointer to rotator configuration
708 * return: 0 if success; error code otherwise
709 */
Benjamin Chan59a06052017-01-12 18:06:03 -0500710int sde_rotator_verify_config_input(struct sde_rot_mgr *rot_dev,
711 struct sde_rotation_config *config);
712
Alan Kwongf94a2552016-12-28 09:41:22 -0800713/*
714 * sde_rotator_verify_config_output - verify rotation output configuration
715 * @rot_dev: Pointer to rotator device
716 * @config: Pointer to rotator configuration
717 * return: 0 if success; error code otherwise
718 */
Benjamin Chan59a06052017-01-12 18:06:03 -0500719int sde_rotator_verify_config_output(struct sde_rot_mgr *rot_dev,
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -0700720 struct sde_rotation_config *config);
721
Alan Kwongf94a2552016-12-28 09:41:22 -0800722/*
723 * sde_rotator_validate_request - validates given rotation request with
724 * previous rotator configuration
725 * @rot_dev: Pointer to rotator device
726 * @private: Pointer to rotator manager per file context
727 * @req: Pointer to rotation request
728 * return: 0 if success; error code otherwise
729 */
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -0700730int sde_rotator_validate_request(struct sde_rot_mgr *rot_dev,
731 struct sde_rot_file_private *ctx,
732 struct sde_rot_entry_container *req);
733
Alan Kwongf94a2552016-12-28 09:41:22 -0800734/*
735 * sde_rotator_clk_ctrl - enable/disable rotator clock with reference counting
736 * @mgr: Pointer to rotator manager
737 * @enable: true to enable clock; false to disable clock
738 * return: 0 if success; error code otherwise
739 */
Benjamin Chan0f9e61d2016-09-16 16:01:09 -0400740int sde_rotator_clk_ctrl(struct sde_rot_mgr *mgr, int enable);
741
Alan Kwongf94a2552016-12-28 09:41:22 -0800742/*
Benjamin Chand0a22cf2017-03-01 17:40:20 -0500743 * sde_rotator_cancel_all_requests - cancel all outstanding requests
744 * @mgr: Pointer to rotator manager
745 * @private: Pointer to rotator manager per file context
746 */
747void sde_rotator_cancel_all_requests(struct sde_rot_mgr *mgr,
748 struct sde_rot_file_private *private);
749
750/*
Alan Kwongf94a2552016-12-28 09:41:22 -0800751 * sde_rot_mgr_lock - serialization lock prior to rotator manager calls
752 * @mgr: Pointer to rotator manager
753 */
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -0700754static inline void sde_rot_mgr_lock(struct sde_rot_mgr *mgr)
755{
756 mutex_lock(&mgr->lock);
757}
758
Alan Kwongf94a2552016-12-28 09:41:22 -0800759/*
760 * sde_rot_mgr_lock - serialization unlock after rotator manager calls
761 * @mgr: Pointer to rotator manager
762 */
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -0700763static inline void sde_rot_mgr_unlock(struct sde_rot_mgr *mgr)
764{
765 mutex_unlock(&mgr->lock);
766}
767
Alan Kwong10056f92017-09-22 11:38:04 -0400768/*
769 * sde_rot_mgr_pd_enabled - return true if power domain is enabled
770 * @mgr: Pointer to rotator manager
771 */
772static inline bool sde_rot_mgr_pd_enabled(struct sde_rot_mgr *mgr)
773{
774 return mgr && mgr->device && mgr->device->pm_domain;
775}
776
Alan Kwong3428f672016-04-18 12:32:06 -0400777#if defined(CONFIG_PM)
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -0700778int sde_rotator_runtime_resume(struct device *dev);
779int sde_rotator_runtime_suspend(struct device *dev);
780int sde_rotator_runtime_idle(struct device *dev);
781#endif
782
783#if defined(CONFIG_PM_SLEEP)
784int sde_rotator_pm_suspend(struct device *dev);
785int sde_rotator_pm_resume(struct device *dev);
786#endif
787
788#if defined(CONFIG_PM) && !defined(CONFIG_PM_SLEEP)
789int sde_rotator_suspend(struct platform_device *dev, pm_message_t state);
790int sde_rotator_resume(struct platform_device *dev);
791#else
792#define sde_rotator_suspend NULL
793#define sde_rotator_resume NULL
794#endif
795#endif /* __SDE_ROTATOR_CORE_H__ */