summaryrefslogtreecommitdiff
path: root/drivers/video/fbdev/msm/mdss_rotator_internal.h
blob: 30d460abf5b7b3e8aacbd269474a70af240ddaf3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
/* Copyright (c) 2014-2016, The Linux Foundation. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 and
 * only version 2 as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 */

#ifndef MDSS_MDP_ROTATOR_INTERNAL_H
#define MDSS_MDP_ROTATOR_INTERNAL_H

#include <linux/list.h>
#include <linux/file.h>
#include <linux/mdss_rotator.h>
#include <linux/mutex.h>
#include <linux/types.h>
#include <linux/cdev.h>
#include <sync.h>
#include <sw_sync.h>

#include  "mdss_mdp.h"

/*
 * Defining characteristics about rotation work, that has corresponding
 * fmt and roi checks in open session
 */
#define MDSS_MDP_DEFINING_FLAG_BITS MDP_ROTATION_90

struct mdss_rot_entry;
struct mdss_rot_perf;

enum mdss_rotator_clk_type {
	MDSS_CLK_ROTATOR_AHB,
	MDSS_CLK_ROTATOR_CORE,
	MDSS_CLK_ROTATOR_END_IDX,
};

/*
 * placeholder for performance profiling
 * or debug support, not used currently
 */
struct mdss_rot_entry_cb_intf {
	void (*pre_commit)(struct mdss_rot_entry *entry, void *data);
	void (*post_commit)(struct mdss_rot_entry *entry,
		void *data, int status);
};

struct mdss_rot_timeline {
	struct mutex lock;
	struct sw_sync_timeline *timeline;
	u32 next_value;
	char fence_name[32];
};

struct mdss_rot_hw_resource {
	struct mdss_mdp_ctl *ctl;
	struct mdss_mdp_mixer *mixer;
	struct mdss_mdp_pipe *pipe;
	struct mdss_mdp_writeback *wb;
	u32 pipe_id;
	u32 wb_id;

	u32 pending_count;
	struct mdss_rot_entry *workload;
};

struct mdss_rot_queue {
	struct workqueue_struct *rot_work_queue;
	struct mdss_rot_timeline timeline;

	struct mutex hw_lock;
	struct mdss_rot_hw_resource *hw;
};

struct mdss_rot_entry_container {
	struct list_head list;
	u32 flags;
	u32 count;
	atomic_t pending_count;
	struct mdss_rot_entry *entries;
};

struct mdss_rot_entry {
	struct mdp_rotation_item item;
	struct work_struct commit_work;

	struct mdss_rot_queue *queue;
	struct mdss_rot_entry_container *request;

	struct mdss_mdp_data src_buf;
	struct mdss_mdp_data dst_buf;

	struct sync_fence *input_fence;

	int output_fence_fd;
	struct sync_fence *output_fence;
	bool output_signaled;

	u32 dnsc_factor_w;
	u32 dnsc_factor_h;

	struct mdss_rot_entry_cb_intf intf;
	void *intf_data;

	struct mdss_rot_perf *perf;
	bool work_assigned; /* Used when cleaning up work_distribution */
};

struct mdss_rot_perf {
	struct list_head list;
	struct mdp_rotation_config config;
	unsigned long clk_rate;
	u64 bw;
	struct mutex work_dis_lock;
	u32 *work_distribution;
	int last_wb_idx; /* last known wb index, used when above count is 0 */
};

struct mdss_rot_file_private {
	struct list_head list;

	struct mutex req_lock;
	struct list_head req_list;

	struct mutex perf_lock;
	struct list_head perf_list;

	struct file *file;
};

struct mdss_rot_bus_data_type {
	struct msm_bus_scale_pdata *bus_scale_pdata;
	u32 bus_hdl;
	u32 curr_bw_uc_idx;
	u64 curr_quota_val;
};

struct mdss_rot_mgr {
	struct mutex lock;

	atomic_t device_suspended;

	u32 session_id_generator;

	struct platform_device *pdev;

	dev_t dev_num;
	struct cdev cdev;
	struct class *class;
	struct device *device;

	/*
	 * mangaing rotation queues, depends on
	 * how many hw pipes availabe on the system
	 */
	int queue_count;
	struct mdss_rot_queue *queues;

	struct mutex file_lock;
	/*
	 * managing all the open file sessions to bw calculations,
	 * and resource clean up during suspend
	 */
	struct list_head file_list;

	struct mutex bus_lock;
	u64 pending_close_bw_vote;
	struct mdss_rot_bus_data_type data_bus;
	struct mdss_rot_bus_data_type reg_bus;

	/* Module power is only used for regulator management */
	struct dss_module_power module_power;
	bool regulator_enable;

	struct mutex clk_lock;
	int res_ref_cnt;
	struct clk *rot_clk[MDSS_CLK_ROTATOR_END_IDX];
	int rot_enable_clk_cnt;

	bool has_downscale;
	bool has_ubwc;
};

#ifdef CONFIG_COMPAT

/* open a rotation session */
#define MDSS_ROTATION_OPEN32 \
	_IOWR(MDSS_ROTATOR_IOCTL_MAGIC, 1, compat_caddr_t)

/* change the rotation session configuration */
#define MDSS_ROTATION_CONFIG32 \
	_IOWR(MDSS_ROTATOR_IOCTL_MAGIC, 2, compat_caddr_t)

/* queue the rotation request */
#define MDSS_ROTATION_REQUEST32 \
	_IOWR(MDSS_ROTATOR_IOCTL_MAGIC, 3, compat_caddr_t)

/* close a rotation session with the specified rotation session ID */
#define MDSS_ROTATION_CLOSE32 \
	_IOW(MDSS_ROTATOR_IOCTL_MAGIC, 4, unsigned int)

struct mdp_rotation_request32 {
	uint32_t version;
	uint32_t flags;
	uint32_t count;
	compat_caddr_t list;
	uint32_t reserved[6];
};
#endif

static inline int __compare_session_item_rect(
	struct mdp_rotation_buf_info *s_rect,
	struct mdp_rect *i_rect, uint32_t i_fmt, bool src)
{
	if ((s_rect->width != i_rect->w) || (s_rect->height != i_rect->h) ||
			(s_rect->format != i_fmt)) {
		pr_err("%s: session{%u,%u}f:%u mismatch from item{%u,%u}f:%u\n",
			(src ? "src":"dst"), s_rect->width, s_rect->height,
			s_rect->format, i_rect->w, i_rect->h, i_fmt);
		return -EINVAL;
	}
	return 0;
}

/*
 * Compare all important flag bits associated with rotation between session
 * config and item request. Format and roi validation is done during open
 * session and is based certain defining bits. If these defining bits are
 * different in item request, there is a possibility that rotation item
 * is not a valid configuration.
 */
static inline int __compare_session_rotations(uint32_t cfg_flag,
	uint32_t item_flag)
{
	cfg_flag &= MDSS_MDP_DEFINING_FLAG_BITS;
	item_flag &= MDSS_MDP_DEFINING_FLAG_BITS;
	if (cfg_flag != item_flag) {
		pr_err("Rotation degree request different from open session\n");
		return -EINVAL;
	}
	return 0;
}

#endif