bcm27xx: switch to 5.15
[openwrt/staging/chunkeey.git] / target / linux / bcm27xx / patches-5.10 / 950-0613-RFC-media-Add-media_request_-pin-unpin-API.patch
1 From 739b9c6a80058d1aaeb66fdfe2910662f7f411ad Mon Sep 17 00:00:00 2001
2 From: Ezequiel Garcia <ezequiel@collabora.com>
3 Date: Sun, 21 Mar 2021 16:38:54 -0300
4 Subject: [PATCH] RFC: media: Add media_request_{pin,unpin} API
5
6 This is probably not the API we will want to add, but it
7 should show what semantics are needed by drivers.
8
9 The goal is to allow the OUTPUT (aka source) buffer and the
10 controls associated to a request to be released from the request,
11 and in particular return the OUTPUT buffer back to userspace,
12 without signalling the media request fd.
13
14 This is useful for devices that are able to pre-process
15 the OUTPUT buffer, therefore able to release it before
16 the decoding is finished. These drivers should signal
17 the media request fd only after the CAPTURE buffer is done.
18
19 Tested-by: John Cox <jc@kynesim.co.uk>
20 Signed-off-by: Ezequiel Garcia <ezequiel@collabora.com>
21 ---
22 drivers/media/mc/mc-request.c | 35 +++++++++++++++++++++++++++++++++++
23 include/media/media-request.h | 12 ++++++++++++
24 2 files changed, 47 insertions(+)
25
26 --- a/drivers/media/mc/mc-request.c
27 +++ b/drivers/media/mc/mc-request.c
28 @@ -504,3 +504,38 @@ unlock:
29 media_request_put(req);
30 }
31 EXPORT_SYMBOL_GPL(media_request_object_complete);
32 +
33 +void media_request_pin(struct media_request *req)
34 +{
35 + unsigned long flags;
36 +
37 + spin_lock_irqsave(&req->lock, flags);
38 + if (WARN_ON(req->state != MEDIA_REQUEST_STATE_QUEUED))
39 + goto unlock;
40 + req->num_incomplete_objects++;
41 +unlock:
42 + spin_unlock_irqrestore(&req->lock, flags);
43 +}
44 +EXPORT_SYMBOL_GPL(media_request_pin);
45 +
46 +void media_request_unpin(struct media_request *req)
47 +{
48 + unsigned long flags;
49 + bool completed = false;
50 +
51 + spin_lock_irqsave(&req->lock, flags);
52 + if (WARN_ON(!req->num_incomplete_objects) ||
53 + WARN_ON(req->state != MEDIA_REQUEST_STATE_QUEUED))
54 + goto unlock;
55 +
56 + if (!--req->num_incomplete_objects) {
57 + req->state = MEDIA_REQUEST_STATE_COMPLETE;
58 + wake_up_interruptible_all(&req->poll_wait);
59 + completed = true;
60 + }
61 +unlock:
62 + spin_unlock_irqrestore(&req->lock, flags);
63 + if (completed)
64 + media_request_put(req);
65 +}
66 +EXPORT_SYMBOL_GPL(media_request_unpin);
67 --- a/include/media/media-request.h
68 +++ b/include/media/media-request.h
69 @@ -189,6 +189,10 @@ static inline void media_request_get(str
70 */
71 void media_request_put(struct media_request *req);
72
73 +void media_request_pin(struct media_request *req);
74 +
75 +void media_request_unpin(struct media_request *req);
76 +
77 /**
78 * media_request_get_by_fd - Get a media request by fd
79 *
80 @@ -228,6 +232,14 @@ static inline void media_request_put(str
81 {
82 }
83
84 +static inline void media_request_pin(struct media_request *req)
85 +{
86 +}
87 +
88 +static inline void media_request_unpin(struct media_request *req)
89 +{
90 +}
91 +
92 static inline struct media_request *
93 media_request_get_by_fd(struct media_device *mdev, int request_fd)
94 {