blob: 8dd400e6edf24c690aac2fdbb9ef66fdf63e43b3 [file] [log] [blame]
Sachin Bhayareeeb88892018-01-02 16:36:01 +05301/* Copyright (c) 2014-2016, 2018, 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 MDSS_MDP_ROTATOR_INTERNAL_H
15#define MDSS_MDP_ROTATOR_INTERNAL_H
16
17#include <linux/list.h>
18#include <linux/sync.h>
19#include <linux/file.h>
20#include <linux/mdss_rotator.h>
21#include <linux/sw_sync.h>
22#include <linux/mutex.h>
23#include <linux/types.h>
24#include <linux/cdev.h>
25
26#include "mdss_mdp.h"
27
28/*
29 * Defining characteristics about rotation work, that has corresponding
30 * fmt and roi checks in open session
31 */
32#define MDSS_MDP_DEFINING_FLAG_BITS MDP_ROTATION_90
33
34struct mdss_rot_entry;
35struct mdss_rot_perf;
36
37enum mdss_rotator_clk_type {
38 MDSS_CLK_ROTATOR_AHB,
39 MDSS_CLK_ROTATOR_CORE,
40 MDSS_CLK_ROTATOR_END_IDX,
41};
42
43/*
44 * placeholder for performance profiling
45 * or debug support, not used currently
46 */
47struct mdss_rot_entry_cb_intf {
48 void (*pre_commit)(struct mdss_rot_entry *entry, void *data);
49 void (*post_commit)(struct mdss_rot_entry *entry,
50 void *data, int status);
51};
52
53struct mdss_rot_timeline {
54 struct mutex lock;
55 struct sw_sync_timeline *timeline;
56 u32 next_value;
57 char fence_name[32];
58};
59
60struct mdss_rot_hw_resource {
61 struct mdss_mdp_ctl *ctl;
62 struct mdss_mdp_mixer *mixer;
63 struct mdss_mdp_pipe *pipe;
64 struct mdss_mdp_writeback *wb;
65 u32 pipe_id;
66 u32 wb_id;
67
68 u32 pending_count;
69 struct mdss_rot_entry *workload;
70};
71
72struct mdss_rot_queue {
73 struct workqueue_struct *rot_work_queue;
74 struct mdss_rot_timeline timeline;
75
76 struct mutex hw_lock;
77 struct mdss_rot_hw_resource *hw;
78};
79
80struct mdss_rot_entry_container {
81 struct list_head list;
82 u32 flags;
83 u32 count;
84 atomic_t pending_count;
85 struct mdss_rot_entry *entries;
86};
87
88struct mdss_rot_entry {
89 struct mdp_rotation_item item;
90 struct work_struct commit_work;
91
92 struct mdss_rot_queue *queue;
93 struct mdss_rot_entry_container *request;
94
95 struct mdss_mdp_data src_buf;
96 struct mdss_mdp_data dst_buf;
97
98 struct sync_fence *input_fence;
99
100 int output_fence_fd;
101 struct sync_fence *output_fence;
102 bool output_signaled;
103
104 u32 dnsc_factor_w;
105 u32 dnsc_factor_h;
106
107 struct mdss_rot_entry_cb_intf intf;
108 void *intf_data;
109
110 struct mdss_rot_perf *perf;
111 bool work_assigned; /* Used when cleaning up work_distribution */
112};
113
114struct mdss_rot_perf {
115 struct list_head list;
116 struct mdp_rotation_config config;
117 unsigned long clk_rate;
118 u64 bw;
119 struct mutex work_dis_lock;
120 u32 *work_distribution;
121 int last_wb_idx; /* last known wb index, used when above count is 0 */
122};
123
124struct mdss_rot_file_private {
125 struct list_head list;
126
127 struct mutex req_lock;
128 struct list_head req_list;
129
130 struct mutex perf_lock;
131 struct list_head perf_list;
132
133 struct file *file;
134};
135
136struct mdss_rot_bus_data_type {
137 struct msm_bus_scale_pdata *bus_scale_pdata;
138 u32 bus_hdl;
139 u32 curr_bw_uc_idx;
140 u64 curr_quota_val;
141};
142
143struct mdss_rot_mgr {
144 struct mutex lock;
145
146 atomic_t device_suspended;
147
148 u32 session_id_generator;
149
150 struct platform_device *pdev;
151
152 dev_t dev_num;
153 struct cdev cdev;
154 struct class *class;
155 struct device *device;
156
157 /*
158 * mangaing rotation queues, depends on
159 * how many hw pipes available on the system
160 */
161 int queue_count;
162 struct mdss_rot_queue *queues;
163
164 struct mutex file_lock;
165 /*
166 * managing all the open file sessions to bw calculations,
167 * and resource clean up during suspend
168 */
169 struct list_head file_list;
170
171 struct mutex bus_lock;
172 u64 pending_close_bw_vote;
173 struct mdss_rot_bus_data_type data_bus;
174 struct mdss_rot_bus_data_type reg_bus;
175
176 /* Module power is only used for regulator management */
177 struct dss_module_power module_power;
178 bool regulator_enable;
179
180 struct mutex clk_lock;
181 int res_ref_cnt;
182 struct clk *rot_clk[MDSS_CLK_ROTATOR_END_IDX];
183 int rot_enable_clk_cnt;
184
185 bool has_downscale;
186 bool has_ubwc;
187};
188
189#ifdef CONFIG_COMPAT
190
191/* open a rotation session */
192#define MDSS_ROTATION_OPEN32 \
193 _IOWR(MDSS_ROTATOR_IOCTL_MAGIC, 1, compat_caddr_t)
194
195/* change the rotation session configuration */
196#define MDSS_ROTATION_CONFIG32 \
197 _IOWR(MDSS_ROTATOR_IOCTL_MAGIC, 2, compat_caddr_t)
198
199/* queue the rotation request */
200#define MDSS_ROTATION_REQUEST32 \
201 _IOWR(MDSS_ROTATOR_IOCTL_MAGIC, 3, compat_caddr_t)
202
203/* close a rotation session with the specified rotation session ID */
204#define MDSS_ROTATION_CLOSE32 \
205 _IOW(MDSS_ROTATOR_IOCTL_MAGIC, 4, unsigned int)
206
207struct mdp_rotation_request32 {
208 uint32_t version;
209 uint32_t flags;
210 uint32_t count;
211 compat_caddr_t list;
212 uint32_t reserved[6];
213};
214#endif
215
216static inline int __compare_session_item_rect(
217 struct mdp_rotation_buf_info *s_rect,
218 struct mdp_rect *i_rect, uint32_t i_fmt, bool src)
219{
220 if ((s_rect->width != i_rect->w) || (s_rect->height != i_rect->h) ||
221 (s_rect->format != i_fmt)) {
222 pr_err("%s: session{%u,%u}f:%u mismatch from item{%u,%u}f:%u\n",
223 (src ? "src":"dst"), s_rect->width, s_rect->height,
224 s_rect->format, i_rect->w, i_rect->h, i_fmt);
225 return -EINVAL;
226 }
227 return 0;
228}
229
230/*
231 * Compare all important flag bits associated with rotation between session
232 * config and item request. Format and roi validation is done during open
233 * session and is based certain defining bits. If these defining bits are
234 * different in item request, there is a possibility that rotation item
235 * is not a valid configuration.
236 */
237static inline int __compare_session_rotations(uint32_t cfg_flag,
238 uint32_t item_flag)
239{
240 cfg_flag &= MDSS_MDP_DEFINING_FLAG_BITS;
241 item_flag &= MDSS_MDP_DEFINING_FLAG_BITS;
242 if (cfg_flag != item_flag) {
243 pr_err("Rotation degree request different from open session\n");
244 return -EINVAL;
245 }
246 return 0;
247}
248
249#endif