This source file includes following definitions.
- media_request_lock_for_access
- media_request_unlock_for_access
- media_request_lock_for_update
- media_request_unlock_for_update
- media_request_get
- media_request_get
- media_request_put
- media_request_get_by_fd
- media_request_object_get
- media_request_lock_for_access
- media_request_unlock_for_access
- media_request_lock_for_update
- media_request_unlock_for_update
- media_request_object_get
- media_request_object_put
- media_request_object_find
- media_request_object_init
- media_request_object_bind
- media_request_object_unbind
- media_request_object_complete
1
2
3
4
5
6
7
8
9
10
11
12 #ifndef MEDIA_REQUEST_H
13 #define MEDIA_REQUEST_H
14
15 #include <linux/list.h>
16 #include <linux/slab.h>
17 #include <linux/spinlock.h>
18 #include <linux/refcount.h>
19
20 #include <media/media-device.h>
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37 enum media_request_state {
38 MEDIA_REQUEST_STATE_IDLE,
39 MEDIA_REQUEST_STATE_VALIDATING,
40 MEDIA_REQUEST_STATE_QUEUED,
41 MEDIA_REQUEST_STATE_COMPLETE,
42 MEDIA_REQUEST_STATE_CLEANING,
43 MEDIA_REQUEST_STATE_UPDATING,
44 NR_OF_MEDIA_REQUEST_STATE,
45 };
46
47 struct media_request_object;
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62 struct media_request {
63 struct media_device *mdev;
64 struct kref kref;
65 char debug_str[TASK_COMM_LEN + 11];
66 enum media_request_state state;
67 unsigned int updating_count;
68 unsigned int access_count;
69 struct list_head objects;
70 unsigned int num_incomplete_objects;
71 wait_queue_head_t poll_wait;
72 spinlock_t lock;
73 };
74
75 #ifdef CONFIG_MEDIA_CONTROLLER
76
77
78
79
80
81
82
83
84
85
86 static inline int __must_check
87 media_request_lock_for_access(struct media_request *req)
88 {
89 unsigned long flags;
90 int ret = -EBUSY;
91
92 spin_lock_irqsave(&req->lock, flags);
93 if (req->state == MEDIA_REQUEST_STATE_COMPLETE) {
94 req->access_count++;
95 ret = 0;
96 }
97 spin_unlock_irqrestore(&req->lock, flags);
98
99 return ret;
100 }
101
102
103
104
105
106
107
108
109
110
111 static inline void media_request_unlock_for_access(struct media_request *req)
112 {
113 unsigned long flags;
114
115 spin_lock_irqsave(&req->lock, flags);
116 if (!WARN_ON(!req->access_count))
117 req->access_count--;
118 spin_unlock_irqrestore(&req->lock, flags);
119 }
120
121
122
123
124
125
126
127
128
129
130
131 static inline int __must_check
132 media_request_lock_for_update(struct media_request *req)
133 {
134 unsigned long flags;
135 int ret = 0;
136
137 spin_lock_irqsave(&req->lock, flags);
138 if (req->state == MEDIA_REQUEST_STATE_IDLE ||
139 req->state == MEDIA_REQUEST_STATE_UPDATING) {
140 req->state = MEDIA_REQUEST_STATE_UPDATING;
141 req->updating_count++;
142 } else {
143 ret = -EBUSY;
144 }
145 spin_unlock_irqrestore(&req->lock, flags);
146
147 return ret;
148 }
149
150
151
152
153
154
155
156
157
158
159 static inline void media_request_unlock_for_update(struct media_request *req)
160 {
161 unsigned long flags;
162
163 spin_lock_irqsave(&req->lock, flags);
164 WARN_ON(req->updating_count <= 0);
165 if (!--req->updating_count)
166 req->state = MEDIA_REQUEST_STATE_IDLE;
167 spin_unlock_irqrestore(&req->lock, flags);
168 }
169
170
171
172
173
174
175
176
177 static inline void media_request_get(struct media_request *req)
178 {
179 kref_get(&req->kref);
180 }
181
182
183
184
185
186
187
188
189
190 void media_request_put(struct media_request *req);
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207 struct media_request *
208 media_request_get_by_fd(struct media_device *mdev, int request_fd);
209
210
211
212
213
214
215
216
217
218 int media_request_alloc(struct media_device *mdev,
219 int *alloc_fd);
220
221 #else
222
223 static inline void media_request_get(struct media_request *req)
224 {
225 }
226
227 static inline void media_request_put(struct media_request *req)
228 {
229 }
230
231 static inline struct media_request *
232 media_request_get_by_fd(struct media_device *mdev, int request_fd)
233 {
234 return ERR_PTR(-EBADR);
235 }
236
237 #endif
238
239
240
241
242
243
244
245
246
247 struct media_request_object_ops {
248 int (*prepare)(struct media_request_object *object);
249 void (*unprepare)(struct media_request_object *object);
250 void (*queue)(struct media_request_object *object);
251 void (*unbind)(struct media_request_object *object);
252 void (*release)(struct media_request_object *object);
253 };
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269 struct media_request_object {
270 const struct media_request_object_ops *ops;
271 void *priv;
272 struct media_request *req;
273 struct list_head list;
274 struct kref kref;
275 bool completed;
276 };
277
278 #ifdef CONFIG_MEDIA_CONTROLLER
279
280
281
282
283
284
285
286
287 static inline void media_request_object_get(struct media_request_object *obj)
288 {
289 kref_get(&obj->kref);
290 }
291
292
293
294
295
296
297
298
299
300 void media_request_object_put(struct media_request_object *obj);
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317 struct media_request_object *
318 media_request_object_find(struct media_request *req,
319 const struct media_request_object_ops *ops,
320 void *priv);
321
322
323
324
325
326
327
328
329
330
331 void media_request_object_init(struct media_request_object *obj);
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 int media_request_object_bind(struct media_request *req,
357 const struct media_request_object_ops *ops,
358 void *priv, bool is_buffer,
359 struct media_request_object *obj);
360
361
362
363
364
365
366
367
368 void media_request_object_unbind(struct media_request_object *obj);
369
370
371
372
373
374
375
376
377
378 void media_request_object_complete(struct media_request_object *obj);
379
380 #else
381
382 static inline int __must_check
383 media_request_lock_for_access(struct media_request *req)
384 {
385 return -EINVAL;
386 }
387
388 static inline void media_request_unlock_for_access(struct media_request *req)
389 {
390 }
391
392 static inline int __must_check
393 media_request_lock_for_update(struct media_request *req)
394 {
395 return -EINVAL;
396 }
397
398 static inline void media_request_unlock_for_update(struct media_request *req)
399 {
400 }
401
402 static inline void media_request_object_get(struct media_request_object *obj)
403 {
404 }
405
406 static inline void media_request_object_put(struct media_request_object *obj)
407 {
408 }
409
410 static inline struct media_request_object *
411 media_request_object_find(struct media_request *req,
412 const struct media_request_object_ops *ops,
413 void *priv)
414 {
415 return NULL;
416 }
417
418 static inline void media_request_object_init(struct media_request_object *obj)
419 {
420 obj->ops = NULL;
421 obj->req = NULL;
422 }
423
424 static inline int media_request_object_bind(struct media_request *req,
425 const struct media_request_object_ops *ops,
426 void *priv, bool is_buffer,
427 struct media_request_object *obj)
428 {
429 return 0;
430 }
431
432 static inline void media_request_object_unbind(struct media_request_object *obj)
433 {
434 }
435
436 static inline void media_request_object_complete(struct media_request_object *obj)
437 {
438 }
439
440 #endif
441
442 #endif