2021-10-01 12:35:10

by Ricardo Ribalda

[permalink] [raw]
Subject: [PATCH v3 0/8] media: ipu3 + i2c: Fix v4l2-compliance issues

Fix some issues found with v4l2-compliance. Tested in Soraka which also
has some subdevices that had some issues with v4l2-compliance.

v1->v3: Changelog

- Rename cio2 to imgu
- Refactor bytesperline calculation

Ricardo Ribalda (8):
media: ipu3-cio2 Check num_planes and sizes in queue_setup
media: ipu3-imgu: Refactor bytesperpixel calculation
media: ipu3-imgu: Set valid initial format
media: ipu3-imgu: imgu_fmt: Handle properly try
media: ipu3-imgu: VIDIOC_QUERYCAP: Fix bus_info
media: dw9714: Add implementation for events
media: ov13858: Add implementation for events
media: ov5670: Add implementation for events

drivers/media/i2c/dw9714.c | 14 ++++++++++++--
drivers/media/i2c/ov13858.c | 11 ++++++++++-
drivers/media/i2c/ov5670.c | 11 ++++++++++-
drivers/media/pci/intel/ipu3/ipu3-cio2-main.c | 8 ++++++--
drivers/staging/media/ipu3/ipu3-css.c | 19 +++----------------
drivers/staging/media/ipu3/ipu3-css.h | 1 -
drivers/staging/media/ipu3/ipu3-v4l2.c | 11 +++++++----
drivers/staging/media/ipu3/ipu3.h | 12 ++++++++++++
8 files changed, 60 insertions(+), 27 deletions(-)

--
2.33.0.800.g4c38ced690-goog


2021-10-01 12:36:00

by Ricardo Ribalda

[permalink] [raw]
Subject: [PATCH v3 1/8] media: ipu3-cio2 Check num_planes and sizes in queue_setup

If num_planes is different than zero num_planes and sizes must be
checked to support the format.

Fix the following v4l2-compliance error:

Buffer ioctls (Input 0):
fail: v4l2-test-buffers.cpp(717): q.create_bufs(node, 1, &fmt) != EINVAL
test VIDIOC_REQBUFS/CREATE_BUFS/QUERYBUF: FAIL

