diff mbox series

[2/5] rcar-vin: Remove handling of user-space buffers when stopping

Message ID 20201015231408.2399933-3-niklas.soderlund+renesas@ragnatech.se (mailing list archive)
State Accepted
Delegated to: Kieran Bingham
Headers show
Series rcar-vin: Support suspend and resume | expand

Commit Message

Niklas Söderlund Oct. 15, 2020, 11:14 p.m. UTC
When returning buffers to user-space it's no longer needed to examine
the buffers given to hardware as recent changes guarantees the only
buffer present in the hardware registers when the driver is not in the
running state is the scratch buffer.

Remove the special case and rename the function to better describe it
now only deals with buffers queued to the driver but not yet recorded in
the hardware registers.

Signed-off-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
---
 drivers/media/platform/rcar-vin/rcar-dma.c | 31 +++++-----------------
 1 file changed, 7 insertions(+), 24 deletions(-)

Comments

Jacopo Mondi Oct. 16, 2020, 3:55 p.m. UTC | #1
Hi Niklas,

On Fri, Oct 16, 2020 at 01:14:05AM +0200, Niklas Söderlund wrote:
> When returning buffers to user-space it's no longer needed to examine
> the buffers given to hardware as recent changes guarantees the only
> buffer present in the hardware registers when the driver is not in the
> running state is the scratch buffer.
>
> Remove the special case and rename the function to better describe it
> now only deals with buffers queued to the driver but not yet recorded in
> the hardware registers.
>
> Signed-off-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>

Reviewed-by: Jacopo Mondi <jacopo+renesas@jmondi.org>

Thanks
  j

> ---
>  drivers/media/platform/rcar-vin/rcar-dma.c | 31 +++++-----------------
>  1 file changed, 7 insertions(+), 24 deletions(-)
>
> diff --git a/drivers/media/platform/rcar-vin/rcar-dma.c b/drivers/media/platform/rcar-vin/rcar-dma.c
> index ca90bde8d29f77d1..680160f9f851d8a3 100644
> --- a/drivers/media/platform/rcar-vin/rcar-dma.c
> +++ b/drivers/media/platform/rcar-vin/rcar-dma.c
> @@ -1051,27 +1051,10 @@ static irqreturn_t rvin_irq(int irq, void *data)
>  }
>
>  /* Need to hold qlock before calling */
> -static void return_all_buffers(struct rvin_dev *vin,
> -			       enum vb2_buffer_state state)
> +static void return_unused_buffers(struct rvin_dev *vin,
> +				  enum vb2_buffer_state state)
>  {
>  	struct rvin_buffer *buf, *node;
> -	struct vb2_v4l2_buffer *freed[HW_BUFFER_NUM];
> -	unsigned int i, n;
> -
> -	for (i = 0; i < HW_BUFFER_NUM; i++) {
> -		freed[i] = vin->buf_hw[i].buffer;
> -		vin->buf_hw[i].buffer = NULL;
> -
> -		for (n = 0; n < i; n++) {
> -			if (freed[i] == freed[n]) {
> -				freed[i] = NULL;
> -				break;
> -			}
> -		}
> -
> -		if (freed[i])
> -			vb2_buffer_done(&freed[i]->vb2_buf, state);
> -	}
>
>  	list_for_each_entry_safe(buf, node, &vin->buf_list, list) {
>  		vb2_buffer_done(&buf->vb.vb2_buf, state);
> @@ -1271,7 +1254,7 @@ static int rvin_start_streaming(struct vb2_queue *vq, unsigned int count)
>  					  &vin->scratch_phys, GFP_KERNEL);
>  	if (!vin->scratch) {
>  		spin_lock_irqsave(&vin->qlock, flags);
> -		return_all_buffers(vin, VB2_BUF_STATE_QUEUED);
> +		return_unused_buffers(vin, VB2_BUF_STATE_QUEUED);
>  		spin_unlock_irqrestore(&vin->qlock, flags);
>  		vin_err(vin, "Failed to allocate scratch buffer\n");
>  		return -ENOMEM;
> @@ -1280,7 +1263,7 @@ static int rvin_start_streaming(struct vb2_queue *vq, unsigned int count)
>  	ret = rvin_set_stream(vin, 1);
>  	if (ret) {
>  		spin_lock_irqsave(&vin->qlock, flags);
> -		return_all_buffers(vin, VB2_BUF_STATE_QUEUED);
> +		return_unused_buffers(vin, VB2_BUF_STATE_QUEUED);
>  		spin_unlock_irqrestore(&vin->qlock, flags);
>  		goto out;
>  	}
> @@ -1291,7 +1274,7 @@ static int rvin_start_streaming(struct vb2_queue *vq, unsigned int count)
>
>  	ret = rvin_capture_start(vin);
>  	if (ret) {
> -		return_all_buffers(vin, VB2_BUF_STATE_QUEUED);
> +		return_unused_buffers(vin, VB2_BUF_STATE_QUEUED);
>  		rvin_set_stream(vin, 0);
>  	}
>
> @@ -1358,8 +1341,8 @@ static void rvin_stop_streaming(struct vb2_queue *vq)
>  		vin->state = STOPPED;
>  	}
>
> -	/* Release all active buffers */
> -	return_all_buffers(vin, VB2_BUF_STATE_ERROR);
> +	/* Return all unused buffers. */
> +	return_unused_buffers(vin, VB2_BUF_STATE_ERROR);
>
>  	spin_unlock_irqrestore(&vin->qlock, flags);
>
> --
> 2.28.0
>
diff mbox series

Patch

diff --git a/drivers/media/platform/rcar-vin/rcar-dma.c b/drivers/media/platform/rcar-vin/rcar-dma.c
index ca90bde8d29f77d1..680160f9f851d8a3 100644
--- a/drivers/media/platform/rcar-vin/rcar-dma.c
+++ b/drivers/media/platform/rcar-vin/rcar-dma.c
@@ -1051,27 +1051,10 @@  static irqreturn_t rvin_irq(int irq, void *data)
 }
 
 /* Need to hold qlock before calling */
