linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Benoit Parrot <bparrot@ti.com>
To: <linux-media@vger.kernel.org>, Hans Verkuil <hverkuil@xs4all.nl>
Cc: <linux-kernel@vger.kernel.org>,
	Tomi Valkeinen <tomi.valkeinen@ti.com>,
	Jyri Sarha <jsarha@ti.com>,
	Peter Ujfalusi <peter.ujfalusi@ti.com>,
	Benoit Parrot <bparrot@ti.com>
Subject: [Patch v2 11/35] media: ti-vpe: vpdma: Add support for setting max width height
Date: Fri, 18 Nov 2016 17:20:21 -0600	[thread overview]
Message-ID: <20161118232045.24665-12-bparrot@ti.com> (raw)
In-Reply-To: <20161118232045.24665-1-bparrot@ti.com>

From: Nikhil Devshatwar <nikhil.nd@ti.com>

Add a helper function to be able to set the maximum
VPDMA transfer size to limit potential buffer overrun.

Added enums for max_width and max_height fields of the
outbound data descriptor.

Changed vpdma_add_out_dtd to accept two more arguments
for max width and height.

Make use of different max width & height sets for different
of capture module (i.e. slices).

Signed-off-by: Nikhil Devshatwar <nikhil.nd@ti.com>
Signed-off-by: Benoit Parrot <bparrot@ti.com>
Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
---
 drivers/media/platform/ti-vpe/vpdma.c      | 27 ++++++++++++++++----
 drivers/media/platform/ti-vpe/vpdma.h      | 32 ++++++++++++++++++++++--
 drivers/media/platform/ti-vpe/vpdma_priv.h | 40 +++---------------------------
 drivers/media/platform/ti-vpe/vpe.c        |  7 +++++-
 4 files changed, 62 insertions(+), 44 deletions(-)

diff --git a/drivers/media/platform/ti-vpe/vpdma.c b/drivers/media/platform/ti-vpe/vpdma.c
index 133154628543..1a0152842a17 100644
--- a/drivers/media/platform/ti-vpe/vpdma.c
+++ b/drivers/media/platform/ti-vpe/vpdma.c
@@ -493,6 +493,22 @@ void vpdma_update_dma_addr(struct vpdma_data *vpdma,
 }
 EXPORT_SYMBOL(vpdma_update_dma_addr);
 
