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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
|
/*
* Copyright (C) 2012 Spreadtrum Communications Inc.
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
* may be copied, distributed, and modified under those terms.
*
* 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.
*/
#include <linux/compat.h>
#include <linux/fs.h>
#include <linux/uaccess.h>
#include <video/sprd_isp.h>
#include "compat_isp_drv.h"
struct compat_isp_capability {
uint32_t isp_id;
uint32_t index;
compat_uptr_t property_param;
};
struct compat_isp_io_param {
uint32_t isp_id;
uint32_t sub_block;
uint32_t property;
compat_uptr_t property_param;
};
struct compat_isp_reg_param {
compat_ulong_t reg_param;
uint32_t counts;
};
struct compat_isp_reg_bits {
compat_ulong_t reg_addr;
compat_ulong_t reg_value;
};
#define COMPAT_ISP_IO_CAPABILITY _IOR(ISP_IO_MAGIC, 0, struct compat_isp_capability)
#define COMPAT_ISP_IO_READ _IOR(ISP_IO_MAGIC, 2, struct compat_isp_reg_param)
#define COMPAT_ISP_IO_WRITE _IOW(ISP_IO_MAGIC, 3, struct compat_isp_reg_param)
#define CAMPAT_ISP_IO_CFG_PARAM _IOWR(ISP_IO_MAGIC, 7, struct compat_isp_io_param)
#define CAMPAT_ISP_REG_READ _IOR(ISP_IO_MAGIC, 8, struct compat_isp_reg_bits)
static int compat_get_capability_param(
struct compat_isp_capability __user *data32,
struct isp_capability __user *data)
{
int err = 0;
uint32_t tmp;
compat_uptr_t parm;
err = get_user(tmp, &data32->isp_id);
err |= put_user(tmp, &data->isp_id);
err |= get_user(tmp, &data32->index);
err |= put_user(tmp, &data->index);
err |= get_user(parm, &data32->property_param);
err |= put_user(parm, &data->property_param);
return err;
}
static int compat_get_cfg_param(
struct compat_isp_io_param __user *data32,
struct isp_io_param __user *data)
{
int err =0;
uint32_t tmp;
compat_uptr_t parm;
err = get_user(tmp, &data32->isp_id);
err |= put_user(tmp, &data->isp_id);
err |= get_user(tmp, &data32->sub_block);
err |= put_user(tmp, &data->sub_block);
err |= get_user(tmp, &data32->property);
err |= put_user(tmp, &data->property);
err |= get_user(parm, &data32->property_param);
err |= put_user(parm, &data->property_param);
return err;
}
static int compat_get_rw_param(
struct compat_isp_reg_param __user *data32,
struct isp_reg_param __user *data)
{
int err = 0;
compat_ulong_t addr;
uint32_t cnt;
err = get_user(addr, &data32->reg_param);
err |= put_user(addr, &data->reg_param);
err |= get_user(cnt, &data32->counts);
err |= put_user(cnt, &data->counts);
return err;
}
static int compat_get_rw_param_detail(
struct isp_reg_param __user *data)
{
int err = 0;
int i;
int cnt;
compat_ulong_t addr;
compat_ulong_t val;
struct compat_isp_reg_bits __user *data32;
struct isp_reg_bits __user *reg_data;
struct isp_reg_bits __user *data_tmp;
if (NULL == data) {
printk("compat_get_rw_param_detail: data is NULL.\n");
return -EFAULT;
}
cnt = data->counts;
data32 = compat_ptr(data->reg_param);
reg_data = (struct isp_reg_bits __user *)((unsigned long)data + sizeof(struct isp_reg_param));
data->reg_param = reg_data;
if (NULL == reg_data) {
printk("compat_get_rw_param_detail: reg_data is NULL.\n");
return -EFAULT;
}
data_tmp = reg_data;
for (i = 0; i < cnt; i++) {
err = get_user(addr, &data32->reg_addr);
err |= put_user(addr, &data_tmp->reg_addr);
err |= get_user(val, &data32->reg_value);
err |= put_user(val, &data_tmp->reg_value);
if (err) {
printk("compat_get_rw_param_detail: failed to get register addr&val cnt %d err %d\n", cnt, err);
break;
}
data32++;
data_tmp++;
}
return err;
}
static int compat_put_read_param(
struct compat_isp_reg_param __user *data32,
struct isp_reg_param __user *data)
{
int err = 0;
int i;
int cnt;
compat_ulong_t val;
struct compat_isp_reg_bits __user *reg_data32;
struct isp_reg_bits __user *reg_data;
cnt = data->counts;
reg_data32 = (struct compat_isp_reg_bits __user *)data32->reg_param;
reg_data = (struct isp_reg_bits __user *)data->reg_param;
for (i = 0; i < cnt; i++) {
err = get_user(val, ®_data->reg_value);
err |= put_user(val, ®_data32->reg_value);
if (err) {
printk("compat_put_read_param: failed to get register val err %d\n", err);
break;
}
reg_data32++;
reg_data++;
}
return err;
}
long compat_isp_ioctl(struct file *file, unsigned int cmd, unsigned long param)
{
long ret;
int err = 0;
void __user *up = compat_ptr(param);
if (!file->f_op || !file->f_op->unlocked_ioctl)
return -ENOTTY;
switch (cmd) {
case ISP_IO_IRQ:
case ISP_IO_RST:
case ISP_IO_STOP:
case ISP_IO_INT:
ret = file->f_op->unlocked_ioctl(file, cmd, (unsigned long)up);
break;
case COMPAT_ISP_IO_CAPABILITY:
{
struct compat_isp_capability __user *data32;
struct isp_capability __user *data;
data32 = compat_ptr(param);
data = compat_alloc_user_space(sizeof(*data));
if (NULL == data) {
printk("compat_isp_ioctl: failed to compat_alloc_user_space.\n");
return -EFAULT;
}
err = compat_get_capability_param(data32, data);
if (err) {
printk("compat_isp_ioctl: failed to get capability param.\n");
return err;
}
ret = file->f_op->unlocked_ioctl(file, ISP_IO_CAPABILITY, (unsigned long)data);
break;
}
case COMPAT_ISP_IO_READ:
{
struct compat_isp_reg_param __user *data32;
struct isp_reg_param __user *data;
uint32_t cnt;
data32 = compat_ptr(param);
err = get_user(cnt, &data32->counts);
data = compat_alloc_user_space(sizeof(struct isp_reg_param) + cnt*sizeof(struct isp_reg_bits));
if (NULL == data) {
printk("compat_isp_ioctl: failed to compat_alloc_user_space.\n");
return -EFAULT;
}
err = compat_get_rw_param(data32, data);
if (err) {
printk("compat_isp_ioctl: failed to get isp_reg_param.\n");
return err;
}
err = compat_get_rw_param_detail(data);
if (err) {
printk("compat_isp_ioctl: failed to get isp_reg_param detail.\n");
return err;
}
ret = file->f_op->unlocked_ioctl(file, ISP_IO_READ, (unsigned long)data);
err = compat_put_read_param(data32, data);
ret = ret ? ret : err;
break;
}
case CAMPAT_ISP_REG_READ:
{
struct compat_isp_reg_bits __user *data32;
struct isp_reg_bits __user *data;
unsigned long reg_cnt = 20467;
compat_ulong_t addr;
compat_ulong_t val;
int i;
int err = 0;
data32 = compat_ptr(param);
data = compat_alloc_user_space(reg_cnt * sizeof(struct isp_reg_bits));
if (NULL == data) {
printk("compat_isp_ioctl: CAMPAT_ISP_REG_READ:failed to compat_alloc_user_space.\n");
return -EFAULT;
}
ret = file->f_op->unlocked_ioctl(file, ISP_REG_READ, (unsigned long)data);
for (i = 0; i < reg_cnt; i++) {
err = get_user(val, &data->reg_value);
err |= put_user(val, &data32->reg_value);
if (err) {
printk("compat_put_read_param: CAMPAT_ISP_REG_READ:failed to get reg_value%d\n", err);
break;
}
err = get_user(val, &data->reg_addr);
err |= put_user(val, &data32->reg_addr);
if (err) {
printk("compat_put_read_param: CAMPAT_ISP_REG_READ:failed to get reg_addr%d\n", err);
break;
}
data32++;
data++;
}
ret = ret ? ret : err;
break;
}
case COMPAT_ISP_IO_WRITE:
{
struct compat_isp_reg_param __user *data32;
struct isp_reg_param __user *data;
uint32_t cnt;
data32 = compat_ptr(param);
err = get_user(cnt, &data32->counts);
if (err) {
printk("compat_isp_ioctl: failed to get register count.\n");
return err;
}
data = compat_alloc_user_space(sizeof(struct isp_reg_param) + cnt*sizeof(struct isp_reg_bits));
if (NULL == data) {
printk("compat_isp_ioctl: failed to compat_alloc_user_space.\n");
return -EFAULT;
}
err = compat_get_rw_param(data32, data);
if (err) {
printk("compat_isp_ioctl: failed to get isp_reg_param.\n");
return err;
}
err = compat_get_rw_param_detail(data);
if (err) {
printk("compat_isp_ioctl: failed to get isp_reg_param detail.\n");
return err;
}
ret = file->f_op->unlocked_ioctl(file, ISP_IO_WRITE, (unsigned long)data);
break;
}
case CAMPAT_ISP_IO_CFG_PARAM:
{
struct compat_isp_io_param __user *data32;
struct isp_io_param __user *data;
data32 = compat_ptr(param);
data = compat_alloc_user_space(sizeof(*data));
if (NULL == data) {
printk("compat_isp_ioctl: failed to compat_alloc_user_space.\n");
return -EFAULT;
}
err = compat_get_cfg_param(data32, data);
if (err) {
printk("compat_isp_ioctl: failed to get cfg param.\n");
return err;
}
ret = file->f_op->unlocked_ioctl(file, ISP_IO_CFG_PARAM, (unsigned long)data);
break;
}
default:
printk("compat_isp_ioctl, don't support cmd 0x%x", cmd);
break;
}
exit:
return ret;
}
|