blob: 0aee4f70b1efb415737d651fe0d614e1f78a24bf [file] [log] [blame]
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -07001/* Copyright (c) 2015-2016, The Linux Foundation. All rights reserved.
2 *
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
Alan Kwonga94684f2016-01-16 22:06:36 -050062/**********************************************************************
63 * configuration structures
64 **********************************************************************/
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -070065
66struct sde_rotation_buf_info {
67 uint32_t width;
68 uint32_t height;
69 uint32_t format;
70 struct sde_mult_factor comp_ratio;
71};
72
73struct sde_rotation_config {
74 uint32_t session_id;
75 struct sde_rotation_buf_info input;
76 struct sde_rotation_buf_info output;
77 uint32_t frame_rate;
78 uint32_t flags;
79};
80
81enum sde_rotator_ts {
82 SDE_ROTATOR_TS_SRCQB, /* enqueue source buffer */
83 SDE_ROTATOR_TS_DSTQB, /* enqueue destination buffer */
84 SDE_ROTATOR_TS_FENCE, /* wait for source buffer fence */
85 SDE_ROTATOR_TS_QUEUE, /* wait for h/w resource */
86 SDE_ROTATOR_TS_COMMIT, /* prepare h/w command */
87 SDE_ROTATOR_TS_FLUSH, /* initiate h/w processing */
88 SDE_ROTATOR_TS_DONE, /* receive h/w completion */
89 SDE_ROTATOR_TS_RETIRE, /* signal destination buffer fence */
90 SDE_ROTATOR_TS_SRCDQB, /* dequeue source buffer */
91 SDE_ROTATOR_TS_DSTDQB, /* dequeue destination buffer */
92 SDE_ROTATOR_TS_MAX
93};
94
95struct sde_rotation_item {
96 /* rotation request flag */
97 uint32_t flags;
98
99 /* Source crop rectangle */
100 struct sde_rect src_rect;
101
102 /* Destination rectangle */
103 struct sde_rect dst_rect;
104
105 /* Input buffer for the request */
106 struct sde_layer_buffer input;
107
108 /* The output buffer for the request */
109 struct sde_layer_buffer output;
110
Alan Kwonga94684f2016-01-16 22:06:36 -0500111 /*
112 * DMA pipe selection for this request by client:
113 * 0: DMA pipe 0
114 * 1: DMA pipe 1
115 * or SDE_ROTATION_HW_ANY if client wants
116 * driver to allocate any that is available
117 *
118 * OR
119 *
120 * Reserved
121 */
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -0700122 uint32_t pipe_idx;
123
Alan Kwonga94684f2016-01-16 22:06:36 -0500124 /*
125 * Write-back block selection for this request by client:
126 * 0: Write-back block 0
127 * 1: Write-back block 1
128 * or SDE_ROTATION_HW_ANY if client wants
129 * driver to allocate any that is available
130 *
131 * OR
132 *
133 * Priority selection for this request by client:
134 * 0: Highest
135 * 1..n: Limited by the lowest available priority
136 */
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -0700137 uint32_t wb_idx;
138
Alan Kwonga94684f2016-01-16 22:06:36 -0500139 /*
140 * Sequence ID of this request within the session
141 */
Adrian Salido-Moreno5c150382016-04-06 09:29:37 -0700142 uint32_t sequence_id;
143
144 /* Which session ID is this request scheduled on */
145 uint32_t session_id;
146
147 /* Time stamp for profiling purposes */
148 ktime_t *ts;
149};
150
151/*
152 * Defining characteristics about rotation work, that has corresponding
153 * fmt and roi checks in open session
154 */
155#define SDE_ROT_DEFINING_FLAG_BITS SDE_ROTATION_90
156
157struct sde_rot_entry;
158struct sde_rot_perf;
159
160struct sde_rot_clk {
161 struct clk *clk;
162 char clk_name[32];
163 unsigned long rate;
164};
165
166struct sde_rot_hw_resource {
167 u32 wb_id;
168 u32 pending_count;
169 atomic_t num_active;
170 int max_active;
171 wait_queue_head_t wait_queue;
172 struct sde_rot_entry *workload;
173};
174
175struct sde_rot_queue {
176 struct workqueue_struct *rot_work_queue;
177 struct sde_rot_timeline *timeline;
178 struct sde_rot_hw_resource *hw;
179};
180
181struct sde_rot_entry_container {
182 struct list_head list;
183 u32 flags;
184 u32 count;
185 atomic_t pending_count;
186 atomic_t failed_count;
187 struct workqueue_struct *retireq;
188 struct work_struct *retire_work;
189 struct sde_rot_entry *entries;
190};
191
192struct sde_rot_mgr;
193struct sde_rot_file_private;
194
195struct sde_rot_entry {
196 struct sde_rotation_item item;
197 struct work_struct commit_work;
198 struct work_struct done_work;
199 struct sde_rot_queue *commitq;
200 struct sde_rot_queue *fenceq;
201 struct sde_rot_queue *doneq;
202 struct sde_rot_entry_container *request;
203
204 struct sde_mdp_data src_buf;
205 struct sde_mdp_data dst_buf;
206
207 struct sde_rot_sync_fence *input_fence;
208
209 struct sde_rot_sync_fence *output_fence;
210 bool output_signaled;
211
212 u32 dnsc_factor_w;
213 u32 dnsc_factor_h;
214
215 struct sde_rot_perf *perf;
216 bool work_assigned; /* Used when cleaning up work_distribution */
217 struct sde_rot_file_private *private;
218};
219
220struct sde_rot_perf {
221 struct list_head list;
222 struct sde_rotation_config config;
223 unsigned long clk_rate;
224 u64 bw;
225 struct mutex work_dis_lock;
226 u32 *work_distribution;
227 int last_wb_idx; /* last known wb index, used when above count is 0 */
228};
229
230struct sde_rot_file_private {
231 struct list_head list;
232 struct list_head req_list;
233 struct list_head perf_list;
234 struct sde_rot_mgr *mgr;
235 struct sde_rot_queue *fenceq;
236};
237
238struct sde_rot_bus_data_type {
239 struct msm_bus_scale_pdata *bus_scale_pdata;
240 u32 bus_hdl;
241 u32 curr_bw_uc_idx;
242 u64 curr_quota_val;
243};
244
245struct sde_rot_mgr {
246 struct mutex lock;
247 atomic_t device_suspended;
248 struct platform_device *pdev;
249 struct device *device;
250
251 /*
252 * Managing rotation queues, depends on
253 * how many hw pipes available on the system
254 */
255 int queue_count;
256 struct sde_rot_queue *commitq;
257 struct sde_rot_queue *doneq;
258
259 /*
260 * managing all the open file sessions to bw calculations,
261 * and resource clean up during suspend
262 */
263 struct list_head file_list;
264
265 u64 pending_close_bw_vote;
266 struct sde_rot_bus_data_type data_bus;
267 struct sde_rot_bus_data_type reg_bus;
268
269 /* Module power is only used for regulator management */
270 struct sde_module_power module_power;
271 bool regulator_enable;
272
273 int res_ref_cnt;
274 int rot_enable_clk_cnt;
275 struct sde_rot_clk *rot_clk;
276 int num_rot_clk;
277 int core_clk_idx;
278
279 u32 hwacquire_timeout;
280 struct sde_mult_factor pixel_per_clk;
281
282 int (*ops_config_hw)(struct sde_rot_hw_resource *hw,
283 struct sde_rot_entry *entry);
284 int (*ops_kickoff_entry)(struct sde_rot_hw_resource *hw,
285 struct sde_rot_entry *entry);
286 int (*ops_wait_for_entry)(struct sde_rot_hw_resource *hw,
287 struct sde_rot_entry *entry);
288 struct sde_rot_hw_resource *(*ops_hw_alloc)(struct sde_rot_mgr *mgr,
289 u32 pipe_id, u32 wb_id);
290 void (*ops_hw_free)(struct sde_rot_mgr *mgr,
291 struct sde_rot_hw_resource *hw);
292 int (*ops_hw_init)(struct sde_rot_mgr *mgr);
293 void (*ops_hw_destroy)(struct sde_rot_mgr *mgr);
294 ssize_t (*ops_hw_show_caps)(struct sde_rot_mgr *mgr,
295 struct device_attribute *attr, char *buf, ssize_t len);
296 ssize_t (*ops_hw_show_state)(struct sde_rot_mgr *mgr,
297 struct device_attribute *attr, char *buf, ssize_t len);
298 int (*ops_hw_create_debugfs)(struct sde_rot_mgr *mgr,
299 struct dentry *debugfs_root);
300 int (*ops_hw_validate_entry)(struct sde_rot_mgr *mgr,
301 struct sde_rot_entry *entry);
302
303 void *hw_data;
304};
305
306static inline int __compare_session_item_rect(
307 struct sde_rotation_buf_info *s_rect,
308 struct sde_rect *i_rect, uint32_t i_fmt, bool src)
309{
310 if ((s_rect->width != i_rect->w) || (s_rect->height != i_rect->h) ||
311 (s_rect->format != i_fmt)) {
312 SDEROT_DBG(
313 "%s: session{%u,%u}f:%u mismatch from item{%u,%u}f:%u\n",
314 (src ? "src":"dst"), s_rect->width, s_rect->height,
315 s_rect->format, i_rect->w, i_rect->h, i_fmt);
316 return -EINVAL;
317 }
318 return 0;
319}
320
321/*
322 * Compare all important flag bits associated with rotation between session
323 * config and item request. Format and roi validation is done during open
324 * session and is based certain defining bits. If these defining bits are
325 * different in item request, there is a possibility that rotation item
326 * is not a valid configuration.
327 */
328static inline int __compare_session_rotations(uint32_t cfg_flag,
329 uint32_t item_flag)
330{
331 cfg_flag &= SDE_ROT_DEFINING_FLAG_BITS;
332 item_flag &= SDE_ROT_DEFINING_FLAG_BITS;
333 if (cfg_flag != item_flag) {
334 SDEROT_DBG(
335 "Rotation degree request different from open session\n");
336 return -EINVAL;
337 }
338 return 0;
339}
340
341int sde_rotator_core_init(struct sde_rot_mgr **pmgr,
342 struct platform_device *pdev);
343
344void sde_rotator_core_destroy(struct sde_rot_mgr *mgr);
345
346int sde_rotator_session_open(struct sde_rot_mgr *mgr,
347 struct sde_rot_file_private **pprivate, int session_id,
348 struct sde_rot_queue *queue);
349
350void sde_rotator_session_close(struct sde_rot_mgr *mgr,
351 struct sde_rot_file_private *private, int session_id);
352
353int sde_rotator_session_config(struct sde_rot_mgr *mgr,
354 struct sde_rot_file_private *private,
355 struct sde_rotation_config *config);
356
357struct sde_rot_entry_container *sde_rotator_req_init(
358 struct sde_rot_mgr *rot_dev,
359 struct sde_rot_file_private *private,
360 struct sde_rotation_item *items,
361 u32 count, u32 flags);
362
363int sde_rotator_handle_request_common(struct sde_rot_mgr *rot_dev,
364 struct sde_rot_file_private *ctx,
365 struct sde_rot_entry_container *req,
366 struct sde_rotation_item *items);
367
368void sde_rotator_queue_request(struct sde_rot_mgr *rot_dev,
369 struct sde_rot_file_private *ctx,
370 struct sde_rot_entry_container *req);
371
372void sde_rotator_remove_request(struct sde_rot_mgr *mgr,
373 struct sde_rot_file_private *private,
374 struct sde_rot_entry_container *req);
375
376int sde_rotator_verify_config(struct sde_rot_mgr *rot_dev,
377 struct sde_rotation_config *config);
378
379int sde_rotator_validate_request(struct sde_rot_mgr *rot_dev,
380 struct sde_rot_file_private *ctx,
381 struct sde_rot_entry_container *req);
382
383static inline void sde_rot_mgr_lock(struct sde_rot_mgr *mgr)
384{
385 mutex_lock(&mgr->lock);
386}
387
388static inline void sde_rot_mgr_unlock(struct sde_rot_mgr *mgr)
389{
390 mutex_unlock(&mgr->lock);
391}
392
393#if defined(CONFIG_PM_RUNTIME)
394int sde_rotator_runtime_resume(struct device *dev);
395int sde_rotator_runtime_suspend(struct device *dev);
396int sde_rotator_runtime_idle(struct device *dev);
397#endif
398
399#if defined(CONFIG_PM_SLEEP)
400int sde_rotator_pm_suspend(struct device *dev);
401int sde_rotator_pm_resume(struct device *dev);
402#endif
403
404#if defined(CONFIG_PM) && !defined(CONFIG_PM_SLEEP)
405int sde_rotator_suspend(struct platform_device *dev, pm_message_t state);
406int sde_rotator_resume(struct platform_device *dev);
407#else
408#define sde_rotator_suspend NULL
409#define sde_rotator_resume NULL
410#endif
411#endif /* __SDE_ROTATOR_CORE_H__ */