-static void return_all_buffers(struct rvin_dev *vin,
-			       enum vb2_buffer_state state)
+static void return_unused_buffers(struct rvin_dev *vin,
+				  enum vb2_buffer_state state)
 {
 	struct rvin_buffer *buf, *node;
-	struct vb2_v4l2_buffer *freed[HW_BUFFER_NUM];
-	unsigned int i, n;
-
-	for (i = 0; i < HW_BUFFER_NUM; i++) {
-		freed[i] = vin->buf_hw[i].buffer;
-		vin->buf_hw[i].buffer = NULL;
-
-		for (n = 0; n < i; n++) {
-			if (freed[i] == freed[n]) {
-				freed[i] = NULL;
-				break;
-			}
-		}
-
-		if (freed[i])
-			vb2_buffer_done(&freed[i]->vb2_buf, state);
-	}
 
 	list_for_each_entry_safe(buf, node, &vin->buf_list, list) {
 		vb2_buffer_done(&buf->vb.vb2_buf, state);
@@ -1271,7 +1254,7 @@  static int rvin_start_streaming(struct vb2_queue *vq, unsigned int count)
 					  &vin->scratch_phys, GFP_KERNEL);
 	if (!vin->scratch) {
 		spin_lock_irqsave(&vin->qlock, flags);
-		return_all_buffers(vin, VB2_BUF_STATE_QUEUED);
+		return_unused_buffers(vin, VB2_BUF_STATE_QUEUED);
 		spin_unlock_irqrestore(&vin->qlock, flags);
 		vin_err(vin, "Failed to allocate scratch buffer\n");
 		return -ENOMEM;
@@ -1280,7 +1263,7 @@  static int rvin_start_streaming(struct vb2_queue *vq, unsigned int count)
 	ret = rvin_set_stream(vin, 1);
 	if (ret) {
 		spin_lock_irqsave(&vin->qlock, flags);
-		return_all_buffers(vin, VB2_BUF_STATE_QUEUED);
+		return_unused_buffers(vin, VB2_BUF_STATE_QUEUED);
 		spin_unlock_irqrestore(&vin->qlock, flags);
 		goto out;
 	}
@@ -1291,7 +1274,7 @@  static int rvin_start_streaming(struct vb2_queue *vq, unsigned int count)
 
 	ret = rvin_capture_start(vin);
 	if (ret) {
-		return_all_buffers(vin, VB2_BUF_STATE_QUEUED);
+		return_unused_buffers(vin, VB2_BUF_STATE_QUEUED);
 		rvin_set_stream(vin, 0);
 	}
 
@@ -1358,8 +1341,8 @@  static void rvin_stop_streaming(struct vb2_queue *vq)
 		vin->state = STOPPED;
 	}
 
-	/* Release all active buffers */
-	return_all_buffers(vin, VB2_BUF_STATE_ERROR);
+	/* Return all unused buffers. */
+	return_unused_buffers(vin, VB2_BUF_STATE_ERROR);
 
 	spin_unlock_irqrestore(&vin->qlock, flags);