0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #ifndef MEDIA_REQUEST_H
0013 #define MEDIA_REQUEST_H
0014
0015 #include <linux/list.h>
0016 #include <linux/slab.h>
0017 #include <linux/spinlock.h>
0018 #include <linux/refcount.h>
0019
0020 #include <media/media-device.h>
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037 enum media_request_state {
0038 MEDIA_REQUEST_STATE_IDLE,
0039 MEDIA_REQUEST_STATE_VALIDATING,
0040 MEDIA_REQUEST_STATE_QUEUED,
0041 MEDIA_REQUEST_STATE_COMPLETE,
0042 MEDIA_REQUEST_STATE_CLEANING,
0043 MEDIA_REQUEST_STATE_UPDATING,
0044 NR_OF_MEDIA_REQUEST_STATE,
0045 };
0046
0047 struct media_request_object;
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062 struct media_request {
0063 struct media_device *mdev;
0064 struct kref kref;
0065 char debug_str[TASK_COMM_LEN + 11];
0066 enum media_request_state state;
0067 unsigned int updating_count;
0068 unsigned int access_count;
0069 struct list_head objects;
0070 unsigned int num_incomplete_objects;
0071 wait_queue_head_t poll_wait;
0072 spinlock_t lock;
0073 };
0074
0075 #ifdef CONFIG_MEDIA_CONTROLLER
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086 static inline int __must_check
0087 media_request_lock_for_access(struct media_request *req)
0088 {
0089 unsigned long flags;
0090 int ret = -EBUSY;
0091
0092 spin_lock_irqsave(&req->lock, flags);
0093 if (req->state == MEDIA_REQUEST_STATE_COMPLETE) {
0094 req->access_count++;
0095 ret = 0;
0096 }
0097 spin_unlock_irqrestore(&req->lock, flags);
0098
0099 return ret;
0100 }
0101
0102
0103
0104
0105
0106
0107
0108
0109
0110
0111 static inline void media_request_unlock_for_access(struct media_request *req)
0112 {
0113 unsigned long flags;
0114
0115 spin_lock_irqsave(&req->lock, flags);
0116 if (!WARN_ON(!req->access_count))
0117 req->access_count--;
0118 spin_unlock_irqrestore(&req->lock, flags);
0119 }
0120
0121
0122
0123
0124
0125
0126
0127
0128
0129
0130
0131 static inline int __must_check
0132 media_request_lock_for_update(struct media_request *req)
0133 {
0134 unsigned long flags;
0135 int ret = 0;
0136
0137 spin_lock_irqsave(&req->lock, flags);
0138 if (req->state == MEDIA_REQUEST_STATE_IDLE ||
0139 req->state == MEDIA_REQUEST_STATE_UPDATING) {
0140 req->state = MEDIA_REQUEST_STATE_UPDATING;
0141 req->updating_count++;
0142 } else {
0143 ret = -EBUSY;
0144 }
0145 spin_unlock_irqrestore(&req->lock, flags);
0146
0147 return ret;
0148 }
0149
0150
0151
0152
0153
0154
0155
0156
0157
0158
0159 static inline void media_request_unlock_for_update(struct media_request *req)
0160 {
0161 unsigned long flags;
0162
0163 spin_lock_irqsave(&req->lock, flags);
0164 WARN_ON(req->updating_count <= 0);
0165 if (!--req->updating_count)
0166 req->state = MEDIA_REQUEST_STATE_IDLE;
0167 spin_unlock_irqrestore(&req->lock, flags);
0168 }
0169
0170
0171
0172
0173
0174
0175
0176
0177 static inline void media_request_get(struct media_request *req)
0178 {
0179 kref_get(&req->kref);
0180 }
0181
0182
0183
0184
0185
0186
0187
0188
0189
0190 void media_request_put(struct media_request *req);
0191
0192
0193
0194
0195
0196
0197
0198
0199
0200
0201
0202
0203
0204
0205
0206
0207 struct media_request *
0208 media_request_get_by_fd(struct media_device *mdev, int request_fd);
0209
0210
0211
0212
0213
0214
0215
0216
0217
0218 int media_request_alloc(struct media_device *mdev,
0219 int *alloc_fd);
0220
0221 #else
0222
0223 static inline void media_request_get(struct media_request *req)
0224 {
0225 }
0226
0227 static inline void media_request_put(struct media_request *req)
0228 {
0229 }
0230
0231 static inline struct media_request *
0232 media_request_get_by_fd(struct media_device *mdev, int request_fd)
0233 {
0234 return ERR_PTR(-EBADR);
0235 }
0236
0237 #endif
0238
0239
0240
0241
0242
0243
0244
0245
0246
0247 struct media_request_object_ops {
0248 int (*prepare)(struct media_request_object *object);
0249 void (*unprepare)(struct media_request_object *object);
0250 void (*queue)(struct media_request_object *object);
0251 void (*unbind)(struct media_request_object *object);
0252 void (*release)(struct media_request_object *object);
0253 };
0254
0255
0256
0257
0258
0259
0260
0261
0262
0263
0264
0265
0266
0267
0268
0269 struct media_request_object {
0270 const struct media_request_object_ops *ops;
0271 void *priv;
0272 struct media_request *req;
0273 struct list_head list;
0274 struct kref kref;
0275 bool completed;
0276 };
0277
0278 #ifdef CONFIG_MEDIA_CONTROLLER
0279
0280
0281
0282
0283
0284
0285
0286
0287 static inline void media_request_object_get(struct media_request_object *obj)
0288 {
0289 kref_get(&obj->kref);
0290 }
0291
0292
0293
0294
0295
0296
0297
0298
0299
0300 void media_request_object_put(struct media_request_object *obj);
0301
0302
0303
0304
0305
0306
0307
0308
0309
0310
0311
0312
0313
0314
0315
0316
0317 struct media_request_object *
0318 media_request_object_find(struct media_request *req,
0319 const struct media_request_object_ops *ops,
0320 void *priv);
0321
0322
0323
0324
0325
0326
0327
0328
0329
0330
0331 void media_request_object_init(struct media_request_object *obj);
0332
0333
0334
0335
0336
0337
0338
0339
0340
0341
0342
0343
0344
0345
0346
0347
0348
0349
0350
0351
0352
0353
0354
0355
0356 int media_request_object_bind(struct media_request *req,
0357 const struct media_request_object_ops *ops,
0358 void *priv, bool is_buffer,
0359 struct media_request_object *obj);
0360
0361
0362
0363
0364
0365
0366
0367
0368 void media_request_object_unbind(struct media_request_object *obj);
0369
0370
0371
0372
0373
0374
0375
0376
0377
0378 void media_request_object_complete(struct media_request_object *obj);
0379
0380 #else
0381
0382 static inline int __must_check
0383 media_request_lock_for_access(struct media_request *req)
0384 {
0385 return -EINVAL;
0386 }
0387
0388 static inline void media_request_unlock_for_access(struct media_request *req)
0389 {
0390 }
0391
0392 static inline int __must_check
0393 media_request_lock_for_update(struct media_request *req)
0394 {
0395 return -EINVAL;
0396 }
0397
0398 static inline void media_request_unlock_for_update(struct media_request *req)
0399 {
0400 }
0401
0402 static inline void media_request_object_get(struct media_request_object *obj)
0403 {
0404 }
0405
0406 static inline void media_request_object_put(struct media_request_object *obj)
0407 {
0408 }
0409
0410 static inline struct media_request_object *
0411 media_request_object_find(struct media_request *req,
0412 const struct media_request_object_ops *ops,
0413 void *priv)
0414 {
0415 return NULL;
0416 }
0417
0418 static inline void media_request_object_init(struct media_request_object *obj)
0419 {
0420 obj->ops = NULL;
0421 obj->req = NULL;
0422 }
0423
0424 static inline int media_request_object_bind(struct media_request *req,
0425 const struct media_request_object_ops *ops,
0426 void *priv, bool is_buffer,
0427 struct media_request_object *obj)
0428 {
0429 return 0;
0430 }
0431
0432 static inline void media_request_object_unbind(struct media_request_object *obj)
0433 {
0434 }
0435
0436 static inline void media_request_object_complete(struct media_request_object *obj)
0437 {
0438 }
0439
0440 #endif
0441
0442 #endif