linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Michael Tretter <m.tretter@pengutronix.de>
To: linux-media@vger.kernel.org
Cc: hverkuil-cisco@xs4all.nl, kernel@pengutronix.de,
	Michael Tretter <m.tretter@pengutronix.de>
Subject: [PATCH 15/18] media: allegro: verify source and destination buffer in VCU response
Date: Mon, 17 Feb 2020 16:13:55 +0100	[thread overview]
Message-ID: <20200217151358.5695-16-m.tretter@pengutronix.de> (raw)
In-Reply-To: <20200217151358.5695-1-m.tretter@pengutronix.de>

The PUT_STREAM_BUFFER and ENCODE_FRAME request have fields that allow to
pass arbitrary 64 bit values through the firmware to the ENCODE_FRAME
response. Use these values to verify that the buffers when finishing the
frame are actually the same buffers that have been sent for encoding a
frame.

Signed-off-by: Michael Tretter <m.tretter@pengutronix.de>
---
 .../staging/media/allegro-dvt/allegro-core.c  | 21 ++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/drivers/staging/media/allegro-dvt/allegro-core.c b/drivers/staging/media/allegro-dvt/allegro-core.c
index cedb09ea649f..4f525920c194 100644
--- a/drivers/staging/media/allegro-dvt/allegro-core.c
+++ b/drivers/staging/media/allegro-dvt/allegro-core.c
@@ -1198,7 +1198,8 @@ static int allegro_mcu_send_destroy_channel(struct allegro_dev *dev,
 static int allegro_mcu_send_put_stream_buffer(struct allegro_dev *dev,
 					      struct allegro_channel *channel,
 					      dma_addr_t paddr,
-					      unsigned long size)
+					      unsigned long size,
+					      u64 stream_id)
 {
 	struct mcu_msg_put_stream_buffer msg;
 
@@ -1212,7 +1213,7 @@ static int allegro_mcu_send_put_stream_buffer(struct allegro_dev *dev,
 	msg.mcu_addr = to_mcu_addr(dev, paddr);
 	msg.size = size;
 	msg.offset = ENCODER_STREAM_OFFSET;
-	msg.stream_id = 0; /* copied to mcu_msg_encode_frame_response */
+	msg.stream_id = stream_id; /* copied to mcu_msg_encode_frame_response */
 
 	allegro_mbox_write(dev, &dev->mbox_command, &msg, sizeof(msg));
 	allegro_mcu_interrupt(dev);
@@ -1222,7 +1223,8 @@ static int allegro_mcu_send_put_stream_buffer(struct allegro_dev *dev,
 
 static int allegro_mcu_send_encode_frame(struct allegro_dev *dev,
 					 struct allegro_channel *channel,
-					 dma_addr_t src_y, dma_addr_t src_uv)
+					 dma_addr_t src_y, dma_addr_t src_uv,
+					 u64 src_handle)
 {
 	struct mcu_msg_encode_frame msg;
 
@@ -1235,7 +1237,7 @@ static int allegro_mcu_send_encode_frame(struct allegro_dev *dev,
 	msg.encoding_options = AL_OPT_FORCE_LOAD;
 	msg.pps_qp = 26; /* qp are relative to 26 */
 	msg.user_param = 0; /* copied to mcu_msg_encode_frame_response */
-	msg.src_handle = 0; /* copied to mcu_msg_encode_frame_response */
+	msg.src_handle = src_handle; /* copied to mcu_msg_encode_frame_response */
 	msg.src_y = to_codec_addr(dev, src_y);
 	msg.src_uv = to_codec_addr(dev, src_uv);
 	msg.stride = channel->stride;
@@ -1584,8 +1586,13 @@ static void allegro_channel_finish_frame(struct allegro_channel *channel,
 	ssize_t free;
 
 	src_buf = v4l2_m2m_src_buf_remove(channel->fh.m2m_ctx);
-
 	dst_buf = v4l2_m2m_dst_buf_remove(channel->fh.m2m_ctx);
+
+	if ((u64)src_buf != msg->src_handle || (u64)dst_buf != msg->stream_id)
+		v4l2_err(&dev->v4l2_dev,
+			 "channel %d: check failed\n",
+			 channel->mcu_channel_id);
+
 	dst_buf->sequence = channel->csequence++;
 
 	if (msg->error_code & AL_ERROR) {
@@ -2954,14 +2961,14 @@ static void allegro_device_run(void *priv)
 	dst_buf = v4l2_m2m_next_dst_buf(channel->fh.m2m_ctx);
 	dst_addr = vb2_dma_contig_plane_dma_addr(&dst_buf->vb2_buf, 0);
 	dst_size = vb2_plane_size(&dst_buf->vb2_buf, 0);
-	allegro_mcu_send_put_stream_buffer(dev, channel, dst_addr, dst_size);
+	allegro_mcu_send_put_stream_buffer(dev, channel, dst_addr, dst_size, (u64)dst_buf);
 
 	src_buf = v4l2_m2m_next_src_buf(channel->fh.m2m_ctx);
 	src_buf->sequence = channel->osequence++;
 
 	src_y = vb2_dma_contig_plane_dma_addr(&src_buf->vb2_buf, 0);
 	src_uv = src_y + (channel->stride * channel->height);
-	allegro_mcu_send_encode_frame(dev, channel, src_y, src_uv);
+	allegro_mcu_send_encode_frame(dev, channel, src_y, src_uv, (u64)src_buf);
 }
 
 static const struct v4l2_m2m_ops allegro_m2m_ops = {
-- 
2.20.1


  parent reply	other threads:[~2020-02-17 15:14 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-17 15:13 [PATCH 00/18] media: allegro: fixes and new features Michael Tretter
2020-02-17 15:13 ` [PATCH 01/18] media: allegro: print message on mcu error Michael Tretter
2020-02-17 15:13 ` [PATCH 02/18] media: allegro: fail encoding only on actual errors Michael Tretter
2020-02-17 15:13 ` [PATCH 03/18] media: allegro: fix type of gop_length in channel_create message Michael Tretter
2020-02-17 15:13 ` [PATCH 04/18] media: allegro: remove unknown39 field from create_channel Michael Tretter
2020-02-17 15:13 ` [PATCH 05/18] media: allegro: start a GOP with an IDR frame Michael Tretter
2020-02-17 15:13 ` [PATCH 06/18] media: allegro: fix calculation of CPB size Michael Tretter
2020-02-17 15:13 ` [PATCH 07/18] media: allegro: fix reset if WAKEUP has not been set properly Michael Tretter
2020-02-17 15:13 ` [PATCH 08/18] media: allegro: extract mcu and codec address calculation Michael Tretter
2020-02-17 15:13 ` [PATCH 09/18] media: allegro: warn if response message has an unexpected size Michael Tretter
2020-02-17 15:13 ` [PATCH 10/18] media: allegro: skip filler data if possible Michael Tretter
2020-02-17 15:13 ` [PATCH 11/18] media: allegro: make frame rate configurable Michael Tretter
2020-02-17 15:13 ` [PATCH 12/18] media: allegro: make QP configurable Michael Tretter
2020-02-17 15:13 ` [PATCH 13/18] media: allegro: read bitrate mode directly from control Michael Tretter
2020-02-17 15:13 ` [PATCH 14/18] media: allegro: handle dependency of bitrate and bitrate_peak Michael Tretter
2020-02-25 14:14   ` Hans Verkuil
2020-02-17 15:13 ` Michael Tretter [this message]
2020-02-19 15:41   ` [PATCH 15/18] media: allegro: verify source and destination buffer in VCU response kbuild test robot
2020-02-17 15:13 ` [PATCH 16/18] media: allegro: pass buffers through firmware Michael Tretter
2020-02-25 14:09   ` Hans Verkuil
2020-03-03 15:40     ` Michael Tretter
2020-02-17 15:13 ` [PATCH 17/18] media: allegro: move mail definitions to separate file Michael Tretter
2020-02-17 15:13 ` [PATCH 18/18] media: allegro: create new struct for channel parameters Michael Tretter
2020-02-25 14:20 ` [PATCH 00/18] media: allegro: fixes and new features Hans Verkuil
2020-03-03 15:42   ` Michael Tretter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200217151358.5695-16-m.tretter@pengutronix.de \
    --to=m.tretter@pengutronix.de \
    --cc=hverkuil-cisco@xs4all.nl \
    --cc=kernel@pengutronix.de \
    --cc=linux-media@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).