+void vpdma_set_max_size(struct vpdma_data *vpdma, int reg_addr,
+			u32 width, u32 height)
+{
+	if (reg_addr != VPDMA_MAX_SIZE1 && reg_addr != VPDMA_MAX_SIZE2 &&
+	    reg_addr != VPDMA_MAX_SIZE3)
+		reg_addr = VPDMA_MAX_SIZE1;
+
+	write_field_reg(vpdma, reg_addr, width - 1,
+			VPDMA_MAX_SIZE_WIDTH_MASK, VPDMA_MAX_SIZE_WIDTH_SHFT);
+
+	write_field_reg(vpdma, reg_addr, height - 1,
+			VPDMA_MAX_SIZE_HEIGHT_MASK, VPDMA_MAX_SIZE_HEIGHT_SHFT);
+
+}
+EXPORT_SYMBOL(vpdma_set_max_size);
+
 static void dump_cfd(struct vpdma_cfd *cfd)
 {
 	int class;
@@ -667,23 +683,25 @@ static void dump_dtd(struct vpdma_dtd *dtd)
  * @c_rect: compose params of output image
  * @fmt: vpdma data format of the buffer
  * dma_addr: dma address as seen by VPDMA
+ * max_width: enum for maximum width of data transfer
+ * max_height: enum for maximum height of data transfer
  * chan: VPDMA channel
  * flags: VPDMA flags to configure some descriptor fileds
  */
 void vpdma_add_out_dtd(struct vpdma_desc_list *list, int width,
 		const struct v4l2_rect *c_rect,
 		const struct vpdma_data_format *fmt, dma_addr_t dma_addr,
-		enum vpdma_channel chan, u32 flags)
+		int max_w, int max_h, enum vpdma_channel chan, u32 flags)
 {
 	vpdma_rawchan_add_out_dtd(list, width, c_rect, fmt, dma_addr,
-				  chan_info[chan].num, flags);
+				  max_w, max_h, chan_info[chan].num, flags);
 }
 EXPORT_SYMBOL(vpdma_add_out_dtd);
 
 void vpdma_rawchan_add_out_dtd(struct vpdma_desc_list *list, int width,
 		const struct v4l2_rect *c_rect,
 		const struct vpdma_data_format *fmt, dma_addr_t dma_addr,
-		int raw_vpdma_chan, u32 flags)
+		int max_w, int max_h, int raw_vpdma_chan, u32 flags)
 {
 	int priority = 0;
 	int field = 0;
@@ -722,8 +740,7 @@ void vpdma_rawchan_add_out_dtd(struct vpdma_desc_list *list, int width,
 	dtd->pkt_ctl = dtd_pkt_ctl(!!(flags & VPDMA_DATA_MODE_TILED),
 				DTD_DIR_OUT, channel, priority, next_chan);
 	dtd->desc_write_addr = dtd_desc_write_addr(0, 0, 0, 0);
-	dtd->max_width_height = dtd_max_width_height(MAX_OUT_WIDTH_1920,
-					MAX_OUT_HEIGHT_1080);
+	dtd->max_width_height = dtd_max_width_height(max_w, max_h);
 	dtd->client_attr0 = 0;
 	dtd->client_attr1 = 0;
 
diff --git a/drivers/media/platform/ti-vpe/vpdma.h b/drivers/media/platform/ti-vpe/vpdma.h
index 220dc7e793f6..32b9ed5191c5 100644
--- a/drivers/media/platform/ti-vpe/vpdma.h
+++ b/drivers/media/platform/ti-vpe/vpdma.h
@@ -117,6 +117,30 @@ enum vpdma_frame_start_event {
 	VPDMA_FSEVENT_CHANNEL_ACTIVE,
 };
 
+/* max width configurations */
+enum vpdma_max_width {
+	MAX_OUT_WIDTH_UNLIMITED = 0,
+	MAX_OUT_WIDTH_REG1,
+	MAX_OUT_WIDTH_REG2,
+	MAX_OUT_WIDTH_REG3,
+	MAX_OUT_WIDTH_352,
+	MAX_OUT_WIDTH_768,
+	MAX_OUT_WIDTH_1280,
+	MAX_OUT_WIDTH_1920,
+};
+
+/* max height configurations */
+enum vpdma_max_height {
+	MAX_OUT_HEIGHT_UNLIMITED = 0,
+	MAX_OUT_HEIGHT_REG1,
+	MAX_OUT_HEIGHT_REG2,
+	MAX_OUT_HEIGHT_REG3,
+	MAX_OUT_HEIGHT_288,
+	MAX_OUT_HEIGHT_576,
+	MAX_OUT_HEIGHT_720,
+	MAX_OUT_HEIGHT_1080,
+};
+
 /*
  * VPDMA channel numbers
  */
@@ -198,11 +222,12 @@ void vpdma_add_sync_on_channel_ctd(struct vpdma_desc_list *list,
 void vpdma_add_out_dtd(struct vpdma_desc_list *list, int width,
 		const struct v4l2_rect *c_rect,
 		const struct vpdma_data_format *fmt, dma_addr_t dma_addr,
-		enum vpdma_channel chan, u32 flags);
+		int max_w, int max_h, enum vpdma_channel chan, u32 flags);
 void vpdma_rawchan_add_out_dtd(struct vpdma_desc_list *list, int width,
 		const struct v4l2_rect *c_rect,
 		const struct vpdma_data_format *fmt, dma_addr_t dma_addr,
-		int raw_vpdma_chan, u32 flags);
+		int max_w, int max_h, int raw_vpdma_chan, u32 flags);
+
 void vpdma_add_in_dtd(struct vpdma_desc_list *list, int width,
 		const struct v4l2_rect *c_rect,
 		const struct vpdma_data_format *fmt, dma_addr_t dma_addr,
@@ -221,6 +246,9 @@ void vpdma_set_line_mode(struct vpdma_data *vpdma, int line_mode,
 		enum vpdma_channel chan);
 void vpdma_set_frame_start_event(struct vpdma_data *vpdma,
 		enum vpdma_frame_start_event fs_event, enum vpdma_channel chan);
+void vpdma_set_max_size(struct vpdma_data *vpdma, int reg_addr,
+			u32 width, u32 height);
+
 void vpdma_set_bg_color(struct vpdma_data *vpdma,
 			struct vpdma_data_format *fmt, u32 color);
 void vpdma_dump_regs(struct vpdma_data *vpdma);
diff --git a/drivers/media/platform/ti-vpe/vpdma_priv.h b/drivers/media/platform/ti-vpe/vpdma_priv.h
index aeade5edc8ac..54b6aa866c74 100644
--- a/drivers/media/platform/ti-vpe/vpdma_priv.h
+++ b/drivers/media/platform/ti-vpe/vpdma_priv.h
@@ -28,6 +28,10 @@
 #define VPDMA_MAX_SIZE1		0x34
 #define VPDMA_MAX_SIZE2		0x38
 #define VPDMA_MAX_SIZE3		0x3c
+#define VPDMA_MAX_SIZE_WIDTH_MASK	0xffff
+#define VPDMA_MAX_SIZE_WIDTH_SHFT	16
+#define VPDMA_MAX_SIZE_HEIGHT_MASK	0xffff
+#define VPDMA_MAX_SIZE_HEIGHT_SHFT	0
 
 /* Interrupts */
 #define VPDMA_INT_CHAN_STAT(grp)	(0x40 + grp * 8)
@@ -227,42 +231,6 @@ struct vpdma_dtd {
 #define DTD_MAX_HEIGHT_MASK	0x07
 #define DTD_MAX_HEIGHT_SHFT	0
 
-/* max width configurations */
- /* unlimited width */
-#define	MAX_OUT_WIDTH_UNLIMITED		0
-/* as specified in max_size1 reg */
-#define MAX_OUT_WIDTH_REG1		1
-/* as specified in max_size2 reg */
-#define MAX_OUT_WIDTH_REG2		2
-/* as specified in max_size3 reg */
-#define	MAX_OUT_WIDTH_REG3		3
-/* maximum of 352 pixels as width */
-#define MAX_OUT_WIDTH_352		4
-/* maximum of 768 pixels as width */
-#define	MAX_OUT_WIDTH_768		5
-/* maximum of 1280 pixels width */
-#define	MAX_OUT_WIDTH_1280		6
-/* maximum of 1920 pixels as width */
-#define	MAX_OUT_WIDTH_1920		7
-
-/* max height configurations */
- /* unlimited height */
-#define	MAX_OUT_HEIGHT_UNLIMITED	0
-/* as specified in max_size1 reg */
-#define MAX_OUT_HEIGHT_REG1		1
-/* as specified in max_size2 reg */
-#define MAX_OUT_HEIGHT_REG2		2
-/* as specified in max_size3 reg */
-#define	MAX_OUT_HEIGHT_REG3		3
-/* maximum of 288 lines as height */
-#define MAX_OUT_HEIGHT_288		4
-/* maximum of 576 lines as height */
-#define	MAX_OUT_HEIGHT_576		5
-/* maximum of 720 lines as height */
-#define	MAX_OUT_HEIGHT_720		6
-/* maximum of 1080 lines as height */
-#define	MAX_OUT_HEIGHT_1080		7
-
 static inline u32 dtd_type_ctl_stride(int type, bool notify, int field,
 			bool one_d, bool even_line_skip, bool odd_line_skip,
 			int line_stride)
diff --git a/drivers/media/platform/ti-vpe/vpe.c b/drivers/media/platform/ti-vpe/vpe.c
index f2b90d42b408..151a9280bb85 100644
--- a/drivers/media/platform/ti-vpe/vpe.c
+++ b/drivers/media/platform/ti-vpe/vpe.c
@@ -44,6 +44,7 @@
 #include <media/videobuf2-dma-contig.h>
 
 #include "vpdma.h"
+#include "vpdma_priv.h"
 #include "vpe_regs.h"
 #include "sc.h"
 #include "csc.h"
@@ -1035,8 +1036,12 @@ static void add_out_dtd(struct vpe_ctx *ctx, int port)
 	if (q_data->flags & Q_DATA_MODE_TILED)
 		flags |= VPDMA_DATA_MODE_TILED;
 
+	vpdma_set_max_size(ctx->dev->vpdma, VPDMA_MAX_SIZE1,
+			   MAX_W, MAX_H);
+
 	vpdma_add_out_dtd(&ctx->desc_list, q_data->width, &q_data->c_rect,
-		vpdma_fmt, dma_addr, p_data->channel, flags);
+			  vpdma_fmt, dma_addr, MAX_OUT_WIDTH_REG1,
+			  MAX_OUT_HEIGHT_REG1, p_data->channel, flags);
 }
 
 static void add_in_dtd(struct vpe_ctx *ctx, int port)
-- 
2.9.0

  parent reply	other threads:[~2016-11-18 23:27 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-18 23:20 [Patch v2 00/35] media: ti-vpe: fixes and enhancements Benoit Parrot
2016-11-18 23:20 ` [Patch v2 01/35] media: ti-vpe: vpdma: Make vpdma library into its own module Benoit Parrot
2016-11-18 23:20 ` [Patch v2 02/35] media: ti-vpe: vpdma: Add multi-instance and multi-client support Benoit Parrot
2016-11-18 23:20 ` [Patch v2 03/35] media: ti-vpe: vpdma: Add helper to set a background color Benoit Parrot
2016-11-18 23:20 ` [Patch v2 04/35] media: ti-vpe: vpdma: Fix bus error when vpdma is writing a descriptor Benoit Parrot
2016-11-18 23:20 ` [Patch v2 05/35] media: ti-vpe: Use line average de-interlacing for first 2 frames Benoit Parrot
2016-11-18 23:20 ` [Patch v2 06/35] media: ti-vpe: vpe: Do not perform job transaction atomically Benoit Parrot
2016-11-18 23:20 ` [Patch v2 07/35] media: ti-vpe: Add support for SEQ_TB buffers Benoit Parrot
2016-11-18 23:20 ` [Patch v2 08/35] media: ti-vpe: Increasing max buffer height and width Benoit Parrot
2016-11-18 23:20 ` [Patch v2 09/35] media: ti-vpe: vpe: Return NULL for invalid buffer type Benoit Parrot
2016-11-18 23:20 ` [Patch v2 10/35] media: ti-vpe: Free vpdma buffers in vpe_release Benoit Parrot
2016-11-18 23:20 ` Benoit Parrot [this message]
2016-11-18 23:20 ` [Patch v2 12/35] media: ti-vpe: vpdma: Add abort channel desc and cleanup APIs Benoit Parrot
2016-11-18 23:20 ` [Patch v2 13/35] media: ti-vpe: vpdma: Make list post atomic operation Benoit Parrot
2016-11-18 23:20 ` [Patch v2 14/35] media: ti-vpe: vpdma: Clear IRQs for individual lists Benoit Parrot
2016-11-18 23:20 ` [Patch v2 15/35] media: ti-vpe: vpe: configure line mode separately Benoit Parrot
2016-11-18 23:20 ` [Patch v2 16/35] media: ti-vpe: vpe: Setup srcdst parameters in start_streaming Benoit Parrot
2016-11-18 23:20 ` [Patch v2 17/35] media: ti-vpe: vpe: Post next descriptor only for list complete IRQ Benoit Parrot
2016-11-18 23:20 ` [Patch v2 18/35] media: ti-vpe: vpe: Add RGB565 and RGB5551 support Benoit Parrot
2016-11-18 23:20 ` [Patch v2 19/35] media: ti-vpe: vpdma: allocate and maintain hwlist Benoit Parrot
2016-11-18 23:20 ` [Patch v2 20/35] media: ti-vpe: vpe: Added MODULE_DEVICE_TABLE hint Benoit Parrot
2016-11-18 23:20 ` [Patch v2 21/35] media: ti-vpe: vpdma: Corrected YUV422 data type label Benoit Parrot
2016-11-18 23:20 ` [Patch v2 22/35] media: ti-vpe: vpdma: RGB data type yield inverted data Benoit Parrot
2016-11-18 23:20 ` [Patch v2 23/35] media: ti-vpe: sc: Fix incorrect optimization Benoit Parrot
2016-11-18 23:20 ` [Patch v2 24/35] media: ti-vpe: vpe: Fix vb2 buffer cleanup Benoit Parrot
2016-11-18 23:20 ` [Patch v2 25/35] media: ti-vpe: vpdma: Fix race condition for firmware loading Benoit Parrot
2016-11-18 23:20 ` [Patch v2 26/35] media: ti-vpe: vpdma: Use bidirectional cached buffers Benoit Parrot
2016-11-18 23:20 ` [Patch v2 27/35] media: ti-vpe: vpe: Fix line stride for output motion vector Benoit Parrot
2016-11-18 23:20 ` [Patch v2 28/35] media: ti-vpe: vpe: Enable DMABUF export Benoit Parrot
2016-11-18 23:20 ` [Patch v2 29/35] media: ti-vpe: Make scaler library into its own module Benoit Parrot
2016-11-18 23:20 ` [Patch v2 30/35] media: ti-vpe: scaler: Add debug support for multi-instance Benoit Parrot
2016-11-18 23:20 ` [Patch v2 31/35] media: ti-vpe: vpe: Make sure frame size dont exceed scaler capacity Benoit Parrot
2016-11-18 23:20 ` [Patch v2 32/35] media: ti-vpe: vpdma: Add RAW8 and RAW16 data types Benoit Parrot
2016-11-18 23:20 ` [Patch v2 33/35] media: ti-vpe: Make colorspace converter library into its own module Benoit Parrot
2016-11-18 23:20 ` [Patch v2 34/35] media: ti-vpe: csc: Add debug support for multi-instance Benoit Parrot
2016-11-18 23:20 ` [Patch v2 35/35] media: ti-vpe: vpe: Add proper support single and multi-plane buffer Benoit Parrot

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=20161118232045.24665-12-bparrot@ti.com \
    --to=bparrot@ti.com \
    --cc=hverkuil@xs4all.nl \
    --cc=jsarha@ti.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=peter.ujfalusi@ti.com \
    --cc=tomi.valkeinen@ti.com \
    /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).