blob: 91c830f6310ad3c462d98fbe1292bf83a861b40d [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
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -0700144struct sde_rotation_item {
145 /* rotation request flag */
146 uint32_t flags;
147
Alan Kwong6bc64622017-02-04 17:36:03 -0800148 /* rotation trigger mode */
149 uint32_t trigger;
150
Alan Kwong498d59f2017-02-11 18:56:34 -0800151 /* prefill bandwidth in Bps */
152 uint64_t prefill_bw;
153
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -0700154 /* Source crop rectangle */
155 struct sde_rect src_rect;
156
157 /* Destination rectangle */
158 struct sde_rect dst_rect;
159
160 /* Input buffer for the request */
161 struct sde_layer_buffer input;
162
163 /* The output buffer for the request */
164 struct sde_layer_buffer output;
165
Alan Kwonga94684f2016-01-16 22:06:36 -0500166 /*
167 * DMA pipe selection for this request by client:
168 * 0: DMA pipe 0
169 * 1: DMA pipe 1
170 * or SDE_ROTATION_HW_ANY if client wants
171 * driver to allocate any that is available
172 *
173 * OR
174 *
175 * Reserved
176 */
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -0700177 uint32_t pipe_idx;
178
Alan Kwonga94684f2016-01-16 22:06:36 -0500179 /*
180 * Write-back block selection for this request by client:
181 * 0: Write-back block 0
182 * 1: Write-back block 1
183 * or SDE_ROTATION_HW_ANY if client wants
184 * driver to allocate any that is available
185 *
186 * OR
187 *
188 * Priority selection for this request by client:
189 * 0: Highest
190 * 1..n: Limited by the lowest available priority
191 */
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -0700192 uint32_t wb_idx;
193
Alan Kwonga94684f2016-01-16 22:06:36 -0500194 /*
195 * Sequence ID of this request within the session
196 */
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -0700197 uint32_t sequence_id;
198
199 /* Which session ID is this request scheduled on */
200 uint32_t session_id;
201
202 /* Time stamp for profiling purposes */
203 ktime_t *ts;
Clarence Ipb25c65c2017-05-17 12:09:23 -0400204
205 /* Completion structure for inline rotation */
206 struct completion inline_start;
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -0700207};
208
209/*
210 * Defining characteristics about rotation work, that has corresponding
211 * fmt and roi checks in open session
212 */
213#define SDE_ROT_DEFINING_FLAG_BITS SDE_ROTATION_90
214
215struct sde_rot_entry;
216struct sde_rot_perf;
217
218struct sde_rot_clk {
219 struct clk *clk;
220 char clk_name[32];
221 unsigned long rate;
222};
223
224struct sde_rot_hw_resource {
225 u32 wb_id;
226 u32 pending_count;
227 atomic_t num_active;
228 int max_active;
229 wait_queue_head_t wait_queue;
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -0700230};
231
232struct sde_rot_queue {
Benjamin Chanf8d9a462016-11-08 21:38:10 -0500233 struct kthread_worker rot_kw;
234 struct task_struct *rot_thread;
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -0700235 struct sde_rot_timeline *timeline;
236 struct sde_rot_hw_resource *hw;
237};
238
Alan Kwongf94a2552016-12-28 09:41:22 -0800239/*
240 * struct sde_rot_entry_container - rotation request
241 * @list: list of active requests managed by rotator manager
242 * @flags: reserved
243 * @count: size of rotation entries
244 * @pending_count: count of entries pending completion
245 * @failed_count: count of entries failed completion
246 * @finished: true if client is finished with the request
247 * @retireq: workqueue to post completion notification
248 * @retire_work: work for completion notification
249 * @entries: array of rotation entries
250 */
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -0700251struct sde_rot_entry_container {
252 struct list_head list;
253 u32 flags;
254 u32 count;
255 atomic_t pending_count;
256 atomic_t failed_count;
Benjamin Chanf8d9a462016-11-08 21:38:10 -0500257 struct kthread_worker *retire_kw;
258 struct kthread_work *retire_work;
Alan Kwongf94a2552016-12-28 09:41:22 -0800259 bool finished;
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -0700260 struct sde_rot_entry *entries;
261};
262
263struct sde_rot_mgr;
264struct sde_rot_file_private;
265
Alan Kwong6bc64622017-02-04 17:36:03 -0800266/*
267 * struct sde_rot_entry - rotation entry
268 * @item: rotation item
269 * @commit_work: work descriptor for commit handler
270 * @done_work: work descriptor for done handler
271 * @commitq: pointer to commit handler rotator queue
272 * @fenceq: pointer to fence signaling rotator queue
273 * @doneq: pointer to done handler rotator queue
274 * @request: pointer to containing request
275 * @src_buf: descriptor of source buffer
276 * @dst_buf: descriptor of destination buffer
277 * @input_fence: pointer to input fence for when input content is available
278 * @output_fence: pointer to output fence for when output content is available
279 * @output_signaled: true if output fence of this entry has been signaled
280 * @dnsc_factor_w: calculated width downscale factor for this entry
281 * @dnsc_factor_w: calculated height downscale factor for this entry
282 * @perf: pointer to performance configuration associated with this entry
283 * @work_assigned: true if this item is assigned to h/w queue/unit
284 * @private: pointer to controlling session context
285 */
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -0700286struct sde_rot_entry {
287 struct sde_rotation_item item;
Benjamin Chanf8d9a462016-11-08 21:38:10 -0500288 struct kthread_work commit_work;
289 struct kthread_work done_work;
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -0700290 struct sde_rot_queue *commitq;
291 struct sde_rot_queue *fenceq;
292 struct sde_rot_queue *doneq;
293 struct sde_rot_entry_container *request;
294
295 struct sde_mdp_data src_buf;
296 struct sde_mdp_data dst_buf;
297
298 struct sde_rot_sync_fence *input_fence;
299
300 struct sde_rot_sync_fence *output_fence;
301 bool output_signaled;
302
303 u32 dnsc_factor_w;
304 u32 dnsc_factor_h;
305
306 struct sde_rot_perf *perf;
307 bool work_assigned; /* Used when cleaning up work_distribution */
308 struct sde_rot_file_private *private;
309};
310
Alan Kwong6bc64622017-02-04 17:36:03 -0800311/*
312 * struct sde_rot_perf - rotator session performance configuration
313 * @list: list of performance configuration under one session
314 * @config: current rotation configuration
315 * @clk_rate: current clock rate in Hz
316 * @bw: current bandwidth in byte per second
317 * @work_dis_lock: serialization lock for updating work distribution (not used)
318 * @work_distribution: work distribution among multiple hardware queue/unit
319 * @last_wb_idx: last queue/unit index, used to account for pre-distributed work
320 * @rdot_limit: read OT limit of this session
321 * @wrot_limit: write OT limit of this session
322 */
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -0700323struct sde_rot_perf {
324 struct list_head list;
325 struct sde_rotation_config config;
326 unsigned long clk_rate;
327 u64 bw;
328 struct mutex work_dis_lock;
329 u32 *work_distribution;
330 int last_wb_idx; /* last known wb index, used when above count is 0 */
Alan Kwongeffb5ee2016-03-12 19:47:45 -0500331 u32 rdot_limit;
332 u32 wrot_limit;
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -0700333};
334
Alan Kwong6bc64622017-02-04 17:36:03 -0800335/*
336 * struct sde_rot_file_private - rotator manager per session context
337 * @list: list of all session context
338 * @req_list: list of rotation request for this session
339 * @perf_list: list of performance configuration for this session (only one)
340 * @mgr: pointer to the controlling rotator manager
341 * @fenceq: pointer to rotator queue to signal when entry is done
342 */
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -0700343struct sde_rot_file_private {
344 struct list_head list;
345 struct list_head req_list;
346 struct list_head perf_list;
347 struct sde_rot_mgr *mgr;
348 struct sde_rot_queue *fenceq;
349};
350
Alan Kwong6bc64622017-02-04 17:36:03 -0800351/*
352 * struct sde_rot_bus_data_type - rotator bus scaling configuration
353 * @bus_cale_pdata: pointer to bus scaling configuration table
354 * @bus_hdl: msm bus scaling handle
355 * @curr_bw_uc_idx; current usecase index into configuration table
356 * @curr_quota_val: current bandwidth request in byte per second
357 */
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -0700358struct sde_rot_bus_data_type {
359 struct msm_bus_scale_pdata *bus_scale_pdata;
360 u32 bus_hdl;
361 u32 curr_bw_uc_idx;
362 u64 curr_quota_val;
363};
364
Alan Kwong6bc64622017-02-04 17:36:03 -0800365/*
366 * struct sde_rot_mgr - core rotator manager
367 * @lock: serialization lock to rotator manager functions
368 * @device_suspended: 0 if device is not suspended; non-zero suspended
369 * @pdev: pointer to controlling platform device
370 * @device: pointer to controlling device
371 * @queue_count: number of hardware queue/unit available
372 * @commitq: array of rotator commit queue corresponding to hardware queue
373 * @doneq: array of rotator done queue corresponding to hardware queue
374 * @file_list: list of all sessions managed by rotator manager
375 * @pending_close_bw_vote: bandwidth of closed sessions with pending work
Alan Kwong30ab1ce2017-03-03 12:09:32 -0800376 * @minimum_bw_vote: minimum bandwidth required for current use case
377 * @enable_bw_vote: minimum bandwidth required for power enable
Alan Kwong6bc64622017-02-04 17:36:03 -0800378 * @data_bus: data bus configuration state
379 * @reg_bus: register bus configuration state
380 * @module_power: power/clock configuration state
381 * @regulator_enable: true if foot switch is enabled; false otherwise
Clarence Ip1c5b3b02017-04-26 19:34:18 -0700382 * @rsc_client: pointer to rsc client handle
Alan Kwong6bc64622017-02-04 17:36:03 -0800383 * @res_ref_cnt: reference count of how many times resource is requested
384 * @rot_enable_clk_cnt: reference count of how many times clock is requested
385 * @rot_clk: array of rotator and periphery clocks
386 * @num_rot_clk: size of the rotator clock array
387 * @rdot_limit: current read OT limit
388 * @wrot_limit: current write OT limit
389 * @hwacquire_timeout: maximum wait time for hardware availability in msec
390 * @pixel_per_clk: rotator hardware performance in pixel for clock
391 * @fudge_factor: fudge factor for clock calculation
392 * @overhead: software overhead for offline rotation in msec
393 * @sbuf_ctx: pointer to sbuf session context
394 * @ops_xxx: function pointers of rotator HAL layer
395 * @hw_data: private handle of rotator HAL layer
396 */
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -0700397struct sde_rot_mgr {
398 struct mutex lock;
399 atomic_t device_suspended;
400 struct platform_device *pdev;
401 struct device *device;
402
403 /*
404 * Managing rotation queues, depends on
405 * how many hw pipes available on the system
406 */
407 int queue_count;
408 struct sde_rot_queue *commitq;
409 struct sde_rot_queue *doneq;
410
411 /*
412 * managing all the open file sessions to bw calculations,
413 * and resource clean up during suspend
414 */
415 struct list_head file_list;
416
417 u64 pending_close_bw_vote;
Alan Kwong30ab1ce2017-03-03 12:09:32 -0800418 u64 minimum_bw_vote;
419 u64 enable_bw_vote;
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -0700420 struct sde_rot_bus_data_type data_bus;
421 struct sde_rot_bus_data_type reg_bus;
422
423 /* Module power is only used for regulator management */
424 struct sde_module_power module_power;
425 bool regulator_enable;
426
Clarence Ip1c5b3b02017-04-26 19:34:18 -0700427 struct sde_rsc_client *rsc_client;
428
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -0700429 int res_ref_cnt;
430 int rot_enable_clk_cnt;
431 struct sde_rot_clk *rot_clk;
432 int num_rot_clk;
Alan Kwongeffb5ee2016-03-12 19:47:45 -0500433 u32 rdot_limit;
434 u32 wrot_limit;
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -0700435
436 u32 hwacquire_timeout;
437 struct sde_mult_factor pixel_per_clk;
Benjamin Chandbe13112016-09-26 12:10:06 -0400438 struct sde_mult_factor fudge_factor;
439 struct sde_mult_factor overhead;
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -0700440
Alan Kwong6bc64622017-02-04 17:36:03 -0800441 struct sde_rot_file_private *sbuf_ctx;
442
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -0700443 int (*ops_config_hw)(struct sde_rot_hw_resource *hw,
444 struct sde_rot_entry *entry);
Clarence Ip3ce07c02017-08-11 16:21:45 -0400445 int (*ops_cancel_hw)(struct sde_rot_hw_resource *hw,
446 struct sde_rot_entry *entry);
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -0700447 int (*ops_kickoff_entry)(struct sde_rot_hw_resource *hw,
448 struct sde_rot_entry *entry);
449 int (*ops_wait_for_entry)(struct sde_rot_hw_resource *hw,
450 struct sde_rot_entry *entry);
451 struct sde_rot_hw_resource *(*ops_hw_alloc)(struct sde_rot_mgr *mgr,
452 u32 pipe_id, u32 wb_id);
453 void (*ops_hw_free)(struct sde_rot_mgr *mgr,
454 struct sde_rot_hw_resource *hw);
455 int (*ops_hw_init)(struct sde_rot_mgr *mgr);
Benjamin Chan0f9e61d2016-09-16 16:01:09 -0400456 void (*ops_hw_pre_pmevent)(struct sde_rot_mgr *mgr, bool pmon);
457 void (*ops_hw_post_pmevent)(struct sde_rot_mgr *mgr, bool pmon);
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -0700458 void (*ops_hw_destroy)(struct sde_rot_mgr *mgr);
459 ssize_t (*ops_hw_show_caps)(struct sde_rot_mgr *mgr,
460 struct device_attribute *attr, char *buf, ssize_t len);
461 ssize_t (*ops_hw_show_state)(struct sde_rot_mgr *mgr,
462 struct device_attribute *attr, char *buf, ssize_t len);
463 int (*ops_hw_create_debugfs)(struct sde_rot_mgr *mgr,
464 struct dentry *debugfs_root);
465 int (*ops_hw_validate_entry)(struct sde_rot_mgr *mgr,
466 struct sde_rot_entry *entry);
Alan Kwongda16e442016-08-14 20:47:18 -0400467 u32 (*ops_hw_get_pixfmt)(struct sde_rot_mgr *mgr, int index,
468 bool input);
469 int (*ops_hw_is_valid_pixfmt)(struct sde_rot_mgr *mgr, u32 pixfmt,
470 bool input);
Alan Kwong6bc64622017-02-04 17:36:03 -0800471 int (*ops_hw_get_downscale_caps)(struct sde_rot_mgr *mgr, char *caps,
472 int len);
Alan Kwongb6c049c2017-03-31 12:50:27 -0700473 int (*ops_hw_get_maxlinewidth)(struct sde_rot_mgr *mgr);
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -0700474
475 void *hw_data;
476};
477
Alan Kwongda16e442016-08-14 20:47:18 -0400478static inline int sde_rotator_is_valid_pixfmt(struct sde_rot_mgr *mgr,
479 u32 pixfmt, bool input)
480{
481 if (mgr && mgr->ops_hw_is_valid_pixfmt)
482 return mgr->ops_hw_is_valid_pixfmt(mgr, pixfmt, input);
483
484 return false;
485}
486
487static inline u32 sde_rotator_get_pixfmt(struct sde_rot_mgr *mgr,
488 int index, bool input)
489{
490 if (mgr && mgr->ops_hw_get_pixfmt)
491 return mgr->ops_hw_get_pixfmt(mgr, index, input);
492
493 return 0;
494}
495
Alan Kwong6bc64622017-02-04 17:36:03 -0800496static inline int sde_rotator_get_downscale_caps(struct sde_rot_mgr *mgr,
497 char *caps, int len)
498{
499 if (mgr && mgr->ops_hw_get_downscale_caps)
500 return mgr->ops_hw_get_downscale_caps(mgr, caps, len);
501
502 return 0;
503}
504
Alan Kwongb6c049c2017-03-31 12:50:27 -0700505static inline int sde_rotator_get_maxlinewidth(struct sde_rot_mgr *mgr)
506{
507 if (mgr && mgr->ops_hw_get_maxlinewidth)
508 return mgr->ops_hw_get_maxlinewidth(mgr);
509
510 return 2048;
511}
512
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -0700513static inline int __compare_session_item_rect(
514 struct sde_rotation_buf_info *s_rect,
515 struct sde_rect *i_rect, uint32_t i_fmt, bool src)
516{
517 if ((s_rect->width != i_rect->w) || (s_rect->height != i_rect->h) ||
518 (s_rect->format != i_fmt)) {
519 SDEROT_DBG(
520 "%s: session{%u,%u}f:%u mismatch from item{%u,%u}f:%u\n",
521 (src ? "src":"dst"), s_rect->width, s_rect->height,
522 s_rect->format, i_rect->w, i_rect->h, i_fmt);
523 return -EINVAL;
524 }
525 return 0;
526}
527
528/*
529 * Compare all important flag bits associated with rotation between session
530 * config and item request. Format and roi validation is done during open
531 * session and is based certain defining bits. If these defining bits are
532 * different in item request, there is a possibility that rotation item
533 * is not a valid configuration.
534 */
535static inline int __compare_session_rotations(uint32_t cfg_flag,
536 uint32_t item_flag)
537{
538 cfg_flag &= SDE_ROT_DEFINING_FLAG_BITS;
539 item_flag &= SDE_ROT_DEFINING_FLAG_BITS;
540 if (cfg_flag != item_flag) {
541 SDEROT_DBG(
542 "Rotation degree request different from open session\n");
543 return -EINVAL;
544 }
545 return 0;
546}
547
Alan Kwongf94a2552016-12-28 09:41:22 -0800548/*
549 * sde_rotator_core_init - initialize rotator manager for the given platform
550 * device
551 * @pmgr: Pointer to pointer of the newly initialized rotator manager
552 * @pdev: Pointer to platform device
553 * return: 0 if success; error code otherwise
554 */
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -0700555int sde_rotator_core_init(struct sde_rot_mgr **pmgr,
556 struct platform_device *pdev);
557
Alan Kwongf94a2552016-12-28 09:41:22 -0800558/*
559 * sde_rotator_core_destroy - destroy given rotator manager
560 * @mgr: Pointer to rotator manager
561 * return: none
562 */
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -0700563void sde_rotator_core_destroy(struct sde_rot_mgr *mgr);
564
Alan Kwongf94a2552016-12-28 09:41:22 -0800565/*
566 * sde_rotator_session_open - open a new rotator per file session
567 * @mgr: Pointer to rotator manager
568 * @pprivate: Pointer to pointer of the newly initialized per file session
569 * @session_id: identifier of the newly created session
570 * @queue: Pointer to fence queue of the new session
571 * return: 0 if success; error code otherwise
572 */
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -0700573int sde_rotator_session_open(struct sde_rot_mgr *mgr,
574 struct sde_rot_file_private **pprivate, int session_id,
575 struct sde_rot_queue *queue);
576
Alan Kwongf94a2552016-12-28 09:41:22 -0800577/*
578 * sde_rotator_session_close - close the given rotator per file session
579 * @mgr: Pointer to rotator manager
580 * @private: Pointer to per file session
581 * @session_id: identifier of the session
582 * return: none
583 */
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -0700584void sde_rotator_session_close(struct sde_rot_mgr *mgr,
585 struct sde_rot_file_private *private, int session_id);
586
Alan Kwongf94a2552016-12-28 09:41:22 -0800587/*
588 * sde_rotator_session_config - configure the given rotator per file session
589 * @mgr: Pointer to rotator manager
590 * @private: Pointer to per file session
591 * @config: Pointer to rotator configuration
592 * return: 0 if success; error code otherwise
593 */
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -0700594int sde_rotator_session_config(struct sde_rot_mgr *mgr,
595 struct sde_rot_file_private *private,
596 struct sde_rotation_config *config);
597
Alan Kwongf94a2552016-12-28 09:41:22 -0800598/*
599 * sde_rotator_req_init - allocate a new request and initialzie with given
600 * array of rotation items
601 * @rot_dev: Pointer to rotator device
602 * @private: Pointer to rotator manager per file context
603 * @items: Pointer to array of rotation item
604 * @count: size of rotation item array
605 * @flags: rotation request flags
606 * return: Pointer to new rotation request if success; ERR_PTR otherwise
607 */
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -0700608struct sde_rot_entry_container *sde_rotator_req_init(
609 struct sde_rot_mgr *rot_dev,
610 struct sde_rot_file_private *private,
611 struct sde_rotation_item *items,
612 u32 count, u32 flags);
613
Alan Kwongf94a2552016-12-28 09:41:22 -0800614/*
Clarence Ipb25c65c2017-05-17 12:09:23 -0400615 * sde_rotator_req_reset_start - reset inline h/w 'start' indicator
616 * For inline rotations, the time of rotation start is not controlled
617 * by the rotator driver. This function resets an internal 'start'
618 * indicator that allows the rotator to delay its rotator
619 * timeout waiting until such time as the inline rotation has
620 * really started.
Clarence Ip3ce07c02017-08-11 16:21:45 -0400621 * @mgr: Pointer to rotator manager
Clarence Ipb25c65c2017-05-17 12:09:23 -0400622 * @req: Pointer to rotation request
623 */
Clarence Ip3ce07c02017-08-11 16:21:45 -0400624void sde_rotator_req_reset_start(struct sde_rot_mgr *mgr,
625 struct sde_rot_entry_container *req);
Clarence Ipb25c65c2017-05-17 12:09:23 -0400626
627/*
628 * sde_rotator_req_set_start - set inline h/w 'start' indicator
Clarence Ip3ce07c02017-08-11 16:21:45 -0400629 * @mgr: Pointer to rotator manager
Clarence Ipb25c65c2017-05-17 12:09:23 -0400630 * @req: Pointer to rotation request
631 */
Clarence Ip3ce07c02017-08-11 16:21:45 -0400632void sde_rotator_req_set_start(struct sde_rot_mgr *mgr,
633 struct sde_rot_entry_container *req);
634
635/*
636 * sde_rotator_req_wait_start - wait for inline h/w 'start' indicator
637 * @mgr: Pointer to rotator manager
638 * @req: Pointer to rotation request
639 * return: Zero on success
640 */
641int sde_rotator_req_wait_start(struct sde_rot_mgr *mgr,
642 struct sde_rot_entry_container *req);
Clarence Ipb25c65c2017-05-17 12:09:23 -0400643
644/*
Alan Kwongf94a2552016-12-28 09:41:22 -0800645 * sde_rotator_req_finish - notify manager that client is finished with the
646 * given request and manager can release the request as required
Clarence Ip3ce07c02017-08-11 16:21:45 -0400647 * @mgr: Pointer to rotator manager
Alan Kwongf94a2552016-12-28 09:41:22 -0800648 * @private: Pointer to rotator manager per file context
649 * @req: Pointer to rotation request
650 * return: none
651 */
652void sde_rotator_req_finish(struct sde_rot_mgr *mgr,
653 struct sde_rot_file_private *private,
654 struct sde_rot_entry_container *req);
655
656/*
657 * sde_rotator_handle_request_common - add the given request to rotator
658 * manager and clean up completed requests
659 * @rot_dev: Pointer to rotator device
660 * @private: Pointer to rotator manager per file context
661 * @req: Pointer to rotation request
662 * return: 0 if success; error code otherwise
663 */
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -0700664int sde_rotator_handle_request_common(struct sde_rot_mgr *rot_dev,
665 struct sde_rot_file_private *ctx,
Alan Kwongf94a2552016-12-28 09:41:22 -0800666 struct sde_rot_entry_container *req);
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -0700667
Alan Kwongf94a2552016-12-28 09:41:22 -0800668/*
669 * sde_rotator_queue_request - queue/schedule the given request for h/w commit
670 * @rot_dev: Pointer to rotator device
671 * @private: Pointer to rotator manager per file context
672 * @req: Pointer to rotation request
673 * return: 0 if success; error code otherwise
674 */
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -0700675void sde_rotator_queue_request(struct sde_rot_mgr *rot_dev,
676 struct sde_rot_file_private *ctx,
677 struct sde_rot_entry_container *req);
678
Alan Kwongf94a2552016-12-28 09:41:22 -0800679/*
680 * sde_rotator_verify_config_all - verify given rotation configuration
681 * @rot_dev: Pointer to rotator device
682 * @config: Pointer to rotator configuration
683 * return: 0 if success; error code otherwise
684 */
Benjamin Chan59a06052017-01-12 18:06:03 -0500685int sde_rotator_verify_config_all(struct sde_rot_mgr *rot_dev,
686 struct sde_rotation_config *config);
687
Alan Kwongf94a2552016-12-28 09:41:22 -0800688/*
689 * sde_rotator_verify_config_input - verify rotation input configuration
690 * @rot_dev: Pointer to rotator device
691 * @config: Pointer to rotator configuration
692 * return: 0 if success; error code otherwise
693 */
Benjamin Chan59a06052017-01-12 18:06:03 -0500694int sde_rotator_verify_config_input(struct sde_rot_mgr *rot_dev,
695 struct sde_rotation_config *config);
696
Alan Kwongf94a2552016-12-28 09:41:22 -0800697/*
698 * sde_rotator_verify_config_output - verify rotation output configuration
699 * @rot_dev: Pointer to rotator device
700 * @config: Pointer to rotator configuration
701 * return: 0 if success; error code otherwise
702 */
Benjamin Chan59a06052017-01-12 18:06:03 -0500703int sde_rotator_verify_config_output(struct sde_rot_mgr *rot_dev,
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -0700704 struct sde_rotation_config *config);
705
Alan Kwongf94a2552016-12-28 09:41:22 -0800706/*
707 * sde_rotator_validate_request - validates given rotation request with
708 * previous rotator configuration
709 * @rot_dev: Pointer to rotator device
710 * @private: Pointer to rotator manager per file context
711 * @req: Pointer to rotation request
712 * return: 0 if success; error code otherwise
713 */
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -0700714int sde_rotator_validate_request(struct sde_rot_mgr *rot_dev,
715 struct sde_rot_file_private *ctx,
716 struct sde_rot_entry_container *req);
717
Alan Kwongf94a2552016-12-28 09:41:22 -0800718/*
719 * sde_rotator_clk_ctrl - enable/disable rotator clock with reference counting
720 * @mgr: Pointer to rotator manager
721 * @enable: true to enable clock; false to disable clock
722 * return: 0 if success; error code otherwise
723 */
Benjamin Chan0f9e61d2016-09-16 16:01:09 -0400724int sde_rotator_clk_ctrl(struct sde_rot_mgr *mgr, int enable);
725
Alan Kwongf94a2552016-12-28 09:41:22 -0800726/*
Benjamin Chand0a22cf2017-03-01 17:40:20 -0500727 * sde_rotator_cancel_all_requests - cancel all outstanding requests
728 * @mgr: Pointer to rotator manager
729 * @private: Pointer to rotator manager per file context
730 */
731void sde_rotator_cancel_all_requests(struct sde_rot_mgr *mgr,
732 struct sde_rot_file_private *private);
733
734/*
Alan Kwongf94a2552016-12-28 09:41:22 -0800735 * sde_rot_mgr_lock - serialization lock prior to rotator manager calls
736 * @mgr: Pointer to rotator manager
737 */
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -0700738static inline void sde_rot_mgr_lock(struct sde_rot_mgr *mgr)
739{
740 mutex_lock(&mgr->lock);
741}
742
Alan Kwongf94a2552016-12-28 09:41:22 -0800743/*
744 * sde_rot_mgr_lock - serialization unlock after rotator manager calls
745 * @mgr: Pointer to rotator manager
746 */
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -0700747static inline void sde_rot_mgr_unlock(struct sde_rot_mgr *mgr)
748{
749 mutex_unlock(&mgr->lock);
750}
751
Alan Kwong3428f672016-04-18 12:32:06 -0400752#if defined(CONFIG_PM)
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -0700753int sde_rotator_runtime_resume(struct device *dev);
754int sde_rotator_runtime_suspend(struct device *dev);
755int sde_rotator_runtime_idle(struct device *dev);
756#endif
757
758#if defined(CONFIG_PM_SLEEP)
759int sde_rotator_pm_suspend(struct device *dev);
760int sde_rotator_pm_resume(struct device *dev);
761#endif
762
763#if defined(CONFIG_PM) && !defined(CONFIG_PM_SLEEP)
764int sde_rotator_suspend(struct platform_device *dev, pm_message_t state);
765int sde_rotator_resume(struct platform_device *dev);
766#else
767#define sde_rotator_suspend NULL
768#define sde_rotator_resume NULL
769#endif
770#endif /* __SDE_ROTATOR_CORE_H__ */