blob: 16eaae1debc8c09f46b555895c38c1c3d5881dc6 [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>
24
25#include "sde_rotator_base.h"
26#include "sde_rotator_util.h"
27#include "sde_rotator_sync.h"
28
29/**********************************************************************
30 * Rotation request flag
31 **********************************************************************/
32/* no rotation flag */
33#define SDE_ROTATION_NOP 0x01
34
35/* left/right flip */
36#define SDE_ROTATION_FLIP_LR 0x02
37
38/* up/down flip */
39#define SDE_ROTATION_FLIP_UD 0x04
40
41/* rotate 90 degree */
42#define SDE_ROTATION_90 0x08
43
44/* rotate 180 degre */
45#define SDE_ROTATION_180 (SDE_ROTATION_FLIP_LR | SDE_ROTATION_FLIP_UD)
46
47/* rotate 270 degree */
48#define SDE_ROTATION_270 (SDE_ROTATION_90 | SDE_ROTATION_180)
49
50/* format is interlaced */
51#define SDE_ROTATION_DEINTERLACE 0x10
52
53/* secure data */
54#define SDE_ROTATION_SECURE 0x80
55
56/* verify input configuration only */
57#define SDE_ROTATION_VERIFY_INPUT_ONLY 0x10000
58
59/* use client provided dma buf instead of ion fd */
60#define SDE_ROTATION_EXT_DMA_BUF 0x20000
61
Abhijit Kulkarni298c8232016-09-26 22:32:10 -070062/* secure camera operation*/
63#define SDE_ROTATION_SECURE_CAMERA 0x40000
64
Alan Kwonga94684f2016-01-16 22:06:36 -050065/**********************************************************************
66 * configuration structures
67 **********************************************************************/
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -070068
69struct sde_rotation_buf_info {
70 uint32_t width;
71 uint32_t height;
72 uint32_t format;
73 struct sde_mult_factor comp_ratio;
74};
75
76struct sde_rotation_config {
77 uint32_t session_id;
78 struct sde_rotation_buf_info input;
79 struct sde_rotation_buf_info output;
80 uint32_t frame_rate;
81 uint32_t flags;
82};
83
84enum sde_rotator_ts {
85 SDE_ROTATOR_TS_SRCQB, /* enqueue source buffer */
86 SDE_ROTATOR_TS_DSTQB, /* enqueue destination buffer */
87 SDE_ROTATOR_TS_FENCE, /* wait for source buffer fence */
88 SDE_ROTATOR_TS_QUEUE, /* wait for h/w resource */
89 SDE_ROTATOR_TS_COMMIT, /* prepare h/w command */
90 SDE_ROTATOR_TS_FLUSH, /* initiate h/w processing */
91 SDE_ROTATOR_TS_DONE, /* receive h/w completion */
92 SDE_ROTATOR_TS_RETIRE, /* signal destination buffer fence */
93 SDE_ROTATOR_TS_SRCDQB, /* dequeue source buffer */
94 SDE_ROTATOR_TS_DSTDQB, /* dequeue destination buffer */
95 SDE_ROTATOR_TS_MAX
96};
97
Benjamin Chan77aed192016-10-17 17:49:41 -040098enum sde_rotator_clk_type {
99 SDE_ROTATOR_CLK_MDSS_AHB,
100 SDE_ROTATOR_CLK_MDSS_AXI,
101 SDE_ROTATOR_CLK_ROT_CORE,
102 SDE_ROTATOR_CLK_MDSS_ROT,
103 SDE_ROTATOR_CLK_MNOC_AHB,
Alan Kwonge1947ab2016-11-26 13:32:25 -0800104 SDE_ROTATOR_CLK_GCC_AHB,
105 SDE_ROTATOR_CLK_GCC_AXI,
Benjamin Chan77aed192016-10-17 17:49:41 -0400106 SDE_ROTATOR_CLK_MAX
107};
108
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -0700109struct sde_rotation_item {
110 /* rotation request flag */
111 uint32_t flags;
112
113 /* Source crop rectangle */
114 struct sde_rect src_rect;
115
116 /* Destination rectangle */
117 struct sde_rect dst_rect;
118
119 /* Input buffer for the request */
120 struct sde_layer_buffer input;
121
122 /* The output buffer for the request */
123 struct sde_layer_buffer output;
124
Alan Kwonga94684f2016-01-16 22:06:36 -0500125 /*
126 * DMA pipe selection for this request by client:
127 * 0: DMA pipe 0
128 * 1: DMA pipe 1
129 * or SDE_ROTATION_HW_ANY if client wants
130 * driver to allocate any that is available
131 *
132 * OR
133 *
134 * Reserved
135 */
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -0700136 uint32_t pipe_idx;
137
Alan Kwonga94684f2016-01-16 22:06:36 -0500138 /*
139 * Write-back block selection for this request by client:
140 * 0: Write-back block 0
141 * 1: Write-back block 1
142 * or SDE_ROTATION_HW_ANY if client wants
143 * driver to allocate any that is available
144 *
145 * OR
146 *
147 * Priority selection for this request by client:
148 * 0: Highest
149 * 1..n: Limited by the lowest available priority
150 */
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -0700151 uint32_t wb_idx;
152
Alan Kwonga94684f2016-01-16 22:06:36 -0500153 /*
154 * Sequence ID of this request within the session
155 */
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -0700156 uint32_t sequence_id;
157
158 /* Which session ID is this request scheduled on */
159 uint32_t session_id;
160
161 /* Time stamp for profiling purposes */
162 ktime_t *ts;
163};
164
165/*
166 * Defining characteristics about rotation work, that has corresponding
167 * fmt and roi checks in open session
168 */
169#define SDE_ROT_DEFINING_FLAG_BITS SDE_ROTATION_90
170
171struct sde_rot_entry;
172struct sde_rot_perf;
173
174struct sde_rot_clk {
175 struct clk *clk;
176 char clk_name[32];
177 unsigned long rate;
178};
179
180struct sde_rot_hw_resource {
181 u32 wb_id;
182 u32 pending_count;
183 atomic_t num_active;
184 int max_active;
185 wait_queue_head_t wait_queue;
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -0700186};
187
188struct sde_rot_queue {
189 struct workqueue_struct *rot_work_queue;
190 struct sde_rot_timeline *timeline;
191 struct sde_rot_hw_resource *hw;
192};
193
194struct sde_rot_entry_container {
195 struct list_head list;
196 u32 flags;
197 u32 count;
198 atomic_t pending_count;
199 atomic_t failed_count;
200 struct workqueue_struct *retireq;
201 struct work_struct *retire_work;
202 struct sde_rot_entry *entries;
203};
204
205struct sde_rot_mgr;
206struct sde_rot_file_private;
207
208struct sde_rot_entry {
209 struct sde_rotation_item item;
210 struct work_struct commit_work;
211 struct work_struct done_work;
212 struct sde_rot_queue *commitq;
213 struct sde_rot_queue *fenceq;
214 struct sde_rot_queue *doneq;
215 struct sde_rot_entry_container *request;
216
217 struct sde_mdp_data src_buf;
218 struct sde_mdp_data dst_buf;
219
220 struct sde_rot_sync_fence *input_fence;
221
222 struct sde_rot_sync_fence *output_fence;
223 bool output_signaled;
224
225 u32 dnsc_factor_w;
226 u32 dnsc_factor_h;
227
228 struct sde_rot_perf *perf;
229 bool work_assigned; /* Used when cleaning up work_distribution */
230 struct sde_rot_file_private *private;
231};
232
233struct sde_rot_perf {
234 struct list_head list;
235 struct sde_rotation_config config;
236 unsigned long clk_rate;
237 u64 bw;
238 struct mutex work_dis_lock;
239 u32 *work_distribution;
240 int last_wb_idx; /* last known wb index, used when above count is 0 */
Alan Kwongeffb5ee2016-03-12 19:47:45 -0500241 u32 rdot_limit;
242 u32 wrot_limit;
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -0700243};
244
245struct sde_rot_file_private {
246 struct list_head list;
247 struct list_head req_list;
248 struct list_head perf_list;
249 struct sde_rot_mgr *mgr;
250 struct sde_rot_queue *fenceq;
251};
252
253struct sde_rot_bus_data_type {
254 struct msm_bus_scale_pdata *bus_scale_pdata;
255 u32 bus_hdl;
256 u32 curr_bw_uc_idx;
257 u64 curr_quota_val;
258};
259
260struct sde_rot_mgr {
261 struct mutex lock;
262 atomic_t device_suspended;
263 struct platform_device *pdev;
264 struct device *device;
265
266 /*
267 * Managing rotation queues, depends on
268 * how many hw pipes available on the system
269 */
270 int queue_count;
271 struct sde_rot_queue *commitq;
272 struct sde_rot_queue *doneq;
273
274 /*
275 * managing all the open file sessions to bw calculations,
276 * and resource clean up during suspend
277 */
278 struct list_head file_list;
279
280 u64 pending_close_bw_vote;
281 struct sde_rot_bus_data_type data_bus;
282 struct sde_rot_bus_data_type reg_bus;
283
284 /* Module power is only used for regulator management */
285 struct sde_module_power module_power;
286 bool regulator_enable;
287
288 int res_ref_cnt;
289 int rot_enable_clk_cnt;
290 struct sde_rot_clk *rot_clk;
291 int num_rot_clk;
Alan Kwongeffb5ee2016-03-12 19:47:45 -0500292 u32 rdot_limit;
293 u32 wrot_limit;
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -0700294
295 u32 hwacquire_timeout;
296 struct sde_mult_factor pixel_per_clk;
Benjamin Chandbe13112016-09-26 12:10:06 -0400297 struct sde_mult_factor fudge_factor;
298 struct sde_mult_factor overhead;
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -0700299
300 int (*ops_config_hw)(struct sde_rot_hw_resource *hw,
301 struct sde_rot_entry *entry);
302 int (*ops_kickoff_entry)(struct sde_rot_hw_resource *hw,
303 struct sde_rot_entry *entry);
304 int (*ops_wait_for_entry)(struct sde_rot_hw_resource *hw,
305 struct sde_rot_entry *entry);
306 struct sde_rot_hw_resource *(*ops_hw_alloc)(struct sde_rot_mgr *mgr,
307 u32 pipe_id, u32 wb_id);
308 void (*ops_hw_free)(struct sde_rot_mgr *mgr,
309 struct sde_rot_hw_resource *hw);
310 int (*ops_hw_init)(struct sde_rot_mgr *mgr);
Benjamin Chan0f9e61d2016-09-16 16:01:09 -0400311 void (*ops_hw_pre_pmevent)(struct sde_rot_mgr *mgr, bool pmon);
312 void (*ops_hw_post_pmevent)(struct sde_rot_mgr *mgr, bool pmon);
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -0700313 void (*ops_hw_destroy)(struct sde_rot_mgr *mgr);
314 ssize_t (*ops_hw_show_caps)(struct sde_rot_mgr *mgr,
315 struct device_attribute *attr, char *buf, ssize_t len);
316 ssize_t (*ops_hw_show_state)(struct sde_rot_mgr *mgr,
317 struct device_attribute *attr, char *buf, ssize_t len);
318 int (*ops_hw_create_debugfs)(struct sde_rot_mgr *mgr,
319 struct dentry *debugfs_root);
320 int (*ops_hw_validate_entry)(struct sde_rot_mgr *mgr,
321 struct sde_rot_entry *entry);
Alan Kwongda16e442016-08-14 20:47:18 -0400322 u32 (*ops_hw_get_pixfmt)(struct sde_rot_mgr *mgr, int index,
323 bool input);
324 int (*ops_hw_is_valid_pixfmt)(struct sde_rot_mgr *mgr, u32 pixfmt,
325 bool input);
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -0700326
327 void *hw_data;
328};
329
Alan Kwongda16e442016-08-14 20:47:18 -0400330static inline int sde_rotator_is_valid_pixfmt(struct sde_rot_mgr *mgr,
331 u32 pixfmt, bool input)
332{
333 if (mgr && mgr->ops_hw_is_valid_pixfmt)
334 return mgr->ops_hw_is_valid_pixfmt(mgr, pixfmt, input);
335
336 return false;
337}
338
339static inline u32 sde_rotator_get_pixfmt(struct sde_rot_mgr *mgr,
340 int index, bool input)
341{
342 if (mgr && mgr->ops_hw_get_pixfmt)
343 return mgr->ops_hw_get_pixfmt(mgr, index, input);
344
345 return 0;
346}
347
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -0700348static inline int __compare_session_item_rect(
349 struct sde_rotation_buf_info *s_rect,
350 struct sde_rect *i_rect, uint32_t i_fmt, bool src)
351{
352 if ((s_rect->width != i_rect->w) || (s_rect->height != i_rect->h) ||
353 (s_rect->format != i_fmt)) {
354 SDEROT_DBG(
355 "%s: session{%u,%u}f:%u mismatch from item{%u,%u}f:%u\n",
356 (src ? "src":"dst"), s_rect->width, s_rect->height,
357 s_rect->format, i_rect->w, i_rect->h, i_fmt);
358 return -EINVAL;
359 }
360 return 0;
361}
362
363/*
364 * Compare all important flag bits associated with rotation between session
365 * config and item request. Format and roi validation is done during open
366 * session and is based certain defining bits. If these defining bits are
367 * different in item request, there is a possibility that rotation item
368 * is not a valid configuration.
369 */
370static inline int __compare_session_rotations(uint32_t cfg_flag,
371 uint32_t item_flag)
372{
373 cfg_flag &= SDE_ROT_DEFINING_FLAG_BITS;
374 item_flag &= SDE_ROT_DEFINING_FLAG_BITS;
375 if (cfg_flag != item_flag) {
376 SDEROT_DBG(
377 "Rotation degree request different from open session\n");
378 return -EINVAL;
379 }
380 return 0;
381}
382
383int sde_rotator_core_init(struct sde_rot_mgr **pmgr,
384 struct platform_device *pdev);
385
386void sde_rotator_core_destroy(struct sde_rot_mgr *mgr);
387
388int sde_rotator_session_open(struct sde_rot_mgr *mgr,
389 struct sde_rot_file_private **pprivate, int session_id,
390 struct sde_rot_queue *queue);
391
392void sde_rotator_session_close(struct sde_rot_mgr *mgr,
393 struct sde_rot_file_private *private, int session_id);
394
395int sde_rotator_session_config(struct sde_rot_mgr *mgr,
396 struct sde_rot_file_private *private,
397 struct sde_rotation_config *config);
398
399struct sde_rot_entry_container *sde_rotator_req_init(
400 struct sde_rot_mgr *rot_dev,
401 struct sde_rot_file_private *private,
402 struct sde_rotation_item *items,
403 u32 count, u32 flags);
404
405int sde_rotator_handle_request_common(struct sde_rot_mgr *rot_dev,
406 struct sde_rot_file_private *ctx,
407 struct sde_rot_entry_container *req,
408 struct sde_rotation_item *items);
409
410void sde_rotator_queue_request(struct sde_rot_mgr *rot_dev,
411 struct sde_rot_file_private *ctx,
412 struct sde_rot_entry_container *req);
413
414void sde_rotator_remove_request(struct sde_rot_mgr *mgr,
415 struct sde_rot_file_private *private,
416 struct sde_rot_entry_container *req);
417
Benjamin Chan59a06052017-01-12 18:06:03 -0500418int sde_rotator_verify_config_all(struct sde_rot_mgr *rot_dev,
419 struct sde_rotation_config *config);
420
421int sde_rotator_verify_config_input(struct sde_rot_mgr *rot_dev,
422 struct sde_rotation_config *config);
423
424int sde_rotator_verify_config_output(struct sde_rot_mgr *rot_dev,
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -0700425 struct sde_rotation_config *config);
426
427int sde_rotator_validate_request(struct sde_rot_mgr *rot_dev,
428 struct sde_rot_file_private *ctx,
429 struct sde_rot_entry_container *req);
430
Benjamin Chan0f9e61d2016-09-16 16:01:09 -0400431int sde_rotator_clk_ctrl(struct sde_rot_mgr *mgr, int enable);
432
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -0700433static inline void sde_rot_mgr_lock(struct sde_rot_mgr *mgr)
434{
435 mutex_lock(&mgr->lock);
436}
437
438static inline void sde_rot_mgr_unlock(struct sde_rot_mgr *mgr)
439{
440 mutex_unlock(&mgr->lock);
441}
442
Alan Kwong3428f672016-04-18 12:32:06 -0400443#if defined(CONFIG_PM)
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -0700444int sde_rotator_runtime_resume(struct device *dev);
445int sde_rotator_runtime_suspend(struct device *dev);
446int sde_rotator_runtime_idle(struct device *dev);
447#endif
448
449#if defined(CONFIG_PM_SLEEP)
450int sde_rotator_pm_suspend(struct device *dev);
451int sde_rotator_pm_resume(struct device *dev);
452#endif
453
454#if defined(CONFIG_PM) && !defined(CONFIG_PM_SLEEP)
455int sde_rotator_suspend(struct platform_device *dev, pm_message_t state);
456int sde_rotator_resume(struct platform_device *dev);
457#else
458#define sde_rotator_suspend NULL
459#define sde_rotator_resume NULL
460#endif
461#endif /* __SDE_ROTATOR_CORE_H__ */