Reviewed-by: Bingbu Cao <[email protected]>
Signed-off-by: Ricardo Ribalda <[email protected]>
---
drivers/media/pci/intel/ipu3/ipu3-cio2-main.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/media/pci/intel/ipu3/ipu3-cio2-main.c b/drivers/media/pci/intel/ipu3/ipu3-cio2-main.c
index 47db0ee0fcbfa..36099e95d29f2 100644
--- a/drivers/media/pci/intel/ipu3/ipu3-cio2-main.c
+++ b/drivers/media/pci/intel/ipu3/ipu3-cio2-main.c
@@ -798,13 +798,17 @@ static int cio2_vb2_queue_setup(struct vb2_queue *vq,
struct cio2_queue *q = vb2q_to_cio2_queue(vq);
unsigned int i;

- *num_planes = q->format.num_planes;
+ if (*num_planes && *num_planes < q->format.num_planes)
+ return -EINVAL;

- for (i = 0; i < *num_planes; ++i) {
+ for (i = 0; i < q->format.num_planes; ++i) {
+ if (*num_planes && sizes[i] < q->format.plane_fmt[i].sizeimage)
+ return -EINVAL;
sizes[i] = q->format.plane_fmt[i].sizeimage;
alloc_devs[i] = &cio2->pci_dev->dev;
}

+ *num_planes = q->format.num_planes;
*num_buffers = clamp_val(*num_buffers, 1, CIO2_MAX_BUFFERS);

/* Initialize buffer queue */
--
2.33.0.800.g4c38ced690-goog

2021-10-01 12:58:02

by Ricardo Ribalda

[permalink] [raw]
Subject: [PATCH v3 2/8] media: ipu3-imgu: Refactor bytesperpixel calculation

Move the calculation to an inline function, to it can be used by other
parts of the driver.

Signed-off-by: Ricardo Ribalda <[email protected]>
---
drivers/staging/media/ipu3/ipu3-css.c | 19 +++----------------
drivers/staging/media/ipu3/ipu3-css.h | 1 -
drivers/staging/media/ipu3/ipu3.h | 12 ++++++++++++
3 files changed, 15 insertions(+), 17 deletions(-)

diff --git a/drivers/staging/media/ipu3/ipu3-css.c b/drivers/staging/media/ipu3/ipu3-css.c
index 608dcacf12b2c..8c70497d744c9 100644
--- a/drivers/staging/media/ipu3/ipu3-css.c
+++ b/drivers/staging/media/ipu3/ipu3-css.c
@@ -5,6 +5,7 @@
#include <linux/iopoll.h>
#include <linux/slab.h>

+#include "ipu3.h"
#include "ipu3-css.h"
#include "ipu3-css-fw.h"
#include "ipu3-css-params.h"
@@ -53,7 +54,6 @@ static const struct imgu_css_format imgu_css_formats[] = {
.frame_format = IMGU_ABI_FRAME_FORMAT_NV12,
.osys_format = IMGU_ABI_OSYS_FORMAT_NV12,
.osys_tiling = IMGU_ABI_OSYS_TILING_NONE,
- .bytesperpixel_num = 1 * IPU3_CSS_FORMAT_BPP_DEN,
.chroma_decim = 4,
.width_align = IPU3_UAPI_ISP_VEC_ELEMS,
.flags = IPU3_CSS_FORMAT_FL_OUT | IPU3_CSS_FORMAT_FL_VF,
@@ -64,7 +64,6 @@ static const struct imgu_css_format imgu_css_formats[] = {
.frame_format = IMGU_ABI_FRAME_FORMAT_RAW_PACKED,
.bayer_order = IMGU_ABI_BAYER_ORDER_BGGR,
.bit_depth = 10,
- .bytesperpixel_num = 64,
.width_align = 2 * IPU3_UAPI_ISP_VEC_ELEMS,
.flags = IPU3_CSS_FORMAT_FL_IN,
}, {
@@ -73,7 +72,6 @@ static const struct imgu_css_format imgu_css_formats[] = {
.frame_format = IMGU_ABI_FRAME_FORMAT_RAW_PACKED,
.bayer_order = IMGU_ABI_BAYER_ORDER_GBRG,
.bit_depth = 10,
- .bytesperpixel_num = 64,
.width_align = 2 * IPU3_UAPI_ISP_VEC_ELEMS,
.flags = IPU3_CSS_FORMAT_FL_IN,
}, {
@@ -82,7 +80,6 @@ static const struct imgu_css_format imgu_css_formats[] = {
.frame_format = IMGU_ABI_FRAME_FORMAT_RAW_PACKED,
.bayer_order = IMGU_ABI_BAYER_ORDER_GRBG,
.bit_depth = 10,
- .bytesperpixel_num = 64,
.width_align = 2 * IPU3_UAPI_ISP_VEC_ELEMS,
.flags = IPU3_CSS_FORMAT_FL_IN,
}, {
@@ -91,7 +88,6 @@ static const struct imgu_css_format imgu_css_formats[] = {
.frame_format = IMGU_ABI_FRAME_FORMAT_RAW_PACKED,
.bayer_order = IMGU_ABI_BAYER_ORDER_RGGB,
.bit_depth = 10,
- .bytesperpixel_num = 64,
.width_align = 2 * IPU3_UAPI_ISP_VEC_ELEMS,
.flags = IPU3_CSS_FORMAT_FL_IN,
},
@@ -150,17 +146,8 @@ static int imgu_css_queue_init(struct imgu_css_queue *queue,
f->height = ALIGN(clamp_t(u32, f->height,
IPU3_CSS_MIN_RES, IPU3_CSS_MAX_H), 2);
queue->width_pad = ALIGN(f->width, queue->css_fmt->width_align);
- if (queue->css_fmt->frame_format != IMGU_ABI_FRAME_FORMAT_RAW_PACKED)
- f->plane_fmt[0].bytesperline = DIV_ROUND_UP(queue->width_pad *
- queue->css_fmt->bytesperpixel_num,
- IPU3_CSS_FORMAT_BPP_DEN);
- else
- /* For packed raw, alignment for bpl is by 50 to the width */
- f->plane_fmt[0].bytesperline =
- DIV_ROUND_UP(f->width,
- IPU3_CSS_FORMAT_BPP_DEN) *
- queue->css_fmt->bytesperpixel_num;
-
+ f->plane_fmt[0].bytesperline =
+ imgu_bytesperline(f->width, queue->css_fmt->frame_format);
sizeimage = f->height * f->plane_fmt[0].bytesperline;
if (queue->css_fmt->chroma_decim)
sizeimage += 2 * sizeimage / queue->css_fmt->chroma_decim;
diff --git a/drivers/staging/media/ipu3/ipu3-css.h b/drivers/staging/media/ipu3/ipu3-css.h
index 6108a068b228f..ab64e95212032 100644
--- a/drivers/staging/media/ipu3/ipu3-css.h
+++ b/drivers/staging/media/ipu3/ipu3-css.h
@@ -82,7 +82,6 @@ struct imgu_css_format {
enum imgu_abi_bayer_order bayer_order;
enum imgu_abi_osys_format osys_format;
enum imgu_abi_osys_tiling osys_tiling;
- u32 bytesperpixel_num; /* Bytes per pixel in first plane * 50 */
u8 bit_depth; /* Effective bits per pixel */
u8 chroma_decim; /* Chroma plane decimation, 0=no chroma plane */
u8 width_align; /* Alignment requirement for width_pad */
diff --git a/drivers/staging/media/ipu3/ipu3.h b/drivers/staging/media/ipu3/ipu3.h
index eb46b527dd233..d2ad0a95c5aab 100644
--- a/drivers/staging/media/ipu3/ipu3.h
+++ b/drivers/staging/media/ipu3/ipu3.h
@@ -164,4 +164,16 @@ void imgu_v4l2_buffer_done(struct vb2_buffer *vb, enum vb2_buffer_state state);

int imgu_s_stream(struct imgu_device *imgu, int enable);

+static inline u32 imgu_bytesperline(const unsigned int width,
+ enum imgu_abi_frame_format frame_format)
+{
+ if (frame_format == IMGU_ABI_FRAME_FORMAT_NV12)
+ return ALIGN(width, IPU3_UAPI_ISP_VEC_ELEMS);
+ /*
+ * 64 bytes for every 50 pixels, the line length
+ * in bytes is multiple of 64 (line end alignment).
+ */
+ return DIV_ROUND_UP(width, 50) * 64;
+}
+
#endif
--
2.33.0.800.g4c38ced690-goog

2021-10-06 21:58:48

by Sakari Ailus

[permalink] [raw]
Subject: Re: [PATCH v3 1/8] media: ipu3-cio2 Check num_planes and sizes in queue_setup

Hi Ricardo,

On Fri, Oct 01, 2021 at 11:25:15AM +0000, Ricardo Ribalda wrote:
> If num_planes is different than zero num_planes and sizes must be
> checked to support the format.
>
> Fix the following v4l2-compliance error:
>
> Buffer ioctls (Input 0):
> fail: v4l2-test-buffers.cpp(717): q.create_bufs(node, 1, &fmt) != EINVAL
> test VIDIOC_REQBUFS/CREATE_BUFS/QUERYBUF: FAIL
>
> Reviewed-by: Bingbu Cao <[email protected]>
> Signed-off-by: Ricardo Ribalda <[email protected]>

I attempted to apply the set to my tree but it doesn't seem to.

Do you happen to have extra patches in your tree?

I just pushed mine to the master branch here:

https://git.linuxtv.org/sailus/media_tree.git/

--
Sakari Ailus

2021-10-06 22:30:02

by Ricardo Ribalda

[permalink] [raw]
Subject: Re: [PATCH v3 1/8] media: ipu3-cio2 Check num_planes and sizes in queue_setup

Hi Sakari

Thanks for your review :)

On Wed, 6 Oct 2021 at 23:56, Sakari Ailus <[email protected]> wrote:
>
> Hi Ricardo,
>
> On Fri, Oct 01, 2021 at 11:25:15AM +0000, Ricardo Ribalda wrote:
> > If num_planes is different than zero num_planes and sizes must be
> > checked to support the format.
> >
> > Fix the following v4l2-compliance error:
> >
> > Buffer ioctls (Input 0):
> > fail: v4l2-test-buffers.cpp(717): q.create_bufs(node, 1, &fmt) != EINVAL
> > test VIDIOC_REQBUFS/CREATE_BUFS/QUERYBUF: FAIL
> >
> > Reviewed-by: Bingbu Cao <[email protected]>
> > Signed-off-by: Ricardo Ribalda <[email protected]>
>
> I attempted to apply the set to my tree but it doesn't seem to.
>
> Do you happen to have extra patches in your tree?


I think that I was on top of Linus.
I just rebased it on top of yours and resend it as v4

Thanks!


>
> I just pushed mine to the master branch here:
>
> https://git.linuxtv.org/sailus/media_tree.git/
>
> --
> Sakari Ailus



--
Ricardo Ribalda