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