[PATCH v10 9/9] media: hantro: IMX8M: add variant for G2/HEVC codec

2021-04-20 Thread Benjamin Gaignard
Add variant to IMX8M to enable G2/HEVC codec.
Define the capabilities for the hardware up to 3840x2160.
G2 doesn't have a postprocessor, uses the same clocks and has it
own interrupt.

Signed-off-by: Benjamin Gaignard 
Reviewed-by: Philipp Zabel 
Reviewed-by: Ezequiel Garcia 
---
 drivers/staging/media/hantro/hantro_drv.c   |  1 +
 drivers/staging/media/hantro/hantro_hw.h|  1 +
 drivers/staging/media/hantro/imx8m_vpu_hw.c | 74 -
 3 files changed, 75 insertions(+), 1 deletion(-)

diff --git a/drivers/staging/media/hantro/hantro_drv.c 
b/drivers/staging/media/hantro/hantro_drv.c
index 905a69758b37..d6f4958f6292 100644
--- a/drivers/staging/media/hantro/hantro_drv.c
+++ b/drivers/staging/media/hantro/hantro_drv.c
@@ -574,6 +574,7 @@ static const struct of_device_id of_hantro_match[] = {
 #endif
 #ifdef CONFIG_VIDEO_HANTRO_IMX8M
{ .compatible = "nxp,imx8mq-vpu", .data = _vpu_variant, },
+   { .compatible = "nxp,imx8mq-vpu-g2", .data = _vpu_g2_variant },
 #endif
{ /* sentinel */ }
 };
diff --git a/drivers/staging/media/hantro/hantro_hw.h 
b/drivers/staging/media/hantro/hantro_hw.h
index 41f3d5b92357..682fea1fe914 100644
--- a/drivers/staging/media/hantro/hantro_hw.h
+++ b/drivers/staging/media/hantro/hantro_hw.h
@@ -205,6 +205,7 @@ extern const struct hantro_variant rk3399_vpu_variant;
 extern const struct hantro_variant rk3328_vpu_variant;
 extern const struct hantro_variant rk3288_vpu_variant;
 extern const struct hantro_variant imx8mq_vpu_variant;
+extern const struct hantro_variant imx8mq_vpu_g2_variant;
 
 extern const struct hantro_postproc_regs hantro_g1_postproc_regs;
 
diff --git a/drivers/staging/media/hantro/imx8m_vpu_hw.c 
b/drivers/staging/media/hantro/imx8m_vpu_hw.c
index c222de075ef4..2a6ac5248f6e 100644
--- a/drivers/staging/media/hantro/imx8m_vpu_hw.c
+++ b/drivers/staging/media/hantro/imx8m_vpu_hw.c
@@ -11,6 +11,7 @@
 #include "hantro.h"
 #include "hantro_jpeg.h"
 #include "hantro_g1_regs.h"
+#include "hantro_g2_regs.h"
 
 #define CTRL_SOFT_RESET0x00
 #define RESET_G1   BIT(1)
@@ -130,6 +131,26 @@ static const struct hantro_fmt imx8m_vpu_dec_fmts[] = {
},
 };
 
+static const struct hantro_fmt imx8m_vpu_g2_dec_fmts[] = {
+   {
+   .fourcc = V4L2_PIX_FMT_NV12,
+   .codec_mode = HANTRO_MODE_NONE,
+   },
+   {
+   .fourcc = V4L2_PIX_FMT_HEVC_SLICE,
+   .codec_mode = HANTRO_MODE_HEVC_DEC,
+   .max_depth = 2,
+   .frmsize = {
+   .min_width = 48,
+   .max_width = 3840,
+   .step_width = MB_DIM,
+   .min_height = 48,
+   .max_height = 2160,
+   .step_height = MB_DIM,
+   },
+   },
+};
+
 static irqreturn_t imx8m_vpu_g1_irq(int irq, void *dev_id)
 {
struct hantro_dev *vpu = dev_id;
@@ -148,6 +169,24 @@ static irqreturn_t imx8m_vpu_g1_irq(int irq, void *dev_id)
return IRQ_HANDLED;
 }
 
+static irqreturn_t imx8m_vpu_g2_irq(int irq, void *dev_id)
+{
+   struct hantro_dev *vpu = dev_id;
+   enum vb2_buffer_state state;
+   u32 status;
+
+   status = vdpu_read(vpu, HEVC_REG_INTERRUPT);
+   state = (status & HEVC_REG_INTERRUPT_DEC_RDY_INT) ?
+VB2_BUF_STATE_DONE : VB2_BUF_STATE_ERROR;
+
+   vdpu_write(vpu, 0, HEVC_REG_INTERRUPT);
+   vdpu_write(vpu, HEVC_REG_CONFIG_DEC_CLK_GATE_E, HEVC_REG_CONFIG);
+
+   hantro_irq_done(vpu, state);
+
+   return IRQ_HANDLED;
+}
+
 static int imx8mq_vpu_hw_init(struct hantro_dev *vpu)
 {
vpu->dec_base = vpu->reg_bases[0];
@@ -163,6 +202,13 @@ static void imx8m_vpu_g1_reset(struct hantro_ctx *ctx)
imx8m_soft_reset(vpu, RESET_G1);
 }
 
+static void imx8m_vpu_g2_reset(struct hantro_ctx *ctx)
+{
+   struct hantro_dev *vpu = ctx->dev;
+
+   imx8m_soft_reset(vpu, RESET_G2);
+}
+
 /*
  * Supported codec ops.
  */
@@ -188,13 +234,25 @@ static const struct hantro_codec_ops 
imx8mq_vpu_codec_ops[] = {
},
 };
 
+static const struct hantro_codec_ops imx8mq_vpu_g2_codec_ops[] = {
+   [HANTRO_MODE_HEVC_DEC] = {
+   .run = hantro_g2_hevc_dec_run,
+   .reset = imx8m_vpu_g2_reset,
+   .init = hantro_hevc_dec_init,
+   .exit = hantro_hevc_dec_exit,
+   },
+};
+
 /*
  * VPU variants.
  */
 
 static const struct hantro_irq imx8mq_irqs[] = {
{ "g1", imx8m_vpu_g1_irq },
-   { "g2", NULL /* TODO: imx8m_vpu_g2_irq */ },
+};
+
+static const struct hantro_irq imx8mq_g2_irqs[] = {
+   { "g2", imx8m_vpu_g2_irq },
 };
 
 static const char * const imx8mq_clk_names[] = { "g1", "g2", "bus" };
@@ -218,3 +276,17 @@ const struct hantro_variant imx8mq_vpu_variant = {
.reg_names = imx8mq_reg_names,
  

[PATCH v10 8/9] media: hantro: Introduce G2/HEVC decoder

2021-04-20 Thread Benjamin Gaignard
Implement all the logic to get G2 hardware decoding HEVC frames.
It supports up level 5.1 HEVC stream.
It doesn't support yet 10 bits formats or the scaling feature.

Add HANTRO HEVC dedicated control to skip some bits at the beginning
of the slice header. That is very specific to this hardware so can't
go into uapi structures. Computing the needed value is complex and requires
information from the stream that only the userland knows so let it
provide the correct value to the driver.

Signed-off-by: Benjamin Gaignard 
Co-developed-by: Adrian Ratiu 
Signed-off-by: Adrian Ratiu 
Co-developed-by: Ezequiel Garcia 
Signed-off-by: Ezequiel Garcia 
---
 drivers/staging/media/hantro/Makefile |   2 +
 drivers/staging/media/hantro/hantro.h |   2 +
 drivers/staging/media/hantro/hantro_drv.c |  36 ++
 .../staging/media/hantro/hantro_g2_hevc_dec.c | 587 ++
 drivers/staging/media/hantro/hantro_g2_regs.h | 198 ++
 drivers/staging/media/hantro/hantro_hevc.c| 327 ++
 drivers/staging/media/hantro/hantro_hw.h  |  49 ++
 7 files changed, 1201 insertions(+)
 create mode 100644 drivers/staging/media/hantro/hantro_g2_hevc_dec.c
 create mode 100644 drivers/staging/media/hantro/hantro_g2_regs.h
 create mode 100644 drivers/staging/media/hantro/hantro_hevc.c

diff --git a/drivers/staging/media/hantro/Makefile 
b/drivers/staging/media/hantro/Makefile
index 743ce08eb184..0357f1772267 100644
--- a/drivers/staging/media/hantro/Makefile
+++ b/drivers/staging/media/hantro/Makefile
@@ -9,12 +9,14 @@ hantro-vpu-y += \
hantro_h1_jpeg_enc.o \
hantro_g1_h264_dec.o \
hantro_g1_mpeg2_dec.o \
+   hantro_g2_hevc_dec.o \
hantro_g1_vp8_dec.o \
rk3399_vpu_hw_jpeg_enc.o \
rk3399_vpu_hw_mpeg2_dec.o \
rk3399_vpu_hw_vp8_dec.o \
hantro_jpeg.o \
hantro_h264.o \
+   hantro_hevc.o \
hantro_mpeg2.o \
hantro_vp8.o
 
diff --git a/drivers/staging/media/hantro/hantro.h 
b/drivers/staging/media/hantro/hantro.h
index e50d39b51902..a70c386de6f1 100644
--- a/drivers/staging/media/hantro/hantro.h
+++ b/drivers/staging/media/hantro/hantro.h
@@ -221,6 +221,7 @@ struct hantro_dev {
  * @jpeg_enc:  JPEG-encoding context.
  * @mpeg2_dec: MPEG-2-decoding context.
  * @vp8_dec:   VP8-decoding context.
+ * @hevc_dec:  HEVC-decoding context.
  */
 struct hantro_ctx {
struct hantro_dev *dev;
@@ -247,6 +248,7 @@ struct hantro_ctx {
struct hantro_jpeg_enc_hw_ctx jpeg_enc;
struct hantro_mpeg2_dec_hw_ctx mpeg2_dec;
struct hantro_vp8_dec_hw_ctx vp8_dec;
+   struct hantro_hevc_dec_hw_ctx hevc_dec;
};
 };
 
diff --git a/drivers/staging/media/hantro/hantro_drv.c 
b/drivers/staging/media/hantro/hantro_drv.c
index d9a3a5ef9330..905a69758b37 100644
--- a/drivers/staging/media/hantro/hantro_drv.c
+++ b/drivers/staging/media/hantro/hantro_drv.c
@@ -281,6 +281,26 @@ static int hantro_jpeg_s_ctrl(struct v4l2_ctrl *ctrl)
return 0;
 }
 
+static int hantro_hevc_s_ctrl(struct v4l2_ctrl *ctrl)
+{
+   struct hantro_ctx *ctx;
+
+   ctx = container_of(ctrl->handler,
+  struct hantro_ctx, ctrl_handler);
+
+   vpu_debug(1, "s_ctrl: id = %d, val = %d\n", ctrl->id, ctrl->val);
+
+   switch (ctrl->id) {
+   case V4L2_CID_HANTRO_HEVC_SLICE_HEADER_SKIP:
+   ctx->hevc_dec.ctrls.hevc_hdr_skip_length = ctrl->val;
+   break;
+   default:
+   return -EINVAL;
+   }
+
+   return 0;
+}
+
 static const struct v4l2_ctrl_ops hantro_ctrl_ops = {
.try_ctrl = hantro_try_ctrl,
 };
@@ -289,6 +309,10 @@ static const struct v4l2_ctrl_ops hantro_jpeg_ctrl_ops = {
.s_ctrl = hantro_jpeg_s_ctrl,
 };
 
+static const struct v4l2_ctrl_ops hantro_hevc_ctrl_ops = {
+   .s_ctrl = hantro_hevc_s_ctrl,
+};
+
 static const struct hantro_ctrl controls[] = {
{
.codec = HANTRO_JPEG_ENCODER,
@@ -409,6 +433,18 @@ static const struct hantro_ctrl controls[] = {
.cfg = {
.id = V4L2_CID_MPEG_VIDEO_HEVC_DECODE_PARAMS,
},
+   }, {
+   .codec = HANTRO_HEVC_DECODER,
+   .cfg = {
+   .id = V4L2_CID_HANTRO_HEVC_SLICE_HEADER_SKIP,
+   .name = "Hantro HEVC slice header skip bytes",
+   .type = V4L2_CTRL_TYPE_INTEGER,
+   .min = 0,
+   .def = 0,
+   .max = 0x100,
+   .step = 1,
+   .ops = _hevc_ctrl_ops,
+   },
},
 };
 
diff --git a/drivers/staging/media/hantro/hantro_g2_hevc_dec.c 
b/drivers/staging/media/hantro/hantro_g2_hevc_dec.c
new file mode 100644
ind

[PATCH v10 6/9] media: uapi: Add a control for HANTRO driver

2021-04-20 Thread Benjamin Gaignard
The HEVC HANTRO driver needs to know the number of bits to skip at
the beginning of the slice header.
That is a hardware specific requirement so create a dedicated control
for this purpose.

Signed-off-by: Benjamin Gaignard 
---
 .../userspace-api/media/drivers/hantro.rst| 19 +++
 .../userspace-api/media/drivers/index.rst |  1 +
 include/media/hevc-ctrls.h| 13 +
 3 files changed, 33 insertions(+)
 create mode 100644 Documentation/userspace-api/media/drivers/hantro.rst

diff --git a/Documentation/userspace-api/media/drivers/hantro.rst 
b/Documentation/userspace-api/media/drivers/hantro.rst
new file mode 100644
index ..cd9754b4e005
--- /dev/null
+++ b/Documentation/userspace-api/media/drivers/hantro.rst
@@ -0,0 +1,19 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+Hantro video decoder driver
+===
+
+The Hantro video decoder driver implements the following driver-specific 
controls:
+
+``V4L2_CID_HANTRO_HEVC_SLICE_HEADER_SKIP (integer)``
+Specifies to Hantro HEVC video decoder driver the number of data (in bits) 
to
+skip in the slice segment header.
+If non-IDR, the bits to be skipped go from syntax element "pic_output_flag"
+to before syntax element "slice_temporal_mvp_enabled_flag".
+If IDR, the skipped bits are just "pic_output_flag"
+(separate_colour_plane_flag is not supported).
+
+.. note::
+
+This control is not yet part of the public kernel API and
+it is expected to change.
diff --git a/Documentation/userspace-api/media/drivers/index.rst 
b/Documentation/userspace-api/media/drivers/index.rst
index 1a9038f5f9fa..12e3c512d718 100644
--- a/Documentation/userspace-api/media/drivers/index.rst
+++ b/Documentation/userspace-api/media/drivers/index.rst
@@ -33,6 +33,7 @@ For more details see the file COPYING in the source 
distribution of Linux.
 
ccs
cx2341x-uapi
+hantro
imx-uapi
max2175
meye-uapi
diff --git a/include/media/hevc-ctrls.h b/include/media/hevc-ctrls.h
index 8e0109eea454..b713eeed1915 100644
--- a/include/media/hevc-ctrls.h
+++ b/include/media/hevc-ctrls.h
@@ -224,4 +224,17 @@ struct v4l2_ctrl_hevc_decode_params {
__u64   flags;
 };
 
+/*  MPEG-class control IDs specific to the Hantro driver as defined by V4L2 */
+#define V4L2_CID_CODEC_HANTRO_BASE 
(V4L2_CTRL_CLASS_CODEC | 0x1200)
+/*
+ * V4L2_CID_HANTRO_HEVC_SLICE_HEADER_SKIP -
+ * the number of data (in bits) to skip in the
+ * slice segment header.
+ * If non-IDR, the bits to be skipped go from syntax element "pic_output_flag"
+ * to before syntax element "slice_temporal_mvp_enabled_flag".
+ * If IDR, the skipped bits are just "pic_output_flag"
+ * (separate_colour_plane_flag is not supported).
+ */
+#define V4L2_CID_HANTRO_HEVC_SLICE_HEADER_SKIP (V4L2_CID_CODEC_HANTRO_BASE + 0)
+
 #endif
-- 
2.25.1



[PATCH v10 7/9] media: hantro: handle V4L2_PIX_FMT_HEVC_SLICE control

2021-04-20 Thread Benjamin Gaignard
Make sure that V4L2_PIX_FMT_HEVC_SLICE is correctly handled by the driver.

Signed-off-by: Benjamin Gaignard 
Reviewed-by: Ezequiel Garcia 
---
 drivers/staging/media/hantro/hantro_v4l2.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/staging/media/hantro/hantro_v4l2.c 
b/drivers/staging/media/hantro/hantro_v4l2.c
index 77d7fe62ce81..0655324fd0d4 100644
--- a/drivers/staging/media/hantro/hantro_v4l2.c
+++ b/drivers/staging/media/hantro/hantro_v4l2.c
@@ -392,6 +392,7 @@ hantro_update_requires_request(struct hantro_ctx *ctx, u32 
fourcc)
case V4L2_PIX_FMT_MPEG2_SLICE:
case V4L2_PIX_FMT_VP8_FRAME:
case V4L2_PIX_FMT_H264_SLICE:
+   case V4L2_PIX_FMT_HEVC_SLICE:
ctx->fh.m2m_ctx->out_q_ctx.q.requires_requests = true;
break;
default:
-- 
2.25.1



[PATCH v10 5/9] media: hantro: Only use postproc when post processed formats are defined

2021-04-20 Thread Benjamin Gaignard
If the variant doesn't support postprocessed formats make sure it will
be ok.

Signed-off-by: Benjamin Gaignard 
Reviewed-by: Ezequiel Garcia 
---
 drivers/staging/media/hantro/hantro.h  |  8 ++--
 drivers/staging/media/hantro/hantro_postproc.c | 14 ++
 drivers/staging/media/hantro/hantro_v4l2.c |  4 +++-
 3 files changed, 19 insertions(+), 7 deletions(-)

diff --git a/drivers/staging/media/hantro/hantro.h 
b/drivers/staging/media/hantro/hantro.h
index 4368c0962768..e50d39b51902 100644
--- a/drivers/staging/media/hantro/hantro.h
+++ b/drivers/staging/media/hantro/hantro.h
@@ -413,12 +413,8 @@ hantro_get_dst_buf(struct hantro_ctx *ctx)
return v4l2_m2m_next_dst_buf(ctx->fh.m2m_ctx);
 }
 
-static inline bool
-hantro_needs_postproc(const struct hantro_ctx *ctx,
- const struct hantro_fmt *fmt)
-{
-   return !ctx->is_encoder && fmt->fourcc != V4L2_PIX_FMT_NV12;
-}
+bool hantro_needs_postproc(const struct hantro_ctx *ctx,
+  const struct hantro_fmt *fmt);
 
 static inline dma_addr_t
 hantro_get_dec_buf_addr(struct hantro_ctx *ctx, struct vb2_buffer *vb)
diff --git a/drivers/staging/media/hantro/hantro_postproc.c 
b/drivers/staging/media/hantro/hantro_postproc.c
index 6d2a8f2a8f0b..ed8916c950a4 100644
--- a/drivers/staging/media/hantro/hantro_postproc.c
+++ b/drivers/staging/media/hantro/hantro_postproc.c
@@ -50,6 +50,20 @@ const struct hantro_postproc_regs hantro_g1_postproc_regs = {
.display_width = {G1_REG_PP_DISPLAY_WIDTH, 0, 0xfff},
 };
 
+bool hantro_needs_postproc(const struct hantro_ctx *ctx,
+  const struct hantro_fmt *fmt)
+{
+   struct hantro_dev *vpu = ctx->dev;
+
+   if (ctx->is_encoder)
+   return false;
+
+   if (!vpu->variant->postproc_fmts)
+   return false;
+
+   return fmt->fourcc != V4L2_PIX_FMT_NV12;
+}
+
 void hantro_postproc_enable(struct hantro_ctx *ctx)
 {
struct hantro_dev *vpu = ctx->dev;
diff --git a/drivers/staging/media/hantro/hantro_v4l2.c 
b/drivers/staging/media/hantro/hantro_v4l2.c
index 1bc118e375a1..77d7fe62ce81 100644
--- a/drivers/staging/media/hantro/hantro_v4l2.c
+++ b/drivers/staging/media/hantro/hantro_v4l2.c
@@ -55,7 +55,9 @@ static const struct hantro_fmt *
 hantro_get_postproc_formats(const struct hantro_ctx *ctx,
unsigned int *num_fmts)
 {
-   if (ctx->is_encoder) {
+   struct hantro_dev *vpu = ctx->dev;
+
+   if (ctx->is_encoder || !vpu->variant->postproc_fmts) {
*num_fmts = 0;
return NULL;
}
-- 
2.25.1



[PATCH v10 4/9] media: hantro: Define HEVC codec profiles and supported features

2021-04-20 Thread Benjamin Gaignard
Define which HEVC profiles (up to level 5.1) and features
(no scaling, no 10 bits) are supported by the driver.

Signed-off-by: Benjamin Gaignard 
Reviewed-by: Ezequiel Garcia 
---
 drivers/staging/media/hantro/hantro.h |  3 ++
 drivers/staging/media/hantro/hantro_drv.c | 58 +++
 2 files changed, 61 insertions(+)

diff --git a/drivers/staging/media/hantro/hantro.h 
b/drivers/staging/media/hantro/hantro.h
index 6c1b888abe75..4368c0962768 100644
--- a/drivers/staging/media/hantro/hantro.h
+++ b/drivers/staging/media/hantro/hantro.h
@@ -34,6 +34,7 @@ struct hantro_codec_ops;
 #define HANTRO_MPEG2_DECODER   BIT(16)
 #define HANTRO_VP8_DECODER BIT(17)
 #define HANTRO_H264_DECODERBIT(18)
+#define HANTRO_HEVC_DECODERBIT(19)
 #define HANTRO_DECODERS0x
 
 /**
@@ -99,6 +100,7 @@ struct hantro_variant {
  * @HANTRO_MODE_H264_DEC: H264 decoder.
  * @HANTRO_MODE_MPEG2_DEC: MPEG-2 decoder.
  * @HANTRO_MODE_VP8_DEC: VP8 decoder.
+ * @HANTRO_MODE_HEVC_DEC: HEVC decoder.
  */
 enum hantro_codec_mode {
HANTRO_MODE_NONE = -1,
@@ -106,6 +108,7 @@ enum hantro_codec_mode {
HANTRO_MODE_H264_DEC,
HANTRO_MODE_MPEG2_DEC,
HANTRO_MODE_VP8_DEC,
+   HANTRO_MODE_HEVC_DEC,
 };
 
 /*
diff --git a/drivers/staging/media/hantro/hantro_drv.c 
b/drivers/staging/media/hantro/hantro_drv.c
index 02c5c2f1a88b..d9a3a5ef9330 100644
--- a/drivers/staging/media/hantro/hantro_drv.c
+++ b/drivers/staging/media/hantro/hantro_drv.c
@@ -245,6 +245,18 @@ static int hantro_try_ctrl(struct v4l2_ctrl *ctrl)
if (sps->bit_depth_luma_minus8 != 0)
/* Only 8-bit is supported */
return -EINVAL;
+   } else if (ctrl->id == V4L2_CID_MPEG_VIDEO_HEVC_SPS) {
+   const struct v4l2_ctrl_hevc_sps *sps = ctrl->p_new.p_hevc_sps;
+
+   if (sps->bit_depth_luma_minus8 != sps->bit_depth_chroma_minus8)
+   /* Luma and chroma bit depth mismatch */
+   return -EINVAL;
+   if (sps->bit_depth_luma_minus8 != 0)
+   /* Only 8-bit is supported */
+   return -EINVAL;
+   if (sps->flags & V4L2_HEVC_SPS_FLAG_SCALING_LIST_ENABLED)
+   /* No scaling support */
+   return -EINVAL;
}
return 0;
 }
@@ -351,6 +363,52 @@ static const struct hantro_ctrl controls[] = {
.def = V4L2_MPEG_VIDEO_H264_PROFILE_MAIN,
}
}, {
+   .codec = HANTRO_HEVC_DECODER,
+   .cfg = {
+   .id = V4L2_CID_MPEG_VIDEO_HEVC_DECODE_MODE,
+   .min = V4L2_MPEG_VIDEO_HEVC_DECODE_MODE_FRAME_BASED,
+   .max = V4L2_MPEG_VIDEO_HEVC_DECODE_MODE_FRAME_BASED,
+   .def = V4L2_MPEG_VIDEO_HEVC_DECODE_MODE_FRAME_BASED,
+   },
+   }, {
+   .codec = HANTRO_HEVC_DECODER,
+   .cfg = {
+   .id = V4L2_CID_MPEG_VIDEO_HEVC_START_CODE,
+   .min = V4L2_MPEG_VIDEO_HEVC_START_CODE_ANNEX_B,
+   .max = V4L2_MPEG_VIDEO_HEVC_START_CODE_ANNEX_B,
+   .def = V4L2_MPEG_VIDEO_HEVC_START_CODE_ANNEX_B,
+   },
+   }, {
+   .codec = HANTRO_HEVC_DECODER,
+   .cfg = {
+   .id = V4L2_CID_MPEG_VIDEO_HEVC_PROFILE,
+   .min = V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN,
+   .max = V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN_10,
+   .def = V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN,
+   },
+   }, {
+   .codec = HANTRO_HEVC_DECODER,
+   .cfg = {
+   .id = V4L2_CID_MPEG_VIDEO_HEVC_LEVEL,
+   .min = V4L2_MPEG_VIDEO_HEVC_LEVEL_1,
+   .max = V4L2_MPEG_VIDEO_HEVC_LEVEL_5_1,
+   },
+   }, {
+   .codec = HANTRO_HEVC_DECODER,
+   .cfg = {
+   .id = V4L2_CID_MPEG_VIDEO_HEVC_SPS,
+   .ops = _ctrl_ops,
+   },
+   }, {
+   .codec = HANTRO_HEVC_DECODER,
+   .cfg = {
+   .id = V4L2_CID_MPEG_VIDEO_HEVC_PPS,
+   },
+   }, {
+   .codec = HANTRO_HEVC_DECODER,
+   .cfg = {
+   .id = V4L2_CID_MPEG_VIDEO_HEVC_DECODE_PARAMS,
+   },
},
 };
 
-- 
2.25.1



[PATCH v10 3/9] media: hantro: change hantro_codec_ops run prototype to return errors

2021-04-20 Thread Benjamin Gaignard
Change hantro_codec_ops run prototype from 'void' to 'int'.
This allows the driver to cancel the job if an error occurs while configuring
the hardware.

Signed-off-by: Benjamin Gaignard 
Reviewed-by: Ezequiel Garcia 
---
 drivers/staging/media/hantro/hantro_drv.c |  4 +++-
 .../staging/media/hantro/hantro_g1_h264_dec.c | 10 +++---
 .../media/hantro/hantro_g1_mpeg2_dec.c|  4 +++-
 .../staging/media/hantro/hantro_g1_vp8_dec.c  |  6 --
 .../staging/media/hantro/hantro_h1_jpeg_enc.c |  4 +++-
 drivers/staging/media/hantro/hantro_hw.h  | 19 ++-
 .../media/hantro/rk3399_vpu_hw_jpeg_enc.c |  4 +++-
 .../media/hantro/rk3399_vpu_hw_mpeg2_dec.c|  4 +++-
 .../media/hantro/rk3399_vpu_hw_vp8_dec.c  |  6 --
 9 files changed, 40 insertions(+), 21 deletions(-)

diff --git a/drivers/staging/media/hantro/hantro_drv.c 
b/drivers/staging/media/hantro/hantro_drv.c
index 595e82a82728..02c5c2f1a88b 100644
--- a/drivers/staging/media/hantro/hantro_drv.c
+++ b/drivers/staging/media/hantro/hantro_drv.c
@@ -161,7 +161,9 @@ static void device_run(void *priv)
 
v4l2_m2m_buf_copy_metadata(src, dst, true);
 
-   ctx->codec_ops->run(ctx);
+   if (ctx->codec_ops->run(ctx))
+   goto err_cancel_job;
+
return;
 
 err_cancel_job:
diff --git a/drivers/staging/media/hantro/hantro_g1_h264_dec.c 
b/drivers/staging/media/hantro/hantro_g1_h264_dec.c
index 845bef73d218..5c792b7bcb79 100644
--- a/drivers/staging/media/hantro/hantro_g1_h264_dec.c
+++ b/drivers/staging/media/hantro/hantro_g1_h264_dec.c
@@ -273,13 +273,15 @@ static void set_buffers(struct hantro_ctx *ctx)
vdpu_write_relaxed(vpu, ctx->h264_dec.priv.dma, G1_REG_ADDR_QTABLE);
 }
 
-void hantro_g1_h264_dec_run(struct hantro_ctx *ctx)
+int hantro_g1_h264_dec_run(struct hantro_ctx *ctx)
 {
struct hantro_dev *vpu = ctx->dev;
+   int ret;
 
/* Prepare the H264 decoder context. */
-   if (hantro_h264_dec_prepare_run(ctx))
-   return;
+   ret = hantro_h264_dec_prepare_run(ctx);
+   if (ret)
+   return ret;
 
/* Configure hardware registers. */
set_params(ctx);
@@ -301,4 +303,6 @@ void hantro_g1_h264_dec_run(struct hantro_ctx *ctx)
   G1_REG_CONFIG_DEC_CLK_GATE_E,
   G1_REG_CONFIG);
vdpu_write(vpu, G1_REG_INTERRUPT_DEC_E, G1_REG_INTERRUPT);
+
+   return 0;
 }
diff --git a/drivers/staging/media/hantro/hantro_g1_mpeg2_dec.c 
b/drivers/staging/media/hantro/hantro_g1_mpeg2_dec.c
index 6386a3989bfe..5e8943d31dc5 100644
--- a/drivers/staging/media/hantro/hantro_g1_mpeg2_dec.c
+++ b/drivers/staging/media/hantro/hantro_g1_mpeg2_dec.c
@@ -155,7 +155,7 @@ hantro_g1_mpeg2_dec_set_buffers(struct hantro_dev *vpu, 
struct hantro_ctx *ctx,
vdpu_write_relaxed(vpu, backward_addr, G1_REG_REFER3_BASE);
 }
 
-void hantro_g1_mpeg2_dec_run(struct hantro_ctx *ctx)
+int hantro_g1_mpeg2_dec_run(struct hantro_ctx *ctx)
 {
struct hantro_dev *vpu = ctx->dev;
struct vb2_v4l2_buffer *src_buf, *dst_buf;
@@ -248,4 +248,6 @@ void hantro_g1_mpeg2_dec_run(struct hantro_ctx *ctx)
 
reg = G1_REG_DEC_E(1);
vdpu_write(vpu, reg, G1_SWREG(1));
+
+   return 0;
 }
diff --git a/drivers/staging/media/hantro/hantro_g1_vp8_dec.c 
b/drivers/staging/media/hantro/hantro_g1_vp8_dec.c
index 57002ba70176..96622a7f8279 100644
--- a/drivers/staging/media/hantro/hantro_g1_vp8_dec.c
+++ b/drivers/staging/media/hantro/hantro_g1_vp8_dec.c
@@ -425,7 +425,7 @@ static void cfg_buffers(struct hantro_ctx *ctx,
vdpu_write_relaxed(vpu, dst_dma, G1_REG_ADDR_DST);
 }
 
-void hantro_g1_vp8_dec_run(struct hantro_ctx *ctx)
+int hantro_g1_vp8_dec_run(struct hantro_ctx *ctx)
 {
const struct v4l2_ctrl_vp8_frame *hdr;
struct hantro_dev *vpu = ctx->dev;
@@ -438,7 +438,7 @@ void hantro_g1_vp8_dec_run(struct hantro_ctx *ctx)
 
hdr = hantro_get_ctrl(ctx, V4L2_CID_STATELESS_VP8_FRAME);
if (WARN_ON(!hdr))
-   return;
+   return -EINVAL;
 
/* Reset segment_map buffer in keyframe */
if (V4L2_VP8_FRAME_IS_KEY_FRAME(hdr) && ctx->vp8_dec.segment_map.cpu)
@@ -498,4 +498,6 @@ void hantro_g1_vp8_dec_run(struct hantro_ctx *ctx)
hantro_end_prepare_run(ctx);
 
vdpu_write(vpu, G1_REG_INTERRUPT_DEC_E, G1_REG_INTERRUPT);
+
+   return 0;
 }
diff --git a/drivers/staging/media/hantro/hantro_h1_jpeg_enc.c 
b/drivers/staging/media/hantro/hantro_h1_jpeg_enc.c
index b88dc4ed06db..56cf261a8e95 100644
--- a/drivers/staging/media/hantro/hantro_h1_jpeg_enc.c
+++ b/drivers/staging/media/hantro/hantro_h1_jpeg_enc.c
@@ -88,7 +88,7 @@ hantro_h1_jpeg_enc_set_qtable(struct hantro_dev *vpu,
}
 }
 
-void hantro_h1_jpeg_enc_run(struct hantro_ctx *ctx)
+int hantro_h1_jpeg_enc_run(struct hantro_ctx *ctx)
 {
struct hantro_dev *vpu = ctx->dev;
struct vb2_v4l2_buffer *src_b

[PATCH v10 2/9] media: hevc: Add decode params control

2021-04-20 Thread Benjamin Gaignard
Add decode params control and the associated structure to group
all the information that are needed to decode a reference frame as
is described in ITU-T Rec. H.265 section "8.3.2 Decoding process
for reference picture set".

Adapt Cedrus driver to these changes.

Signed-off-by: Benjamin Gaignard 
Reviewed-by: Ezequiel Garcia 
---
 .../media/v4l/ext-ctrls-codec.rst | 94 +++
 .../media/v4l/vidioc-queryctrl.rst|  6 ++
 drivers/media/v4l2-core/v4l2-ctrls.c  | 28 --
 drivers/staging/media/sunxi/cedrus/cedrus.c   |  6 ++
 drivers/staging/media/sunxi/cedrus/cedrus.h   |  1 +
 .../staging/media/sunxi/cedrus/cedrus_dec.c   |  2 +
 .../staging/media/sunxi/cedrus/cedrus_h265.c  | 12 ++-
 include/media/hevc-ctrls.h| 29 --
 8 files changed, 138 insertions(+), 40 deletions(-)

diff --git a/Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst 
b/Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst
index aabcb0e63a5e..7b90cb939e9d 100644
--- a/Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst
+++ b/Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst
@@ -3214,9 +3214,6 @@ enum v4l2_mpeg_video_hevc_size_of_length_field -
 * - __u8
   - ``pic_struct``
   -
-* - __u8
-  - ``num_active_dpb_entries``
-  - The number of entries in ``dpb``.
 * - __u8
   - ``ref_idx_l0[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]``
   - The list of L0 reference elements as indices in the DPB.
@@ -3224,22 +3221,8 @@ enum v4l2_mpeg_video_hevc_size_of_length_field -
   - ``ref_idx_l1[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]``
   - The list of L1 reference elements as indices in the DPB.
 * - __u8
-  - ``num_rps_poc_st_curr_before``
-  - The number of reference pictures in the short-term set that come before
-the current frame.
-* - __u8
-  - ``num_rps_poc_st_curr_after``
-  - The number of reference pictures in the short-term set that come after
-the current frame.
-* - __u8
-  - ``num_rps_poc_lt_curr``
-  - The number of reference pictures in the long-term set.
-* - __u8
-  - ``padding[7]``
+  - ``padding``
   - Applications and drivers must set this to zero.
-* - struct :c:type:`v4l2_hevc_dpb_entry`
-  - ``dpb[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]``
-  - The decoded picture buffer, for meta-data about reference frames.
 * - struct :c:type:`v4l2_hevc_pred_weight_table`
   - ``pred_weight_table``
   - The prediction weight coefficients for inter-picture prediction.
@@ -3492,3 +3475,78 @@ enum v4l2_mpeg_video_hevc_size_of_length_field -
 encoding the next frame queued after setting this control.
 This provides a bitmask which consists of bits [0, LTR_COUNT-1].
 This is applicable to the H264 and HEVC encoders.
+
+``V4L2_CID_MPEG_VIDEO_HEVC_DECODE_PARAMS (struct)``
+Specifies various decode parameters, especially the references picture 
order
+count (POC) for all the lists (short, long, before, current, after) and the
+number of entries for each of them.
+These parameters are defined according to :ref:`hevc`.
+They are described in section 8.3 "Slice decoding process" of the
+specification.
+
+.. c:type:: v4l2_ctrl_hevc_decode_params
+
+.. cssclass:: longtable
+
+.. flat-table:: struct v4l2_ctrl_hevc_decode_params
+:header-rows:  0
+:stub-columns: 0
+:widths:   1 1 2
+
+* - __s32
+  - ``pic_order_cnt_val``
+  - PicOrderCntVal as described in section 8.3.1 "Decoding process
+for picture order count" of the specification.
+* - __u8
+  - ``num_active_dpb_entries``
+  - The number of entries in ``dpb``.
+* - struct :c:type:`v4l2_hevc_dpb_entry`
+  - ``dpb[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]``
+  - The decoded picture buffer, for meta-data about reference frames.
+* - __u8
+  - ``num_poc_st_curr_before``
+  - The number of reference pictures in the short-term set that come before
+the current frame.
+* - __u8
+  - ``num_poc_st_curr_after``
+  - The number of reference pictures in the short-term set that come after
+the current frame.
+* - __u8
+  - ``num_poc_lt_curr``
+  - The number of reference pictures in the long-term set.
+* - __u8
+  - ``poc_st_curr_before[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]``
+  - PocStCurrBefore as described in section 8.3.2 "Decoding process for 
reference
+picture set.
+* - __u8
+  - ``poc_st_curr_after[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]``
+  - PocStCurrAfter as described in section 8.3.2 "Decoding process for 
reference
+picture set.
+* - __u8
+  - ``poc_lt_curr[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]``
+  - PocLtCurr as described in section 8.3.2 "Decoding process for reference
+picture set.
+* - __u64
+  - ``flags``
+  - See :ref:`Decode Parameters Flags `
+
+.. _hevc_deco

[PATCH v10 1/9] media: hevc: Add fields and flags for hevc PPS

2021-04-20 Thread Benjamin Gaignard
Add fields and flags as they are defined in
7.4.3.3.1 "General picture parameter set RBSP semantics of the
H.265 ITU specification.

Signed-off-by: Benjamin Gaignard 
Reviewed-by: Ezequiel Garcia 
---
 .../userspace-api/media/v4l/ext-ctrls-codec.rst| 14 ++
 include/media/hevc-ctrls.h |  4 
 2 files changed, 18 insertions(+)

diff --git a/Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst 
b/Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst
index b0de4e6e7ebd..aabcb0e63a5e 100644
--- a/Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst
+++ b/Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst
@@ -3000,6 +3000,12 @@ enum v4l2_mpeg_video_hevc_size_of_length_field -
 * - __u8
   - ``num_extra_slice_header_bits``
   -
+* - __u8
+  - ``num_ref_idx_l0_default_active_minus1``
+  - Specifies the inferred value of num_ref_idx_l0_active_minus1
+* - __u8
+  - ``num_ref_idx_l1_default_active_minus1``
+  - Specifies the inferred value of num_ref_idx_l1_active_minus1
 * - __s8
   - ``init_qp_minus26``
   -
@@ -3110,6 +3116,14 @@ enum v4l2_mpeg_video_hevc_size_of_length_field -
 * - ``V4L2_HEVC_PPS_FLAG_SLICE_SEGMENT_HEADER_EXTENSION_PRESENT``
   - 0x0004
   -
+* - ``V4L2_HEVC_PPS_FLAG_DEBLOCKING_FILTER_CONTROL_PRESENT``
+  - 0x0008
+  - Specifies the presence of deblocking filter control syntax elements in
+the PPS
+* - ``V4L2_HEVC_PPS_FLAG_UNIFORM_SPACING``
+  - 0x0010
+  - Specifies that tile column boundaries and likewise tile row boundaries
+are distributed uniformly across the picture
 
 .. raw:: latex
 
diff --git a/include/media/hevc-ctrls.h b/include/media/hevc-ctrls.h
index b4cb2ef02f17..003f819ecb26 100644
--- a/include/media/hevc-ctrls.h
+++ b/include/media/hevc-ctrls.h
@@ -100,10 +100,14 @@ struct v4l2_ctrl_hevc_sps {
 #define V4L2_HEVC_PPS_FLAG_PPS_DISABLE_DEBLOCKING_FILTER   (1ULL << 16)
 #define V4L2_HEVC_PPS_FLAG_LISTS_MODIFICATION_PRESENT  (1ULL << 17)
 #define V4L2_HEVC_PPS_FLAG_SLICE_SEGMENT_HEADER_EXTENSION_PRESENT (1ULL << 18)
+#define V4L2_HEVC_PPS_FLAG_DEBLOCKING_FILTER_CONTROL_PRESENT   (1ULL << 19)
+#define V4L2_HEVC_PPS_FLAG_UNIFORM_SPACING (1ULL << 20)
 
 struct v4l2_ctrl_hevc_pps {
/* ISO/IEC 23008-2, ITU-T Rec. H.265: Picture parameter set */
__u8num_extra_slice_header_bits;
+   __u8num_ref_idx_l0_default_active_minus1;
+   __u8num_ref_idx_l1_default_active_minus1;
__s8init_qp_minus26;
__u8diff_cu_qp_delta_depth;
__s8pps_cb_qp_offset;
-- 
2.25.1



[PATCH v10 0/9] Add HANTRO G2/HEVC decoder support for IMX8MQ

2021-04-20 Thread Benjamin Gaignard
The IMX8MQ got two VPUs but until now only G1 has been enabled.
This series aim to add the second VPU (aka G2) and provide basic 
HEVC decoding support.

To be able to decode HEVC it is needed to add/update some of the
structures in the uapi. In addition of them one HANTRO dedicated
control is required to inform the driver of the number of bits to skip
at the beginning of the slice header.
The hardware require to allocate few auxiliary buffers to store the
references frame or tile size data.

The driver has been tested with fluster test suite stream.
For example with this command: ./fluster.py run -ts JCT-VC-HEVC_V1 -d 
GStreamer-H.265-V4L2SL-Gst1.0

version 10:
 - Shorter version of the previous series without ctrl block patches
   and no DT modifications.
   The scope of this series is limited to HEVC support.

version 9:
 - Corrections in commits messages.
 - Define the dedicated control in hevc-controls.h
 - Add note in documentation.
 - Change max value of the dedicated control.
 - Rebased on media_tree/master branch.

version 8:
 - Add reviewed-by and ack-by tags 
 - Fix the warnings reported by kernel test robot
 - Only patch 9 (adding dedicated control), patch 11 (HEVC support) and
   patch 13 (DT changes) are still missing of review/ack tag.

version 7:
 - Remove 'q' from syscon phandle name to make usable for iMX8MM too.
   Update the bindings documentation.
 - Add review/ack tags.
 - Rebase on top of media_tree/master
 - Be more accurate when computing the size of the memory needed motion
   vectors.
 - Explain why the all clocks need to set in the both DT node.

version 6:
 - fix the errors reported by kernel test robot

version 5:
 - use syscon instead of VPU reset driver.
 - Do not break kernel/DT backward compatibility.
 - Add documentation for dedicated Hantro control.
 - Fix the remarks done by Ezequeil (typo, comments, unused function)
 - Run v4l2-compliance without errors (see below).
 - Do not add field to distinguish version, check postproc reg instead

version 4:
- Split the changes in hevc controls in 2 commits to make them easier to
  review.
- Change hantro_codec_ops run() prototype to return errors   
- Hantro v4l2 dedicated control is now only an integer
- rebase on top of VPU reset changes posted here:
  https://www.spinics.net/lists/arm-kernel/msg878440.html
- Various fix from previous remarks
- Limit the modifications in API to what the driver needs

version 3:
- Fix typo in Hantro v4l2 dedicated control
- Add documentation for the new structures and fields
- Rebased on top of media_tree for-linus-5.12-rc1 tag

version 2:
- remove all change related to scaling
- squash commits to a coherent split
- be more verbose about the added fields
- fix the comments done by Ezequiel about dma_alloc_coherent usage
- fix Dan's comments about control copy, reverse the test logic
in tile_buffer_reallocate, rework some goto and return cases.
- be more verbose about why I change the bindings
- remove all sign-off expect mime since it is confusing
- remove useless clocks in VPUs nodes

Benjamin Gaignard (9):
  media: hevc: Add fields and flags for hevc PPS
  media: hevc: Add decode params control
  media: hantro: change hantro_codec_ops run prototype to return errors
  media: hantro: Define HEVC codec profiles and supported features
  media: hantro: Only use postproc when post processed formats are
defined
  media: uapi: Add a control for HANTRO driver
  media: hantro: handle V4L2_PIX_FMT_HEVC_SLICE control
  media: hantro: Introduce G2/HEVC decoder
  media: hantro: IMX8M: add variant for G2/HEVC codec

 .../userspace-api/media/drivers/hantro.rst|  19 +
 .../userspace-api/media/drivers/index.rst |   1 +
 .../media/v4l/ext-ctrls-codec.rst | 108 +++-
 .../media/v4l/vidioc-queryctrl.rst|   6 +
 drivers/media/v4l2-core/v4l2-ctrls.c  |  28 +-
 drivers/staging/media/hantro/Makefile |   2 +
 drivers/staging/media/hantro/hantro.h |  13 +-
 drivers/staging/media/hantro/hantro_drv.c |  99 ++-
 .../staging/media/hantro/hantro_g1_h264_dec.c |  10 +-
 .../media/hantro/hantro_g1_mpeg2_dec.c|   4 +-
 .../staging/media/hantro/hantro_g1_vp8_dec.c  |   6 +-
 .../staging/media/hantro/hantro_g2_hevc_dec.c | 587 ++
 drivers/staging/media/hantro/hantro_g2_regs.h | 198 ++
 .../staging/media/hantro/hantro_h1_jpeg_enc.c |   4 +-
 drivers/staging/media/hantro/hantro_hevc.c| 327 ++
 drivers/staging/media/hantro/hantro_hw.h  |  69 +-
 .../staging/media/hantro/hantro_postproc.c|  14 +
 drivers/staging/media/hantro/hantro_v4l2.c|   5 +-
 drivers/staging/media/hantro/imx8m_vpu_hw.c   |  74 ++-
 .../media/hantro/rk3399_vpu_hw_jpeg_enc.c |   4 +-
 .../media/hantro/rk3399_vpu_hw_mpeg2_dec.c|   4 +-
 .../media/hantro/rk3399_vpu_hw_vp8_dec.c  |   6 +-
 drivers/staging/media/sunxi/cedrus/cedrus.c   |   6 +
 drivers/staging/media/sunxi/cedrus/cedrus.h   |   1 +
 .../staging/media/sunxi/cedrus/cedrus_dec.c

Re: [PATCH v9 03/13] media: hantro: Use syscon instead of 'ctrl' register

2021-04-20 Thread Benjamin Gaignard



Le 20/04/2021 à 11:16, Hans Verkuil a écrit :

On 20/04/2021 11:10, Benjamin Gaignard wrote:

Le 16/04/2021 à 17:14, Lucas Stach a écrit :

Am Freitag, dem 16.04.2021 um 15:08 +0200 schrieb Benjamin Gaignard:

Le 16/04/2021 à 12:54, Lucas Stach a écrit :

Am Mittwoch, dem 07.04.2021 um 09:35 +0200 schrieb Benjamin Gaignard:

In order to be able to share the control hardware block between
VPUs use a syscon instead a ioremap it in the driver.
To keep the compatibility with older DT if 'nxp,imx8mq-vpu-ctrl'
phandle is not found look at 'ctrl' reg-name.
With the method it becomes useless to provide a list of register
names so remove it.

Sorry for putting a spoke in the wheel after many iterations of the
series.

We just discussed a way forward on how to handle the clocks and resets
provided by the blkctl block on i.MX8MM and later and it seems there is
a consensus on trying to provide virtual power domains from a blkctl
driver, controlling clocks and resets for the devices in the power
domain. I would like to avoid introducing yet another way of handling
the blkctl and thus would like to align the i.MX8MQ VPU blkctl with
what we are planning to do on the later chip generations.

CC'ing Jacky Bai and Peng Fan from NXP, as they were going to give this
virtual power domain thing a shot.

That could replace the 3 first patches and Dt patche of this series
but that will not impact the hevc part, so I wonder if pure hevc patches
could be merged anyway ?
They are reviewed and don't depend of how the ctrl block is managed.

I'm not really in a position to give any informed opinion about that
hvec patches, as I only skimmed them, but I don't see any reason to
delay patches 04-11 from this series until the i.MX8M platform issues
are sorted. AFAICS those things are totally orthogonal.

Hi Hans,
What do you think about this proposal to split this series ?
Get hevc part merged could allow me to continue to add features
like scaling lists, compressed reference buffers and 10-bit supports.

Makes sense to me!


Great !
If the latest version match your expectations how would you like to processed ?
Can you merged patches 4 to 12 ? or should I resend them in a new shorted 
series ?

Regards,
Benjamin



Regards,

Hans



Re: [PATCH v9 03/13] media: hantro: Use syscon instead of 'ctrl' register

2021-04-20 Thread Benjamin Gaignard



Le 16/04/2021 à 17:14, Lucas Stach a écrit :

Am Freitag, dem 16.04.2021 um 15:08 +0200 schrieb Benjamin Gaignard:

Le 16/04/2021 à 12:54, Lucas Stach a écrit :

Am Mittwoch, dem 07.04.2021 um 09:35 +0200 schrieb Benjamin Gaignard:

In order to be able to share the control hardware block between
VPUs use a syscon instead a ioremap it in the driver.
To keep the compatibility with older DT if 'nxp,imx8mq-vpu-ctrl'
phandle is not found look at 'ctrl' reg-name.
With the method it becomes useless to provide a list of register
names so remove it.

Sorry for putting a spoke in the wheel after many iterations of the
series.

We just discussed a way forward on how to handle the clocks and resets
provided by the blkctl block on i.MX8MM and later and it seems there is
a consensus on trying to provide virtual power domains from a blkctl
driver, controlling clocks and resets for the devices in the power
domain. I would like to avoid introducing yet another way of handling
the blkctl and thus would like to align the i.MX8MQ VPU blkctl with
what we are planning to do on the later chip generations.

CC'ing Jacky Bai and Peng Fan from NXP, as they were going to give this
virtual power domain thing a shot.

That could replace the 3 first patches and Dt patche of this series
but that will not impact the hevc part, so I wonder if pure hevc patches
could be merged anyway ?
They are reviewed and don't depend of how the ctrl block is managed.

I'm not really in a position to give any informed opinion about that
hvec patches, as I only skimmed them, but I don't see any reason to
delay patches 04-11 from this series until the i.MX8M platform issues
are sorted. AFAICS those things are totally orthogonal.


Hi Hans,
What do you think about this proposal to split this series ?
Get hevc part merged could allow me to continue to add features
like scaling lists, compressed reference buffers and 10-bit supports.

Regards,
Benjamin



Regards,
Lucas


Regards,
Lucas


Signed-off-by: Benjamin Gaignard 
Reviewed-by: Philipp Zabel 
---
version 9:
   - Corrections in commit message

version 7:
   - Add Philipp reviewed-by tag.
   - Change syscon phandle name.
   







version 5:
   - use syscon instead of VPU reset driver.
   - if DT doesn't provide syscon keep backward compatibilty by using
 'ctrl' reg-name.

   drivers/staging/media/hantro/hantro.h   |  5 +-
   drivers/staging/media/hantro/imx8m_vpu_hw.c | 52 -
   2 files changed, 34 insertions(+), 23 deletions(-)

diff --git a/drivers/staging/media/hantro/hantro.h 
b/drivers/staging/media/hantro/hantro.h
index 6c1b888abe75..37b9ce04bd4e 100644
--- a/drivers/staging/media/hantro/hantro.h
+++ b/drivers/staging/media/hantro/hantro.h
@@ -13,6 +13,7 @@
   #define HANTRO_H_
   







   #include 
+#include 
   #include 
   #include 
   #include 
@@ -167,7 +168,7 @@ hantro_vdev_to_func(struct video_device *vdev)
    * @reg_bases:   Mapped addresses of VPU registers.
    * @enc_base:Mapped address of VPU encoder register for 
convenience.
    * @dec_base:Mapped address of VPU decoder register for 
convenience.
- * @ctrl_base: Mapped address of VPU control block.
+ * @ctrl_base: Regmap of VPU control block.
    * @vpu_mutex:   Mutex to synchronize V4L2 calls.
    * @irqlock: Spinlock to synchronize access to data structures
    *   shared with interrupt handlers.
@@ -186,7 +187,7 @@ struct hantro_dev {
    void __iomem **reg_bases;
    void __iomem *enc_base;
    void __iomem *dec_base;
-   void __iomem *ctrl_base;
+   struct regmap *ctrl_base;
   







    struct mutex vpu_mutex; /* video_device lock */
    spinlock_t irqlock;
diff --git a/drivers/staging/media/hantro/imx8m_vpu_hw.c 
b/drivers/staging/media/hantro/imx8m_vpu_hw.c
index c222de075ef4..8d0c3425234b 100644
--- a/drivers/staging/media/hantro/imx8m_vpu_hw.c
+++ b/drivers/staging/media/hantro/imx8m_vpu_hw.c
@@ -7,6 +7,7 @@
   







   #include 
   #include 
+#include 
   







   #include "hantro.h"
   #include "hantro_jpeg.h"
@@ -24,30 +25,28 @@
   #define CTRL_G1_PP_FUSE  0x0c
   #define CTRL_G2_DEC_FUSE 0x10
   







+static const struct regmap_config ctrl_regmap_ctrl = {
+   .reg_bits = 32,
+   .val_bits = 32,
+   .reg_stride = 0x14,
+};
+
   static void imx8m_soft_reset(struct hantro_dev *vpu, u32 reset_bits)
   {
-   u32 val;
-
    /* Assert */
-   val = readl(vpu->ctrl_base + CTRL_SOFT_RESET);
-   val &= ~reset_bits;
-   writel(val, vpu->ctrl_base + CTRL_SOFT_RESET);
+   regmap_update_bits(vpu->ctrl_base, CTRL_SOFT_RESET, reset_bits, 0);
   







    udelay(2);
   







    /* Release */
-   val = readl(vpu->ctrl_base + CTRL_SOFT_RESET);
-   val |= reset_bits;
-   writel(val, vpu->ctrl_base + CTRL_SOFT_RESET);
+   regmap_upda

Re: [PATCH v9 03/13] media: hantro: Use syscon instead of 'ctrl' register

2021-04-16 Thread Benjamin Gaignard



Le 16/04/2021 à 12:54, Lucas Stach a écrit :

Am Mittwoch, dem 07.04.2021 um 09:35 +0200 schrieb Benjamin Gaignard:

In order to be able to share the control hardware block between
VPUs use a syscon instead a ioremap it in the driver.
To keep the compatibility with older DT if 'nxp,imx8mq-vpu-ctrl'
phandle is not found look at 'ctrl' reg-name.
With the method it becomes useless to provide a list of register
names so remove it.

Sorry for putting a spoke in the wheel after many iterations of the
series.

We just discussed a way forward on how to handle the clocks and resets
provided by the blkctl block on i.MX8MM and later and it seems there is
a consensus on trying to provide virtual power domains from a blkctl
driver, controlling clocks and resets for the devices in the power
domain. I would like to avoid introducing yet another way of handling
the blkctl and thus would like to align the i.MX8MQ VPU blkctl with
what we are planning to do on the later chip generations.

CC'ing Jacky Bai and Peng Fan from NXP, as they were going to give this
virtual power domain thing a shot.


That could replace the 3 first patches and Dt patche of this series
but that will not impact the hevc part, so I wonder if pure hevc patches
could be merged anyway ?
They are reviewed and don't depend of how the ctrl block is managed.

Regards,
Benjamin



Regards,
Lucas


Signed-off-by: Benjamin Gaignard 
Reviewed-by: Philipp Zabel 
---
version 9:
  - Corrections in commit message

version 7:
  - Add Philipp reviewed-by tag.
  - Change syscon phandle name.
  




version 5:
  - use syscon instead of VPU reset driver.
  - if DT doesn't provide syscon keep backward compatibilty by using
    'ctrl' reg-name.

  drivers/staging/media/hantro/hantro.h   |  5 +-
  drivers/staging/media/hantro/imx8m_vpu_hw.c | 52 -
  2 files changed, 34 insertions(+), 23 deletions(-)

diff --git a/drivers/staging/media/hantro/hantro.h 
b/drivers/staging/media/hantro/hantro.h
index 6c1b888abe75..37b9ce04bd4e 100644
--- a/drivers/staging/media/hantro/hantro.h
+++ b/drivers/staging/media/hantro/hantro.h
@@ -13,6 +13,7 @@
  #define HANTRO_H_
  




  #include 
+#include 
  #include 
  #include 
  #include 
@@ -167,7 +168,7 @@ hantro_vdev_to_func(struct video_device *vdev)
   * @reg_bases:Mapped addresses of VPU registers.
   * @enc_base: Mapped address of VPU encoder register for convenience.
   * @dec_base: Mapped address of VPU decoder register for convenience.
- * @ctrl_base: Mapped address of VPU control block.
+ * @ctrl_base: Regmap of VPU control block.
   * @vpu_mutex:Mutex to synchronize V4L2 calls.
   * @irqlock:  Spinlock to synchronize access to data structures
   *shared with interrupt handlers.
@@ -186,7 +187,7 @@ struct hantro_dev {
    void __iomem **reg_bases;
    void __iomem *enc_base;
    void __iomem *dec_base;
-   void __iomem *ctrl_base;
+   struct regmap *ctrl_base;
  




    struct mutex vpu_mutex; /* video_device lock */
    spinlock_t irqlock;
diff --git a/drivers/staging/media/hantro/imx8m_vpu_hw.c 
b/drivers/staging/media/hantro/imx8m_vpu_hw.c
index c222de075ef4..8d0c3425234b 100644
--- a/drivers/staging/media/hantro/imx8m_vpu_hw.c
+++ b/drivers/staging/media/hantro/imx8m_vpu_hw.c
@@ -7,6 +7,7 @@
  




  #include 
  #include 
+#include 
  




  #include "hantro.h"
  #include "hantro_jpeg.h"
@@ -24,30 +25,28 @@
  #define CTRL_G1_PP_FUSE   0x0c
  #define CTRL_G2_DEC_FUSE  0x10
  




+static const struct regmap_config ctrl_regmap_ctrl = {
+   .reg_bits = 32,
+   .val_bits = 32,
+   .reg_stride = 0x14,
+};
+
  static void imx8m_soft_reset(struct hantro_dev *vpu, u32 reset_bits)
  {
-   u32 val;
-
    /* Assert */
-   val = readl(vpu->ctrl_base + CTRL_SOFT_RESET);
-   val &= ~reset_bits;
-   writel(val, vpu->ctrl_base + CTRL_SOFT_RESET);
+   regmap_update_bits(vpu->ctrl_base, CTRL_SOFT_RESET, reset_bits, 0);
  




    udelay(2);
  




    /* Release */
-   val = readl(vpu->ctrl_base + CTRL_SOFT_RESET);
-   val |= reset_bits;
-   writel(val, vpu->ctrl_base + CTRL_SOFT_RESET);
+   regmap_update_bits(vpu->ctrl_base, CTRL_SOFT_RESET,
+  reset_bits, reset_bits);
  }
  




  static void imx8m_clk_enable(struct hantro_dev *vpu, u32 clock_bits)
  {
-   u32 val;
-
-   val = readl(vpu->ctrl_base + CTRL_CLOCK_ENABLE);
-   val |= clock_bits;
-   writel(val, vpu->ctrl_base + CTRL_CLOCK_ENABLE);
+   regmap_update_bits(vpu->ctrl_base, CTRL_CLOCK_ENABLE,
+  clock_bits, clock_bits);
  }
  




  static int imx8mq_runtime_resume(struct hantro_dev *vpu)
@@ -64,9 +63,9 @@ static int imx8mq_runtime_resume(struct hantro_dev *vpu)
    imx8m_clk_enable(vpu, CLOCK_G1 | CLOCK_G2);
  




    /* Set values of t

[PATCH v9 11/13] media: hantro: Introduce G2/HEVC decoder

2021-04-07 Thread Benjamin Gaignard
Implement all the logic to get G2 hardware decoding HEVC frames.
It supports up level 5.1 HEVC stream.
It doesn't support yet 10 bits formats or the scaling feature.

Add HANTRO HEVC dedicated control to skip some bits at the beginning
of the slice header. That is very specific to this hardware so can't
go into uapi structures. Computing the needed value is complex and requires
information from the stream that only the userland knows so let it
provide the correct value to the driver.

Signed-off-by: Benjamin Gaignard 
Co-developed-by: Adrian Ratiu 
Signed-off-by: Adrian Ratiu 
Co-developed-by: Ezequiel Garcia 
Signed-off-by: Ezequiel Garcia 
---
version 9:
 - Corrections in commit message
 - Change V4L2_CID_HANTRO_HEVC_SLICE_HEADER_SKIP control's max value 

version 8:
 - Fix compilation warnings

version 7:
 - Improve motion vectors requested memory size computation.

 drivers/staging/media/hantro/Makefile |   2 +
 drivers/staging/media/hantro/hantro.h |   2 +
 drivers/staging/media/hantro/hantro_drv.c |  36 ++
 .../staging/media/hantro/hantro_g2_hevc_dec.c | 587 ++
 drivers/staging/media/hantro/hantro_g2_regs.h | 198 ++
 drivers/staging/media/hantro/hantro_hevc.c| 327 ++
 drivers/staging/media/hantro/hantro_hw.h  |  49 ++
 7 files changed, 1201 insertions(+)
 create mode 100644 drivers/staging/media/hantro/hantro_g2_hevc_dec.c
 create mode 100644 drivers/staging/media/hantro/hantro_g2_regs.h
 create mode 100644 drivers/staging/media/hantro/hantro_hevc.c

diff --git a/drivers/staging/media/hantro/Makefile 
b/drivers/staging/media/hantro/Makefile
index 743ce08eb184..0357f1772267 100644
--- a/drivers/staging/media/hantro/Makefile
+++ b/drivers/staging/media/hantro/Makefile
@@ -9,12 +9,14 @@ hantro-vpu-y += \
hantro_h1_jpeg_enc.o \
hantro_g1_h264_dec.o \
hantro_g1_mpeg2_dec.o \
+   hantro_g2_hevc_dec.o \
hantro_g1_vp8_dec.o \
rk3399_vpu_hw_jpeg_enc.o \
rk3399_vpu_hw_mpeg2_dec.o \
rk3399_vpu_hw_vp8_dec.o \
hantro_jpeg.o \
hantro_h264.o \
+   hantro_hevc.o \
hantro_mpeg2.o \
hantro_vp8.o
 
diff --git a/drivers/staging/media/hantro/hantro.h 
b/drivers/staging/media/hantro/hantro.h
index 7a5ad93466c8..6a21d1e95b34 100644
--- a/drivers/staging/media/hantro/hantro.h
+++ b/drivers/staging/media/hantro/hantro.h
@@ -222,6 +222,7 @@ struct hantro_dev {
  * @jpeg_enc:  JPEG-encoding context.
  * @mpeg2_dec: MPEG-2-decoding context.
  * @vp8_dec:   VP8-decoding context.
+ * @hevc_dec:  HEVC-decoding context.
  */
 struct hantro_ctx {
struct hantro_dev *dev;
@@ -248,6 +249,7 @@ struct hantro_ctx {
struct hantro_jpeg_enc_hw_ctx jpeg_enc;
struct hantro_mpeg2_dec_hw_ctx mpeg2_dec;
struct hantro_vp8_dec_hw_ctx vp8_dec;
+   struct hantro_hevc_dec_hw_ctx hevc_dec;
};
 };
 
diff --git a/drivers/staging/media/hantro/hantro_drv.c 
b/drivers/staging/media/hantro/hantro_drv.c
index d9a3a5ef9330..905a69758b37 100644
--- a/drivers/staging/media/hantro/hantro_drv.c
+++ b/drivers/staging/media/hantro/hantro_drv.c
@@ -281,6 +281,26 @@ static int hantro_jpeg_s_ctrl(struct v4l2_ctrl *ctrl)
return 0;
 }
 
+static int hantro_hevc_s_ctrl(struct v4l2_ctrl *ctrl)
+{
+   struct hantro_ctx *ctx;
+
+   ctx = container_of(ctrl->handler,
+  struct hantro_ctx, ctrl_handler);
+
+   vpu_debug(1, "s_ctrl: id = %d, val = %d\n", ctrl->id, ctrl->val);
+
+   switch (ctrl->id) {
+   case V4L2_CID_HANTRO_HEVC_SLICE_HEADER_SKIP:
+   ctx->hevc_dec.ctrls.hevc_hdr_skip_length = ctrl->val;
+   break;
+   default:
+   return -EINVAL;
+   }
+
+   return 0;
+}
+
 static const struct v4l2_ctrl_ops hantro_ctrl_ops = {
.try_ctrl = hantro_try_ctrl,
 };
@@ -289,6 +309,10 @@ static const struct v4l2_ctrl_ops hantro_jpeg_ctrl_ops = {
.s_ctrl = hantro_jpeg_s_ctrl,
 };
 
+static const struct v4l2_ctrl_ops hantro_hevc_ctrl_ops = {
+   .s_ctrl = hantro_hevc_s_ctrl,
+};
+
 static const struct hantro_ctrl controls[] = {
{
.codec = HANTRO_JPEG_ENCODER,
@@ -409,6 +433,18 @@ static const struct hantro_ctrl controls[] = {
.cfg = {
.id = V4L2_CID_MPEG_VIDEO_HEVC_DECODE_PARAMS,
},
+   }, {
+   .codec = HANTRO_HEVC_DECODER,
+   .cfg = {
+   .id = V4L2_CID_HANTRO_HEVC_SLICE_HEADER_SKIP,
+   .name = "Hantro HEVC slice header skip bytes",
+   .type = V4L2_CTRL_TYPE_INTEGER,
+   .min = 0,
+   .def = 0,
+   .max = 0x100,
+   .

[PATCH v9 13/13] arm64: dts: imx8mq: Add node to G2 hardware

2021-04-07 Thread Benjamin Gaignard
Split the VPU node in two: one for G1 and one for G2 since they are
different hardware blocks.
Add syscon for the hardware control block.
Remove the reg-names property that is useless.
Each VPU node only needs one interrupt.
Change G2 assigned clock to match the specification.
In both nodes all the clocks need to be assigned to make
sure that the control block will be correctly clocked even if
only one device node is enabled.

Signed-off-by: Benjamin Gaignard 
---
version 9:
 - Corrections in commit message

version 7:
 - use nxp,imx8m-vpu-ctrl as phandle syscon property name

version 5:
 - use syscon instead of VPU reset

 arch/arm64/boot/dts/freescale/imx8mq.dtsi | 43 ++-
 1 file changed, 34 insertions(+), 9 deletions(-)

diff --git a/arch/arm64/boot/dts/freescale/imx8mq.dtsi 
b/arch/arm64/boot/dts/freescale/imx8mq.dtsi
index 17c449e12c2e..65158414d255 100644
--- a/arch/arm64/boot/dts/freescale/imx8mq.dtsi
+++ b/arch/arm64/boot/dts/freescale/imx8mq.dtsi
@@ -1329,15 +1329,16 @@ usb3_phy1: usb-phy@382f0040 {
status = "disabled";
};
 
-   vpu: video-codec@3830 {
+   vpu_ctrl: syscon@3832 {
+   compatible = "nxp,imx8mq-vpu-ctrl", "syscon";
+   reg = <0x3832 0x1>;
+   };
+
+   vpu_g1: video-codec@3830 {
compatible = "nxp,imx8mq-vpu";
-   reg = <0x3830 0x1>,
- <0x3831 0x1>,
- <0x3832 0x1>;
-   reg-names = "g1", "g2", "ctrl";
-   interrupts = ,
-;
-   interrupt-names = "g1", "g2";
+   reg = <0x3830 0x1>;
+   interrupts = ;
+   interrupt-names = "g1";
clocks = < IMX8MQ_CLK_VPU_G1_ROOT>,
 < IMX8MQ_CLK_VPU_G2_ROOT>,
 < IMX8MQ_CLK_VPU_DEC_ROOT>;
@@ -1350,9 +1351,33 @@ vpu: video-codec@3830 {
 < IMX8MQ_VPU_PLL_OUT>,
 < IMX8MQ_SYS1_PLL_800M>,
 < IMX8MQ_VPU_PLL>;
-   assigned-clock-rates = <6>, <6>,
+   assigned-clock-rates = <6>, <3>,
+  <8>, <0>;
+   power-domains = <_vpu>;
+   nxp,imx8m-vpu-ctrl = <_ctrl>;
+   };
+
+   vpu_g2: video-codec@3831 {
+   compatible = "nxp,imx8mq-vpu-g2";
+   reg = <0x3831 0x1>;
+   interrupts = ;
+   interrupt-names = "g2";
+   clocks = < IMX8MQ_CLK_VPU_G1_ROOT>,
+< IMX8MQ_CLK_VPU_G2_ROOT>,
+< IMX8MQ_CLK_VPU_DEC_ROOT>;
+   clock-names = "g1", "g2",  "bus";
+   assigned-clocks = < IMX8MQ_CLK_VPU_G1>,
+ < IMX8MQ_CLK_VPU_G2>,
+ < IMX8MQ_CLK_VPU_BUS>,
+ < IMX8MQ_VPU_PLL_BYPASS>;
+   assigned-clock-parents = < IMX8MQ_VPU_PLL_OUT>,
+< IMX8MQ_VPU_PLL_OUT>,
+< IMX8MQ_SYS1_PLL_800M>,
+< IMX8MQ_VPU_PLL>;
+   assigned-clock-rates = <6>, <3>,
   <8>, <0>;
power-domains = <_vpu>;
+   nxp,imx8m-vpu-ctrl = <_ctrl>;
};
 
pcie0: pcie@3380 {
-- 
2.25.1



[PATCH v9 12/13] media: hantro: IMX8M: add variant for G2/HEVC codec

2021-04-07 Thread Benjamin Gaignard
Add variant to IMX8M to enable G2/HEVC codec.
Define the capabilities for the hardware up to 3840x2160.
G2 doesn't have a postprocessor, uses the same clocks and has it
own interrupt.

Signed-off-by: Benjamin Gaignard 
Reviewed-by: Philipp Zabel 
Reviewed-by: Ezequiel Garcia 
---
version 9:
 - Corrections in commit message

version 8:
 - Add Ezequiel Reviewed-by tag.

version 7:
 - Add Philipp Reviewed-by tag.

version 5:
 - remove useless postproc fields for G2

version 2:
- remove useless clocks

 drivers/staging/media/hantro/hantro_drv.c   |  1 +
 drivers/staging/media/hantro/hantro_hw.h|  1 +
 drivers/staging/media/hantro/imx8m_vpu_hw.c | 76 -
 3 files changed, 76 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/media/hantro/hantro_drv.c 
b/drivers/staging/media/hantro/hantro_drv.c
index 905a69758b37..d6f4958f6292 100644
--- a/drivers/staging/media/hantro/hantro_drv.c
+++ b/drivers/staging/media/hantro/hantro_drv.c
@@ -574,6 +574,7 @@ static const struct of_device_id of_hantro_match[] = {
 #endif
 #ifdef CONFIG_VIDEO_HANTRO_IMX8M
{ .compatible = "nxp,imx8mq-vpu", .data = _vpu_variant, },
+   { .compatible = "nxp,imx8mq-vpu-g2", .data = _vpu_g2_variant },
 #endif
{ /* sentinel */ }
 };
diff --git a/drivers/staging/media/hantro/hantro_hw.h 
b/drivers/staging/media/hantro/hantro_hw.h
index 41f3d5b92357..682fea1fe914 100644
--- a/drivers/staging/media/hantro/hantro_hw.h
+++ b/drivers/staging/media/hantro/hantro_hw.h
@@ -205,6 +205,7 @@ extern const struct hantro_variant rk3399_vpu_variant;
 extern const struct hantro_variant rk3328_vpu_variant;
 extern const struct hantro_variant rk3288_vpu_variant;
 extern const struct hantro_variant imx8mq_vpu_variant;
+extern const struct hantro_variant imx8mq_vpu_g2_variant;
 
 extern const struct hantro_postproc_regs hantro_g1_postproc_regs;
 
diff --git a/drivers/staging/media/hantro/imx8m_vpu_hw.c 
b/drivers/staging/media/hantro/imx8m_vpu_hw.c
index 8d0c3425234b..6de43e0edc36 100644
--- a/drivers/staging/media/hantro/imx8m_vpu_hw.c
+++ b/drivers/staging/media/hantro/imx8m_vpu_hw.c
@@ -12,6 +12,7 @@
 #include "hantro.h"
 #include "hantro_jpeg.h"
 #include "hantro_g1_regs.h"
+#include "hantro_g2_regs.h"
 
 #define CTRL_SOFT_RESET0x00
 #define RESET_G1   BIT(1)
@@ -129,6 +130,26 @@ static const struct hantro_fmt imx8m_vpu_dec_fmts[] = {
},
 };
 
+static const struct hantro_fmt imx8m_vpu_g2_dec_fmts[] = {
+   {
+   .fourcc = V4L2_PIX_FMT_NV12,
+   .codec_mode = HANTRO_MODE_NONE,
+   },
+   {
+   .fourcc = V4L2_PIX_FMT_HEVC_SLICE,
+   .codec_mode = HANTRO_MODE_HEVC_DEC,
+   .max_depth = 2,
+   .frmsize = {
+   .min_width = 48,
+   .max_width = 3840,
+   .step_width = MB_DIM,
+   .min_height = 48,
+   .max_height = 2160,
+   .step_height = MB_DIM,
+   },
+   },
+};
+
 static irqreturn_t imx8m_vpu_g1_irq(int irq, void *dev_id)
 {
struct hantro_dev *vpu = dev_id;
@@ -147,6 +168,24 @@ static irqreturn_t imx8m_vpu_g1_irq(int irq, void *dev_id)
return IRQ_HANDLED;
 }
 
+static irqreturn_t imx8m_vpu_g2_irq(int irq, void *dev_id)
+{
+   struct hantro_dev *vpu = dev_id;
+   enum vb2_buffer_state state;
+   u32 status;
+
+   status = vdpu_read(vpu, HEVC_REG_INTERRUPT);
+   state = (status & HEVC_REG_INTERRUPT_DEC_RDY_INT) ?
+VB2_BUF_STATE_DONE : VB2_BUF_STATE_ERROR;
+
+   vdpu_write(vpu, 0, HEVC_REG_INTERRUPT);
+   vdpu_write(vpu, HEVC_REG_CONFIG_DEC_CLK_GATE_E, HEVC_REG_CONFIG);
+
+   hantro_irq_done(vpu, state);
+
+   return IRQ_HANDLED;
+}
+
 static int imx8mq_vpu_hw_init(struct hantro_dev *vpu)
 {
struct device_node *np = vpu->dev->of_node;
@@ -176,6 +215,13 @@ static void imx8m_vpu_g1_reset(struct hantro_ctx *ctx)
imx8m_soft_reset(vpu, RESET_G1);
 }
 
+static void imx8m_vpu_g2_reset(struct hantro_ctx *ctx)
+{
+   struct hantro_dev *vpu = ctx->dev;
+
+   imx8m_soft_reset(vpu, RESET_G2);
+}
+
 /*
  * Supported codec ops.
  */
@@ -201,16 +247,28 @@ static const struct hantro_codec_ops 
imx8mq_vpu_codec_ops[] = {
},
 };
 
+static const struct hantro_codec_ops imx8mq_vpu_g2_codec_ops[] = {
+   [HANTRO_MODE_HEVC_DEC] = {
+   .run = hantro_g2_hevc_dec_run,
+   .reset = imx8m_vpu_g2_reset,
+   .init = hantro_hevc_dec_init,
+   .exit = hantro_hevc_dec_exit,
+   },
+};
+
 /*
  * VPU variants.
  */
 
 static const struct hantro_irq imx8mq_irqs[] = {
{ "g1", imx8m_vpu_g1_irq },
-   { "g2", NULL /* TODO: imx8m_vpu_g2_irq */ },
 };
 
-static const char * const imx8mq_clk_names[] = { "g1", "g2", "bus

[PATCH v9 10/13] media: hantro: handle V4L2_PIX_FMT_HEVC_SLICE control

2021-04-07 Thread Benjamin Gaignard
Make sure that V4L2_PIX_FMT_HEVC_SLICE is correctly handled by the driver.

Signed-off-by: Benjamin Gaignard 
Reviewed-by: Ezequiel Garcia 
---
version 9:
 - Corrections in commit message

version 8:
 - Add Ezequiel review tag

 drivers/staging/media/hantro/hantro_v4l2.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/staging/media/hantro/hantro_v4l2.c 
b/drivers/staging/media/hantro/hantro_v4l2.c
index 77d7fe62ce81..0655324fd0d4 100644
--- a/drivers/staging/media/hantro/hantro_v4l2.c
+++ b/drivers/staging/media/hantro/hantro_v4l2.c
@@ -392,6 +392,7 @@ hantro_update_requires_request(struct hantro_ctx *ctx, u32 
fourcc)
case V4L2_PIX_FMT_MPEG2_SLICE:
case V4L2_PIX_FMT_VP8_FRAME:
case V4L2_PIX_FMT_H264_SLICE:
+   case V4L2_PIX_FMT_HEVC_SLICE:
ctx->fh.m2m_ctx->out_q_ctx.q.requires_requests = true;
break;
default:
-- 
2.25.1



[PATCH v9 09/13] media: uapi: Add a control for HANTRO driver

2021-04-07 Thread Benjamin Gaignard
The HEVC HANTRO driver needs to know the number of bits to skip at
the beginning of the slice header.
That is a hardware specific requirement so create a dedicated control
for this purpose.

Signed-off-by: Benjamin Gaignard 
---
version 9:
 - Corrections in commit message.
 - Move control definition in hevc-ctrls.h
 - Add note in documentation to explain that this control
   may change in the futur

version 5:
 - Be even more verbose in control documentation.
 - Do not create class for the control.
version 4:
- The control is now an integer which is enough to provide the numbers
  of bits to skip.
version 3:
- Fix typo in field name

 .../userspace-api/media/drivers/hantro.rst| 19 +++
 .../userspace-api/media/drivers/index.rst |  1 +
 include/media/hevc-ctrls.h| 13 +
 3 files changed, 33 insertions(+)
 create mode 100644 Documentation/userspace-api/media/drivers/hantro.rst

diff --git a/Documentation/userspace-api/media/drivers/hantro.rst 
b/Documentation/userspace-api/media/drivers/hantro.rst
new file mode 100644
index ..cd9754b4e005
--- /dev/null
+++ b/Documentation/userspace-api/media/drivers/hantro.rst
@@ -0,0 +1,19 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+Hantro video decoder driver
+===
+
+The Hantro video decoder driver implements the following driver-specific 
controls:
+
+``V4L2_CID_HANTRO_HEVC_SLICE_HEADER_SKIP (integer)``
+Specifies to Hantro HEVC video decoder driver the number of data (in bits) 
to
+skip in the slice segment header.
+If non-IDR, the bits to be skipped go from syntax element "pic_output_flag"
+to before syntax element "slice_temporal_mvp_enabled_flag".
+If IDR, the skipped bits are just "pic_output_flag"
+(separate_colour_plane_flag is not supported).
+
+.. note::
+
+This control is not yet part of the public kernel API and
+it is expected to change.
diff --git a/Documentation/userspace-api/media/drivers/index.rst 
b/Documentation/userspace-api/media/drivers/index.rst
index 1a9038f5f9fa..12e3c512d718 100644
--- a/Documentation/userspace-api/media/drivers/index.rst
+++ b/Documentation/userspace-api/media/drivers/index.rst
@@ -33,6 +33,7 @@ For more details see the file COPYING in the source 
distribution of Linux.
 
ccs
cx2341x-uapi
+hantro
imx-uapi
max2175
meye-uapi
diff --git a/include/media/hevc-ctrls.h b/include/media/hevc-ctrls.h
index 8e0109eea454..b713eeed1915 100644
--- a/include/media/hevc-ctrls.h
+++ b/include/media/hevc-ctrls.h
@@ -224,4 +224,17 @@ struct v4l2_ctrl_hevc_decode_params {
__u64   flags;
 };
 
+/*  MPEG-class control IDs specific to the Hantro driver as defined by V4L2 */
+#define V4L2_CID_CODEC_HANTRO_BASE 
(V4L2_CTRL_CLASS_CODEC | 0x1200)
+/*
+ * V4L2_CID_HANTRO_HEVC_SLICE_HEADER_SKIP -
+ * the number of data (in bits) to skip in the
+ * slice segment header.
+ * If non-IDR, the bits to be skipped go from syntax element "pic_output_flag"
+ * to before syntax element "slice_temporal_mvp_enabled_flag".
+ * If IDR, the skipped bits are just "pic_output_flag"
+ * (separate_colour_plane_flag is not supported).
+ */
+#define V4L2_CID_HANTRO_HEVC_SLICE_HEADER_SKIP (V4L2_CID_CODEC_HANTRO_BASE + 0)
+
 #endif
-- 
2.25.1



[PATCH v9 07/13] media: hantro: Define HEVC codec profiles and supported features

2021-04-07 Thread Benjamin Gaignard
Define which HEVC profiles (up to level 5.1) and features
(no scaling, no 10 bits) are supported by the driver.

Signed-off-by: Benjamin Gaignard 
Reviewed-by: Ezequiel Garcia 
---
version 8:
 - add Ezequiel review tag

 drivers/staging/media/hantro/hantro.h |  3 ++
 drivers/staging/media/hantro/hantro_drv.c | 58 +++
 2 files changed, 61 insertions(+)

diff --git a/drivers/staging/media/hantro/hantro.h 
b/drivers/staging/media/hantro/hantro.h
index 37b9ce04bd4e..edb4561a6887 100644
--- a/drivers/staging/media/hantro/hantro.h
+++ b/drivers/staging/media/hantro/hantro.h
@@ -35,6 +35,7 @@ struct hantro_codec_ops;
 #define HANTRO_MPEG2_DECODER   BIT(16)
 #define HANTRO_VP8_DECODER BIT(17)
 #define HANTRO_H264_DECODERBIT(18)
+#define HANTRO_HEVC_DECODERBIT(19)
 #define HANTRO_DECODERS0x
 
 /**
@@ -100,6 +101,7 @@ struct hantro_variant {
  * @HANTRO_MODE_H264_DEC: H264 decoder.
  * @HANTRO_MODE_MPEG2_DEC: MPEG-2 decoder.
  * @HANTRO_MODE_VP8_DEC: VP8 decoder.
+ * @HANTRO_MODE_HEVC_DEC: HEVC decoder.
  */
 enum hantro_codec_mode {
HANTRO_MODE_NONE = -1,
@@ -107,6 +109,7 @@ enum hantro_codec_mode {
HANTRO_MODE_H264_DEC,
HANTRO_MODE_MPEG2_DEC,
HANTRO_MODE_VP8_DEC,
+   HANTRO_MODE_HEVC_DEC,
 };
 
 /*
diff --git a/drivers/staging/media/hantro/hantro_drv.c 
b/drivers/staging/media/hantro/hantro_drv.c
index 02c5c2f1a88b..d9a3a5ef9330 100644
--- a/drivers/staging/media/hantro/hantro_drv.c
+++ b/drivers/staging/media/hantro/hantro_drv.c
@@ -245,6 +245,18 @@ static int hantro_try_ctrl(struct v4l2_ctrl *ctrl)
if (sps->bit_depth_luma_minus8 != 0)
/* Only 8-bit is supported */
return -EINVAL;
+   } else if (ctrl->id == V4L2_CID_MPEG_VIDEO_HEVC_SPS) {
+   const struct v4l2_ctrl_hevc_sps *sps = ctrl->p_new.p_hevc_sps;
+
+   if (sps->bit_depth_luma_minus8 != sps->bit_depth_chroma_minus8)
+   /* Luma and chroma bit depth mismatch */
+   return -EINVAL;
+   if (sps->bit_depth_luma_minus8 != 0)
+   /* Only 8-bit is supported */
+   return -EINVAL;
+   if (sps->flags & V4L2_HEVC_SPS_FLAG_SCALING_LIST_ENABLED)
+   /* No scaling support */
+   return -EINVAL;
}
return 0;
 }
@@ -351,6 +363,52 @@ static const struct hantro_ctrl controls[] = {
.def = V4L2_MPEG_VIDEO_H264_PROFILE_MAIN,
}
}, {
+   .codec = HANTRO_HEVC_DECODER,
+   .cfg = {
+   .id = V4L2_CID_MPEG_VIDEO_HEVC_DECODE_MODE,
+   .min = V4L2_MPEG_VIDEO_HEVC_DECODE_MODE_FRAME_BASED,
+   .max = V4L2_MPEG_VIDEO_HEVC_DECODE_MODE_FRAME_BASED,
+   .def = V4L2_MPEG_VIDEO_HEVC_DECODE_MODE_FRAME_BASED,
+   },
+   }, {
+   .codec = HANTRO_HEVC_DECODER,
+   .cfg = {
+   .id = V4L2_CID_MPEG_VIDEO_HEVC_START_CODE,
+   .min = V4L2_MPEG_VIDEO_HEVC_START_CODE_ANNEX_B,
+   .max = V4L2_MPEG_VIDEO_HEVC_START_CODE_ANNEX_B,
+   .def = V4L2_MPEG_VIDEO_HEVC_START_CODE_ANNEX_B,
+   },
+   }, {
+   .codec = HANTRO_HEVC_DECODER,
+   .cfg = {
+   .id = V4L2_CID_MPEG_VIDEO_HEVC_PROFILE,
+   .min = V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN,
+   .max = V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN_10,
+   .def = V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN,
+   },
+   }, {
+   .codec = HANTRO_HEVC_DECODER,
+   .cfg = {
+   .id = V4L2_CID_MPEG_VIDEO_HEVC_LEVEL,
+   .min = V4L2_MPEG_VIDEO_HEVC_LEVEL_1,
+   .max = V4L2_MPEG_VIDEO_HEVC_LEVEL_5_1,
+   },
+   }, {
+   .codec = HANTRO_HEVC_DECODER,
+   .cfg = {
+   .id = V4L2_CID_MPEG_VIDEO_HEVC_SPS,
+   .ops = _ctrl_ops,
+   },
+   }, {
+   .codec = HANTRO_HEVC_DECODER,
+   .cfg = {
+   .id = V4L2_CID_MPEG_VIDEO_HEVC_PPS,
+   },
+   }, {
+   .codec = HANTRO_HEVC_DECODER,
+   .cfg = {
+   .id = V4L2_CID_MPEG_VIDEO_HEVC_DECODE_PARAMS,
+   },
},
 };
 
-- 
2.25.1



[PATCH v9 06/13] media: hantro: change hantro_codec_ops run prototype to return errors

2021-04-07 Thread Benjamin Gaignard
Change hantro_codec_ops run prototype from 'void' to 'int'.
This allows the driver to cancel the job if an error occurs while configuring
the hardware.

Signed-off-by: Benjamin Gaignard 
Reviewed-by: Ezequiel Garcia 
---
version 9:
 - Corrections in commit message

version 8:
 - add Ezequiel review tag

version 5:
 - forward hantro_h264_dec_prepare_run() return value in case
   of error

 drivers/staging/media/hantro/hantro_drv.c |  4 +++-
 .../staging/media/hantro/hantro_g1_h264_dec.c | 10 +++---
 .../media/hantro/hantro_g1_mpeg2_dec.c|  4 +++-
 .../staging/media/hantro/hantro_g1_vp8_dec.c  |  6 --
 .../staging/media/hantro/hantro_h1_jpeg_enc.c |  4 +++-
 drivers/staging/media/hantro/hantro_hw.h  | 19 ++-
 .../media/hantro/rk3399_vpu_hw_jpeg_enc.c |  4 +++-
 .../media/hantro/rk3399_vpu_hw_mpeg2_dec.c|  4 +++-
 .../media/hantro/rk3399_vpu_hw_vp8_dec.c  |  6 --
 9 files changed, 40 insertions(+), 21 deletions(-)

diff --git a/drivers/staging/media/hantro/hantro_drv.c 
b/drivers/staging/media/hantro/hantro_drv.c
index 595e82a82728..02c5c2f1a88b 100644
--- a/drivers/staging/media/hantro/hantro_drv.c
+++ b/drivers/staging/media/hantro/hantro_drv.c
@@ -161,7 +161,9 @@ static void device_run(void *priv)
 
v4l2_m2m_buf_copy_metadata(src, dst, true);
 
-   ctx->codec_ops->run(ctx);
+   if (ctx->codec_ops->run(ctx))
+   goto err_cancel_job;
+
return;
 
 err_cancel_job:
diff --git a/drivers/staging/media/hantro/hantro_g1_h264_dec.c 
b/drivers/staging/media/hantro/hantro_g1_h264_dec.c
index 845bef73d218..5c792b7bcb79 100644
--- a/drivers/staging/media/hantro/hantro_g1_h264_dec.c
+++ b/drivers/staging/media/hantro/hantro_g1_h264_dec.c
@@ -273,13 +273,15 @@ static void set_buffers(struct hantro_ctx *ctx)
vdpu_write_relaxed(vpu, ctx->h264_dec.priv.dma, G1_REG_ADDR_QTABLE);
 }
 
-void hantro_g1_h264_dec_run(struct hantro_ctx *ctx)
+int hantro_g1_h264_dec_run(struct hantro_ctx *ctx)
 {
struct hantro_dev *vpu = ctx->dev;
+   int ret;
 
/* Prepare the H264 decoder context. */
-   if (hantro_h264_dec_prepare_run(ctx))
-   return;
+   ret = hantro_h264_dec_prepare_run(ctx);
+   if (ret)
+   return ret;
 
/* Configure hardware registers. */
set_params(ctx);
@@ -301,4 +303,6 @@ void hantro_g1_h264_dec_run(struct hantro_ctx *ctx)
   G1_REG_CONFIG_DEC_CLK_GATE_E,
   G1_REG_CONFIG);
vdpu_write(vpu, G1_REG_INTERRUPT_DEC_E, G1_REG_INTERRUPT);
+
+   return 0;
 }
diff --git a/drivers/staging/media/hantro/hantro_g1_mpeg2_dec.c 
b/drivers/staging/media/hantro/hantro_g1_mpeg2_dec.c
index 6386a3989bfe..5e8943d31dc5 100644
--- a/drivers/staging/media/hantro/hantro_g1_mpeg2_dec.c
+++ b/drivers/staging/media/hantro/hantro_g1_mpeg2_dec.c
@@ -155,7 +155,7 @@ hantro_g1_mpeg2_dec_set_buffers(struct hantro_dev *vpu, 
struct hantro_ctx *ctx,
vdpu_write_relaxed(vpu, backward_addr, G1_REG_REFER3_BASE);
 }
 
-void hantro_g1_mpeg2_dec_run(struct hantro_ctx *ctx)
+int hantro_g1_mpeg2_dec_run(struct hantro_ctx *ctx)
 {
struct hantro_dev *vpu = ctx->dev;
struct vb2_v4l2_buffer *src_buf, *dst_buf;
@@ -248,4 +248,6 @@ void hantro_g1_mpeg2_dec_run(struct hantro_ctx *ctx)
 
reg = G1_REG_DEC_E(1);
vdpu_write(vpu, reg, G1_SWREG(1));
+
+   return 0;
 }
diff --git a/drivers/staging/media/hantro/hantro_g1_vp8_dec.c 
b/drivers/staging/media/hantro/hantro_g1_vp8_dec.c
index 57002ba70176..96622a7f8279 100644
--- a/drivers/staging/media/hantro/hantro_g1_vp8_dec.c
+++ b/drivers/staging/media/hantro/hantro_g1_vp8_dec.c
@@ -425,7 +425,7 @@ static void cfg_buffers(struct hantro_ctx *ctx,
vdpu_write_relaxed(vpu, dst_dma, G1_REG_ADDR_DST);
 }
 
-void hantro_g1_vp8_dec_run(struct hantro_ctx *ctx)
+int hantro_g1_vp8_dec_run(struct hantro_ctx *ctx)
 {
const struct v4l2_ctrl_vp8_frame *hdr;
struct hantro_dev *vpu = ctx->dev;
@@ -438,7 +438,7 @@ void hantro_g1_vp8_dec_run(struct hantro_ctx *ctx)
 
hdr = hantro_get_ctrl(ctx, V4L2_CID_STATELESS_VP8_FRAME);
if (WARN_ON(!hdr))
-   return;
+   return -EINVAL;
 
/* Reset segment_map buffer in keyframe */
if (V4L2_VP8_FRAME_IS_KEY_FRAME(hdr) && ctx->vp8_dec.segment_map.cpu)
@@ -498,4 +498,6 @@ void hantro_g1_vp8_dec_run(struct hantro_ctx *ctx)
hantro_end_prepare_run(ctx);
 
vdpu_write(vpu, G1_REG_INTERRUPT_DEC_E, G1_REG_INTERRUPT);
+
+   return 0;
 }
diff --git a/drivers/staging/media/hantro/hantro_h1_jpeg_enc.c 
b/drivers/staging/media/hantro/hantro_h1_jpeg_enc.c
index b88dc4ed06db..56cf261a8e95 100644
--- a/drivers/staging/media/hantro/hantro_h1_jpeg_enc.c
+++ b/drivers/staging/media/hantro/hantro_h1_jpeg_enc.c
@@ -88,7 +88,7 @@ hantro_h1_jpeg_enc_set_qtable(struct hantro_dev *vpu,
}
 }
 
-void hantro_h1_jpeg_e

[PATCH v9 08/13] media: hantro: Only use postproc when post processed formats are defined

2021-04-07 Thread Benjamin Gaignard
If the variant doesn't support postprocessed formats make sure it will
be ok.

Signed-off-by: Benjamin Gaignard 
Reviewed-by: Ezequiel Garcia 
---
version 9:
 - Corrections in commit message

version 8:
 - add Ezequiel review tag

 drivers/staging/media/hantro/hantro.h  |  8 ++--
 drivers/staging/media/hantro/hantro_postproc.c | 14 ++
 drivers/staging/media/hantro/hantro_v4l2.c |  4 +++-
 3 files changed, 19 insertions(+), 7 deletions(-)

diff --git a/drivers/staging/media/hantro/hantro.h 
b/drivers/staging/media/hantro/hantro.h
index edb4561a6887..7a5ad93466c8 100644
--- a/drivers/staging/media/hantro/hantro.h
+++ b/drivers/staging/media/hantro/hantro.h
@@ -414,12 +414,8 @@ hantro_get_dst_buf(struct hantro_ctx *ctx)
return v4l2_m2m_next_dst_buf(ctx->fh.m2m_ctx);
 }
 
-static inline bool
-hantro_needs_postproc(const struct hantro_ctx *ctx,
- const struct hantro_fmt *fmt)
-{
-   return !ctx->is_encoder && fmt->fourcc != V4L2_PIX_FMT_NV12;
-}
+bool hantro_needs_postproc(const struct hantro_ctx *ctx,
+  const struct hantro_fmt *fmt);
 
 static inline dma_addr_t
 hantro_get_dec_buf_addr(struct hantro_ctx *ctx, struct vb2_buffer *vb)
diff --git a/drivers/staging/media/hantro/hantro_postproc.c 
b/drivers/staging/media/hantro/hantro_postproc.c
index 6d2a8f2a8f0b..ed8916c950a4 100644
--- a/drivers/staging/media/hantro/hantro_postproc.c
+++ b/drivers/staging/media/hantro/hantro_postproc.c
@@ -50,6 +50,20 @@ const struct hantro_postproc_regs hantro_g1_postproc_regs = {
.display_width = {G1_REG_PP_DISPLAY_WIDTH, 0, 0xfff},
 };
 
+bool hantro_needs_postproc(const struct hantro_ctx *ctx,
+  const struct hantro_fmt *fmt)
+{
+   struct hantro_dev *vpu = ctx->dev;
+
+   if (ctx->is_encoder)
+   return false;
+
+   if (!vpu->variant->postproc_fmts)
+   return false;
+
+   return fmt->fourcc != V4L2_PIX_FMT_NV12;
+}
+
 void hantro_postproc_enable(struct hantro_ctx *ctx)
 {
struct hantro_dev *vpu = ctx->dev;
diff --git a/drivers/staging/media/hantro/hantro_v4l2.c 
b/drivers/staging/media/hantro/hantro_v4l2.c
index 1bc118e375a1..77d7fe62ce81 100644
--- a/drivers/staging/media/hantro/hantro_v4l2.c
+++ b/drivers/staging/media/hantro/hantro_v4l2.c
@@ -55,7 +55,9 @@ static const struct hantro_fmt *
 hantro_get_postproc_formats(const struct hantro_ctx *ctx,
unsigned int *num_fmts)
 {
-   if (ctx->is_encoder) {
+   struct hantro_dev *vpu = ctx->dev;
+
+   if (ctx->is_encoder || !vpu->variant->postproc_fmts) {
*num_fmts = 0;
return NULL;
}
-- 
2.25.1



[PATCH v9 05/13] media: hevc: Add decode params control

2021-04-07 Thread Benjamin Gaignard
Add decode params control and the associated structure to group
all the information that are needed to decode a reference frame as
is described in ITU-T Rec. H.265 section "8.3.2 Decoding process
for reference picture set".

Adapt Cedrus driver to these changes.

Signed-off-by: Benjamin Gaignard 
Reviewed-by: Ezequiel Garcia 
---
version 9:
 - Corrections in commit message

version 8:
 - add Ezequiel review tag

version 7:
 - rebased on top of media_tree/master branch

version 6:
 - fix compilation errors

 .../media/v4l/ext-ctrls-codec.rst | 94 +++
 .../media/v4l/vidioc-queryctrl.rst|  6 ++
 drivers/media/v4l2-core/v4l2-ctrls.c  | 28 --
 drivers/staging/media/sunxi/cedrus/cedrus.c   |  6 ++
 drivers/staging/media/sunxi/cedrus/cedrus.h   |  1 +
 .../staging/media/sunxi/cedrus/cedrus_dec.c   |  2 +
 .../staging/media/sunxi/cedrus/cedrus_h265.c  | 12 ++-
 include/media/hevc-ctrls.h| 29 --
 8 files changed, 138 insertions(+), 40 deletions(-)

diff --git a/Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst 
b/Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst
index aabcb0e63a5e..7b90cb939e9d 100644
--- a/Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst
+++ b/Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst
@@ -3214,9 +3214,6 @@ enum v4l2_mpeg_video_hevc_size_of_length_field -
 * - __u8
   - ``pic_struct``
   -
-* - __u8
-  - ``num_active_dpb_entries``
-  - The number of entries in ``dpb``.
 * - __u8
   - ``ref_idx_l0[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]``
   - The list of L0 reference elements as indices in the DPB.
@@ -3224,22 +3221,8 @@ enum v4l2_mpeg_video_hevc_size_of_length_field -
   - ``ref_idx_l1[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]``
   - The list of L1 reference elements as indices in the DPB.
 * - __u8
-  - ``num_rps_poc_st_curr_before``
-  - The number of reference pictures in the short-term set that come before
-the current frame.
-* - __u8
-  - ``num_rps_poc_st_curr_after``
-  - The number of reference pictures in the short-term set that come after
-the current frame.
-* - __u8
-  - ``num_rps_poc_lt_curr``
-  - The number of reference pictures in the long-term set.
-* - __u8
-  - ``padding[7]``
+  - ``padding``
   - Applications and drivers must set this to zero.
-* - struct :c:type:`v4l2_hevc_dpb_entry`
-  - ``dpb[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]``
-  - The decoded picture buffer, for meta-data about reference frames.
 * - struct :c:type:`v4l2_hevc_pred_weight_table`
   - ``pred_weight_table``
   - The prediction weight coefficients for inter-picture prediction.
@@ -3492,3 +3475,78 @@ enum v4l2_mpeg_video_hevc_size_of_length_field -
 encoding the next frame queued after setting this control.
 This provides a bitmask which consists of bits [0, LTR_COUNT-1].
 This is applicable to the H264 and HEVC encoders.
+
+``V4L2_CID_MPEG_VIDEO_HEVC_DECODE_PARAMS (struct)``
+Specifies various decode parameters, especially the references picture 
order
+count (POC) for all the lists (short, long, before, current, after) and the
+number of entries for each of them.
+These parameters are defined according to :ref:`hevc`.
+They are described in section 8.3 "Slice decoding process" of the
+specification.
+
+.. c:type:: v4l2_ctrl_hevc_decode_params
+
+.. cssclass:: longtable
+
+.. flat-table:: struct v4l2_ctrl_hevc_decode_params
+:header-rows:  0
+:stub-columns: 0
+:widths:   1 1 2
+
+* - __s32
+  - ``pic_order_cnt_val``
+  - PicOrderCntVal as described in section 8.3.1 "Decoding process
+for picture order count" of the specification.
+* - __u8
+  - ``num_active_dpb_entries``
+  - The number of entries in ``dpb``.
+* - struct :c:type:`v4l2_hevc_dpb_entry`
+  - ``dpb[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]``
+  - The decoded picture buffer, for meta-data about reference frames.
+* - __u8
+  - ``num_poc_st_curr_before``
+  - The number of reference pictures in the short-term set that come before
+the current frame.
+* - __u8
+  - ``num_poc_st_curr_after``
+  - The number of reference pictures in the short-term set that come after
+the current frame.
+* - __u8
+  - ``num_poc_lt_curr``
+  - The number of reference pictures in the long-term set.
+* - __u8
+  - ``poc_st_curr_before[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]``
+  - PocStCurrBefore as described in section 8.3.2 "Decoding process for 
reference
+picture set.
+* - __u8
+  - ``poc_st_curr_after[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]``
+  - PocStCurrAfter as described in section 8.3.2 "Decoding process for 
reference
+picture set.
+* - __u8
+  - ``poc_lt_curr[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]``
+  - PocLtCurr as desc

[PATCH v9 04/13] media: hevc: Add fields and flags for hevc PPS

2021-04-07 Thread Benjamin Gaignard
Add fields and flags as they are defined in
7.4.3.3.1 "General picture parameter set RBSP semantics of the
H.265 ITU specification.

Signed-off-by: Benjamin Gaignard 
Reviewed-by: Ezequiel Garcia 
---
version 8:
 - add Ezequiel review tag

 .../userspace-api/media/v4l/ext-ctrls-codec.rst| 14 ++
 include/media/hevc-ctrls.h |  4 
 2 files changed, 18 insertions(+)

diff --git a/Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst 
b/Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst
index b0de4e6e7ebd..aabcb0e63a5e 100644
--- a/Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst
+++ b/Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst
@@ -3000,6 +3000,12 @@ enum v4l2_mpeg_video_hevc_size_of_length_field -
 * - __u8
   - ``num_extra_slice_header_bits``
   -
+* - __u8
+  - ``num_ref_idx_l0_default_active_minus1``
+  - Specifies the inferred value of num_ref_idx_l0_active_minus1
+* - __u8
+  - ``num_ref_idx_l1_default_active_minus1``
+  - Specifies the inferred value of num_ref_idx_l1_active_minus1
 * - __s8
   - ``init_qp_minus26``
   -
@@ -3110,6 +3116,14 @@ enum v4l2_mpeg_video_hevc_size_of_length_field -
 * - ``V4L2_HEVC_PPS_FLAG_SLICE_SEGMENT_HEADER_EXTENSION_PRESENT``
   - 0x0004
   -
+* - ``V4L2_HEVC_PPS_FLAG_DEBLOCKING_FILTER_CONTROL_PRESENT``
+  - 0x0008
+  - Specifies the presence of deblocking filter control syntax elements in
+the PPS
+* - ``V4L2_HEVC_PPS_FLAG_UNIFORM_SPACING``
+  - 0x0010
+  - Specifies that tile column boundaries and likewise tile row boundaries
+are distributed uniformly across the picture
 
 .. raw:: latex
 
diff --git a/include/media/hevc-ctrls.h b/include/media/hevc-ctrls.h
index b4cb2ef02f17..003f819ecb26 100644
--- a/include/media/hevc-ctrls.h
+++ b/include/media/hevc-ctrls.h
@@ -100,10 +100,14 @@ struct v4l2_ctrl_hevc_sps {
 #define V4L2_HEVC_PPS_FLAG_PPS_DISABLE_DEBLOCKING_FILTER   (1ULL << 16)
 #define V4L2_HEVC_PPS_FLAG_LISTS_MODIFICATION_PRESENT  (1ULL << 17)
 #define V4L2_HEVC_PPS_FLAG_SLICE_SEGMENT_HEADER_EXTENSION_PRESENT (1ULL << 18)
+#define V4L2_HEVC_PPS_FLAG_DEBLOCKING_FILTER_CONTROL_PRESENT   (1ULL << 19)
+#define V4L2_HEVC_PPS_FLAG_UNIFORM_SPACING (1ULL << 20)
 
 struct v4l2_ctrl_hevc_pps {
/* ISO/IEC 23008-2, ITU-T Rec. H.265: Picture parameter set */
__u8num_extra_slice_header_bits;
+   __u8num_ref_idx_l0_default_active_minus1;
+   __u8num_ref_idx_l1_default_active_minus1;
__s8init_qp_minus26;
__u8diff_cu_qp_delta_depth;
__s8pps_cb_qp_offset;
-- 
2.25.1



[PATCH v9 03/13] media: hantro: Use syscon instead of 'ctrl' register

2021-04-07 Thread Benjamin Gaignard
In order to be able to share the control hardware block between
VPUs use a syscon instead a ioremap it in the driver.
To keep the compatibility with older DT if 'nxp,imx8mq-vpu-ctrl'
phandle is not found look at 'ctrl' reg-name.
With the method it becomes useless to provide a list of register
names so remove it.

Signed-off-by: Benjamin Gaignard 
Reviewed-by: Philipp Zabel 
---
version 9:
 - Corrections in commit message

version 7:
 - Add Philipp reviewed-by tag.
 - Change syscon phandle name.
 
version 5:
 - use syscon instead of VPU reset driver.
 - if DT doesn't provide syscon keep backward compatibilty by using
   'ctrl' reg-name.

 drivers/staging/media/hantro/hantro.h   |  5 +-
 drivers/staging/media/hantro/imx8m_vpu_hw.c | 52 -
 2 files changed, 34 insertions(+), 23 deletions(-)

diff --git a/drivers/staging/media/hantro/hantro.h 
b/drivers/staging/media/hantro/hantro.h
index 6c1b888abe75..37b9ce04bd4e 100644
--- a/drivers/staging/media/hantro/hantro.h
+++ b/drivers/staging/media/hantro/hantro.h
@@ -13,6 +13,7 @@
 #define HANTRO_H_
 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -167,7 +168,7 @@ hantro_vdev_to_func(struct video_device *vdev)
  * @reg_bases: Mapped addresses of VPU registers.
  * @enc_base:  Mapped address of VPU encoder register for convenience.
  * @dec_base:  Mapped address of VPU decoder register for convenience.
- * @ctrl_base: Mapped address of VPU control block.
+ * @ctrl_base: Regmap of VPU control block.
  * @vpu_mutex: Mutex to synchronize V4L2 calls.
  * @irqlock:   Spinlock to synchronize access to data structures
  * shared with interrupt handlers.
@@ -186,7 +187,7 @@ struct hantro_dev {
void __iomem **reg_bases;
void __iomem *enc_base;
void __iomem *dec_base;
-   void __iomem *ctrl_base;
+   struct regmap *ctrl_base;
 
struct mutex vpu_mutex; /* video_device lock */
spinlock_t irqlock;
diff --git a/drivers/staging/media/hantro/imx8m_vpu_hw.c 
b/drivers/staging/media/hantro/imx8m_vpu_hw.c
index c222de075ef4..8d0c3425234b 100644
--- a/drivers/staging/media/hantro/imx8m_vpu_hw.c
+++ b/drivers/staging/media/hantro/imx8m_vpu_hw.c
@@ -7,6 +7,7 @@
 
 #include 
 #include 
+#include 
 
 #include "hantro.h"
 #include "hantro_jpeg.h"
@@ -24,30 +25,28 @@
 #define CTRL_G1_PP_FUSE0x0c
 #define CTRL_G2_DEC_FUSE   0x10
 
+static const struct regmap_config ctrl_regmap_ctrl = {
+   .reg_bits = 32,
+   .val_bits = 32,
+   .reg_stride = 0x14,
+};
+
 static void imx8m_soft_reset(struct hantro_dev *vpu, u32 reset_bits)
 {
-   u32 val;
-
/* Assert */
-   val = readl(vpu->ctrl_base + CTRL_SOFT_RESET);
-   val &= ~reset_bits;
-   writel(val, vpu->ctrl_base + CTRL_SOFT_RESET);
+   regmap_update_bits(vpu->ctrl_base, CTRL_SOFT_RESET, reset_bits, 0);
 
udelay(2);
 
/* Release */
-   val = readl(vpu->ctrl_base + CTRL_SOFT_RESET);
-   val |= reset_bits;
-   writel(val, vpu->ctrl_base + CTRL_SOFT_RESET);
+   regmap_update_bits(vpu->ctrl_base, CTRL_SOFT_RESET,
+  reset_bits, reset_bits);
 }
 
 static void imx8m_clk_enable(struct hantro_dev *vpu, u32 clock_bits)
 {
-   u32 val;
-
-   val = readl(vpu->ctrl_base + CTRL_CLOCK_ENABLE);
-   val |= clock_bits;
-   writel(val, vpu->ctrl_base + CTRL_CLOCK_ENABLE);
+   regmap_update_bits(vpu->ctrl_base, CTRL_CLOCK_ENABLE,
+  clock_bits, clock_bits);
 }
 
 static int imx8mq_runtime_resume(struct hantro_dev *vpu)
@@ -64,9 +63,9 @@ static int imx8mq_runtime_resume(struct hantro_dev *vpu)
imx8m_clk_enable(vpu, CLOCK_G1 | CLOCK_G2);
 
/* Set values of the fuse registers */
-   writel(0x, vpu->ctrl_base + CTRL_G1_DEC_FUSE);
-   writel(0x, vpu->ctrl_base + CTRL_G1_PP_FUSE);
-   writel(0x, vpu->ctrl_base + CTRL_G2_DEC_FUSE);
+   regmap_write(vpu->ctrl_base, CTRL_G1_DEC_FUSE, 0x);
+   regmap_write(vpu->ctrl_base, CTRL_G1_PP_FUSE, 0x);
+   regmap_write(vpu->ctrl_base, CTRL_G2_DEC_FUSE, 0x);
 
clk_bulk_disable_unprepare(vpu->variant->num_clocks, vpu->clocks);
 
@@ -150,8 +149,22 @@ static irqreturn_t imx8m_vpu_g1_irq(int irq, void *dev_id)
 
 static int imx8mq_vpu_hw_init(struct hantro_dev *vpu)
 {
-   vpu->dec_base = vpu->reg_bases[0];
-   vpu->ctrl_base = vpu->reg_bases[vpu->variant->num_regs - 1];
+   struct device_node *np = vpu->dev->of_node;
+
+   vpu->ctrl_base = syscon_regmap_lookup_by_phandle(np, 
"nxp,imx8m-vpu-ctrl");
+   if (IS_ERR(vpu->ctrl_base)) {
+   struct resource *res;
+   void __iomem *ctrl;
+
+   res = platform_get_resource_byname(vpu->pde

[PATCH v9 02/13] dt-bindings: media: nxp,imx8mq-vpu: Update the bindings for G2 support

2021-04-07 Thread Benjamin Gaignard
Introducing the G2 hevc video decoder requires modifications of the bindings to 
allow
one node per VPU.

VPUs share one hardware control block which is provided as a phandle on
a syscon.
Each node has now one reg and one interrupt.
Add a compatible for G2 hardware block: nxp,imx8mq-vpu-g2.

To be compatible with older DT the driver is still capable to use the 'ctrl'
reg-name even if it is deprecated now.

Signed-off-by: Benjamin Gaignard 
Reviewed-by: Rob Herring 
Reviewed-by: Philipp Zabel 
---
version 9:
 - Corrections in commit message

version 7:
 - Add Rob and Philipp reviewed-by tag
 - Change syscon phandle name to nxp,imx8m-vpu-ctrl (remove 'q' to be
   usable for iMX8MM too)

version 5:
- This version doesn't break the backward compatibilty between kernel
  and DT.

 .../bindings/media/nxp,imx8mq-vpu.yaml| 53 ---
 1 file changed, 34 insertions(+), 19 deletions(-)

diff --git a/Documentation/devicetree/bindings/media/nxp,imx8mq-vpu.yaml 
b/Documentation/devicetree/bindings/media/nxp,imx8mq-vpu.yaml
index 762be3f96ce9..18e7d40a5f24 100644
--- a/Documentation/devicetree/bindings/media/nxp,imx8mq-vpu.yaml
+++ b/Documentation/devicetree/bindings/media/nxp,imx8mq-vpu.yaml
@@ -15,22 +15,18 @@ description:
 
 properties:
   compatible:
-const: nxp,imx8mq-vpu
+oneOf:
+  - const: nxp,imx8mq-vpu
+  - const: nxp,imx8mq-vpu-g2
 
   reg:
-maxItems: 3
-
-  reg-names:
-items:
-  - const: g1
-  - const: g2
-  - const: ctrl
+maxItems: 1
 
   interrupts:
-maxItems: 2
+maxItems: 1
 
   interrupt-names:
-items:
+oneOf:
   - const: g1
   - const: g2
 
@@ -46,14 +42,18 @@ properties:
   power-domains:
 maxItems: 1
 
+  nxp,imx8m-vpu-ctrl:
+description: Specifies a phandle to syscon VPU hardware control block
+$ref: "/schemas/types.yaml#/definitions/phandle"
+
 required:
   - compatible
   - reg
-  - reg-names
   - interrupts
   - interrupt-names
   - clocks
   - clock-names
+  - nxp,imx8m-vpu-ctrl
 
 additionalProperties: false
 
@@ -62,18 +62,33 @@ examples:
 #include 
 #include 
 
-vpu: video-codec@3830 {
+vpu_ctrl: syscon@3832 {
+ compatible = "nxp,imx8mq-vpu-ctrl", "syscon";
+ reg = <0x3832 0x1>;
+};
+
+vpu_g1: video-codec@3830 {
 compatible = "nxp,imx8mq-vpu";
-reg = <0x3830 0x1>,
-  <0x3831 0x1>,
-  <0x3832 0x1>;
-reg-names = "g1", "g2", "ctrl";
-interrupts = ,
- ;
-interrupt-names = "g1", "g2";
+reg = <0x3830 0x1>;
+interrupts = ;
+interrupt-names = "g1";
+clocks = < IMX8MQ_CLK_VPU_G1_ROOT>,
+ < IMX8MQ_CLK_VPU_G2_ROOT>,
+ < IMX8MQ_CLK_VPU_DEC_ROOT>;
+clock-names = "g1", "g2", "bus";
+power-domains = <_vpu>;
+nxp,imx8m-vpu-ctrl = <_ctrl>;
+};
+
+vpu_g2: video-codec@3831 {
+compatible = "nxp,imx8mq-vpu-g2";
+reg = <0x3830 0x1>;
+interrupts = ;
+interrupt-names = "g2";
 clocks = < IMX8MQ_CLK_VPU_G1_ROOT>,
  < IMX8MQ_CLK_VPU_G2_ROOT>,
  < IMX8MQ_CLK_VPU_DEC_ROOT>;
 clock-names = "g1", "g2", "bus";
 power-domains = <_vpu>;
+nxp,imx8m-vpu-ctrl = <_ctrl>;
 };
-- 
2.25.1



[PATCH v9 01/13] dt-bindings: mfd: Add 'nxp,imx8mq-vpu-ctrl' to syscon list

2021-04-07 Thread Benjamin Gaignard
Add 'nxp,imx8mq-vpu-ctrl' to the list of possible syscon.
It will used to access the VPU control registers.

Signed-off-by: Benjamin Gaignard 
Acked-by: Rob Herring 
Acked-by: Lee Jones 
---
version 9:
 - corrections in commit message

version 8:
 - Add Lee ack

version 7:
 - Add Rob ack

 Documentation/devicetree/bindings/mfd/syscon.yaml | 1 +
 1 file changed, 1 insertion(+)

diff --git a/Documentation/devicetree/bindings/mfd/syscon.yaml 
b/Documentation/devicetree/bindings/mfd/syscon.yaml
index f14ae6da0068..ae22c4730613 100644
--- a/Documentation/devicetree/bindings/mfd/syscon.yaml
+++ b/Documentation/devicetree/bindings/mfd/syscon.yaml
@@ -44,6 +44,7 @@ properties:
   - hisilicon,peri-subctrl
   - microchip,sparx5-cpu-syscon
   - mstar,msc313-pmsleep
+  - nxp,imx8mq-vpu-ctrl
   - rockchip,px30-qos
   - rockchip,rk3066-qos
   - rockchip,rk3288-qos
-- 
2.25.1



[PATCH v9 00/13] Add HANTRO G2/HEVC decoder support for IMX8MQ

2021-04-07 Thread Benjamin Gaignard
)
Driver version   : 5.11.0
Interface Info:
ID   : 0x030c
Type : V4L Video
Entity Info:
ID   : 0x0001 (1)
Name : nxp,imx8mq-vpu-g2-dec-source
Function : V4L2 I/O
Pad 0x0102   : 0: Source
  Link 0x0208: to remote pad 0x104 of entity 
'nxp,imx8mq-vpu-g2-dec-proc': Data, Enabled, Immutable

Required ioctls:
test MC information (see 'Media Driver Info' above): OK
test VIDIOC_QUERYCAP: OK
test invalid ioctls: OK

Allow for multiple opens:
test second /dev/video1 open: OK
test VIDIOC_QUERYCAP: OK
test VIDIOC_G/S_PRIORITY: OK
test for unlimited opens: OK

Debug ioctls:
test VIDIOC_DBG_G/S_REGISTER: OK (Not Supported)
test VIDIOC_LOG_STATUS: OK (Not Supported)

Input ioctls:
test VIDIOC_G/S_TUNER/ENUM_FREQ_BANDS: OK (Not Supported)
test VIDIOC_G/S_FREQUENCY: OK (Not Supported)
test VIDIOC_S_HW_FREQ_SEEK: OK (Not Supported)
test VIDIOC_ENUMAUDIO: OK (Not Supported)
test VIDIOC_G/S/ENUMINPUT: OK (Not Supported)
test VIDIOC_G/S_AUDIO: OK (Not Supported)
Inputs: 0 Audio Inputs: 0 Tuners: 0

Output ioctls:
test VIDIOC_G/S_MODULATOR: OK (Not Supported)
test VIDIOC_G/S_FREQUENCY: OK (Not Supported)
test VIDIOC_ENUMAUDOUT: OK (Not Supported)
test VIDIOC_G/S/ENUMOUTPUT: OK (Not Supported)
test VIDIOC_G/S_AUDOUT: OK (Not Supported)
Outputs: 0 Audio Outputs: 0 Modulators: 0

Input/Output configuration ioctls:
test VIDIOC_ENUM/G/S/QUERY_STD: OK (Not Supported)
test VIDIOC_ENUM/G/S/QUERY_DV_TIMINGS: OK (Not Supported)
test VIDIOC_DV_TIMINGS_CAP: OK (Not Supported)
test VIDIOC_G/S_EDID: OK (Not Supported)

Control ioctls:
test VIDIOC_QUERY_EXT_CTRL/QUERYMENU: OK
test VIDIOC_QUERYCTRL: OK
test VIDIOC_G/S_CTRL: OK
test VIDIOC_G/S/TRY_EXT_CTRLS: OK
test VIDIOC_(UN)SUBSCRIBE_EVENT/DQEVENT: OK
test VIDIOC_G/S_JPEGCOMP: OK (Not Supported)
Standard Controls: 8 Private Controls: 1

Format ioctls:
test VIDIOC_ENUM_FMT/FRAMESIZES/FRAMEINTERVALS: OK
test VIDIOC_G/S_PARM: OK (Not Supported)
test VIDIOC_G_FBUF: OK (Not Supported)
test VIDIOC_G_FMT: OK
test VIDIOC_TRY_FMT: OK
test VIDIOC_S_FMT: OK
test VIDIOC_G_SLICED_VBI_CAP: OK (Not Supported)
test Cropping: OK (Not Supported)
test Composing: OK (Not Supported)
test Scaling: OK (Not Supported)

Codec ioctls:
test VIDIOC_(TRY_)ENCODER_CMD: OK (Not Supported)
test VIDIOC_G_ENC_INDEX: OK (Not Supported)
test VIDIOC_(TRY_)DECODER_CMD: OK (Not Supported)

Buffer ioctls:
test VIDIOC_REQBUFS/CREATE_BUFS/QUERYBUF: OK
test VIDIOC_EXPBUF: OK
test Requests: OK

Total for hantro-vpu device /dev/video1: 46, Succeeded: 46, Failed: 0, 
Warnings: 0

Grand Total for hantro-vpu device /dev/media1: 54, Succeeded: 54, Failed: 0, 
Warnings: 0

Benjamin
 
Benjamin Gaignard (13):
  dt-bindings: mfd: Add 'nxp,imx8mq-vpu-ctrl' to syscon list
  dt-bindings: media: nxp,imx8mq-vpu: Update the bindings for G2 support
  media: hantro: Use syscon instead of 'ctrl' register
  media: hevc: Add fields and flags for hevc PPS
  media: hevc: Add decode params control
  media: hantro: change hantro_codec_ops run prototype to return errors
  media: hantro: Define HEVC codec profiles and supported features
  media: hantro: Only use postproc when post processed formats are
defined
  media: uapi: Add a control for HANTRO driver
  media: hantro: handle V4L2_PIX_FMT_HEVC_SLICE control
  media: hantro: Introduce G2/HEVC decoder
  media: hantro: IMX8M: add variant for G2/HEVC codec
  arm64: dts: imx8mq: Add node to G2 hardware

 .../bindings/media/nxp,imx8mq-vpu.yaml|  53 +-
 .../devicetree/bindings/mfd/syscon.yaml   |   1 +
 .../userspace-api/media/drivers/hantro.rst|  19 +
 .../userspace-api/media/drivers/index.rst |   1 +
 .../media/v4l/ext-ctrls-codec.rst | 108 +++-
 .../media/v4l/vidioc-queryctrl.rst|   6 +
 arch/arm64/boot/dts/freescale/imx8mq.dtsi |  43 +-
 drivers/media/v4l2-core/v4l2-ctrls.c  |  28 +-
 drivers/staging/media/hantro/Makefile |   2 +
 drivers/staging/media/hantro/hantro.h |  18 +-
 drivers/staging/media/hantro/hantro_drv.c |  99 ++-
 .../staging/media/hantro/hantro_g1_h264_dec.c |  10 +-
 .../media/hantro/hantro_g1_mpeg2_dec.c|   4 +-
 .../staging/media/hantro/hantro_g1_vp8_dec.c  |   6 +-
 .../staging/media/hantro/hantro_g2_hevc_dec.c | 587 ++
 drivers/staging/media/hantro/hantro_g2_regs.h | 198 ++
 .../staging/media/hantro/hantro_h1_jpeg_enc.c |   4 +-
 drivers/staging/media/hantro/hantro_hevc.c| 327 ++
 drivers/staging/media/hantro/hantro_hw.h  |  69 +-
 .../staging

[PATCH v8 07/13] media: hantro: Define HEVC codec profiles and supported features

2021-04-01 Thread Benjamin Gaignard
Define which HEVC profiles (up to level 5.1) and features
(no scaling, no 10 bits) are supported by the driver.

Signed-off-by: Benjamin Gaignard 
Reviewed-by: Ezequiel Garcia 
---
version 8:
 - add Ezequiel review tag

 drivers/staging/media/hantro/hantro.h |  3 ++
 drivers/staging/media/hantro/hantro_drv.c | 58 +++
 2 files changed, 61 insertions(+)

diff --git a/drivers/staging/media/hantro/hantro.h 
b/drivers/staging/media/hantro/hantro.h
index 37b9ce04bd4e..edb4561a6887 100644
--- a/drivers/staging/media/hantro/hantro.h
+++ b/drivers/staging/media/hantro/hantro.h
@@ -35,6 +35,7 @@ struct hantro_codec_ops;
 #define HANTRO_MPEG2_DECODER   BIT(16)
 #define HANTRO_VP8_DECODER BIT(17)
 #define HANTRO_H264_DECODERBIT(18)
+#define HANTRO_HEVC_DECODERBIT(19)
 #define HANTRO_DECODERS0x
 
 /**
@@ -100,6 +101,7 @@ struct hantro_variant {
  * @HANTRO_MODE_H264_DEC: H264 decoder.
  * @HANTRO_MODE_MPEG2_DEC: MPEG-2 decoder.
  * @HANTRO_MODE_VP8_DEC: VP8 decoder.
+ * @HANTRO_MODE_HEVC_DEC: HEVC decoder.
  */
 enum hantro_codec_mode {
HANTRO_MODE_NONE = -1,
@@ -107,6 +109,7 @@ enum hantro_codec_mode {
HANTRO_MODE_H264_DEC,
HANTRO_MODE_MPEG2_DEC,
HANTRO_MODE_VP8_DEC,
+   HANTRO_MODE_HEVC_DEC,
 };
 
 /*
diff --git a/drivers/staging/media/hantro/hantro_drv.c 
b/drivers/staging/media/hantro/hantro_drv.c
index 02c5c2f1a88b..d9a3a5ef9330 100644
--- a/drivers/staging/media/hantro/hantro_drv.c
+++ b/drivers/staging/media/hantro/hantro_drv.c
@@ -245,6 +245,18 @@ static int hantro_try_ctrl(struct v4l2_ctrl *ctrl)
if (sps->bit_depth_luma_minus8 != 0)
/* Only 8-bit is supported */
return -EINVAL;
+   } else if (ctrl->id == V4L2_CID_MPEG_VIDEO_HEVC_SPS) {
+   const struct v4l2_ctrl_hevc_sps *sps = ctrl->p_new.p_hevc_sps;
+
+   if (sps->bit_depth_luma_minus8 != sps->bit_depth_chroma_minus8)
+   /* Luma and chroma bit depth mismatch */
+   return -EINVAL;
+   if (sps->bit_depth_luma_minus8 != 0)
+   /* Only 8-bit is supported */
+   return -EINVAL;
+   if (sps->flags & V4L2_HEVC_SPS_FLAG_SCALING_LIST_ENABLED)
+   /* No scaling support */
+   return -EINVAL;
}
return 0;
 }
@@ -351,6 +363,52 @@ static const struct hantro_ctrl controls[] = {
.def = V4L2_MPEG_VIDEO_H264_PROFILE_MAIN,
}
}, {
+   .codec = HANTRO_HEVC_DECODER,
+   .cfg = {
+   .id = V4L2_CID_MPEG_VIDEO_HEVC_DECODE_MODE,
+   .min = V4L2_MPEG_VIDEO_HEVC_DECODE_MODE_FRAME_BASED,
+   .max = V4L2_MPEG_VIDEO_HEVC_DECODE_MODE_FRAME_BASED,
+   .def = V4L2_MPEG_VIDEO_HEVC_DECODE_MODE_FRAME_BASED,
+   },
+   }, {
+   .codec = HANTRO_HEVC_DECODER,
+   .cfg = {
+   .id = V4L2_CID_MPEG_VIDEO_HEVC_START_CODE,
+   .min = V4L2_MPEG_VIDEO_HEVC_START_CODE_ANNEX_B,
+   .max = V4L2_MPEG_VIDEO_HEVC_START_CODE_ANNEX_B,
+   .def = V4L2_MPEG_VIDEO_HEVC_START_CODE_ANNEX_B,
+   },
+   }, {
+   .codec = HANTRO_HEVC_DECODER,
+   .cfg = {
+   .id = V4L2_CID_MPEG_VIDEO_HEVC_PROFILE,
+   .min = V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN,
+   .max = V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN_10,
+   .def = V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN,
+   },
+   }, {
+   .codec = HANTRO_HEVC_DECODER,
+   .cfg = {
+   .id = V4L2_CID_MPEG_VIDEO_HEVC_LEVEL,
+   .min = V4L2_MPEG_VIDEO_HEVC_LEVEL_1,
+   .max = V4L2_MPEG_VIDEO_HEVC_LEVEL_5_1,
+   },
+   }, {
+   .codec = HANTRO_HEVC_DECODER,
+   .cfg = {
+   .id = V4L2_CID_MPEG_VIDEO_HEVC_SPS,
+   .ops = _ctrl_ops,
+   },
+   }, {
+   .codec = HANTRO_HEVC_DECODER,
+   .cfg = {
+   .id = V4L2_CID_MPEG_VIDEO_HEVC_PPS,
+   },
+   }, {
+   .codec = HANTRO_HEVC_DECODER,
+   .cfg = {
+   .id = V4L2_CID_MPEG_VIDEO_HEVC_DECODE_PARAMS,
+   },
},
 };
 
-- 
2.25.1



[PATCH v8 02/13] dt-bindings: media: nxp,imx8mq-vpu: Update the bindings for G2 support

2021-04-01 Thread Benjamin Gaignard
Introducing G2 hevc video decoder lead to modify the bindings to allow
to get one node per VPUs.
VPUs share one hardware control block which is provided as a phandle on
an syscon.
Each node got now one reg and one interrupt.
Add a compatible for G2 hardware block: nxp,imx8mq-vpu-g2.

To be compatible with older DT the driver is still capable to use 'ctrl'
reg-name even if it is deprecated now.

Signed-off-by: Benjamin Gaignard 
Reviewed-by: Rob Herring 
Reviewed-by: Philipp Zabel 
---
version 7:
- Add Rob and Philipp reviewed-by tag
- Change syscon phandle name to nxp,imx8m-vpu-ctrl (remove 'q' to be
  usable for iMX8MM too)

version 5:
- This version doesn't break the backward compatibilty between kernel
  and DT.

 .../bindings/media/nxp,imx8mq-vpu.yaml| 53 ---
 1 file changed, 34 insertions(+), 19 deletions(-)

diff --git a/Documentation/devicetree/bindings/media/nxp,imx8mq-vpu.yaml 
b/Documentation/devicetree/bindings/media/nxp,imx8mq-vpu.yaml
index 762be3f96ce9..18e7d40a5f24 100644
--- a/Documentation/devicetree/bindings/media/nxp,imx8mq-vpu.yaml
+++ b/Documentation/devicetree/bindings/media/nxp,imx8mq-vpu.yaml
@@ -15,22 +15,18 @@ description:
 
 properties:
   compatible:
-const: nxp,imx8mq-vpu
+oneOf:
+  - const: nxp,imx8mq-vpu
+  - const: nxp,imx8mq-vpu-g2
 
   reg:
-maxItems: 3
-
-  reg-names:
-items:
-  - const: g1
-  - const: g2
-  - const: ctrl
+maxItems: 1
 
   interrupts:
-maxItems: 2
+maxItems: 1
 
   interrupt-names:
-items:
+oneOf:
   - const: g1
   - const: g2
 
@@ -46,14 +42,18 @@ properties:
   power-domains:
 maxItems: 1
 
+  nxp,imx8m-vpu-ctrl:
+description: Specifies a phandle to syscon VPU hardware control block
+$ref: "/schemas/types.yaml#/definitions/phandle"
+
 required:
   - compatible
   - reg
-  - reg-names
   - interrupts
   - interrupt-names
   - clocks
   - clock-names
+  - nxp,imx8m-vpu-ctrl
 
 additionalProperties: false
 
@@ -62,18 +62,33 @@ examples:
 #include 
 #include 
 
-vpu: video-codec@3830 {
+vpu_ctrl: syscon@3832 {
+ compatible = "nxp,imx8mq-vpu-ctrl", "syscon";
+ reg = <0x3832 0x1>;
+};
+
+vpu_g1: video-codec@3830 {
 compatible = "nxp,imx8mq-vpu";
-reg = <0x3830 0x1>,
-  <0x3831 0x1>,
-  <0x3832 0x1>;
-reg-names = "g1", "g2", "ctrl";
-interrupts = ,
- ;
-interrupt-names = "g1", "g2";
+reg = <0x3830 0x1>;
+interrupts = ;
+interrupt-names = "g1";
+clocks = < IMX8MQ_CLK_VPU_G1_ROOT>,
+ < IMX8MQ_CLK_VPU_G2_ROOT>,
+ < IMX8MQ_CLK_VPU_DEC_ROOT>;
+clock-names = "g1", "g2", "bus";
+power-domains = <_vpu>;
+nxp,imx8m-vpu-ctrl = <_ctrl>;
+};
+
+vpu_g2: video-codec@3831 {
+compatible = "nxp,imx8mq-vpu-g2";
+reg = <0x3830 0x1>;
+interrupts = ;
+interrupt-names = "g2";
 clocks = < IMX8MQ_CLK_VPU_G1_ROOT>,
  < IMX8MQ_CLK_VPU_G2_ROOT>,
  < IMX8MQ_CLK_VPU_DEC_ROOT>;
 clock-names = "g1", "g2", "bus";
 power-domains = <_vpu>;
+nxp,imx8m-vpu-ctrl = <_ctrl>;
 };
-- 
2.25.1



[PATCH v8 10/13] media: hantro: handle V4L2_PIX_FMT_HEVC_SLICE control

2021-04-01 Thread Benjamin Gaignard
Make sure that V4L2_PIX_FMT_HEVC_SLICE is correctly handle by v4l2
of the driver.

Signed-off-by: Benjamin Gaignard 
Reviewed-by: Ezequiel Garcia 
---
version 8:
 - Add Ezequiel review tag

 drivers/staging/media/hantro/hantro_v4l2.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/staging/media/hantro/hantro_v4l2.c 
b/drivers/staging/media/hantro/hantro_v4l2.c
index 77d7fe62ce81..0655324fd0d4 100644
--- a/drivers/staging/media/hantro/hantro_v4l2.c
+++ b/drivers/staging/media/hantro/hantro_v4l2.c
@@ -392,6 +392,7 @@ hantro_update_requires_request(struct hantro_ctx *ctx, u32 
fourcc)
case V4L2_PIX_FMT_MPEG2_SLICE:
case V4L2_PIX_FMT_VP8_FRAME:
case V4L2_PIX_FMT_H264_SLICE:
+   case V4L2_PIX_FMT_HEVC_SLICE:
ctx->fh.m2m_ctx->out_q_ctx.q.requires_requests = true;
break;
default:
-- 
2.25.1



[PATCH v8 12/13] media: hantro: IMX8M: add variant for G2/HEVC codec

2021-04-01 Thread Benjamin Gaignard
Add variant to IMX8M to enable G2/HEVC codec.
Define the capabilities for the hardware up to 3840x2160.
G2 doesn't have postprocessor, use the same clocks and got it
own interruption.

Signed-off-by: Benjamin Gaignard 
Reviewed-by: Philipp Zabel 
Reviewed-by: Ezequiel Garcia 
---
version 8:
 - Add Ezequiel Reviewed-by tag.

version 7:
 - Add Philipp Reviewed-by tag.

version 5:
 - remove useless postproc fields for G2

version 2:
- remove useless clocks

 drivers/staging/media/hantro/hantro_drv.c   |  1 +
 drivers/staging/media/hantro/hantro_hw.h|  1 +
 drivers/staging/media/hantro/imx8m_vpu_hw.c | 76 -
 3 files changed, 76 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/media/hantro/hantro_drv.c 
b/drivers/staging/media/hantro/hantro_drv.c
index 33b8bd38eac1..ed380a8bef93 100644
--- a/drivers/staging/media/hantro/hantro_drv.c
+++ b/drivers/staging/media/hantro/hantro_drv.c
@@ -574,6 +574,7 @@ static const struct of_device_id of_hantro_match[] = {
 #endif
 #ifdef CONFIG_VIDEO_HANTRO_IMX8M
{ .compatible = "nxp,imx8mq-vpu", .data = _vpu_variant, },
+   { .compatible = "nxp,imx8mq-vpu-g2", .data = _vpu_g2_variant },
 #endif
{ /* sentinel */ }
 };
diff --git a/drivers/staging/media/hantro/hantro_hw.h 
b/drivers/staging/media/hantro/hantro_hw.h
index 5788188aae50..b4e7490bbe45 100644
--- a/drivers/staging/media/hantro/hantro_hw.h
+++ b/drivers/staging/media/hantro/hantro_hw.h
@@ -193,6 +193,7 @@ extern const struct hantro_variant rk3399_vpu_variant;
 extern const struct hantro_variant rk3328_vpu_variant;
 extern const struct hantro_variant rk3288_vpu_variant;
 extern const struct hantro_variant imx8mq_vpu_variant;
+extern const struct hantro_variant imx8mq_vpu_g2_variant;
 
 extern const struct hantro_postproc_regs hantro_g1_postproc_regs;
 
diff --git a/drivers/staging/media/hantro/imx8m_vpu_hw.c 
b/drivers/staging/media/hantro/imx8m_vpu_hw.c
index 8d0c3425234b..6de43e0edc36 100644
--- a/drivers/staging/media/hantro/imx8m_vpu_hw.c
+++ b/drivers/staging/media/hantro/imx8m_vpu_hw.c
@@ -12,6 +12,7 @@
 #include "hantro.h"
 #include "hantro_jpeg.h"
 #include "hantro_g1_regs.h"
+#include "hantro_g2_regs.h"
 
 #define CTRL_SOFT_RESET0x00
 #define RESET_G1   BIT(1)
@@ -129,6 +130,26 @@ static const struct hantro_fmt imx8m_vpu_dec_fmts[] = {
},
 };
 
+static const struct hantro_fmt imx8m_vpu_g2_dec_fmts[] = {
+   {
+   .fourcc = V4L2_PIX_FMT_NV12,
+   .codec_mode = HANTRO_MODE_NONE,
+   },
+   {
+   .fourcc = V4L2_PIX_FMT_HEVC_SLICE,
+   .codec_mode = HANTRO_MODE_HEVC_DEC,
+   .max_depth = 2,
+   .frmsize = {
+   .min_width = 48,
+   .max_width = 3840,
+   .step_width = MB_DIM,
+   .min_height = 48,
+   .max_height = 2160,
+   .step_height = MB_DIM,
+   },
+   },
+};
+
 static irqreturn_t imx8m_vpu_g1_irq(int irq, void *dev_id)
 {
struct hantro_dev *vpu = dev_id;
@@ -147,6 +168,24 @@ static irqreturn_t imx8m_vpu_g1_irq(int irq, void *dev_id)
return IRQ_HANDLED;
 }
 
+static irqreturn_t imx8m_vpu_g2_irq(int irq, void *dev_id)
+{
+   struct hantro_dev *vpu = dev_id;
+   enum vb2_buffer_state state;
+   u32 status;
+
+   status = vdpu_read(vpu, HEVC_REG_INTERRUPT);
+   state = (status & HEVC_REG_INTERRUPT_DEC_RDY_INT) ?
+VB2_BUF_STATE_DONE : VB2_BUF_STATE_ERROR;
+
+   vdpu_write(vpu, 0, HEVC_REG_INTERRUPT);
+   vdpu_write(vpu, HEVC_REG_CONFIG_DEC_CLK_GATE_E, HEVC_REG_CONFIG);
+
+   hantro_irq_done(vpu, state);
+
+   return IRQ_HANDLED;
+}
+
 static int imx8mq_vpu_hw_init(struct hantro_dev *vpu)
 {
struct device_node *np = vpu->dev->of_node;
@@ -176,6 +215,13 @@ static void imx8m_vpu_g1_reset(struct hantro_ctx *ctx)
imx8m_soft_reset(vpu, RESET_G1);
 }
 
+static void imx8m_vpu_g2_reset(struct hantro_ctx *ctx)
+{
+   struct hantro_dev *vpu = ctx->dev;
+
+   imx8m_soft_reset(vpu, RESET_G2);
+}
+
 /*
  * Supported codec ops.
  */
@@ -201,16 +247,28 @@ static const struct hantro_codec_ops 
imx8mq_vpu_codec_ops[] = {
},
 };
 
+static const struct hantro_codec_ops imx8mq_vpu_g2_codec_ops[] = {
+   [HANTRO_MODE_HEVC_DEC] = {
+   .run = hantro_g2_hevc_dec_run,
+   .reset = imx8m_vpu_g2_reset,
+   .init = hantro_hevc_dec_init,
+   .exit = hantro_hevc_dec_exit,
+   },
+};
+
 /*
  * VPU variants.
  */
 
 static const struct hantro_irq imx8mq_irqs[] = {
{ "g1", imx8m_vpu_g1_irq },
-   { "g2", NULL /* TODO: imx8m_vpu_g2_irq */ },
 };
 
-static const char * const imx8mq_clk_names[] = { "g1", "g2", "bus" };
+static const struct hantro_irq imx8mq

[PATCH v8 05/13] media: hevc: Add decode params control

2021-04-01 Thread Benjamin Gaignard
Add decode params control and it associated structure to regroup
all the information that are needed to decode a reference frame as
it is describe in ITU-T Rec. H.265 section "8.3.2 Decoding process
for reference picture set".

Adapt Cedrus driver to these changes.

Signed-off-by: Benjamin Gaignard 
Reviewed-by: Ezequiel Garcia 
---
version 8:
 - add Ezequiel review tag

version 7:
 - rebased on top of media_tree/master branch

version 6:
 - fix compilation errors

 .../media/v4l/ext-ctrls-codec.rst | 94 +++
 .../media/v4l/vidioc-queryctrl.rst|  6 ++
 drivers/media/v4l2-core/v4l2-ctrls.c  | 26 +++--
 drivers/staging/media/sunxi/cedrus/cedrus.c   |  6 ++
 drivers/staging/media/sunxi/cedrus/cedrus.h   |  1 +
 .../staging/media/sunxi/cedrus/cedrus_dec.c   |  2 +
 .../staging/media/sunxi/cedrus/cedrus_h265.c  | 12 ++-
 include/media/hevc-ctrls.h| 29 --
 8 files changed, 137 insertions(+), 39 deletions(-)

diff --git a/Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst 
b/Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst
index 92314aec655a..7552869687f7 100644
--- a/Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst
+++ b/Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst
@@ -3181,9 +3181,6 @@ enum v4l2_mpeg_video_hevc_size_of_length_field -
 * - __u8
   - ``pic_struct``
   -
-* - __u8
-  - ``num_active_dpb_entries``
-  - The number of entries in ``dpb``.
 * - __u8
   - ``ref_idx_l0[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]``
   - The list of L0 reference elements as indices in the DPB.
@@ -3191,22 +3188,8 @@ enum v4l2_mpeg_video_hevc_size_of_length_field -
   - ``ref_idx_l1[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]``
   - The list of L1 reference elements as indices in the DPB.
 * - __u8
-  - ``num_rps_poc_st_curr_before``
-  - The number of reference pictures in the short-term set that come before
-the current frame.
-* - __u8
-  - ``num_rps_poc_st_curr_after``
-  - The number of reference pictures in the short-term set that come after
-the current frame.
-* - __u8
-  - ``num_rps_poc_lt_curr``
-  - The number of reference pictures in the long-term set.
-* - __u8
-  - ``padding[7]``
+  - ``padding``
   - Applications and drivers must set this to zero.
-* - struct :c:type:`v4l2_hevc_dpb_entry`
-  - ``dpb[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]``
-  - The decoded picture buffer, for meta-data about reference frames.
 * - struct :c:type:`v4l2_hevc_pred_weight_table`
   - ``pred_weight_table``
   - The prediction weight coefficients for inter-picture prediction.
@@ -3441,3 +3424,78 @@ enum v4l2_mpeg_video_hevc_size_of_length_field -
 so this has to come from client.
 This is applicable to H264 and valid Range is from 0 to 63.
 Source Rec. ITU-T H.264 (06/2019); G.7.4.1.1, G.8.8.1.
+
+``V4L2_CID_MPEG_VIDEO_HEVC_DECODE_PARAMS (struct)``
+Specifies various decode parameters, especially the references picture 
order
+count (POC) for all the lists (short, long, before, current, after) and the
+number of entries for each of them.
+These parameters are defined according to :ref:`hevc`.
+They are described in section 8.3 "Slice decoding process" of the
+specification.
+
+.. c:type:: v4l2_ctrl_hevc_decode_params
+
+.. cssclass:: longtable
+
+.. flat-table:: struct v4l2_ctrl_hevc_decode_params
+:header-rows:  0
+:stub-columns: 0
+:widths:   1 1 2
+
+* - __s32
+  - ``pic_order_cnt_val``
+  - PicOrderCntVal as described in section 8.3.1 "Decoding process
+for picture order count" of the specification.
+* - __u8
+  - ``num_active_dpb_entries``
+  - The number of entries in ``dpb``.
+* - struct :c:type:`v4l2_hevc_dpb_entry`
+  - ``dpb[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]``
+  - The decoded picture buffer, for meta-data about reference frames.
+* - __u8
+  - ``num_poc_st_curr_before``
+  - The number of reference pictures in the short-term set that come before
+the current frame.
+* - __u8
+  - ``num_poc_st_curr_after``
+  - The number of reference pictures in the short-term set that come after
+the current frame.
+* - __u8
+  - ``num_poc_lt_curr``
+  - The number of reference pictures in the long-term set.
+* - __u8
+  - ``poc_st_curr_before[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]``
+  - PocStCurrBefore as described in section 8.3.2 "Decoding process for 
reference
+picture set.
+* - __u8
+  - ``poc_st_curr_after[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]``
+  - PocStCurrAfter as described in section 8.3.2 "Decoding process for 
reference
+picture set.
+* - __u8
+  - ``poc_lt_curr[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]``
+  - PocLtCurr as described in section 8.3.2 "Decoding process for reference
+   

[PATCH v8 00/13] Add HANTRO G2/HEVC decoder support for IMX8MQ

2021-04-01 Thread Benjamin Gaignard
,imx8mq-vpu-g2-dec-source
Function : V4L2 I/O
Pad 0x0102   : 0: Source
  Link 0x0208: to remote pad 0x104 of entity 
'nxp,imx8mq-vpu-g2-dec-proc': Data, Enabled, Immutable

Required ioctls:
test MC information (see 'Media Driver Info' above): OK
test VIDIOC_QUERYCAP: OK
test invalid ioctls: OK

Allow for multiple opens:
test second /dev/video1 open: OK
test VIDIOC_QUERYCAP: OK
test VIDIOC_G/S_PRIORITY: OK
test for unlimited opens: OK

Debug ioctls:
test VIDIOC_DBG_G/S_REGISTER: OK (Not Supported)
test VIDIOC_LOG_STATUS: OK (Not Supported)

Input ioctls:
test VIDIOC_G/S_TUNER/ENUM_FREQ_BANDS: OK (Not Supported)
test VIDIOC_G/S_FREQUENCY: OK (Not Supported)
test VIDIOC_S_HW_FREQ_SEEK: OK (Not Supported)
test VIDIOC_ENUMAUDIO: OK (Not Supported)
test VIDIOC_G/S/ENUMINPUT: OK (Not Supported)
test VIDIOC_G/S_AUDIO: OK (Not Supported)
Inputs: 0 Audio Inputs: 0 Tuners: 0

Output ioctls:
test VIDIOC_G/S_MODULATOR: OK (Not Supported)
test VIDIOC_G/S_FREQUENCY: OK (Not Supported)
test VIDIOC_ENUMAUDOUT: OK (Not Supported)
test VIDIOC_G/S/ENUMOUTPUT: OK (Not Supported)
test VIDIOC_G/S_AUDOUT: OK (Not Supported)
Outputs: 0 Audio Outputs: 0 Modulators: 0

Input/Output configuration ioctls:
test VIDIOC_ENUM/G/S/QUERY_STD: OK (Not Supported)
test VIDIOC_ENUM/G/S/QUERY_DV_TIMINGS: OK (Not Supported)
test VIDIOC_DV_TIMINGS_CAP: OK (Not Supported)
test VIDIOC_G/S_EDID: OK (Not Supported)

Control ioctls:
test VIDIOC_QUERY_EXT_CTRL/QUERYMENU: OK
test VIDIOC_QUERYCTRL: OK
test VIDIOC_G/S_CTRL: OK
test VIDIOC_G/S/TRY_EXT_CTRLS: OK
test VIDIOC_(UN)SUBSCRIBE_EVENT/DQEVENT: OK
test VIDIOC_G/S_JPEGCOMP: OK (Not Supported)
Standard Controls: 8 Private Controls: 1

Format ioctls:
test VIDIOC_ENUM_FMT/FRAMESIZES/FRAMEINTERVALS: OK
test VIDIOC_G/S_PARM: OK (Not Supported)
test VIDIOC_G_FBUF: OK (Not Supported)
test VIDIOC_G_FMT: OK
test VIDIOC_TRY_FMT: OK
test VIDIOC_S_FMT: OK
test VIDIOC_G_SLICED_VBI_CAP: OK (Not Supported)
test Cropping: OK (Not Supported)
test Composing: OK (Not Supported)
test Scaling: OK (Not Supported)

Codec ioctls:
test VIDIOC_(TRY_)ENCODER_CMD: OK (Not Supported)
test VIDIOC_G_ENC_INDEX: OK (Not Supported)
test VIDIOC_(TRY_)DECODER_CMD: OK (Not Supported)

Buffer ioctls:
test VIDIOC_REQBUFS/CREATE_BUFS/QUERYBUF: OK
test VIDIOC_EXPBUF: OK
test Requests: OK

Total for hantro-vpu device /dev/video1: 46, Succeeded: 46, Failed: 0, 
Warnings: 0

Grand Total for hantro-vpu device /dev/media1: 54, Succeeded: 54, Failed: 0, 
Warnings: 0

Benjamin
 
Benjamin Gaignard (13):
  dt-bindings: mfd: Add 'nxp,imx8mq-vpu-ctrl' to syscon list
  dt-bindings: media: nxp,imx8mq-vpu: Update the bindings for G2 support
  media: hantro: Use syscon instead of 'ctrl' register
  media: hevc: Add fields and flags for hevc PPS
  media: hevc: Add decode params control
  media: hantro: change hantro_codec_ops run prototype to return errors
  media: hantro: Define HEVC codec profiles and supported features
  media: hantro: Only use postproc when post processed formats are
defined
  media: uapi: Add a control for HANTRO driver
  media: hantro: handle V4L2_PIX_FMT_HEVC_SLICE control
  media: hantro: Introduce G2/HEVC decoder
  media: hantro: IMX8M: add variant for G2/HEVC codec
  arm64: dts: imx8mq: Add node to G2 hardware

 .../bindings/media/nxp,imx8mq-vpu.yaml|  53 +-
 .../devicetree/bindings/mfd/syscon.yaml   |   1 +
 .../userspace-api/media/drivers/hantro.rst|  14 +
 .../userspace-api/media/drivers/index.rst |   1 +
 .../media/v4l/ext-ctrls-codec.rst | 108 +++-
 .../media/v4l/vidioc-queryctrl.rst|   6 +
 arch/arm64/boot/dts/freescale/imx8mq.dtsi |  43 +-
 drivers/media/v4l2-core/v4l2-ctrls.c  |  26 +-
 drivers/staging/media/hantro/Makefile |   2 +
 drivers/staging/media/hantro/hantro.h |  18 +-
 drivers/staging/media/hantro/hantro_drv.c |  99 ++-
 .../staging/media/hantro/hantro_g1_h264_dec.c |  10 +-
 .../media/hantro/hantro_g1_mpeg2_dec.c|   4 +-
 .../staging/media/hantro/hantro_g1_vp8_dec.c  |   6 +-
 .../staging/media/hantro/hantro_g2_hevc_dec.c | 587 ++
 drivers/staging/media/hantro/hantro_g2_regs.h | 198 ++
 .../staging/media/hantro/hantro_h1_jpeg_enc.c |   4 +-
 drivers/staging/media/hantro/hantro_hevc.c| 325 ++
 drivers/staging/media/hantro/hantro_hw.h  |  69 +-
 .../staging/media/hantro/hantro_postproc.c|  14 +
 drivers/staging/media/hantro/hantro_v4l2.c|   5 +-
 drivers/staging/media/hantro/imx8m_vpu_hw.c   | 128 +++-
 .../media/hantro/rk3399_vpu_hw_jpeg_enc.c |   4

[PATCH v8 11/13] media: hantro: Introduce G2/HEVC decoder

2021-04-01 Thread Benjamin Gaignard
Implement all the logic to get G2 hardware decoding HEVC frames.
It support up level 5.1 HEVC stream.
It doesn't support yet 10 bits formats or scaling feature.

Add HANTRO HEVC dedicated control to skip some bits at the beginning
of the slice header. That is very specific to this hardware so can't
go into uapi structures. Compute the needed value is complex and require
information from the stream that only the userland knows so let it
provide the correct value to the driver.

Signed-off-by: Benjamin Gaignard 
Co-developed-by: Adrian Ratiu 
Signed-off-by: Adrian Ratiu 
Co-developed-by: Ezequiel Garcia 
Signed-off-by: Ezequiel Garcia 
---
version 8:
 - Fix compilation warnings

version 7:
 - Improve motion vectors requested memory size computation.

 drivers/staging/media/hantro/Makefile |   2 +
 drivers/staging/media/hantro/hantro.h |   2 +
 drivers/staging/media/hantro/hantro_drv.c |  36 ++
 .../staging/media/hantro/hantro_g2_hevc_dec.c | 587 ++
 drivers/staging/media/hantro/hantro_g2_regs.h | 198 ++
 drivers/staging/media/hantro/hantro_hevc.c| 325 ++
 drivers/staging/media/hantro/hantro_hw.h  |  49 ++
 7 files changed, 1199 insertions(+)
 create mode 100644 drivers/staging/media/hantro/hantro_g2_hevc_dec.c
 create mode 100644 drivers/staging/media/hantro/hantro_g2_regs.h
 create mode 100644 drivers/staging/media/hantro/hantro_hevc.c

diff --git a/drivers/staging/media/hantro/Makefile 
b/drivers/staging/media/hantro/Makefile
index 743ce08eb184..0357f1772267 100644
--- a/drivers/staging/media/hantro/Makefile
+++ b/drivers/staging/media/hantro/Makefile
@@ -9,12 +9,14 @@ hantro-vpu-y += \
hantro_h1_jpeg_enc.o \
hantro_g1_h264_dec.o \
hantro_g1_mpeg2_dec.o \
+   hantro_g2_hevc_dec.o \
hantro_g1_vp8_dec.o \
rk3399_vpu_hw_jpeg_enc.o \
rk3399_vpu_hw_mpeg2_dec.o \
rk3399_vpu_hw_vp8_dec.o \
hantro_jpeg.o \
hantro_h264.o \
+   hantro_hevc.o \
hantro_mpeg2.o \
hantro_vp8.o
 
diff --git a/drivers/staging/media/hantro/hantro.h 
b/drivers/staging/media/hantro/hantro.h
index 7a5ad93466c8..6a21d1e95b34 100644
--- a/drivers/staging/media/hantro/hantro.h
+++ b/drivers/staging/media/hantro/hantro.h
@@ -222,6 +222,7 @@ struct hantro_dev {
  * @jpeg_enc:  JPEG-encoding context.
  * @mpeg2_dec: MPEG-2-decoding context.
  * @vp8_dec:   VP8-decoding context.
+ * @hevc_dec:  HEVC-decoding context.
  */
 struct hantro_ctx {
struct hantro_dev *dev;
@@ -248,6 +249,7 @@ struct hantro_ctx {
struct hantro_jpeg_enc_hw_ctx jpeg_enc;
struct hantro_mpeg2_dec_hw_ctx mpeg2_dec;
struct hantro_vp8_dec_hw_ctx vp8_dec;
+   struct hantro_hevc_dec_hw_ctx hevc_dec;
};
 };
 
diff --git a/drivers/staging/media/hantro/hantro_drv.c 
b/drivers/staging/media/hantro/hantro_drv.c
index d9a3a5ef9330..33b8bd38eac1 100644
--- a/drivers/staging/media/hantro/hantro_drv.c
+++ b/drivers/staging/media/hantro/hantro_drv.c
@@ -281,6 +281,26 @@ static int hantro_jpeg_s_ctrl(struct v4l2_ctrl *ctrl)
return 0;
 }
 
+static int hantro_hevc_s_ctrl(struct v4l2_ctrl *ctrl)
+{
+   struct hantro_ctx *ctx;
+
+   ctx = container_of(ctrl->handler,
+  struct hantro_ctx, ctrl_handler);
+
+   vpu_debug(1, "s_ctrl: id = %d, val = %d\n", ctrl->id, ctrl->val);
+
+   switch (ctrl->id) {
+   case V4L2_CID_HANTRO_HEVC_SLICE_HEADER_SKIP:
+   ctx->hevc_dec.ctrls.hevc_hdr_skip_length = ctrl->val;
+   break;
+   default:
+   return -EINVAL;
+   }
+
+   return 0;
+}
+
 static const struct v4l2_ctrl_ops hantro_ctrl_ops = {
.try_ctrl = hantro_try_ctrl,
 };
@@ -289,6 +309,10 @@ static const struct v4l2_ctrl_ops hantro_jpeg_ctrl_ops = {
.s_ctrl = hantro_jpeg_s_ctrl,
 };
 
+static const struct v4l2_ctrl_ops hantro_hevc_ctrl_ops = {
+   .s_ctrl = hantro_hevc_s_ctrl,
+};
+
 static const struct hantro_ctrl controls[] = {
{
.codec = HANTRO_JPEG_ENCODER,
@@ -409,6 +433,18 @@ static const struct hantro_ctrl controls[] = {
.cfg = {
.id = V4L2_CID_MPEG_VIDEO_HEVC_DECODE_PARAMS,
},
+   }, {
+   .codec = HANTRO_HEVC_DECODER,
+   .cfg = {
+   .id = V4L2_CID_HANTRO_HEVC_SLICE_HEADER_SKIP,
+   .name = "Hantro HEVC slice header skip bytes",
+   .type = V4L2_CTRL_TYPE_INTEGER,
+   .min = 0,
+   .def = 0,
+   .max = 0x7fff,
+   .step = 1,
+   .ops = _hevc_ctrl_ops,
+   },
},
 };
 
diff --git a/drivers/stagin

[PATCH v8 06/13] media: hantro: change hantro_codec_ops run prototype to return errors

2021-04-01 Thread Benjamin Gaignard
Change hantro_codec_ops run prototype from 'void' to 'int'.
This allow to cancel the job if an error occur while configuring
the hardware.

Signed-off-by: Benjamin Gaignard 
Reviewed-by: Ezequiel Garcia 
---
version 8:
 - add Ezequiel review tag

version 5:
 - forward hantro_h264_dec_prepare_run() return value in case
   of error

 drivers/staging/media/hantro/hantro_drv.c |  4 +++-
 .../staging/media/hantro/hantro_g1_h264_dec.c | 10 +++---
 .../media/hantro/hantro_g1_mpeg2_dec.c|  4 +++-
 .../staging/media/hantro/hantro_g1_vp8_dec.c  |  6 --
 .../staging/media/hantro/hantro_h1_jpeg_enc.c |  4 +++-
 drivers/staging/media/hantro/hantro_hw.h  | 19 ++-
 .../media/hantro/rk3399_vpu_hw_jpeg_enc.c |  4 +++-
 .../media/hantro/rk3399_vpu_hw_mpeg2_dec.c|  4 +++-
 .../media/hantro/rk3399_vpu_hw_vp8_dec.c  |  6 --
 9 files changed, 40 insertions(+), 21 deletions(-)

diff --git a/drivers/staging/media/hantro/hantro_drv.c 
b/drivers/staging/media/hantro/hantro_drv.c
index 595e82a82728..02c5c2f1a88b 100644
--- a/drivers/staging/media/hantro/hantro_drv.c
+++ b/drivers/staging/media/hantro/hantro_drv.c
@@ -161,7 +161,9 @@ static void device_run(void *priv)
 
v4l2_m2m_buf_copy_metadata(src, dst, true);
 
-   ctx->codec_ops->run(ctx);
+   if (ctx->codec_ops->run(ctx))
+   goto err_cancel_job;
+
return;
 
 err_cancel_job:
diff --git a/drivers/staging/media/hantro/hantro_g1_h264_dec.c 
b/drivers/staging/media/hantro/hantro_g1_h264_dec.c
index 845bef73d218..5c792b7bcb79 100644
--- a/drivers/staging/media/hantro/hantro_g1_h264_dec.c
+++ b/drivers/staging/media/hantro/hantro_g1_h264_dec.c
@@ -273,13 +273,15 @@ static void set_buffers(struct hantro_ctx *ctx)
vdpu_write_relaxed(vpu, ctx->h264_dec.priv.dma, G1_REG_ADDR_QTABLE);
 }
 
-void hantro_g1_h264_dec_run(struct hantro_ctx *ctx)
+int hantro_g1_h264_dec_run(struct hantro_ctx *ctx)
 {
struct hantro_dev *vpu = ctx->dev;
+   int ret;
 
/* Prepare the H264 decoder context. */
-   if (hantro_h264_dec_prepare_run(ctx))
-   return;
+   ret = hantro_h264_dec_prepare_run(ctx);
+   if (ret)
+   return ret;
 
/* Configure hardware registers. */
set_params(ctx);
@@ -301,4 +303,6 @@ void hantro_g1_h264_dec_run(struct hantro_ctx *ctx)
   G1_REG_CONFIG_DEC_CLK_GATE_E,
   G1_REG_CONFIG);
vdpu_write(vpu, G1_REG_INTERRUPT_DEC_E, G1_REG_INTERRUPT);
+
+   return 0;
 }
diff --git a/drivers/staging/media/hantro/hantro_g1_mpeg2_dec.c 
b/drivers/staging/media/hantro/hantro_g1_mpeg2_dec.c
index 6386a3989bfe..5e8943d31dc5 100644
--- a/drivers/staging/media/hantro/hantro_g1_mpeg2_dec.c
+++ b/drivers/staging/media/hantro/hantro_g1_mpeg2_dec.c
@@ -155,7 +155,7 @@ hantro_g1_mpeg2_dec_set_buffers(struct hantro_dev *vpu, 
struct hantro_ctx *ctx,
vdpu_write_relaxed(vpu, backward_addr, G1_REG_REFER3_BASE);
 }
 
-void hantro_g1_mpeg2_dec_run(struct hantro_ctx *ctx)
+int hantro_g1_mpeg2_dec_run(struct hantro_ctx *ctx)
 {
struct hantro_dev *vpu = ctx->dev;
struct vb2_v4l2_buffer *src_buf, *dst_buf;
@@ -248,4 +248,6 @@ void hantro_g1_mpeg2_dec_run(struct hantro_ctx *ctx)
 
reg = G1_REG_DEC_E(1);
vdpu_write(vpu, reg, G1_SWREG(1));
+
+   return 0;
 }
diff --git a/drivers/staging/media/hantro/hantro_g1_vp8_dec.c 
b/drivers/staging/media/hantro/hantro_g1_vp8_dec.c
index 57002ba70176..96622a7f8279 100644
--- a/drivers/staging/media/hantro/hantro_g1_vp8_dec.c
+++ b/drivers/staging/media/hantro/hantro_g1_vp8_dec.c
@@ -425,7 +425,7 @@ static void cfg_buffers(struct hantro_ctx *ctx,
vdpu_write_relaxed(vpu, dst_dma, G1_REG_ADDR_DST);
 }
 
-void hantro_g1_vp8_dec_run(struct hantro_ctx *ctx)
+int hantro_g1_vp8_dec_run(struct hantro_ctx *ctx)
 {
const struct v4l2_ctrl_vp8_frame *hdr;
struct hantro_dev *vpu = ctx->dev;
@@ -438,7 +438,7 @@ void hantro_g1_vp8_dec_run(struct hantro_ctx *ctx)
 
hdr = hantro_get_ctrl(ctx, V4L2_CID_STATELESS_VP8_FRAME);
if (WARN_ON(!hdr))
-   return;
+   return -EINVAL;
 
/* Reset segment_map buffer in keyframe */
if (V4L2_VP8_FRAME_IS_KEY_FRAME(hdr) && ctx->vp8_dec.segment_map.cpu)
@@ -498,4 +498,6 @@ void hantro_g1_vp8_dec_run(struct hantro_ctx *ctx)
hantro_end_prepare_run(ctx);
 
vdpu_write(vpu, G1_REG_INTERRUPT_DEC_E, G1_REG_INTERRUPT);
+
+   return 0;
 }
diff --git a/drivers/staging/media/hantro/hantro_h1_jpeg_enc.c 
b/drivers/staging/media/hantro/hantro_h1_jpeg_enc.c
index b88dc4ed06db..56cf261a8e95 100644
--- a/drivers/staging/media/hantro/hantro_h1_jpeg_enc.c
+++ b/drivers/staging/media/hantro/hantro_h1_jpeg_enc.c
@@ -88,7 +88,7 @@ hantro_h1_jpeg_enc_set_qtable(struct hantro_dev *vpu,
}
 }
 
-void hantro_h1_jpeg_enc_run(struct hantro_ctx *ctx)
+int hantro_h1_jpeg_enc_run(struct

[PATCH v8 04/13] media: hevc: Add fields and flags for hevc PPS

2021-04-01 Thread Benjamin Gaignard
Add fields and flags as they are defined in
7.4.3.3.1 "General picture parameter set RBSP semantics of the
H.265 ITU specification.

Signed-off-by: Benjamin Gaignard 
Reviewed-by: Ezequiel Garcia 
---
version 8:
 - add Ezequiel review tag

 .../userspace-api/media/v4l/ext-ctrls-codec.rst| 14 ++
 include/media/hevc-ctrls.h |  4 
 2 files changed, 18 insertions(+)

diff --git a/Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst 
b/Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst
index 188aef8e40d0..92314aec655a 100644
--- a/Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst
+++ b/Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst
@@ -2967,6 +2967,12 @@ enum v4l2_mpeg_video_hevc_size_of_length_field -
 * - __u8
   - ``num_extra_slice_header_bits``
   -
+* - __u8
+  - ``num_ref_idx_l0_default_active_minus1``
+  - Specifies the inferred value of num_ref_idx_l0_active_minus1
+* - __u8
+  - ``num_ref_idx_l1_default_active_minus1``
+  - Specifies the inferred value of num_ref_idx_l1_active_minus1
 * - __s8
   - ``init_qp_minus26``
   -
@@ -3077,6 +3083,14 @@ enum v4l2_mpeg_video_hevc_size_of_length_field -
 * - ``V4L2_HEVC_PPS_FLAG_SLICE_SEGMENT_HEADER_EXTENSION_PRESENT``
   - 0x0004
   -
+* - ``V4L2_HEVC_PPS_FLAG_DEBLOCKING_FILTER_CONTROL_PRESENT``
+  - 0x0008
+  - Specifies the presence of deblocking filter control syntax elements in
+the PPS
+* - ``V4L2_HEVC_PPS_FLAG_UNIFORM_SPACING``
+  - 0x0010
+  - Specifies that tile column boundaries and likewise tile row boundaries
+are distributed uniformly across the picture
 
 .. raw:: latex
 
diff --git a/include/media/hevc-ctrls.h b/include/media/hevc-ctrls.h
index b4cb2ef02f17..003f819ecb26 100644
--- a/include/media/hevc-ctrls.h
+++ b/include/media/hevc-ctrls.h
@@ -100,10 +100,14 @@ struct v4l2_ctrl_hevc_sps {
 #define V4L2_HEVC_PPS_FLAG_PPS_DISABLE_DEBLOCKING_FILTER   (1ULL << 16)
 #define V4L2_HEVC_PPS_FLAG_LISTS_MODIFICATION_PRESENT  (1ULL << 17)
 #define V4L2_HEVC_PPS_FLAG_SLICE_SEGMENT_HEADER_EXTENSION_PRESENT (1ULL << 18)
+#define V4L2_HEVC_PPS_FLAG_DEBLOCKING_FILTER_CONTROL_PRESENT   (1ULL << 19)
+#define V4L2_HEVC_PPS_FLAG_UNIFORM_SPACING (1ULL << 20)
 
 struct v4l2_ctrl_hevc_pps {
/* ISO/IEC 23008-2, ITU-T Rec. H.265: Picture parameter set */
__u8num_extra_slice_header_bits;
+   __u8num_ref_idx_l0_default_active_minus1;
+   __u8num_ref_idx_l1_default_active_minus1;
__s8init_qp_minus26;
__u8diff_cu_qp_delta_depth;
__s8pps_cb_qp_offset;
-- 
2.25.1



[PATCH v8 09/13] media: uapi: Add a control for HANTRO driver

2021-04-01 Thread Benjamin Gaignard
The HEVC HANTRO driver needs to know the number of bits to skip at
the beginning of the slice header.
That is a hardware specific requirement so create a dedicated control
that this purpose.

Signed-off-by: Benjamin Gaignard 
---
version 5:
 - Be even more verbose in control documentation.
 - Do not create class for the control.
version 4:
- The control is now an integer which is enough to provide the numbers
  of bits to skip.
version 3:
- Fix typo in field name

 .../userspace-api/media/drivers/hantro.rst | 14 ++
 .../userspace-api/media/drivers/index.rst  |  1 +
 include/uapi/linux/v4l2-controls.h | 13 +
 3 files changed, 28 insertions(+)
 create mode 100644 Documentation/userspace-api/media/drivers/hantro.rst

diff --git a/Documentation/userspace-api/media/drivers/hantro.rst 
b/Documentation/userspace-api/media/drivers/hantro.rst
new file mode 100644
index ..78dcd2a44a03
--- /dev/null
+++ b/Documentation/userspace-api/media/drivers/hantro.rst
@@ -0,0 +1,14 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+Hantro video decoder driver
+===
+
+The Hantro video decoder driver implements the following driver-specific 
controls:
+
+``V4L2_CID_HANTRO_HEVC_SLICE_HEADER_SKIP (integer)``
+Specifies to Hantro HEVC video decoder driver the number of data (in bits) 
to
+skip in the slice segment header.
+If non-IDR, the bits to be skipped go from syntax element "pic_output_flag"
+to before syntax element "slice_temporal_mvp_enabled_flag".
+If IDR, the skipped bits are just "pic_output_flag"
+(separate_colour_plane_flag is not supported).
diff --git a/Documentation/userspace-api/media/drivers/index.rst 
b/Documentation/userspace-api/media/drivers/index.rst
index 1a9038f5f9fa..12e3c512d718 100644
--- a/Documentation/userspace-api/media/drivers/index.rst
+++ b/Documentation/userspace-api/media/drivers/index.rst
@@ -33,6 +33,7 @@ For more details see the file COPYING in the source 
distribution of Linux.
 
ccs
cx2341x-uapi
+hantro
imx-uapi
max2175
meye-uapi
diff --git a/include/uapi/linux/v4l2-controls.h 
b/include/uapi/linux/v4l2-controls.h
index f3376aafea65..1dfb874b6272 100644
--- a/include/uapi/linux/v4l2-controls.h
+++ b/include/uapi/linux/v4l2-controls.h
@@ -869,6 +869,19 @@ enum v4l2_mpeg_mfc51_video_force_frame_type {
 #define V4L2_CID_MPEG_MFC51_VIDEO_H264_ADAPTIVE_RC_STATIC  
(V4L2_CID_CODEC_MFC51_BASE+53)
 #define V4L2_CID_MPEG_MFC51_VIDEO_H264_NUM_REF_PIC_FOR_P   
(V4L2_CID_CODEC_MFC51_BASE+54)
 
+/*  MPEG-class control IDs specific to the Hantro driver as defined by V4L2 */
+#define V4L2_CID_CODEC_HANTRO_BASE 
(V4L2_CTRL_CLASS_CODEC | 0x1200)
+/*
+ * V4L2_CID_HANTRO_HEVC_SLICE_HEADER_SKIP -
+ * the number of data (in bits) to skip in the
+ * slice segment header.
+ * If non-IDR, the bits to be skipped go from syntax element "pic_output_flag"
+ * to before syntax element "slice_temporal_mvp_enabled_flag".
+ * If IDR, the skipped bits are just "pic_output_flag"
+ * (separate_colour_plane_flag is not supported).
+ */
+#define V4L2_CID_HANTRO_HEVC_SLICE_HEADER_SKIP (V4L2_CID_CODEC_HANTRO_BASE + 0)
+
 /*  Camera class control IDs */
 
 #define V4L2_CID_CAMERA_CLASS_BASE (V4L2_CTRL_CLASS_CAMERA | 0x900)
-- 
2.25.1



[PATCH v8 01/13] dt-bindings: mfd: Add 'nxp,imx8mq-vpu-ctrl' to syscon list

2021-04-01 Thread Benjamin Gaignard
Add 'nxp,imx8mq-vpu-ctrl' in the list of possible syscon.
It will used to access to the VPU control registers.

Signed-off-by: Benjamin Gaignard 
Acked-by: Rob Herring 
Acked-by: Lee Jones 
---
version 8:
 - Add Lee ack

version 7:
 - Add Rob ack

 Documentation/devicetree/bindings/mfd/syscon.yaml | 1 +
 1 file changed, 1 insertion(+)

diff --git a/Documentation/devicetree/bindings/mfd/syscon.yaml 
b/Documentation/devicetree/bindings/mfd/syscon.yaml
index f14ae6da0068..ae22c4730613 100644
--- a/Documentation/devicetree/bindings/mfd/syscon.yaml
+++ b/Documentation/devicetree/bindings/mfd/syscon.yaml
@@ -44,6 +44,7 @@ properties:
   - hisilicon,peri-subctrl
   - microchip,sparx5-cpu-syscon
   - mstar,msc313-pmsleep
+  - nxp,imx8mq-vpu-ctrl
   - rockchip,px30-qos
   - rockchip,rk3066-qos
   - rockchip,rk3288-qos
-- 
2.25.1



[PATCH v8 13/13] arm64: dts: imx8mq: Add node to G2 hardware

2021-04-01 Thread Benjamin Gaignard
Split VPU node in two: one for G1 and one for G2 since they are
different hardware blocks.
Add syscon for hardware control block.
Remove reg-names property that is useless.
Each VPU node only need one interrupt.
Change G2 assigned clock to match to the specifications.
In the both nodes all the clocks need to assigned to make
sure that control block will be correctly clocked even if
only one device node is enabled.

Signed-off-by: Benjamin Gaignard 
---
version 7:
 - use nxp,imx8m-vpu-ctrl as phandle syscon property name

version 5:
 - use syscon instead of VPU reset

 arch/arm64/boot/dts/freescale/imx8mq.dtsi | 43 ++-
 1 file changed, 34 insertions(+), 9 deletions(-)

diff --git a/arch/arm64/boot/dts/freescale/imx8mq.dtsi 
b/arch/arm64/boot/dts/freescale/imx8mq.dtsi
index 17c449e12c2e..65158414d255 100644
--- a/arch/arm64/boot/dts/freescale/imx8mq.dtsi
+++ b/arch/arm64/boot/dts/freescale/imx8mq.dtsi
@@ -1329,15 +1329,16 @@ usb3_phy1: usb-phy@382f0040 {
status = "disabled";
};
 
-   vpu: video-codec@3830 {
+   vpu_ctrl: syscon@3832 {
+   compatible = "nxp,imx8mq-vpu-ctrl", "syscon";
+   reg = <0x3832 0x1>;
+   };
+
+   vpu_g1: video-codec@3830 {
compatible = "nxp,imx8mq-vpu";
-   reg = <0x3830 0x1>,
- <0x3831 0x1>,
- <0x3832 0x1>;
-   reg-names = "g1", "g2", "ctrl";
-   interrupts = ,
-;
-   interrupt-names = "g1", "g2";
+   reg = <0x3830 0x1>;
+   interrupts = ;
+   interrupt-names = "g1";
clocks = < IMX8MQ_CLK_VPU_G1_ROOT>,
 < IMX8MQ_CLK_VPU_G2_ROOT>,
 < IMX8MQ_CLK_VPU_DEC_ROOT>;
@@ -1350,9 +1351,33 @@ vpu: video-codec@3830 {
 < IMX8MQ_VPU_PLL_OUT>,
 < IMX8MQ_SYS1_PLL_800M>,
 < IMX8MQ_VPU_PLL>;
-   assigned-clock-rates = <6>, <6>,
+   assigned-clock-rates = <6>, <3>,
+  <8>, <0>;
+   power-domains = <_vpu>;
+   nxp,imx8m-vpu-ctrl = <_ctrl>;
+   };
+
+   vpu_g2: video-codec@3831 {
+   compatible = "nxp,imx8mq-vpu-g2";
+   reg = <0x3831 0x1>;
+   interrupts = ;
+   interrupt-names = "g2";
+   clocks = < IMX8MQ_CLK_VPU_G1_ROOT>,
+< IMX8MQ_CLK_VPU_G2_ROOT>,
+< IMX8MQ_CLK_VPU_DEC_ROOT>;
+   clock-names = "g1", "g2",  "bus";
+   assigned-clocks = < IMX8MQ_CLK_VPU_G1>,
+ < IMX8MQ_CLK_VPU_G2>,
+ < IMX8MQ_CLK_VPU_BUS>,
+ < IMX8MQ_VPU_PLL_BYPASS>;
+   assigned-clock-parents = < IMX8MQ_VPU_PLL_OUT>,
+< IMX8MQ_VPU_PLL_OUT>,
+< IMX8MQ_SYS1_PLL_800M>,
+< IMX8MQ_VPU_PLL>;
+   assigned-clock-rates = <6>, <3>,
   <8>, <0>;
power-domains = <_vpu>;
+   nxp,imx8m-vpu-ctrl = <_ctrl>;
};
 
pcie0: pcie@3380 {
-- 
2.25.1



[PATCH v8 08/13] media: hantro: Only use postproc when post processed formats are defined

2021-04-01 Thread Benjamin Gaignard
If the variant doesn't offert postprocessed formats make sure it will
be ok.

Signed-off-by: Benjamin Gaignard 
Reviewed-by: Ezequiel Garcia 
---
version 8:
 - add Ezequiel review tag

 drivers/staging/media/hantro/hantro.h  |  8 ++--
 drivers/staging/media/hantro/hantro_postproc.c | 14 ++
 drivers/staging/media/hantro/hantro_v4l2.c |  4 +++-
 3 files changed, 19 insertions(+), 7 deletions(-)

diff --git a/drivers/staging/media/hantro/hantro.h 
b/drivers/staging/media/hantro/hantro.h
index edb4561a6887..7a5ad93466c8 100644
--- a/drivers/staging/media/hantro/hantro.h
+++ b/drivers/staging/media/hantro/hantro.h
@@ -414,12 +414,8 @@ hantro_get_dst_buf(struct hantro_ctx *ctx)
return v4l2_m2m_next_dst_buf(ctx->fh.m2m_ctx);
 }
 
-static inline bool
-hantro_needs_postproc(const struct hantro_ctx *ctx,
- const struct hantro_fmt *fmt)
-{
-   return !ctx->is_encoder && fmt->fourcc != V4L2_PIX_FMT_NV12;
-}
+bool hantro_needs_postproc(const struct hantro_ctx *ctx,
+  const struct hantro_fmt *fmt);
 
 static inline dma_addr_t
 hantro_get_dec_buf_addr(struct hantro_ctx *ctx, struct vb2_buffer *vb)
diff --git a/drivers/staging/media/hantro/hantro_postproc.c 
b/drivers/staging/media/hantro/hantro_postproc.c
index 6d2a8f2a8f0b..ed8916c950a4 100644
--- a/drivers/staging/media/hantro/hantro_postproc.c
+++ b/drivers/staging/media/hantro/hantro_postproc.c
@@ -50,6 +50,20 @@ const struct hantro_postproc_regs hantro_g1_postproc_regs = {
.display_width = {G1_REG_PP_DISPLAY_WIDTH, 0, 0xfff},
 };
 
+bool hantro_needs_postproc(const struct hantro_ctx *ctx,
+  const struct hantro_fmt *fmt)
+{
+   struct hantro_dev *vpu = ctx->dev;
+
+   if (ctx->is_encoder)
+   return false;
+
+   if (!vpu->variant->postproc_fmts)
+   return false;
+
+   return fmt->fourcc != V4L2_PIX_FMT_NV12;
+}
+
 void hantro_postproc_enable(struct hantro_ctx *ctx)
 {
struct hantro_dev *vpu = ctx->dev;
diff --git a/drivers/staging/media/hantro/hantro_v4l2.c 
b/drivers/staging/media/hantro/hantro_v4l2.c
index 1bc118e375a1..77d7fe62ce81 100644
--- a/drivers/staging/media/hantro/hantro_v4l2.c
+++ b/drivers/staging/media/hantro/hantro_v4l2.c
@@ -55,7 +55,9 @@ static const struct hantro_fmt *
 hantro_get_postproc_formats(const struct hantro_ctx *ctx,
unsigned int *num_fmts)
 {
-   if (ctx->is_encoder) {
+   struct hantro_dev *vpu = ctx->dev;
+
+   if (ctx->is_encoder || !vpu->variant->postproc_fmts) {
*num_fmts = 0;
return NULL;
}
-- 
2.25.1



[PATCH v8 03/13] media: hantro: Use syscon instead of 'ctrl' register

2021-04-01 Thread Benjamin Gaignard
In order to be able to share the control hardware block between
VPUs use a syscon instead a ioremap it in the driver.
To keep the compatibility with older DT if 'nxp,imx8mq-vpu-ctrl'
phandle is not found look at 'ctrl' reg-name.
With the method it becomes useless to provide a list of register
names so remove it.

Signed-off-by: Benjamin Gaignard 
Reviewed-by: Philipp Zabel 
---
version 7:
 - Add Philipp reviewed-by tag.
 - Change syscon phandle name.
 
version 5:
 - use syscon instead of VPU reset driver.
 - if DT doesn't provide syscon keep backward compatibilty by using
   'ctrl' reg-name.

 drivers/staging/media/hantro/hantro.h   |  5 +-
 drivers/staging/media/hantro/imx8m_vpu_hw.c | 52 -
 2 files changed, 34 insertions(+), 23 deletions(-)

diff --git a/drivers/staging/media/hantro/hantro.h 
b/drivers/staging/media/hantro/hantro.h
index 6c1b888abe75..37b9ce04bd4e 100644
--- a/drivers/staging/media/hantro/hantro.h
+++ b/drivers/staging/media/hantro/hantro.h
@@ -13,6 +13,7 @@
 #define HANTRO_H_
 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -167,7 +168,7 @@ hantro_vdev_to_func(struct video_device *vdev)
  * @reg_bases: Mapped addresses of VPU registers.
  * @enc_base:  Mapped address of VPU encoder register for convenience.
  * @dec_base:  Mapped address of VPU decoder register for convenience.
- * @ctrl_base: Mapped address of VPU control block.
+ * @ctrl_base: Regmap of VPU control block.
  * @vpu_mutex: Mutex to synchronize V4L2 calls.
  * @irqlock:   Spinlock to synchronize access to data structures
  * shared with interrupt handlers.
@@ -186,7 +187,7 @@ struct hantro_dev {
void __iomem **reg_bases;
void __iomem *enc_base;
void __iomem *dec_base;
-   void __iomem *ctrl_base;
+   struct regmap *ctrl_base;
 
struct mutex vpu_mutex; /* video_device lock */
spinlock_t irqlock;
diff --git a/drivers/staging/media/hantro/imx8m_vpu_hw.c 
b/drivers/staging/media/hantro/imx8m_vpu_hw.c
index c222de075ef4..8d0c3425234b 100644
--- a/drivers/staging/media/hantro/imx8m_vpu_hw.c
+++ b/drivers/staging/media/hantro/imx8m_vpu_hw.c
@@ -7,6 +7,7 @@
 
 #include 
 #include 
+#include 
 
 #include "hantro.h"
 #include "hantro_jpeg.h"
@@ -24,30 +25,28 @@
 #define CTRL_G1_PP_FUSE0x0c
 #define CTRL_G2_DEC_FUSE   0x10
 
+static const struct regmap_config ctrl_regmap_ctrl = {
+   .reg_bits = 32,
+   .val_bits = 32,
+   .reg_stride = 0x14,
+};
+
 static void imx8m_soft_reset(struct hantro_dev *vpu, u32 reset_bits)
 {
-   u32 val;
-
/* Assert */
-   val = readl(vpu->ctrl_base + CTRL_SOFT_RESET);
-   val &= ~reset_bits;
-   writel(val, vpu->ctrl_base + CTRL_SOFT_RESET);
+   regmap_update_bits(vpu->ctrl_base, CTRL_SOFT_RESET, reset_bits, 0);
 
udelay(2);
 
/* Release */
-   val = readl(vpu->ctrl_base + CTRL_SOFT_RESET);
-   val |= reset_bits;
-   writel(val, vpu->ctrl_base + CTRL_SOFT_RESET);
+   regmap_update_bits(vpu->ctrl_base, CTRL_SOFT_RESET,
+  reset_bits, reset_bits);
 }
 
 static void imx8m_clk_enable(struct hantro_dev *vpu, u32 clock_bits)
 {
-   u32 val;
-
-   val = readl(vpu->ctrl_base + CTRL_CLOCK_ENABLE);
-   val |= clock_bits;
-   writel(val, vpu->ctrl_base + CTRL_CLOCK_ENABLE);
+   regmap_update_bits(vpu->ctrl_base, CTRL_CLOCK_ENABLE,
+  clock_bits, clock_bits);
 }
 
 static int imx8mq_runtime_resume(struct hantro_dev *vpu)
@@ -64,9 +63,9 @@ static int imx8mq_runtime_resume(struct hantro_dev *vpu)
imx8m_clk_enable(vpu, CLOCK_G1 | CLOCK_G2);
 
/* Set values of the fuse registers */
-   writel(0x, vpu->ctrl_base + CTRL_G1_DEC_FUSE);
-   writel(0x, vpu->ctrl_base + CTRL_G1_PP_FUSE);
-   writel(0x, vpu->ctrl_base + CTRL_G2_DEC_FUSE);
+   regmap_write(vpu->ctrl_base, CTRL_G1_DEC_FUSE, 0x);
+   regmap_write(vpu->ctrl_base, CTRL_G1_PP_FUSE, 0x);
+   regmap_write(vpu->ctrl_base, CTRL_G2_DEC_FUSE, 0x);
 
clk_bulk_disable_unprepare(vpu->variant->num_clocks, vpu->clocks);
 
@@ -150,8 +149,22 @@ static irqreturn_t imx8m_vpu_g1_irq(int irq, void *dev_id)
 
 static int imx8mq_vpu_hw_init(struct hantro_dev *vpu)
 {
-   vpu->dec_base = vpu->reg_bases[0];
-   vpu->ctrl_base = vpu->reg_bases[vpu->variant->num_regs - 1];
+   struct device_node *np = vpu->dev->of_node;
+
+   vpu->ctrl_base = syscon_regmap_lookup_by_phandle(np, 
"nxp,imx8m-vpu-ctrl");
+   if (IS_ERR(vpu->ctrl_base)) {
+   struct resource *res;
+   void __iomem *ctrl;
+
+   res = platform_get_resource_byname(vpu->pdev, IORESOURCE_MEM, 
"ctrl");
+   ctrl = devm_ior

[PATCH v7 09/13] media: uapi: Add a control for HANTRO driver

2021-03-29 Thread Benjamin Gaignard
The HEVC HANTRO driver needs to know the number of bits to skip at
the beginning of the slice header.
That is a hardware specific requirement so create a dedicated control
that this purpose.

Signed-off-by: Benjamin Gaignard 
---
version 5:
 - Be even more verbose in control documentation.
 - Do not create class for the control.
version 4:
- The control is now an integer which is enough to provide the numbers
  of bits to skip.
version 3:
- Fix typo in field name

 .../userspace-api/media/drivers/hantro.rst | 14 ++
 .../userspace-api/media/drivers/index.rst  |  1 +
 include/uapi/linux/v4l2-controls.h | 13 +
 3 files changed, 28 insertions(+)
 create mode 100644 Documentation/userspace-api/media/drivers/hantro.rst

diff --git a/Documentation/userspace-api/media/drivers/hantro.rst 
b/Documentation/userspace-api/media/drivers/hantro.rst
new file mode 100644
index ..78dcd2a44a03
--- /dev/null
+++ b/Documentation/userspace-api/media/drivers/hantro.rst
@@ -0,0 +1,14 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+Hantro video decoder driver
+===
+
+The Hantro video decoder driver implements the following driver-specific 
controls:
+
+``V4L2_CID_HANTRO_HEVC_SLICE_HEADER_SKIP (integer)``
+Specifies to Hantro HEVC video decoder driver the number of data (in bits) 
to
+skip in the slice segment header.
+If non-IDR, the bits to be skipped go from syntax element "pic_output_flag"
+to before syntax element "slice_temporal_mvp_enabled_flag".
+If IDR, the skipped bits are just "pic_output_flag"
+(separate_colour_plane_flag is not supported).
diff --git a/Documentation/userspace-api/media/drivers/index.rst 
b/Documentation/userspace-api/media/drivers/index.rst
index 1a9038f5f9fa..12e3c512d718 100644
--- a/Documentation/userspace-api/media/drivers/index.rst
+++ b/Documentation/userspace-api/media/drivers/index.rst
@@ -33,6 +33,7 @@ For more details see the file COPYING in the source 
distribution of Linux.
 
ccs
cx2341x-uapi
+hantro
imx-uapi
max2175
meye-uapi
diff --git a/include/uapi/linux/v4l2-controls.h 
b/include/uapi/linux/v4l2-controls.h
index f3376aafea65..1dfb874b6272 100644
--- a/include/uapi/linux/v4l2-controls.h
+++ b/include/uapi/linux/v4l2-controls.h
@@ -869,6 +869,19 @@ enum v4l2_mpeg_mfc51_video_force_frame_type {
 #define V4L2_CID_MPEG_MFC51_VIDEO_H264_ADAPTIVE_RC_STATIC  
(V4L2_CID_CODEC_MFC51_BASE+53)
 #define V4L2_CID_MPEG_MFC51_VIDEO_H264_NUM_REF_PIC_FOR_P   
(V4L2_CID_CODEC_MFC51_BASE+54)
 
+/*  MPEG-class control IDs specific to the Hantro driver as defined by V4L2 */
+#define V4L2_CID_CODEC_HANTRO_BASE 
(V4L2_CTRL_CLASS_CODEC | 0x1200)
+/*
+ * V4L2_CID_HANTRO_HEVC_SLICE_HEADER_SKIP -
+ * the number of data (in bits) to skip in the
+ * slice segment header.
+ * If non-IDR, the bits to be skipped go from syntax element "pic_output_flag"
+ * to before syntax element "slice_temporal_mvp_enabled_flag".
+ * If IDR, the skipped bits are just "pic_output_flag"
+ * (separate_colour_plane_flag is not supported).
+ */
+#define V4L2_CID_HANTRO_HEVC_SLICE_HEADER_SKIP (V4L2_CID_CODEC_HANTRO_BASE + 0)
+
 /*  Camera class control IDs */
 
 #define V4L2_CID_CAMERA_CLASS_BASE (V4L2_CTRL_CLASS_CAMERA | 0x900)
-- 
2.25.1



[PATCH v7 11/13] media: hantro: Introduce G2/HEVC decoder

2021-03-29 Thread Benjamin Gaignard
Implement all the logic to get G2 hardware decoding HEVC frames.
It support up level 5.1 HEVC stream.
It doesn't support yet 10 bits formats or scaling feature.

Add HANTRO HEVC dedicated control to skip some bits at the beginning
of the slice header. That is very specific to this hardware so can't
go into uapi structures. Compute the needed value is complex and require
information from the stream that only the userland knows so let it
provide the correct value to the driver.

Signed-off-by: Benjamin Gaignard 
Co-developed-by: Adrian Ratiu 
Signed-off-by: Adrian Ratiu 
Co-developed-by: Ezequiel Garcia 
Signed-off-by: Ezequiel Garcia 
---
version 7:
 - Improve motion vectors requested memory size computation.

 drivers/staging/media/hantro/Makefile |   2 +
 drivers/staging/media/hantro/hantro.h |   2 +
 drivers/staging/media/hantro/hantro_drv.c |  36 ++
 .../staging/media/hantro/hantro_g2_hevc_dec.c | 587 ++
 drivers/staging/media/hantro/hantro_g2_regs.h | 198 ++
 drivers/staging/media/hantro/hantro_hevc.c| 325 ++
 drivers/staging/media/hantro/hantro_hw.h  |  49 ++
 7 files changed, 1199 insertions(+)
 create mode 100644 drivers/staging/media/hantro/hantro_g2_hevc_dec.c
 create mode 100644 drivers/staging/media/hantro/hantro_g2_regs.h
 create mode 100644 drivers/staging/media/hantro/hantro_hevc.c

diff --git a/drivers/staging/media/hantro/Makefile 
b/drivers/staging/media/hantro/Makefile
index 743ce08eb184..0357f1772267 100644
--- a/drivers/staging/media/hantro/Makefile
+++ b/drivers/staging/media/hantro/Makefile
@@ -9,12 +9,14 @@ hantro-vpu-y += \
hantro_h1_jpeg_enc.o \
hantro_g1_h264_dec.o \
hantro_g1_mpeg2_dec.o \
+   hantro_g2_hevc_dec.o \
hantro_g1_vp8_dec.o \
rk3399_vpu_hw_jpeg_enc.o \
rk3399_vpu_hw_mpeg2_dec.o \
rk3399_vpu_hw_vp8_dec.o \
hantro_jpeg.o \
hantro_h264.o \
+   hantro_hevc.o \
hantro_mpeg2.o \
hantro_vp8.o
 
diff --git a/drivers/staging/media/hantro/hantro.h 
b/drivers/staging/media/hantro/hantro.h
index 7a5ad93466c8..6a21d1e95b34 100644
--- a/drivers/staging/media/hantro/hantro.h
+++ b/drivers/staging/media/hantro/hantro.h
@@ -222,6 +222,7 @@ struct hantro_dev {
  * @jpeg_enc:  JPEG-encoding context.
  * @mpeg2_dec: MPEG-2-decoding context.
  * @vp8_dec:   VP8-decoding context.
+ * @hevc_dec:  HEVC-decoding context.
  */
 struct hantro_ctx {
struct hantro_dev *dev;
@@ -248,6 +249,7 @@ struct hantro_ctx {
struct hantro_jpeg_enc_hw_ctx jpeg_enc;
struct hantro_mpeg2_dec_hw_ctx mpeg2_dec;
struct hantro_vp8_dec_hw_ctx vp8_dec;
+   struct hantro_hevc_dec_hw_ctx hevc_dec;
};
 };
 
diff --git a/drivers/staging/media/hantro/hantro_drv.c 
b/drivers/staging/media/hantro/hantro_drv.c
index d9a3a5ef9330..33b8bd38eac1 100644
--- a/drivers/staging/media/hantro/hantro_drv.c
+++ b/drivers/staging/media/hantro/hantro_drv.c
@@ -281,6 +281,26 @@ static int hantro_jpeg_s_ctrl(struct v4l2_ctrl *ctrl)
return 0;
 }
 
+static int hantro_hevc_s_ctrl(struct v4l2_ctrl *ctrl)
+{
+   struct hantro_ctx *ctx;
+
+   ctx = container_of(ctrl->handler,
+  struct hantro_ctx, ctrl_handler);
+
+   vpu_debug(1, "s_ctrl: id = %d, val = %d\n", ctrl->id, ctrl->val);
+
+   switch (ctrl->id) {
+   case V4L2_CID_HANTRO_HEVC_SLICE_HEADER_SKIP:
+   ctx->hevc_dec.ctrls.hevc_hdr_skip_length = ctrl->val;
+   break;
+   default:
+   return -EINVAL;
+   }
+
+   return 0;
+}
+
 static const struct v4l2_ctrl_ops hantro_ctrl_ops = {
.try_ctrl = hantro_try_ctrl,
 };
@@ -289,6 +309,10 @@ static const struct v4l2_ctrl_ops hantro_jpeg_ctrl_ops = {
.s_ctrl = hantro_jpeg_s_ctrl,
 };
 
+static const struct v4l2_ctrl_ops hantro_hevc_ctrl_ops = {
+   .s_ctrl = hantro_hevc_s_ctrl,
+};
+
 static const struct hantro_ctrl controls[] = {
{
.codec = HANTRO_JPEG_ENCODER,
@@ -409,6 +433,18 @@ static const struct hantro_ctrl controls[] = {
.cfg = {
.id = V4L2_CID_MPEG_VIDEO_HEVC_DECODE_PARAMS,
},
+   }, {
+   .codec = HANTRO_HEVC_DECODER,
+   .cfg = {
+   .id = V4L2_CID_HANTRO_HEVC_SLICE_HEADER_SKIP,
+   .name = "Hantro HEVC slice header skip bytes",
+   .type = V4L2_CTRL_TYPE_INTEGER,
+   .min = 0,
+   .def = 0,
+   .max = 0x7fff,
+   .step = 1,
+   .ops = _hevc_ctrl_ops,
+   },
},
 };
 
diff --git a/drivers/staging/media/hantro/hantro_g2_hevc

[PATCH v7 12/13] media: hantro: IMX8M: add variant for G2/HEVC codec

2021-03-29 Thread Benjamin Gaignard
Add variant to IMX8M to enable G2/HEVC codec.
Define the capabilities for the hardware up to 3840x2160.
G2 doesn't have postprocessor, use the same clocks and got it
own interruption.

Signed-off-by: Benjamin Gaignard 
Reviewed-by: Philipp Zabel 
---
version 7:
 - Add Philipp Reviewed-by tag.

version 5:
 - remove useless postproc fields for G2

version 2:
- remove useless clocks

 drivers/staging/media/hantro/hantro_drv.c   |  1 +
 drivers/staging/media/hantro/hantro_hw.h|  1 +
 drivers/staging/media/hantro/imx8m_vpu_hw.c | 76 -
 3 files changed, 76 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/media/hantro/hantro_drv.c 
b/drivers/staging/media/hantro/hantro_drv.c
index 33b8bd38eac1..ed380a8bef93 100644
--- a/drivers/staging/media/hantro/hantro_drv.c
+++ b/drivers/staging/media/hantro/hantro_drv.c
@@ -574,6 +574,7 @@ static const struct of_device_id of_hantro_match[] = {
 #endif
 #ifdef CONFIG_VIDEO_HANTRO_IMX8M
{ .compatible = "nxp,imx8mq-vpu", .data = _vpu_variant, },
+   { .compatible = "nxp,imx8mq-vpu-g2", .data = _vpu_g2_variant },
 #endif
{ /* sentinel */ }
 };
diff --git a/drivers/staging/media/hantro/hantro_hw.h 
b/drivers/staging/media/hantro/hantro_hw.h
index 5788188aae50..b4e7490bbe45 100644
--- a/drivers/staging/media/hantro/hantro_hw.h
+++ b/drivers/staging/media/hantro/hantro_hw.h
@@ -193,6 +193,7 @@ extern const struct hantro_variant rk3399_vpu_variant;
 extern const struct hantro_variant rk3328_vpu_variant;
 extern const struct hantro_variant rk3288_vpu_variant;
 extern const struct hantro_variant imx8mq_vpu_variant;
+extern const struct hantro_variant imx8mq_vpu_g2_variant;
 
 extern const struct hantro_postproc_regs hantro_g1_postproc_regs;
 
diff --git a/drivers/staging/media/hantro/imx8m_vpu_hw.c 
b/drivers/staging/media/hantro/imx8m_vpu_hw.c
index 8d0c3425234b..6de43e0edc36 100644
--- a/drivers/staging/media/hantro/imx8m_vpu_hw.c
+++ b/drivers/staging/media/hantro/imx8m_vpu_hw.c
@@ -12,6 +12,7 @@
 #include "hantro.h"
 #include "hantro_jpeg.h"
 #include "hantro_g1_regs.h"
+#include "hantro_g2_regs.h"
 
 #define CTRL_SOFT_RESET0x00
 #define RESET_G1   BIT(1)
@@ -129,6 +130,26 @@ static const struct hantro_fmt imx8m_vpu_dec_fmts[] = {
},
 };
 
+static const struct hantro_fmt imx8m_vpu_g2_dec_fmts[] = {
+   {
+   .fourcc = V4L2_PIX_FMT_NV12,
+   .codec_mode = HANTRO_MODE_NONE,
+   },
+   {
+   .fourcc = V4L2_PIX_FMT_HEVC_SLICE,
+   .codec_mode = HANTRO_MODE_HEVC_DEC,
+   .max_depth = 2,
+   .frmsize = {
+   .min_width = 48,
+   .max_width = 3840,
+   .step_width = MB_DIM,
+   .min_height = 48,
+   .max_height = 2160,
+   .step_height = MB_DIM,
+   },
+   },
+};
+
 static irqreturn_t imx8m_vpu_g1_irq(int irq, void *dev_id)
 {
struct hantro_dev *vpu = dev_id;
@@ -147,6 +168,24 @@ static irqreturn_t imx8m_vpu_g1_irq(int irq, void *dev_id)
return IRQ_HANDLED;
 }
 
+static irqreturn_t imx8m_vpu_g2_irq(int irq, void *dev_id)
+{
+   struct hantro_dev *vpu = dev_id;
+   enum vb2_buffer_state state;
+   u32 status;
+
+   status = vdpu_read(vpu, HEVC_REG_INTERRUPT);
+   state = (status & HEVC_REG_INTERRUPT_DEC_RDY_INT) ?
+VB2_BUF_STATE_DONE : VB2_BUF_STATE_ERROR;
+
+   vdpu_write(vpu, 0, HEVC_REG_INTERRUPT);
+   vdpu_write(vpu, HEVC_REG_CONFIG_DEC_CLK_GATE_E, HEVC_REG_CONFIG);
+
+   hantro_irq_done(vpu, state);
+
+   return IRQ_HANDLED;
+}
+
 static int imx8mq_vpu_hw_init(struct hantro_dev *vpu)
 {
struct device_node *np = vpu->dev->of_node;
@@ -176,6 +215,13 @@ static void imx8m_vpu_g1_reset(struct hantro_ctx *ctx)
imx8m_soft_reset(vpu, RESET_G1);
 }
 
+static void imx8m_vpu_g2_reset(struct hantro_ctx *ctx)
+{
+   struct hantro_dev *vpu = ctx->dev;
+
+   imx8m_soft_reset(vpu, RESET_G2);
+}
+
 /*
  * Supported codec ops.
  */
@@ -201,16 +247,28 @@ static const struct hantro_codec_ops 
imx8mq_vpu_codec_ops[] = {
},
 };
 
+static const struct hantro_codec_ops imx8mq_vpu_g2_codec_ops[] = {
+   [HANTRO_MODE_HEVC_DEC] = {
+   .run = hantro_g2_hevc_dec_run,
+   .reset = imx8m_vpu_g2_reset,
+   .init = hantro_hevc_dec_init,
+   .exit = hantro_hevc_dec_exit,
+   },
+};
+
 /*
  * VPU variants.
  */
 
 static const struct hantro_irq imx8mq_irqs[] = {
{ "g1", imx8m_vpu_g1_irq },
-   { "g2", NULL /* TODO: imx8m_vpu_g2_irq */ },
 };
 
-static const char * const imx8mq_clk_names[] = { "g1", "g2", "bus" };
+static const struct hantro_irq imx8mq_g2_irqs[] = {
+   { "g2", imx8m_vpu_g2_irq },
+};
+
+static 

[PATCH v7 13/13] arm64: dts: imx8mq: Add node to G2 hardware

2021-03-29 Thread Benjamin Gaignard
Split VPU node in two: one for G1 and one for G2 since they are
different hardware blocks.
Add syscon for hardware control block.
Remove reg-names property that is useless.
Each VPU node only need one interrupt.
Change G2 assigned clock to match to the specifications.
In the both nodes all the clocks need to assigned to make
sure that control block will be correctly clocked even if
only one device node is enabled.

Signed-off-by: Benjamin Gaignard 
---
version 7:
 - use nxp,imx8m-vpu-ctrl as phandle syscon property name

version 5:
 - use syscon instead of VPU reset

 arch/arm64/boot/dts/freescale/imx8mq.dtsi | 43 ++-
 1 file changed, 34 insertions(+), 9 deletions(-)

diff --git a/arch/arm64/boot/dts/freescale/imx8mq.dtsi 
b/arch/arm64/boot/dts/freescale/imx8mq.dtsi
index 17c449e12c2e..65158414d255 100644
--- a/arch/arm64/boot/dts/freescale/imx8mq.dtsi
+++ b/arch/arm64/boot/dts/freescale/imx8mq.dtsi
@@ -1329,15 +1329,16 @@ usb3_phy1: usb-phy@382f0040 {
status = "disabled";
};
 
-   vpu: video-codec@3830 {
+   vpu_ctrl: syscon@3832 {
+   compatible = "nxp,imx8mq-vpu-ctrl", "syscon";
+   reg = <0x3832 0x1>;
+   };
+
+   vpu_g1: video-codec@3830 {
compatible = "nxp,imx8mq-vpu";
-   reg = <0x3830 0x1>,
- <0x3831 0x1>,
- <0x3832 0x1>;
-   reg-names = "g1", "g2", "ctrl";
-   interrupts = ,
-;
-   interrupt-names = "g1", "g2";
+   reg = <0x3830 0x1>;
+   interrupts = ;
+   interrupt-names = "g1";
clocks = < IMX8MQ_CLK_VPU_G1_ROOT>,
 < IMX8MQ_CLK_VPU_G2_ROOT>,
 < IMX8MQ_CLK_VPU_DEC_ROOT>;
@@ -1350,9 +1351,33 @@ vpu: video-codec@3830 {
 < IMX8MQ_VPU_PLL_OUT>,
 < IMX8MQ_SYS1_PLL_800M>,
 < IMX8MQ_VPU_PLL>;
-   assigned-clock-rates = <6>, <6>,
+   assigned-clock-rates = <6>, <3>,
+  <8>, <0>;
+   power-domains = <_vpu>;
+   nxp,imx8m-vpu-ctrl = <_ctrl>;
+   };
+
+   vpu_g2: video-codec@3831 {
+   compatible = "nxp,imx8mq-vpu-g2";
+   reg = <0x3831 0x1>;
+   interrupts = ;
+   interrupt-names = "g2";
+   clocks = < IMX8MQ_CLK_VPU_G1_ROOT>,
+< IMX8MQ_CLK_VPU_G2_ROOT>,
+< IMX8MQ_CLK_VPU_DEC_ROOT>;
+   clock-names = "g1", "g2",  "bus";
+   assigned-clocks = < IMX8MQ_CLK_VPU_G1>,
+ < IMX8MQ_CLK_VPU_G2>,
+ < IMX8MQ_CLK_VPU_BUS>,
+ < IMX8MQ_VPU_PLL_BYPASS>;
+   assigned-clock-parents = < IMX8MQ_VPU_PLL_OUT>,
+< IMX8MQ_VPU_PLL_OUT>,
+< IMX8MQ_SYS1_PLL_800M>,
+< IMX8MQ_VPU_PLL>;
+   assigned-clock-rates = <6>, <3>,
   <8>, <0>;
power-domains = <_vpu>;
+   nxp,imx8m-vpu-ctrl = <_ctrl>;
};
 
pcie0: pcie@3380 {
-- 
2.25.1



[PATCH v7 10/13] media: hantro: handle V4L2_PIX_FMT_HEVC_SLICE control

2021-03-29 Thread Benjamin Gaignard
Make sure that V4L2_PIX_FMT_HEVC_SLICE is correctly handle by v4l2
of the driver.

Signed-off-by: Benjamin Gaignard 
---
 drivers/staging/media/hantro/hantro_v4l2.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/staging/media/hantro/hantro_v4l2.c 
b/drivers/staging/media/hantro/hantro_v4l2.c
index 77d7fe62ce81..0655324fd0d4 100644
--- a/drivers/staging/media/hantro/hantro_v4l2.c
+++ b/drivers/staging/media/hantro/hantro_v4l2.c
@@ -392,6 +392,7 @@ hantro_update_requires_request(struct hantro_ctx *ctx, u32 
fourcc)
case V4L2_PIX_FMT_MPEG2_SLICE:
case V4L2_PIX_FMT_VP8_FRAME:
case V4L2_PIX_FMT_H264_SLICE:
+   case V4L2_PIX_FMT_HEVC_SLICE:
ctx->fh.m2m_ctx->out_q_ctx.q.requires_requests = true;
break;
default:
-- 
2.25.1



[PATCH v7 07/13] media: hantro: Define HEVC codec profiles and supported features

2021-03-29 Thread Benjamin Gaignard
Define which HEVC profiles (up to level 5.1) and features
(no scaling, no 10 bits) are supported by the driver.

Signed-off-by: Benjamin Gaignard 
---
 drivers/staging/media/hantro/hantro.h |  3 ++
 drivers/staging/media/hantro/hantro_drv.c | 58 +++
 2 files changed, 61 insertions(+)

diff --git a/drivers/staging/media/hantro/hantro.h 
b/drivers/staging/media/hantro/hantro.h
index 37b9ce04bd4e..edb4561a6887 100644
--- a/drivers/staging/media/hantro/hantro.h
+++ b/drivers/staging/media/hantro/hantro.h
@@ -35,6 +35,7 @@ struct hantro_codec_ops;
 #define HANTRO_MPEG2_DECODER   BIT(16)
 #define HANTRO_VP8_DECODER BIT(17)
 #define HANTRO_H264_DECODERBIT(18)
+#define HANTRO_HEVC_DECODERBIT(19)
 #define HANTRO_DECODERS0x
 
 /**
@@ -100,6 +101,7 @@ struct hantro_variant {
  * @HANTRO_MODE_H264_DEC: H264 decoder.
  * @HANTRO_MODE_MPEG2_DEC: MPEG-2 decoder.
  * @HANTRO_MODE_VP8_DEC: VP8 decoder.
+ * @HANTRO_MODE_HEVC_DEC: HEVC decoder.
  */
 enum hantro_codec_mode {
HANTRO_MODE_NONE = -1,
@@ -107,6 +109,7 @@ enum hantro_codec_mode {
HANTRO_MODE_H264_DEC,
HANTRO_MODE_MPEG2_DEC,
HANTRO_MODE_VP8_DEC,
+   HANTRO_MODE_HEVC_DEC,
 };
 
 /*
diff --git a/drivers/staging/media/hantro/hantro_drv.c 
b/drivers/staging/media/hantro/hantro_drv.c
index 02c5c2f1a88b..d9a3a5ef9330 100644
--- a/drivers/staging/media/hantro/hantro_drv.c
+++ b/drivers/staging/media/hantro/hantro_drv.c
@@ -245,6 +245,18 @@ static int hantro_try_ctrl(struct v4l2_ctrl *ctrl)
if (sps->bit_depth_luma_minus8 != 0)
/* Only 8-bit is supported */
return -EINVAL;
+   } else if (ctrl->id == V4L2_CID_MPEG_VIDEO_HEVC_SPS) {
+   const struct v4l2_ctrl_hevc_sps *sps = ctrl->p_new.p_hevc_sps;
+
+   if (sps->bit_depth_luma_minus8 != sps->bit_depth_chroma_minus8)
+   /* Luma and chroma bit depth mismatch */
+   return -EINVAL;
+   if (sps->bit_depth_luma_minus8 != 0)
+   /* Only 8-bit is supported */
+   return -EINVAL;
+   if (sps->flags & V4L2_HEVC_SPS_FLAG_SCALING_LIST_ENABLED)
+   /* No scaling support */
+   return -EINVAL;
}
return 0;
 }
@@ -351,6 +363,52 @@ static const struct hantro_ctrl controls[] = {
.def = V4L2_MPEG_VIDEO_H264_PROFILE_MAIN,
}
}, {
+   .codec = HANTRO_HEVC_DECODER,
+   .cfg = {
+   .id = V4L2_CID_MPEG_VIDEO_HEVC_DECODE_MODE,
+   .min = V4L2_MPEG_VIDEO_HEVC_DECODE_MODE_FRAME_BASED,
+   .max = V4L2_MPEG_VIDEO_HEVC_DECODE_MODE_FRAME_BASED,
+   .def = V4L2_MPEG_VIDEO_HEVC_DECODE_MODE_FRAME_BASED,
+   },
+   }, {
+   .codec = HANTRO_HEVC_DECODER,
+   .cfg = {
+   .id = V4L2_CID_MPEG_VIDEO_HEVC_START_CODE,
+   .min = V4L2_MPEG_VIDEO_HEVC_START_CODE_ANNEX_B,
+   .max = V4L2_MPEG_VIDEO_HEVC_START_CODE_ANNEX_B,
+   .def = V4L2_MPEG_VIDEO_HEVC_START_CODE_ANNEX_B,
+   },
+   }, {
+   .codec = HANTRO_HEVC_DECODER,
+   .cfg = {
+   .id = V4L2_CID_MPEG_VIDEO_HEVC_PROFILE,
+   .min = V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN,
+   .max = V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN_10,
+   .def = V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN,
+   },
+   }, {
+   .codec = HANTRO_HEVC_DECODER,
+   .cfg = {
+   .id = V4L2_CID_MPEG_VIDEO_HEVC_LEVEL,
+   .min = V4L2_MPEG_VIDEO_HEVC_LEVEL_1,
+   .max = V4L2_MPEG_VIDEO_HEVC_LEVEL_5_1,
+   },
+   }, {
+   .codec = HANTRO_HEVC_DECODER,
+   .cfg = {
+   .id = V4L2_CID_MPEG_VIDEO_HEVC_SPS,
+   .ops = _ctrl_ops,
+   },
+   }, {
+   .codec = HANTRO_HEVC_DECODER,
+   .cfg = {
+   .id = V4L2_CID_MPEG_VIDEO_HEVC_PPS,
+   },
+   }, {
+   .codec = HANTRO_HEVC_DECODER,
+   .cfg = {
+   .id = V4L2_CID_MPEG_VIDEO_HEVC_DECODE_PARAMS,
+   },
},
 };
 
-- 
2.25.1



[PATCH v7 08/13] media: hantro: Only use postproc when post processed formats are defined

2021-03-29 Thread Benjamin Gaignard
If the variant doesn't offert postprocessed formats make sure it will
be ok.

Signed-off-by: Benjamin Gaignard 
---
 drivers/staging/media/hantro/hantro.h  |  8 ++--
 drivers/staging/media/hantro/hantro_postproc.c | 14 ++
 drivers/staging/media/hantro/hantro_v4l2.c |  4 +++-
 3 files changed, 19 insertions(+), 7 deletions(-)

diff --git a/drivers/staging/media/hantro/hantro.h 
b/drivers/staging/media/hantro/hantro.h
index edb4561a6887..7a5ad93466c8 100644
--- a/drivers/staging/media/hantro/hantro.h
+++ b/drivers/staging/media/hantro/hantro.h
@@ -414,12 +414,8 @@ hantro_get_dst_buf(struct hantro_ctx *ctx)
return v4l2_m2m_next_dst_buf(ctx->fh.m2m_ctx);
 }
 
-static inline bool
-hantro_needs_postproc(const struct hantro_ctx *ctx,
- const struct hantro_fmt *fmt)
-{
-   return !ctx->is_encoder && fmt->fourcc != V4L2_PIX_FMT_NV12;
-}
+bool hantro_needs_postproc(const struct hantro_ctx *ctx,
+  const struct hantro_fmt *fmt);
 
 static inline dma_addr_t
 hantro_get_dec_buf_addr(struct hantro_ctx *ctx, struct vb2_buffer *vb)
diff --git a/drivers/staging/media/hantro/hantro_postproc.c 
b/drivers/staging/media/hantro/hantro_postproc.c
index 6d2a8f2a8f0b..ed8916c950a4 100644
--- a/drivers/staging/media/hantro/hantro_postproc.c
+++ b/drivers/staging/media/hantro/hantro_postproc.c
@@ -50,6 +50,20 @@ const struct hantro_postproc_regs hantro_g1_postproc_regs = {
.display_width = {G1_REG_PP_DISPLAY_WIDTH, 0, 0xfff},
 };
 
+bool hantro_needs_postproc(const struct hantro_ctx *ctx,
+  const struct hantro_fmt *fmt)
+{
+   struct hantro_dev *vpu = ctx->dev;
+
+   if (ctx->is_encoder)
+   return false;
+
+   if (!vpu->variant->postproc_fmts)
+   return false;
+
+   return fmt->fourcc != V4L2_PIX_FMT_NV12;
+}
+
 void hantro_postproc_enable(struct hantro_ctx *ctx)
 {
struct hantro_dev *vpu = ctx->dev;
diff --git a/drivers/staging/media/hantro/hantro_v4l2.c 
b/drivers/staging/media/hantro/hantro_v4l2.c
index 1bc118e375a1..77d7fe62ce81 100644
--- a/drivers/staging/media/hantro/hantro_v4l2.c
+++ b/drivers/staging/media/hantro/hantro_v4l2.c
@@ -55,7 +55,9 @@ static const struct hantro_fmt *
 hantro_get_postproc_formats(const struct hantro_ctx *ctx,
unsigned int *num_fmts)
 {
-   if (ctx->is_encoder) {
+   struct hantro_dev *vpu = ctx->dev;
+
+   if (ctx->is_encoder || !vpu->variant->postproc_fmts) {
*num_fmts = 0;
return NULL;
}
-- 
2.25.1



[PATCH v7 05/13] media: hevc: Add decode params control

2021-03-29 Thread Benjamin Gaignard
Add decode params control and it associated structure to regroup
all the information that are needed to decode a reference frame as
it is describe in ITU-T Rec. H.265 section "8.3.2 Decoding process
for reference picture set".

Adapt Cedrus driver to these changes.

Signed-off-by: Benjamin Gaignard 
---
version 7:
 - rebased on top of media_tree/master branch

version 6:
 - fix compilation errors

 .../media/v4l/ext-ctrls-codec.rst | 94 +++
 .../media/v4l/vidioc-queryctrl.rst|  6 ++
 drivers/media/v4l2-core/v4l2-ctrls.c  | 26 +++--
 drivers/staging/media/sunxi/cedrus/cedrus.c   |  6 ++
 drivers/staging/media/sunxi/cedrus/cedrus.h   |  1 +
 .../staging/media/sunxi/cedrus/cedrus_dec.c   |  2 +
 .../staging/media/sunxi/cedrus/cedrus_h265.c  | 12 ++-
 include/media/hevc-ctrls.h| 29 --
 8 files changed, 137 insertions(+), 39 deletions(-)

diff --git a/Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst 
b/Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst
index 92314aec655a..7552869687f7 100644
--- a/Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst
+++ b/Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst
@@ -3181,9 +3181,6 @@ enum v4l2_mpeg_video_hevc_size_of_length_field -
 * - __u8
   - ``pic_struct``
   -
-* - __u8
-  - ``num_active_dpb_entries``
-  - The number of entries in ``dpb``.
 * - __u8
   - ``ref_idx_l0[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]``
   - The list of L0 reference elements as indices in the DPB.
@@ -3191,22 +3188,8 @@ enum v4l2_mpeg_video_hevc_size_of_length_field -
   - ``ref_idx_l1[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]``
   - The list of L1 reference elements as indices in the DPB.
 * - __u8
-  - ``num_rps_poc_st_curr_before``
-  - The number of reference pictures in the short-term set that come before
-the current frame.
-* - __u8
-  - ``num_rps_poc_st_curr_after``
-  - The number of reference pictures in the short-term set that come after
-the current frame.
-* - __u8
-  - ``num_rps_poc_lt_curr``
-  - The number of reference pictures in the long-term set.
-* - __u8
-  - ``padding[7]``
+  - ``padding``
   - Applications and drivers must set this to zero.
-* - struct :c:type:`v4l2_hevc_dpb_entry`
-  - ``dpb[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]``
-  - The decoded picture buffer, for meta-data about reference frames.
 * - struct :c:type:`v4l2_hevc_pred_weight_table`
   - ``pred_weight_table``
   - The prediction weight coefficients for inter-picture prediction.
@@ -3441,3 +3424,78 @@ enum v4l2_mpeg_video_hevc_size_of_length_field -
 so this has to come from client.
 This is applicable to H264 and valid Range is from 0 to 63.
 Source Rec. ITU-T H.264 (06/2019); G.7.4.1.1, G.8.8.1.
+
+``V4L2_CID_MPEG_VIDEO_HEVC_DECODE_PARAMS (struct)``
+Specifies various decode parameters, especially the references picture 
order
+count (POC) for all the lists (short, long, before, current, after) and the
+number of entries for each of them.
+These parameters are defined according to :ref:`hevc`.
+They are described in section 8.3 "Slice decoding process" of the
+specification.
+
+.. c:type:: v4l2_ctrl_hevc_decode_params
+
+.. cssclass:: longtable
+
+.. flat-table:: struct v4l2_ctrl_hevc_decode_params
+:header-rows:  0
+:stub-columns: 0
+:widths:   1 1 2
+
+* - __s32
+  - ``pic_order_cnt_val``
+  - PicOrderCntVal as described in section 8.3.1 "Decoding process
+for picture order count" of the specification.
+* - __u8
+  - ``num_active_dpb_entries``
+  - The number of entries in ``dpb``.
+* - struct :c:type:`v4l2_hevc_dpb_entry`
+  - ``dpb[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]``
+  - The decoded picture buffer, for meta-data about reference frames.
+* - __u8
+  - ``num_poc_st_curr_before``
+  - The number of reference pictures in the short-term set that come before
+the current frame.
+* - __u8
+  - ``num_poc_st_curr_after``
+  - The number of reference pictures in the short-term set that come after
+the current frame.
+* - __u8
+  - ``num_poc_lt_curr``
+  - The number of reference pictures in the long-term set.
+* - __u8
+  - ``poc_st_curr_before[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]``
+  - PocStCurrBefore as described in section 8.3.2 "Decoding process for 
reference
+picture set.
+* - __u8
+  - ``poc_st_curr_after[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]``
+  - PocStCurrAfter as described in section 8.3.2 "Decoding process for 
reference
+picture set.
+* - __u8
+  - ``poc_lt_curr[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]``
+  - PocLtCurr as described in section 8.3.2 "Decoding process for reference
+picture set.
+* - __u64
+  - ``flags``
+  - See :ref:`Decode Param

[PATCH v7 03/13] media: hantro: Use syscon instead of 'ctrl' register

2021-03-29 Thread Benjamin Gaignard
In order to be able to share the control hardware block between
VPUs use a syscon instead a ioremap it in the driver.
To keep the compatibility with older DT if 'nxp,imx8mq-vpu-ctrl'
phandle is not found look at 'ctrl' reg-name.
With the method it becomes useless to provide a list of register
names so remove it.

Signed-off-by: Benjamin Gaignard 
Reviewed-by: Philipp Zabel 
---
version 7:
 - Add Philipp reviewed-by tag.
 - Change syscon phandle name.
 
version 5:
 - use syscon instead of VPU reset driver.
 - if DT doesn't provide syscon keep backward compatibilty by using
   'ctrl' reg-name.

 drivers/staging/media/hantro/hantro.h   |  5 +-
 drivers/staging/media/hantro/imx8m_vpu_hw.c | 52 -
 2 files changed, 34 insertions(+), 23 deletions(-)

diff --git a/drivers/staging/media/hantro/hantro.h 
b/drivers/staging/media/hantro/hantro.h
index 6c1b888abe75..37b9ce04bd4e 100644
--- a/drivers/staging/media/hantro/hantro.h
+++ b/drivers/staging/media/hantro/hantro.h
@@ -13,6 +13,7 @@
 #define HANTRO_H_
 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -167,7 +168,7 @@ hantro_vdev_to_func(struct video_device *vdev)
  * @reg_bases: Mapped addresses of VPU registers.
  * @enc_base:  Mapped address of VPU encoder register for convenience.
  * @dec_base:  Mapped address of VPU decoder register for convenience.
- * @ctrl_base: Mapped address of VPU control block.
+ * @ctrl_base: Regmap of VPU control block.
  * @vpu_mutex: Mutex to synchronize V4L2 calls.
  * @irqlock:   Spinlock to synchronize access to data structures
  * shared with interrupt handlers.
@@ -186,7 +187,7 @@ struct hantro_dev {
void __iomem **reg_bases;
void __iomem *enc_base;
void __iomem *dec_base;
-   void __iomem *ctrl_base;
+   struct regmap *ctrl_base;
 
struct mutex vpu_mutex; /* video_device lock */
spinlock_t irqlock;
diff --git a/drivers/staging/media/hantro/imx8m_vpu_hw.c 
b/drivers/staging/media/hantro/imx8m_vpu_hw.c
index c222de075ef4..8d0c3425234b 100644
--- a/drivers/staging/media/hantro/imx8m_vpu_hw.c
+++ b/drivers/staging/media/hantro/imx8m_vpu_hw.c
@@ -7,6 +7,7 @@
 
 #include 
 #include 
+#include 
 
 #include "hantro.h"
 #include "hantro_jpeg.h"
@@ -24,30 +25,28 @@
 #define CTRL_G1_PP_FUSE0x0c
 #define CTRL_G2_DEC_FUSE   0x10
 
+static const struct regmap_config ctrl_regmap_ctrl = {
+   .reg_bits = 32,
+   .val_bits = 32,
+   .reg_stride = 0x14,
+};
+
 static void imx8m_soft_reset(struct hantro_dev *vpu, u32 reset_bits)
 {
-   u32 val;
-
/* Assert */
-   val = readl(vpu->ctrl_base + CTRL_SOFT_RESET);
-   val &= ~reset_bits;
-   writel(val, vpu->ctrl_base + CTRL_SOFT_RESET);
+   regmap_update_bits(vpu->ctrl_base, CTRL_SOFT_RESET, reset_bits, 0);
 
udelay(2);
 
/* Release */
-   val = readl(vpu->ctrl_base + CTRL_SOFT_RESET);
-   val |= reset_bits;
-   writel(val, vpu->ctrl_base + CTRL_SOFT_RESET);
+   regmap_update_bits(vpu->ctrl_base, CTRL_SOFT_RESET,
+  reset_bits, reset_bits);
 }
 
 static void imx8m_clk_enable(struct hantro_dev *vpu, u32 clock_bits)
 {
-   u32 val;
-
-   val = readl(vpu->ctrl_base + CTRL_CLOCK_ENABLE);
-   val |= clock_bits;
-   writel(val, vpu->ctrl_base + CTRL_CLOCK_ENABLE);
+   regmap_update_bits(vpu->ctrl_base, CTRL_CLOCK_ENABLE,
+  clock_bits, clock_bits);
 }
 
 static int imx8mq_runtime_resume(struct hantro_dev *vpu)
@@ -64,9 +63,9 @@ static int imx8mq_runtime_resume(struct hantro_dev *vpu)
imx8m_clk_enable(vpu, CLOCK_G1 | CLOCK_G2);
 
/* Set values of the fuse registers */
-   writel(0x, vpu->ctrl_base + CTRL_G1_DEC_FUSE);
-   writel(0x, vpu->ctrl_base + CTRL_G1_PP_FUSE);
-   writel(0x, vpu->ctrl_base + CTRL_G2_DEC_FUSE);
+   regmap_write(vpu->ctrl_base, CTRL_G1_DEC_FUSE, 0x);
+   regmap_write(vpu->ctrl_base, CTRL_G1_PP_FUSE, 0x);
+   regmap_write(vpu->ctrl_base, CTRL_G2_DEC_FUSE, 0x);
 
clk_bulk_disable_unprepare(vpu->variant->num_clocks, vpu->clocks);
 
@@ -150,8 +149,22 @@ static irqreturn_t imx8m_vpu_g1_irq(int irq, void *dev_id)
 
 static int imx8mq_vpu_hw_init(struct hantro_dev *vpu)
 {
-   vpu->dec_base = vpu->reg_bases[0];
-   vpu->ctrl_base = vpu->reg_bases[vpu->variant->num_regs - 1];
+   struct device_node *np = vpu->dev->of_node;
+
+   vpu->ctrl_base = syscon_regmap_lookup_by_phandle(np, 
"nxp,imx8m-vpu-ctrl");
+   if (IS_ERR(vpu->ctrl_base)) {
+   struct resource *res;
+   void __iomem *ctrl;
+
+   res = platform_get_resource_byname(vpu->pdev, IORESOURCE_MEM, 
"ctrl");
+   ctrl = devm_ior

[PATCH v7 04/13] media: hevc: Add fields and flags for hevc PPS

2021-03-29 Thread Benjamin Gaignard
Add fields and flags as they are defined in
7.4.3.3.1 "General picture parameter set RBSP semantics of the
H.265 ITU specification.

Signed-off-by: Benjamin Gaignard 
---
 .../userspace-api/media/v4l/ext-ctrls-codec.rst| 14 ++
 include/media/hevc-ctrls.h |  4 
 2 files changed, 18 insertions(+)

diff --git a/Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst 
b/Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst
index 188aef8e40d0..92314aec655a 100644
--- a/Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst
+++ b/Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst
@@ -2967,6 +2967,12 @@ enum v4l2_mpeg_video_hevc_size_of_length_field -
 * - __u8
   - ``num_extra_slice_header_bits``
   -
+* - __u8
+  - ``num_ref_idx_l0_default_active_minus1``
+  - Specifies the inferred value of num_ref_idx_l0_active_minus1
+* - __u8
+  - ``num_ref_idx_l1_default_active_minus1``
+  - Specifies the inferred value of num_ref_idx_l1_active_minus1
 * - __s8
   - ``init_qp_minus26``
   -
@@ -3077,6 +3083,14 @@ enum v4l2_mpeg_video_hevc_size_of_length_field -
 * - ``V4L2_HEVC_PPS_FLAG_SLICE_SEGMENT_HEADER_EXTENSION_PRESENT``
   - 0x0004
   -
+* - ``V4L2_HEVC_PPS_FLAG_DEBLOCKING_FILTER_CONTROL_PRESENT``
+  - 0x0008
+  - Specifies the presence of deblocking filter control syntax elements in
+the PPS
+* - ``V4L2_HEVC_PPS_FLAG_UNIFORM_SPACING``
+  - 0x0010
+  - Specifies that tile column boundaries and likewise tile row boundaries
+are distributed uniformly across the picture
 
 .. raw:: latex
 
diff --git a/include/media/hevc-ctrls.h b/include/media/hevc-ctrls.h
index b4cb2ef02f17..003f819ecb26 100644
--- a/include/media/hevc-ctrls.h
+++ b/include/media/hevc-ctrls.h
@@ -100,10 +100,14 @@ struct v4l2_ctrl_hevc_sps {
 #define V4L2_HEVC_PPS_FLAG_PPS_DISABLE_DEBLOCKING_FILTER   (1ULL << 16)
 #define V4L2_HEVC_PPS_FLAG_LISTS_MODIFICATION_PRESENT  (1ULL << 17)
 #define V4L2_HEVC_PPS_FLAG_SLICE_SEGMENT_HEADER_EXTENSION_PRESENT (1ULL << 18)
+#define V4L2_HEVC_PPS_FLAG_DEBLOCKING_FILTER_CONTROL_PRESENT   (1ULL << 19)
+#define V4L2_HEVC_PPS_FLAG_UNIFORM_SPACING (1ULL << 20)
 
 struct v4l2_ctrl_hevc_pps {
/* ISO/IEC 23008-2, ITU-T Rec. H.265: Picture parameter set */
__u8num_extra_slice_header_bits;
+   __u8num_ref_idx_l0_default_active_minus1;
+   __u8num_ref_idx_l1_default_active_minus1;
__s8init_qp_minus26;
__u8diff_cu_qp_delta_depth;
__s8pps_cb_qp_offset;
-- 
2.25.1



[PATCH v7 06/13] media: hantro: change hantro_codec_ops run prototype to return errors

2021-03-29 Thread Benjamin Gaignard
Change hantro_codec_ops run prototype from 'void' to 'int'.
This allow to cancel the job if an error occur while configuring
the hardware.

Signed-off-by: Benjamin Gaignard 
---
version 5:
 - forward hantro_h264_dec_prepare_run() return value in case
   of error

 drivers/staging/media/hantro/hantro_drv.c |  4 +++-
 .../staging/media/hantro/hantro_g1_h264_dec.c | 10 +++---
 .../media/hantro/hantro_g1_mpeg2_dec.c|  4 +++-
 .../staging/media/hantro/hantro_g1_vp8_dec.c  |  6 --
 .../staging/media/hantro/hantro_h1_jpeg_enc.c |  4 +++-
 drivers/staging/media/hantro/hantro_hw.h  | 19 ++-
 .../media/hantro/rk3399_vpu_hw_jpeg_enc.c |  4 +++-
 .../media/hantro/rk3399_vpu_hw_mpeg2_dec.c|  4 +++-
 .../media/hantro/rk3399_vpu_hw_vp8_dec.c  |  6 --
 9 files changed, 40 insertions(+), 21 deletions(-)

diff --git a/drivers/staging/media/hantro/hantro_drv.c 
b/drivers/staging/media/hantro/hantro_drv.c
index 595e82a82728..02c5c2f1a88b 100644
--- a/drivers/staging/media/hantro/hantro_drv.c
+++ b/drivers/staging/media/hantro/hantro_drv.c
@@ -161,7 +161,9 @@ static void device_run(void *priv)
 
v4l2_m2m_buf_copy_metadata(src, dst, true);
 
-   ctx->codec_ops->run(ctx);
+   if (ctx->codec_ops->run(ctx))
+   goto err_cancel_job;
+
return;
 
 err_cancel_job:
diff --git a/drivers/staging/media/hantro/hantro_g1_h264_dec.c 
b/drivers/staging/media/hantro/hantro_g1_h264_dec.c
index 845bef73d218..5c792b7bcb79 100644
--- a/drivers/staging/media/hantro/hantro_g1_h264_dec.c
+++ b/drivers/staging/media/hantro/hantro_g1_h264_dec.c
@@ -273,13 +273,15 @@ static void set_buffers(struct hantro_ctx *ctx)
vdpu_write_relaxed(vpu, ctx->h264_dec.priv.dma, G1_REG_ADDR_QTABLE);
 }
 
-void hantro_g1_h264_dec_run(struct hantro_ctx *ctx)
+int hantro_g1_h264_dec_run(struct hantro_ctx *ctx)
 {
struct hantro_dev *vpu = ctx->dev;
+   int ret;
 
/* Prepare the H264 decoder context. */
-   if (hantro_h264_dec_prepare_run(ctx))
-   return;
+   ret = hantro_h264_dec_prepare_run(ctx);
+   if (ret)
+   return ret;
 
/* Configure hardware registers. */
set_params(ctx);
@@ -301,4 +303,6 @@ void hantro_g1_h264_dec_run(struct hantro_ctx *ctx)
   G1_REG_CONFIG_DEC_CLK_GATE_E,
   G1_REG_CONFIG);
vdpu_write(vpu, G1_REG_INTERRUPT_DEC_E, G1_REG_INTERRUPT);
+
+   return 0;
 }
diff --git a/drivers/staging/media/hantro/hantro_g1_mpeg2_dec.c 
b/drivers/staging/media/hantro/hantro_g1_mpeg2_dec.c
index 6386a3989bfe..5e8943d31dc5 100644
--- a/drivers/staging/media/hantro/hantro_g1_mpeg2_dec.c
+++ b/drivers/staging/media/hantro/hantro_g1_mpeg2_dec.c
@@ -155,7 +155,7 @@ hantro_g1_mpeg2_dec_set_buffers(struct hantro_dev *vpu, 
struct hantro_ctx *ctx,
vdpu_write_relaxed(vpu, backward_addr, G1_REG_REFER3_BASE);
 }
 
-void hantro_g1_mpeg2_dec_run(struct hantro_ctx *ctx)
+int hantro_g1_mpeg2_dec_run(struct hantro_ctx *ctx)
 {
struct hantro_dev *vpu = ctx->dev;
struct vb2_v4l2_buffer *src_buf, *dst_buf;
@@ -248,4 +248,6 @@ void hantro_g1_mpeg2_dec_run(struct hantro_ctx *ctx)
 
reg = G1_REG_DEC_E(1);
vdpu_write(vpu, reg, G1_SWREG(1));
+
+   return 0;
 }
diff --git a/drivers/staging/media/hantro/hantro_g1_vp8_dec.c 
b/drivers/staging/media/hantro/hantro_g1_vp8_dec.c
index 57002ba70176..96622a7f8279 100644
--- a/drivers/staging/media/hantro/hantro_g1_vp8_dec.c
+++ b/drivers/staging/media/hantro/hantro_g1_vp8_dec.c
@@ -425,7 +425,7 @@ static void cfg_buffers(struct hantro_ctx *ctx,
vdpu_write_relaxed(vpu, dst_dma, G1_REG_ADDR_DST);
 }
 
-void hantro_g1_vp8_dec_run(struct hantro_ctx *ctx)
+int hantro_g1_vp8_dec_run(struct hantro_ctx *ctx)
 {
const struct v4l2_ctrl_vp8_frame *hdr;
struct hantro_dev *vpu = ctx->dev;
@@ -438,7 +438,7 @@ void hantro_g1_vp8_dec_run(struct hantro_ctx *ctx)
 
hdr = hantro_get_ctrl(ctx, V4L2_CID_STATELESS_VP8_FRAME);
if (WARN_ON(!hdr))
-   return;
+   return -EINVAL;
 
/* Reset segment_map buffer in keyframe */
if (V4L2_VP8_FRAME_IS_KEY_FRAME(hdr) && ctx->vp8_dec.segment_map.cpu)
@@ -498,4 +498,6 @@ void hantro_g1_vp8_dec_run(struct hantro_ctx *ctx)
hantro_end_prepare_run(ctx);
 
vdpu_write(vpu, G1_REG_INTERRUPT_DEC_E, G1_REG_INTERRUPT);
+
+   return 0;
 }
diff --git a/drivers/staging/media/hantro/hantro_h1_jpeg_enc.c 
b/drivers/staging/media/hantro/hantro_h1_jpeg_enc.c
index b88dc4ed06db..56cf261a8e95 100644
--- a/drivers/staging/media/hantro/hantro_h1_jpeg_enc.c
+++ b/drivers/staging/media/hantro/hantro_h1_jpeg_enc.c
@@ -88,7 +88,7 @@ hantro_h1_jpeg_enc_set_qtable(struct hantro_dev *vpu,
}
 }
 
-void hantro_h1_jpeg_enc_run(struct hantro_ctx *ctx)
+int hantro_h1_jpeg_enc_run(struct hantro_ctx *ctx)
 {
struct hantro_dev *vpu = ctx->dev;
 

[PATCH v7 01/13] dt-bindings: mfd: Add 'nxp,imx8mq-vpu-ctrl' to syscon list

2021-03-29 Thread Benjamin Gaignard
Add 'nxp,imx8mq-vpu-ctrl' in the list of possible syscon.
It will used to access to the VPU control registers.

Signed-off-by: Benjamin Gaignard 
Acked-by: Rob Herring 
---
version 7:
 - Add Rob ack
 Documentation/devicetree/bindings/mfd/syscon.yaml | 1 +
 1 file changed, 1 insertion(+)

diff --git a/Documentation/devicetree/bindings/mfd/syscon.yaml 
b/Documentation/devicetree/bindings/mfd/syscon.yaml
index f14ae6da0068..ae22c4730613 100644
--- a/Documentation/devicetree/bindings/mfd/syscon.yaml
+++ b/Documentation/devicetree/bindings/mfd/syscon.yaml
@@ -44,6 +44,7 @@ properties:
   - hisilicon,peri-subctrl
   - microchip,sparx5-cpu-syscon
   - mstar,msc313-pmsleep
+  - nxp,imx8mq-vpu-ctrl
   - rockchip,px30-qos
   - rockchip,rk3066-qos
   - rockchip,rk3288-qos
-- 
2.25.1



[PATCH v7 02/13] dt-bindings: media: nxp,imx8mq-vpu: Update the bindings for G2 support

2021-03-29 Thread Benjamin Gaignard
Introducing G2 hevc video decoder lead to modify the bindings to allow
to get one node per VPUs.
VPUs share one hardware control block which is provided as a phandle on
an syscon.
Each node got now one reg and one interrupt.
Add a compatible for G2 hardware block: nxp,imx8mq-vpu-g2.

To be compatible with older DT the driver is still capable to use 'ctrl'
reg-name even if it is deprecated now.

Signed-off-by: Benjamin Gaignard 
Reviewed-by: Rob Herring 
Reviewed-by: Philipp Zabel 
---
version 7:
- Add Rob and Philipp reviewed-by tag
- Change syscon phandle name to nxp,imx8m-vpu-ctrl (remove 'q' to be
  usable for iMX8MM too)

version 5:
- This version doesn't break the backward compatibilty between kernel
  and DT.

 .../bindings/media/nxp,imx8mq-vpu.yaml| 53 ---
 1 file changed, 34 insertions(+), 19 deletions(-)

diff --git a/Documentation/devicetree/bindings/media/nxp,imx8mq-vpu.yaml 
b/Documentation/devicetree/bindings/media/nxp,imx8mq-vpu.yaml
index 762be3f96ce9..18e7d40a5f24 100644
--- a/Documentation/devicetree/bindings/media/nxp,imx8mq-vpu.yaml
+++ b/Documentation/devicetree/bindings/media/nxp,imx8mq-vpu.yaml
@@ -15,22 +15,18 @@ description:
 
 properties:
   compatible:
-const: nxp,imx8mq-vpu
+oneOf:
+  - const: nxp,imx8mq-vpu
+  - const: nxp,imx8mq-vpu-g2
 
   reg:
-maxItems: 3
-
-  reg-names:
-items:
-  - const: g1
-  - const: g2
-  - const: ctrl
+maxItems: 1
 
   interrupts:
-maxItems: 2
+maxItems: 1
 
   interrupt-names:
-items:
+oneOf:
   - const: g1
   - const: g2
 
@@ -46,14 +42,18 @@ properties:
   power-domains:
 maxItems: 1
 
+  nxp,imx8m-vpu-ctrl:
+description: Specifies a phandle to syscon VPU hardware control block
+$ref: "/schemas/types.yaml#/definitions/phandle"
+
 required:
   - compatible
   - reg
-  - reg-names
   - interrupts
   - interrupt-names
   - clocks
   - clock-names
+  - nxp,imx8m-vpu-ctrl
 
 additionalProperties: false
 
@@ -62,18 +62,33 @@ examples:
 #include 
 #include 
 
-vpu: video-codec@3830 {
+vpu_ctrl: syscon@3832 {
+ compatible = "nxp,imx8mq-vpu-ctrl", "syscon";
+ reg = <0x3832 0x1>;
+};
+
+vpu_g1: video-codec@3830 {
 compatible = "nxp,imx8mq-vpu";
-reg = <0x3830 0x1>,
-  <0x3831 0x1>,
-  <0x3832 0x1>;
-reg-names = "g1", "g2", "ctrl";
-interrupts = ,
- ;
-interrupt-names = "g1", "g2";
+reg = <0x3830 0x1>;
+interrupts = ;
+interrupt-names = "g1";
+clocks = < IMX8MQ_CLK_VPU_G1_ROOT>,
+ < IMX8MQ_CLK_VPU_G2_ROOT>,
+ < IMX8MQ_CLK_VPU_DEC_ROOT>;
+clock-names = "g1", "g2", "bus";
+power-domains = <_vpu>;
+nxp,imx8m-vpu-ctrl = <_ctrl>;
+};
+
+vpu_g2: video-codec@3831 {
+compatible = "nxp,imx8mq-vpu-g2";
+reg = <0x3830 0x1>;
+interrupts = ;
+interrupt-names = "g2";
 clocks = < IMX8MQ_CLK_VPU_G1_ROOT>,
  < IMX8MQ_CLK_VPU_G2_ROOT>,
  < IMX8MQ_CLK_VPU_DEC_ROOT>;
 clock-names = "g1", "g2", "bus";
 power-domains = <_vpu>;
+nxp,imx8m-vpu-ctrl = <_ctrl>;
 };
-- 
2.25.1



[PATCH v7 00/13] Add HANTRO G2/HEVC decoder support for IMX8MQ

2021-03-29 Thread Benjamin Gaignard
:
test MC information (see 'Media Driver Info' above): OK
test VIDIOC_QUERYCAP: OK
test invalid ioctls: OK

Allow for multiple opens:
test second /dev/video1 open: OK
test VIDIOC_QUERYCAP: OK
test VIDIOC_G/S_PRIORITY: OK
test for unlimited opens: OK

Debug ioctls:
test VIDIOC_DBG_G/S_REGISTER: OK (Not Supported)
test VIDIOC_LOG_STATUS: OK (Not Supported)

Input ioctls:
test VIDIOC_G/S_TUNER/ENUM_FREQ_BANDS: OK (Not Supported)
test VIDIOC_G/S_FREQUENCY: OK (Not Supported)
test VIDIOC_S_HW_FREQ_SEEK: OK (Not Supported)
test VIDIOC_ENUMAUDIO: OK (Not Supported)
test VIDIOC_G/S/ENUMINPUT: OK (Not Supported)
test VIDIOC_G/S_AUDIO: OK (Not Supported)
Inputs: 0 Audio Inputs: 0 Tuners: 0

Output ioctls:
test VIDIOC_G/S_MODULATOR: OK (Not Supported)
test VIDIOC_G/S_FREQUENCY: OK (Not Supported)
test VIDIOC_ENUMAUDOUT: OK (Not Supported)
test VIDIOC_G/S/ENUMOUTPUT: OK (Not Supported)
test VIDIOC_G/S_AUDOUT: OK (Not Supported)
Outputs: 0 Audio Outputs: 0 Modulators: 0

Input/Output configuration ioctls:
test VIDIOC_ENUM/G/S/QUERY_STD: OK (Not Supported)
test VIDIOC_ENUM/G/S/QUERY_DV_TIMINGS: OK (Not Supported)
test VIDIOC_DV_TIMINGS_CAP: OK (Not Supported)
test VIDIOC_G/S_EDID: OK (Not Supported)

Control ioctls:
test VIDIOC_QUERY_EXT_CTRL/QUERYMENU: OK
test VIDIOC_QUERYCTRL: OK
test VIDIOC_G/S_CTRL: OK
test VIDIOC_G/S/TRY_EXT_CTRLS: OK
test VIDIOC_(UN)SUBSCRIBE_EVENT/DQEVENT: OK
test VIDIOC_G/S_JPEGCOMP: OK (Not Supported)
Standard Controls: 8 Private Controls: 1

Format ioctls:
test VIDIOC_ENUM_FMT/FRAMESIZES/FRAMEINTERVALS: OK
test VIDIOC_G/S_PARM: OK (Not Supported)
test VIDIOC_G_FBUF: OK (Not Supported)
test VIDIOC_G_FMT: OK
test VIDIOC_TRY_FMT: OK
test VIDIOC_S_FMT: OK
test VIDIOC_G_SLICED_VBI_CAP: OK (Not Supported)
test Cropping: OK (Not Supported)
test Composing: OK (Not Supported)
test Scaling: OK (Not Supported)

Codec ioctls:
test VIDIOC_(TRY_)ENCODER_CMD: OK (Not Supported)
test VIDIOC_G_ENC_INDEX: OK (Not Supported)
test VIDIOC_(TRY_)DECODER_CMD: OK (Not Supported)

Buffer ioctls:
test VIDIOC_REQBUFS/CREATE_BUFS/QUERYBUF: OK
test VIDIOC_EXPBUF: OK
test Requests: OK

Total for hantro-vpu device /dev/video1: 46, Succeeded: 46, Failed: 0, 
Warnings: 0

Grand Total for hantro-vpu device /dev/media1: 54, Succeeded: 54, Failed: 0, 
Warnings: 0

Benjamin

Benjamin Gaignard (13):
  dt-bindings: mfd: Add 'nxp,imx8mq-vpu-ctrl' to syscon list
  dt-bindings: media: nxp,imx8mq-vpu: Update the bindings for G2 support
  media: hantro: Use syscon instead of 'ctrl' register
  media: hevc: Add fields and flags for hevc PPS
  media: hevc: Add decode params control
  media: hantro: change hantro_codec_ops run prototype to return errors
  media: hantro: Define HEVC codec profiles and supported features
  media: hantro: Only use postproc when post processed formats are
defined
  media: uapi: Add a control for HANTRO driver
  media: hantro: handle V4L2_PIX_FMT_HEVC_SLICE control
  media: hantro: Introduce G2/HEVC decoder
  media: hantro: IMX8M: add variant for G2/HEVC codec
  arm64: dts: imx8mq: Add node to G2 hardware

 .../bindings/media/nxp,imx8mq-vpu.yaml|  53 +-
 .../devicetree/bindings/mfd/syscon.yaml   |   1 +
 .../userspace-api/media/drivers/hantro.rst|  14 +
 .../userspace-api/media/drivers/index.rst |   1 +
 .../media/v4l/ext-ctrls-codec.rst | 108 +++-
 .../media/v4l/vidioc-queryctrl.rst|   6 +
 arch/arm64/boot/dts/freescale/imx8mq.dtsi |  43 +-
 drivers/media/v4l2-core/v4l2-ctrls.c  |  26 +-
 drivers/staging/media/hantro/Makefile |   2 +
 drivers/staging/media/hantro/hantro.h |  18 +-
 drivers/staging/media/hantro/hantro_drv.c |  99 ++-
 .../staging/media/hantro/hantro_g1_h264_dec.c |  10 +-
 .../media/hantro/hantro_g1_mpeg2_dec.c|   4 +-
 .../staging/media/hantro/hantro_g1_vp8_dec.c  |   6 +-
 .../staging/media/hantro/hantro_g2_hevc_dec.c | 587 ++
 drivers/staging/media/hantro/hantro_g2_regs.h | 198 ++
 .../staging/media/hantro/hantro_h1_jpeg_enc.c |   4 +-
 drivers/staging/media/hantro/hantro_hevc.c| 325 ++
 drivers/staging/media/hantro/hantro_hw.h  |  69 +-
 .../staging/media/hantro/hantro_postproc.c|  14 +
 drivers/staging/media/hantro/hantro_v4l2.c|   5 +-
 drivers/staging/media/hantro/imx8m_vpu_hw.c   | 128 +++-
 .../media/hantro/rk3399_vpu_hw_jpeg_enc.c |   4 +-
 .../media/hantro/rk3399_vpu_hw_mpeg2_dec.c|   4 +-
 .../media/hantro/rk3399_vpu_hw_vp8_dec.c  |   6 +-
 drivers/staging/media/sunxi/cedrus/cedrus.c   |   6 +
 drivers/staging/media/sunxi/cedrus/cedrus.h   |   1 +
 .../staging

Re: [PATCH v6 13/13] arm64: dts: imx8mq: Add node to G2 hardware

2021-03-26 Thread Benjamin Gaignard



Le 26/03/2021 à 15:24, Philipp Zabel a écrit :

On Thu, Mar 18, 2021 at 09:20:46AM +0100, Benjamin Gaignard wrote:

Split VPU node in two: one for G1 and one for G2 since they are
different hardware blocks.
Add syscon for hardware control block.
Remove reg-names property that is useless.
Each VPU node only need one interrupt.

Signed-off-by: Benjamin Gaignard 
---
version 5:
  - use syscon instead of VPU reset

  arch/arm64/boot/dts/freescale/imx8mq.dtsi | 43 ++-
  1 file changed, 34 insertions(+), 9 deletions(-)

diff --git a/arch/arm64/boot/dts/freescale/imx8mq.dtsi 
b/arch/arm64/boot/dts/freescale/imx8mq.dtsi
index 17c449e12c2e..b537d153ebbd 100644
--- a/arch/arm64/boot/dts/freescale/imx8mq.dtsi
+++ b/arch/arm64/boot/dts/freescale/imx8mq.dtsi
@@ -1329,15 +1329,16 @@ usb3_phy1: usb-phy@382f0040 {
status = "disabled";
};
  
-		vpu: video-codec@3830 {

+   vpu_ctrl: syscon@3832 {
+   compatible = "nxp,imx8mq-vpu-ctrl", "syscon";
+   reg = <0x3832 0x1>;
+   };
+
+   vpu_g1: video-codec@3830 {
compatible = "nxp,imx8mq-vpu";
-   reg = <0x3830 0x1>,
- <0x3831 0x1>,
- <0x3832 0x1>;
-   reg-names = "g1", "g2", "ctrl";
-   interrupts = ,
-;
-   interrupt-names = "g1", "g2";
+   reg = <0x3830 0x1>;
+   interrupts = ;
+   interrupt-names = "g1";
clocks = < IMX8MQ_CLK_VPU_G1_ROOT>,
 < IMX8MQ_CLK_VPU_G2_ROOT>,
 < IMX8MQ_CLK_VPU_DEC_ROOT>;
@@ -1350,9 +1351,33 @@ vpu: video-codec@3830 {
 < IMX8MQ_VPU_PLL_OUT>,
 < IMX8MQ_SYS1_PLL_800M>,
 < IMX8MQ_VPU_PLL>;
-   assigned-clock-rates = <6>, <6>,
+   assigned-clock-rates = <6>, <3>,

I'd like to see this mentioned in the commit message.


Yes I would do that.
The value comes from the datasheet.




+  <8>, <0>;
+   power-domains = <_vpu>;
+   nxp,imx8mq-vpu-ctrl = <_ctrl>;
+   };
+
+   vpu_g2: video-codec@3831 {
+   compatible = "nxp,imx8mq-vpu-g2";
+   reg = <0x3831 0x1>;
+   interrupts = ;
+   interrupt-names = "g2";
+   clocks = < IMX8MQ_CLK_VPU_G1_ROOT>,
+< IMX8MQ_CLK_VPU_G2_ROOT>,
+< IMX8MQ_CLK_VPU_DEC_ROOT>;
+   clock-names = "g1", "g2",  "bus";
+   assigned-clocks = < IMX8MQ_CLK_VPU_G1>,

Can the G1 clock configuration be dropped from the G2 device node and
the G2 clock configuration from the G1 device node? It looks weird that
these devices configure each other's clocks.


No because if only one device node is enabled we need to configure the both
clocks anyway.

Benjamin



regards
Philipp



Re: [PATCH v6 02/13] dt-bindings: media: nxp,imx8mq-vpu: Update the bindings for G2 support

2021-03-26 Thread Benjamin Gaignard



Le 26/03/2021 à 15:11, Philipp Zabel a écrit :

On Thu, Mar 18, 2021 at 09:20:35AM +0100, Benjamin Gaignard wrote:

Introducing G2 hevc video decoder lead to modify the bindings to allow
to get one node per VPUs.
VPUs share one hardware control block which is provided as a phandle on
an syscon.
Each node got now one reg and one interrupt.
Add a compatible for G2 hardware block: nxp,imx8mq-vpu-g2.

To be compatible with older DT the driver is still capable to use 'ctrl'
reg-name even if it is deprecated now.

Signed-off-by: Benjamin Gaignard 
---
version 5:
- This version doesn't break the backward compatibilty between kernel
   and DT.

  .../bindings/media/nxp,imx8mq-vpu.yaml| 53 ---
  1 file changed, 34 insertions(+), 19 deletions(-)

diff --git a/Documentation/devicetree/bindings/media/nxp,imx8mq-vpu.yaml 
b/Documentation/devicetree/bindings/media/nxp,imx8mq-vpu.yaml
index 762be3f96ce9..79502fc8bde5 100644
--- a/Documentation/devicetree/bindings/media/nxp,imx8mq-vpu.yaml
+++ b/Documentation/devicetree/bindings/media/nxp,imx8mq-vpu.yaml
@@ -15,22 +15,18 @@ description:
  
  properties:

compatible:
-const: nxp,imx8mq-vpu
+oneOf:
+  - const: nxp,imx8mq-vpu
+  - const: nxp,imx8mq-vpu-g2
  
reg:

-maxItems: 3
-
-  reg-names:
-items:
-  - const: g1
-  - const: g2
-  - const: ctrl
+maxItems: 1
  
interrupts:

-maxItems: 2
+maxItems: 1
  
interrupt-names:

-items:
+oneOf:
- const: g1
- const: g2
  
@@ -46,14 +42,18 @@ properties:

power-domains:
  maxItems: 1
  
+  nxp,imx8mq-vpu-ctrl:

+description: Specifies a phandle to syscon VPU hardware control block
+$ref: "/schemas/types.yaml#/definitions/phandle"
+

Should we drop the 'q' here, i.e. nxp,imx8m-vpu-ctrl so we can use the same
binding for i.MX8MM later?


I don't know if the control block is the same or not on IMX8MM, so I have only
put a compatible targeting IMX8MQ.




  required:
- compatible
- reg
-  - reg-names
- interrupts
- interrupt-names
- clocks
- clock-names
+  - nxp,imx8mq-vpu-ctrl
  
  additionalProperties: false
  
@@ -62,18 +62,33 @@ examples:

  #include 
  #include 
  
-vpu: video-codec@3830 {

+vpu_ctrl: syscon@3832 {
+ compatible = "nxp,imx8mq-vpu-ctrl", "syscon";
+ reg = <0x3832 0x1>;
+};
+
+vpu_g1: video-codec@3830 {
  compatible = "nxp,imx8mq-vpu";
-reg = <0x3830 0x1>,
-  <0x3831 0x1>,
-  <0x3832 0x1>;
-reg-names = "g1", "g2", "ctrl";
-interrupts = ,
- ;
-interrupt-names = "g1", "g2";
+reg = <0x3830 0x1>;
+interrupts = ;
+interrupt-names = "g1";
+clocks = < IMX8MQ_CLK_VPU_G1_ROOT>,
+ < IMX8MQ_CLK_VPU_G2_ROOT>,

Does the G1 VPU require the G2 clock and vice versa?


Yes either the control hardware block won't work.

Benjamin



regards
Philipp



[PATCH v6 13/13] arm64: dts: imx8mq: Add node to G2 hardware

2021-03-18 Thread Benjamin Gaignard
Split VPU node in two: one for G1 and one for G2 since they are
different hardware blocks.
Add syscon for hardware control block.
Remove reg-names property that is useless.
Each VPU node only need one interrupt.

Signed-off-by: Benjamin Gaignard 
---
version 5:
 - use syscon instead of VPU reset

 arch/arm64/boot/dts/freescale/imx8mq.dtsi | 43 ++-
 1 file changed, 34 insertions(+), 9 deletions(-)

diff --git a/arch/arm64/boot/dts/freescale/imx8mq.dtsi 
b/arch/arm64/boot/dts/freescale/imx8mq.dtsi
index 17c449e12c2e..b537d153ebbd 100644
--- a/arch/arm64/boot/dts/freescale/imx8mq.dtsi
+++ b/arch/arm64/boot/dts/freescale/imx8mq.dtsi
@@ -1329,15 +1329,16 @@ usb3_phy1: usb-phy@382f0040 {
status = "disabled";
};
 
-   vpu: video-codec@3830 {
+   vpu_ctrl: syscon@3832 {
+   compatible = "nxp,imx8mq-vpu-ctrl", "syscon";
+   reg = <0x3832 0x1>;
+   };
+
+   vpu_g1: video-codec@3830 {
compatible = "nxp,imx8mq-vpu";
-   reg = <0x3830 0x1>,
- <0x3831 0x1>,
- <0x3832 0x1>;
-   reg-names = "g1", "g2", "ctrl";
-   interrupts = ,
-;
-   interrupt-names = "g1", "g2";
+   reg = <0x3830 0x1>;
+   interrupts = ;
+   interrupt-names = "g1";
clocks = < IMX8MQ_CLK_VPU_G1_ROOT>,
 < IMX8MQ_CLK_VPU_G2_ROOT>,
 < IMX8MQ_CLK_VPU_DEC_ROOT>;
@@ -1350,9 +1351,33 @@ vpu: video-codec@3830 {
 < IMX8MQ_VPU_PLL_OUT>,
 < IMX8MQ_SYS1_PLL_800M>,
 < IMX8MQ_VPU_PLL>;
-   assigned-clock-rates = <6>, <6>,
+   assigned-clock-rates = <6>, <3>,
+  <8>, <0>;
+   power-domains = <_vpu>;
+   nxp,imx8mq-vpu-ctrl = <_ctrl>;
+   };
+
+   vpu_g2: video-codec@3831 {
+   compatible = "nxp,imx8mq-vpu-g2";
+   reg = <0x3831 0x1>;
+   interrupts = ;
+   interrupt-names = "g2";
+   clocks = < IMX8MQ_CLK_VPU_G1_ROOT>,
+< IMX8MQ_CLK_VPU_G2_ROOT>,
+< IMX8MQ_CLK_VPU_DEC_ROOT>;
+   clock-names = "g1", "g2",  "bus";
+   assigned-clocks = < IMX8MQ_CLK_VPU_G1>,
+ < IMX8MQ_CLK_VPU_G2>,
+ < IMX8MQ_CLK_VPU_BUS>,
+ < IMX8MQ_VPU_PLL_BYPASS>;
+   assigned-clock-parents = < IMX8MQ_VPU_PLL_OUT>,
+< IMX8MQ_VPU_PLL_OUT>,
+< IMX8MQ_SYS1_PLL_800M>,
+< IMX8MQ_VPU_PLL>;
+   assigned-clock-rates = <6>, <3>,
   <8>, <0>;
power-domains = <_vpu>;
+   nxp,imx8mq-vpu-ctrl = <_ctrl>;
};
 
pcie0: pcie@3380 {
-- 
2.25.1



[PATCH v6 11/13] media: hantro: Introduce G2/HEVC decoder

2021-03-18 Thread Benjamin Gaignard
Implement all the logic to get G2 hardware decoding HEVC frames.
It support up level 5.1 HEVC stream.
It doesn't support yet 10 bits formats or scaling feature.

Add HANTRO HEVC dedicated control to skip some bits at the beginning
of the slice header. That is very specific to this hardware so can't
go into uapi structures. Compute the needed value is complex and require
information from the stream that only the userland knows so let it
provide the correct value to the driver.

Signed-off-by: Benjamin Gaignard 
Co-developed-by: Adrian Ratiu 
Signed-off-by: Adrian Ratiu 
Co-developed-by: Ezequiel Garcia 
Signed-off-by: Ezequiel Garcia 
---
version 6:
 - Add 'static' to hantro_g2_check_idle() prototype

version 5:
 - Add co-author tags.
 - Fix Ezequiel comments (typo, comments, etc).
 - Remove unused functions.
version 4:
- fix Ezequiel comments
- use dedicated control as an integer
- change hantro_g2_hevc_dec_run prototype to return errors

version 2:
- squash multiple commits in this one.
- fix the comments done by Ezequiel about dma_alloc_coherent usage
- fix Dan's comments about control copy, reverse the test logic
in tile_buffer_reallocate, rework some goto and return cases.

 drivers/staging/media/hantro/Makefile |   2 +
 drivers/staging/media/hantro/hantro.h |   2 +
 drivers/staging/media/hantro/hantro_drv.c |  36 ++
 .../staging/media/hantro/hantro_g2_hevc_dec.c | 587 ++
 drivers/staging/media/hantro/hantro_g2_regs.h | 198 ++
 drivers/staging/media/hantro/hantro_hevc.c| 324 ++
 drivers/staging/media/hantro/hantro_hw.h  |  49 ++
 7 files changed, 1198 insertions(+)
 create mode 100644 drivers/staging/media/hantro/hantro_g2_hevc_dec.c
 create mode 100644 drivers/staging/media/hantro/hantro_g2_regs.h
 create mode 100644 drivers/staging/media/hantro/hantro_hevc.c

diff --git a/drivers/staging/media/hantro/Makefile 
b/drivers/staging/media/hantro/Makefile
index 743ce08eb184..0357f1772267 100644
--- a/drivers/staging/media/hantro/Makefile
+++ b/drivers/staging/media/hantro/Makefile
@@ -9,12 +9,14 @@ hantro-vpu-y += \
hantro_h1_jpeg_enc.o \
hantro_g1_h264_dec.o \
hantro_g1_mpeg2_dec.o \
+   hantro_g2_hevc_dec.o \
hantro_g1_vp8_dec.o \
rk3399_vpu_hw_jpeg_enc.o \
rk3399_vpu_hw_mpeg2_dec.o \
rk3399_vpu_hw_vp8_dec.o \
hantro_jpeg.o \
hantro_h264.o \
+   hantro_hevc.o \
hantro_mpeg2.o \
hantro_vp8.o
 
diff --git a/drivers/staging/media/hantro/hantro.h 
b/drivers/staging/media/hantro/hantro.h
index 83299e8d3a6c..976c1903d9ce 100644
--- a/drivers/staging/media/hantro/hantro.h
+++ b/drivers/staging/media/hantro/hantro.h
@@ -221,6 +221,7 @@ struct hantro_dev {
  * @jpeg_enc:  JPEG-encoding context.
  * @mpeg2_dec: MPEG-2-decoding context.
  * @vp8_dec:   VP8-decoding context.
+ * @hevc_dec:  HEVC-decoding context.
  */
 struct hantro_ctx {
struct hantro_dev *dev;
@@ -247,6 +248,7 @@ struct hantro_ctx {
struct hantro_jpeg_enc_hw_ctx jpeg_enc;
struct hantro_mpeg2_dec_hw_ctx mpeg2_dec;
struct hantro_vp8_dec_hw_ctx vp8_dec;
+   struct hantro_hevc_dec_hw_ctx hevc_dec;
};
 };
 
diff --git a/drivers/staging/media/hantro/hantro_drv.c 
b/drivers/staging/media/hantro/hantro_drv.c
index f0b68e16fcc0..13c197ca9ba3 100644
--- a/drivers/staging/media/hantro/hantro_drv.c
+++ b/drivers/staging/media/hantro/hantro_drv.c
@@ -281,6 +281,26 @@ static int hantro_jpeg_s_ctrl(struct v4l2_ctrl *ctrl)
return 0;
 }
 
+static int hantro_hevc_s_ctrl(struct v4l2_ctrl *ctrl)
+{
+   struct hantro_ctx *ctx;
+
+   ctx = container_of(ctrl->handler,
+  struct hantro_ctx, ctrl_handler);
+
+   vpu_debug(1, "s_ctrl: id = %d, val = %d\n", ctrl->id, ctrl->val);
+
+   switch (ctrl->id) {
+   case V4L2_CID_HANTRO_HEVC_SLICE_HEADER_SKIP:
+   ctx->hevc_dec.ctrls.hevc_hdr_skip_length = ctrl->val;
+   break;
+   default:
+   return -EINVAL;
+   }
+
+   return 0;
+}
+
 static const struct v4l2_ctrl_ops hantro_ctrl_ops = {
.try_ctrl = hantro_try_ctrl,
 };
@@ -289,6 +309,10 @@ static const struct v4l2_ctrl_ops hantro_jpeg_ctrl_ops = {
.s_ctrl = hantro_jpeg_s_ctrl,
 };
 
+static const struct v4l2_ctrl_ops hantro_hevc_ctrl_ops = {
+   .s_ctrl = hantro_hevc_s_ctrl,
+};
+
 static const struct hantro_ctrl controls[] = {
{
.codec = HANTRO_JPEG_ENCODER,
@@ -409,6 +433,18 @@ static const struct hantro_ctrl controls[] = {
.cfg = {
.id = V4L2_CID_MPEG_VIDEO_HEVC_DECODE_PARAMS,
},
+   }, {
+   .codec = HANTRO_HEVC_DECODER,
+   .cfg = {

[PATCH v6 09/13] media: uapi: Add a control for HANTRO driver

2021-03-18 Thread Benjamin Gaignard
The HEVC HANTRO driver needs to know the number of bits to skip at
the beginning of the slice header.
That is a hardware specific requirement so create a dedicated control
that this purpose.

Signed-off-by: Benjamin Gaignard 
---
version 5:
 - Be even more verbose in control documentation.
 - Do not create class for the control.
version 4:
- The control is now an integer which is enough to provide the numbers
  of bits to skip.
version 3:
- Fix typo in field name

 .../userspace-api/media/drivers/hantro.rst | 14 ++
 .../userspace-api/media/drivers/index.rst  |  1 +
 include/uapi/linux/v4l2-controls.h | 13 +
 3 files changed, 28 insertions(+)
 create mode 100644 Documentation/userspace-api/media/drivers/hantro.rst

diff --git a/Documentation/userspace-api/media/drivers/hantro.rst 
b/Documentation/userspace-api/media/drivers/hantro.rst
new file mode 100644
index ..78dcd2a44a03
--- /dev/null
+++ b/Documentation/userspace-api/media/drivers/hantro.rst
@@ -0,0 +1,14 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+Hantro video decoder driver
+===
+
+The Hantro video decoder driver implements the following driver-specific 
controls:
+
+``V4L2_CID_HANTRO_HEVC_SLICE_HEADER_SKIP (integer)``
+Specifies to Hantro HEVC video decoder driver the number of data (in bits) 
to
+skip in the slice segment header.
+If non-IDR, the bits to be skipped go from syntax element "pic_output_flag"
+to before syntax element "slice_temporal_mvp_enabled_flag".
+If IDR, the skipped bits are just "pic_output_flag"
+(separate_colour_plane_flag is not supported).
diff --git a/Documentation/userspace-api/media/drivers/index.rst 
b/Documentation/userspace-api/media/drivers/index.rst
index 1a9038f5f9fa..12e3c512d718 100644
--- a/Documentation/userspace-api/media/drivers/index.rst
+++ b/Documentation/userspace-api/media/drivers/index.rst
@@ -33,6 +33,7 @@ For more details see the file COPYING in the source 
distribution of Linux.
 
ccs
cx2341x-uapi
+hantro
imx-uapi
max2175
meye-uapi
diff --git a/include/uapi/linux/v4l2-controls.h 
b/include/uapi/linux/v4l2-controls.h
index 039c0d7add1b..cebfb57080ed 100644
--- a/include/uapi/linux/v4l2-controls.h
+++ b/include/uapi/linux/v4l2-controls.h
@@ -865,6 +865,19 @@ enum v4l2_mpeg_mfc51_video_force_frame_type {
 #define V4L2_CID_MPEG_MFC51_VIDEO_H264_ADAPTIVE_RC_STATIC  
(V4L2_CID_CODEC_MFC51_BASE+53)
 #define V4L2_CID_MPEG_MFC51_VIDEO_H264_NUM_REF_PIC_FOR_P   
(V4L2_CID_CODEC_MFC51_BASE+54)
 
+/*  MPEG-class control IDs specific to the Hantro driver as defined by V4L2 */
+#define V4L2_CID_CODEC_HANTRO_BASE 
(V4L2_CTRL_CLASS_CODEC | 0x1200)
+/*
+ * V4L2_CID_HANTRO_HEVC_SLICE_HEADER_SKIP -
+ * the number of data (in bits) to skip in the
+ * slice segment header.
+ * If non-IDR, the bits to be skipped go from syntax element "pic_output_flag"
+ * to before syntax element "slice_temporal_mvp_enabled_flag".
+ * If IDR, the skipped bits are just "pic_output_flag"
+ * (separate_colour_plane_flag is not supported).
+ */
+#define V4L2_CID_HANTRO_HEVC_SLICE_HEADER_SKIP (V4L2_CID_CODEC_HANTRO_BASE + 0)
+
 /*  Camera class control IDs */
 
 #define V4L2_CID_CAMERA_CLASS_BASE (V4L2_CTRL_CLASS_CAMERA | 0x900)
-- 
2.25.1



[PATCH v6 10/13] media: hantro: handle V4L2_PIX_FMT_HEVC_SLICE control

2021-03-18 Thread Benjamin Gaignard
Make sure that V4L2_PIX_FMT_HEVC_SLICE is correctly handle by v4l2
of the driver.

Signed-off-by: Benjamin Gaignard 
---
 drivers/staging/media/hantro/hantro_v4l2.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/staging/media/hantro/hantro_v4l2.c 
b/drivers/staging/media/hantro/hantro_v4l2.c
index 77d7fe62ce81..0655324fd0d4 100644
--- a/drivers/staging/media/hantro/hantro_v4l2.c
+++ b/drivers/staging/media/hantro/hantro_v4l2.c
@@ -392,6 +392,7 @@ hantro_update_requires_request(struct hantro_ctx *ctx, u32 
fourcc)
case V4L2_PIX_FMT_MPEG2_SLICE:
case V4L2_PIX_FMT_VP8_FRAME:
case V4L2_PIX_FMT_H264_SLICE:
+   case V4L2_PIX_FMT_HEVC_SLICE:
ctx->fh.m2m_ctx->out_q_ctx.q.requires_requests = true;
break;
default:
-- 
2.25.1



[PATCH v6 12/13] media: hantro: IMX8M: add variant for G2/HEVC codec

2021-03-18 Thread Benjamin Gaignard
Add variant to IMX8M to enable G2/HEVC codec.
Define the capabilities for the hardware up to 3840x2160.
G2 doesn't have postprocessor, use the same clocks and got it
own interruption.

Signed-off-by: Benjamin Gaignard 
---
version 5:
 - remove useless postproc fields for G2

version 2:
- remove useless clocks

 drivers/staging/media/hantro/hantro_drv.c   |  1 +
 drivers/staging/media/hantro/hantro_hw.h|  1 +
 drivers/staging/media/hantro/imx8m_vpu_hw.c | 76 -
 3 files changed, 76 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/media/hantro/hantro_drv.c 
b/drivers/staging/media/hantro/hantro_drv.c
index 13c197ca9ba3..659124a52e8a 100644
--- a/drivers/staging/media/hantro/hantro_drv.c
+++ b/drivers/staging/media/hantro/hantro_drv.c
@@ -574,6 +574,7 @@ static const struct of_device_id of_hantro_match[] = {
 #endif
 #ifdef CONFIG_VIDEO_HANTRO_IMX8M
{ .compatible = "nxp,imx8mq-vpu", .data = _vpu_variant, },
+   { .compatible = "nxp,imx8mq-vpu-g2", .data = _vpu_g2_variant },
 #endif
{ /* sentinel */ }
 };
diff --git a/drivers/staging/media/hantro/hantro_hw.h 
b/drivers/staging/media/hantro/hantro_hw.h
index dade3b0769c1..f61f58da05fe 100644
--- a/drivers/staging/media/hantro/hantro_hw.h
+++ b/drivers/staging/media/hantro/hantro_hw.h
@@ -193,6 +193,7 @@ extern const struct hantro_variant rk3399_vpu_variant;
 extern const struct hantro_variant rk3328_vpu_variant;
 extern const struct hantro_variant rk3288_vpu_variant;
 extern const struct hantro_variant imx8mq_vpu_variant;
+extern const struct hantro_variant imx8mq_vpu_g2_variant;
 
 extern const struct hantro_postproc_regs hantro_g1_postproc_regs;
 
diff --git a/drivers/staging/media/hantro/imx8m_vpu_hw.c 
b/drivers/staging/media/hantro/imx8m_vpu_hw.c
index bd9d135dd440..b2ddb1fce0e8 100644
--- a/drivers/staging/media/hantro/imx8m_vpu_hw.c
+++ b/drivers/staging/media/hantro/imx8m_vpu_hw.c
@@ -12,6 +12,7 @@
 #include "hantro.h"
 #include "hantro_jpeg.h"
 #include "hantro_g1_regs.h"
+#include "hantro_g2_regs.h"
 
 #define CTRL_SOFT_RESET0x00
 #define RESET_G1   BIT(1)
@@ -129,6 +130,26 @@ static const struct hantro_fmt imx8m_vpu_dec_fmts[] = {
},
 };
 
+static const struct hantro_fmt imx8m_vpu_g2_dec_fmts[] = {
+   {
+   .fourcc = V4L2_PIX_FMT_NV12,
+   .codec_mode = HANTRO_MODE_NONE,
+   },
+   {
+   .fourcc = V4L2_PIX_FMT_HEVC_SLICE,
+   .codec_mode = HANTRO_MODE_HEVC_DEC,
+   .max_depth = 2,
+   .frmsize = {
+   .min_width = 48,
+   .max_width = 3840,
+   .step_width = MB_DIM,
+   .min_height = 48,
+   .max_height = 2160,
+   .step_height = MB_DIM,
+   },
+   },
+};
+
 static irqreturn_t imx8m_vpu_g1_irq(int irq, void *dev_id)
 {
struct hantro_dev *vpu = dev_id;
@@ -147,6 +168,24 @@ static irqreturn_t imx8m_vpu_g1_irq(int irq, void *dev_id)
return IRQ_HANDLED;
 }
 
+static irqreturn_t imx8m_vpu_g2_irq(int irq, void *dev_id)
+{
+   struct hantro_dev *vpu = dev_id;
+   enum vb2_buffer_state state;
+   u32 status;
+
+   status = vdpu_read(vpu, HEVC_REG_INTERRUPT);
+   state = (status & HEVC_REG_INTERRUPT_DEC_RDY_INT) ?
+VB2_BUF_STATE_DONE : VB2_BUF_STATE_ERROR;
+
+   vdpu_write(vpu, 0, HEVC_REG_INTERRUPT);
+   vdpu_write(vpu, HEVC_REG_CONFIG_DEC_CLK_GATE_E, HEVC_REG_CONFIG);
+
+   hantro_irq_done(vpu, state);
+
+   return IRQ_HANDLED;
+}
+
 static int imx8mq_vpu_hw_init(struct hantro_dev *vpu)
 {
struct device_node *np = vpu->dev->of_node;
@@ -176,6 +215,13 @@ static void imx8m_vpu_g1_reset(struct hantro_ctx *ctx)
imx8m_soft_reset(vpu, RESET_G1);
 }
 
+static void imx8m_vpu_g2_reset(struct hantro_ctx *ctx)
+{
+   struct hantro_dev *vpu = ctx->dev;
+
+   imx8m_soft_reset(vpu, RESET_G2);
+}
+
 /*
  * Supported codec ops.
  */
@@ -201,16 +247,28 @@ static const struct hantro_codec_ops 
imx8mq_vpu_codec_ops[] = {
},
 };
 
+static const struct hantro_codec_ops imx8mq_vpu_g2_codec_ops[] = {
+   [HANTRO_MODE_HEVC_DEC] = {
+   .run = hantro_g2_hevc_dec_run,
+   .reset = imx8m_vpu_g2_reset,
+   .init = hantro_hevc_dec_init,
+   .exit = hantro_hevc_dec_exit,
+   },
+};
+
 /*
  * VPU variants.
  */
 
 static const struct hantro_irq imx8mq_irqs[] = {
{ "g1", imx8m_vpu_g1_irq },
-   { "g2", NULL /* TODO: imx8m_vpu_g2_irq */ },
 };
 
-static const char * const imx8mq_clk_names[] = { "g1", "g2", "bus" };
+static const struct hantro_irq imx8mq_g2_irqs[] = {
+   { "g2", imx8m_vpu_g2_irq },
+};
+
+static const char * const imx8mq_clk_names[] = { "g1", "g2"

[PATCH v6 07/13] media: hantro: Define HEVC codec profiles and supported features

2021-03-18 Thread Benjamin Gaignard
Define which HEVC profiles (up to level 5.1) and features
(no scaling, no 10 bits) are supported by the driver.

Signed-off-by: Benjamin Gaignard 
---
 drivers/staging/media/hantro/hantro.h |  3 ++
 drivers/staging/media/hantro/hantro_drv.c | 58 +++
 2 files changed, 61 insertions(+)

diff --git a/drivers/staging/media/hantro/hantro.h 
b/drivers/staging/media/hantro/hantro.h
index a99a96b84b5e..4ae2071b3bfe 100644
--- a/drivers/staging/media/hantro/hantro.h
+++ b/drivers/staging/media/hantro/hantro.h
@@ -35,6 +35,7 @@ struct hantro_codec_ops;
 #define HANTRO_MPEG2_DECODER   BIT(16)
 #define HANTRO_VP8_DECODER BIT(17)
 #define HANTRO_H264_DECODERBIT(18)
+#define HANTRO_HEVC_DECODERBIT(19)
 #define HANTRO_DECODERS0x
 
 /**
@@ -100,6 +101,7 @@ struct hantro_variant {
  * @HANTRO_MODE_H264_DEC: H264 decoder.
  * @HANTRO_MODE_MPEG2_DEC: MPEG-2 decoder.
  * @HANTRO_MODE_VP8_DEC: VP8 decoder.
+ * @HANTRO_MODE_HEVC_DEC: HEVC decoder.
  */
 enum hantro_codec_mode {
HANTRO_MODE_NONE = -1,
@@ -107,6 +109,7 @@ enum hantro_codec_mode {
HANTRO_MODE_H264_DEC,
HANTRO_MODE_MPEG2_DEC,
HANTRO_MODE_VP8_DEC,
+   HANTRO_MODE_HEVC_DEC,
 };
 
 /*
diff --git a/drivers/staging/media/hantro/hantro_drv.c 
b/drivers/staging/media/hantro/hantro_drv.c
index ac1429f00b33..f0b68e16fcc0 100644
--- a/drivers/staging/media/hantro/hantro_drv.c
+++ b/drivers/staging/media/hantro/hantro_drv.c
@@ -245,6 +245,18 @@ static int hantro_try_ctrl(struct v4l2_ctrl *ctrl)
if (sps->bit_depth_luma_minus8 != 0)
/* Only 8-bit is supported */
return -EINVAL;
+   } else if (ctrl->id == V4L2_CID_MPEG_VIDEO_HEVC_SPS) {
+   const struct v4l2_ctrl_hevc_sps *sps = ctrl->p_new.p_hevc_sps;
+
+   if (sps->bit_depth_luma_minus8 != sps->bit_depth_chroma_minus8)
+   /* Luma and chroma bit depth mismatch */
+   return -EINVAL;
+   if (sps->bit_depth_luma_minus8 != 0)
+   /* Only 8-bit is supported */
+   return -EINVAL;
+   if (sps->flags & V4L2_HEVC_SPS_FLAG_SCALING_LIST_ENABLED)
+   /* No scaling support */
+   return -EINVAL;
}
return 0;
 }
@@ -351,6 +363,52 @@ static const struct hantro_ctrl controls[] = {
.def = V4L2_MPEG_VIDEO_H264_PROFILE_MAIN,
}
}, {
+   .codec = HANTRO_HEVC_DECODER,
+   .cfg = {
+   .id = V4L2_CID_MPEG_VIDEO_HEVC_DECODE_MODE,
+   .min = V4L2_MPEG_VIDEO_HEVC_DECODE_MODE_FRAME_BASED,
+   .max = V4L2_MPEG_VIDEO_HEVC_DECODE_MODE_FRAME_BASED,
+   .def = V4L2_MPEG_VIDEO_HEVC_DECODE_MODE_FRAME_BASED,
+   },
+   }, {
+   .codec = HANTRO_HEVC_DECODER,
+   .cfg = {
+   .id = V4L2_CID_MPEG_VIDEO_HEVC_START_CODE,
+   .min = V4L2_MPEG_VIDEO_HEVC_START_CODE_ANNEX_B,
+   .max = V4L2_MPEG_VIDEO_HEVC_START_CODE_ANNEX_B,
+   .def = V4L2_MPEG_VIDEO_HEVC_START_CODE_ANNEX_B,
+   },
+   }, {
+   .codec = HANTRO_HEVC_DECODER,
+   .cfg = {
+   .id = V4L2_CID_MPEG_VIDEO_HEVC_PROFILE,
+   .min = V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN,
+   .max = V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN_10,
+   .def = V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN,
+   },
+   }, {
+   .codec = HANTRO_HEVC_DECODER,
+   .cfg = {
+   .id = V4L2_CID_MPEG_VIDEO_HEVC_LEVEL,
+   .min = V4L2_MPEG_VIDEO_HEVC_LEVEL_1,
+   .max = V4L2_MPEG_VIDEO_HEVC_LEVEL_5_1,
+   },
+   }, {
+   .codec = HANTRO_HEVC_DECODER,
+   .cfg = {
+   .id = V4L2_CID_MPEG_VIDEO_HEVC_SPS,
+   .ops = _ctrl_ops,
+   },
+   }, {
+   .codec = HANTRO_HEVC_DECODER,
+   .cfg = {
+   .id = V4L2_CID_MPEG_VIDEO_HEVC_PPS,
+   },
+   }, {
+   .codec = HANTRO_HEVC_DECODER,
+   .cfg = {
+   .id = V4L2_CID_MPEG_VIDEO_HEVC_DECODE_PARAMS,
+   },
},
 };
 
-- 
2.25.1



[PATCH v6 08/13] media: hantro: Only use postproc when post processed formats are defined

2021-03-18 Thread Benjamin Gaignard
If the variant doesn't offert postprocessed formats make sure it will
be ok.

Signed-off-by: Benjamin Gaignard 
---
 drivers/staging/media/hantro/hantro.h  |  8 ++--
 drivers/staging/media/hantro/hantro_postproc.c | 14 ++
 drivers/staging/media/hantro/hantro_v4l2.c |  4 +++-
 3 files changed, 19 insertions(+), 7 deletions(-)

diff --git a/drivers/staging/media/hantro/hantro.h 
b/drivers/staging/media/hantro/hantro.h
index 4ae2071b3bfe..83299e8d3a6c 100644
--- a/drivers/staging/media/hantro/hantro.h
+++ b/drivers/staging/media/hantro/hantro.h
@@ -413,12 +413,8 @@ hantro_get_dst_buf(struct hantro_ctx *ctx)
return v4l2_m2m_next_dst_buf(ctx->fh.m2m_ctx);
 }
 
-static inline bool
-hantro_needs_postproc(const struct hantro_ctx *ctx,
- const struct hantro_fmt *fmt)
-{
-   return !ctx->is_encoder && fmt->fourcc != V4L2_PIX_FMT_NV12;
-}
+bool hantro_needs_postproc(const struct hantro_ctx *ctx,
+  const struct hantro_fmt *fmt);
 
 static inline dma_addr_t
 hantro_get_dec_buf_addr(struct hantro_ctx *ctx, struct vb2_buffer *vb)
diff --git a/drivers/staging/media/hantro/hantro_postproc.c 
b/drivers/staging/media/hantro/hantro_postproc.c
index 6d2a8f2a8f0b..ed8916c950a4 100644
--- a/drivers/staging/media/hantro/hantro_postproc.c
+++ b/drivers/staging/media/hantro/hantro_postproc.c
@@ -50,6 +50,20 @@ const struct hantro_postproc_regs hantro_g1_postproc_regs = {
.display_width = {G1_REG_PP_DISPLAY_WIDTH, 0, 0xfff},
 };
 
+bool hantro_needs_postproc(const struct hantro_ctx *ctx,
+  const struct hantro_fmt *fmt)
+{
+   struct hantro_dev *vpu = ctx->dev;
+
+   if (ctx->is_encoder)
+   return false;
+
+   if (!vpu->variant->postproc_fmts)
+   return false;
+
+   return fmt->fourcc != V4L2_PIX_FMT_NV12;
+}
+
 void hantro_postproc_enable(struct hantro_ctx *ctx)
 {
struct hantro_dev *vpu = ctx->dev;
diff --git a/drivers/staging/media/hantro/hantro_v4l2.c 
b/drivers/staging/media/hantro/hantro_v4l2.c
index 1bc118e375a1..77d7fe62ce81 100644
--- a/drivers/staging/media/hantro/hantro_v4l2.c
+++ b/drivers/staging/media/hantro/hantro_v4l2.c
@@ -55,7 +55,9 @@ static const struct hantro_fmt *
 hantro_get_postproc_formats(const struct hantro_ctx *ctx,
unsigned int *num_fmts)
 {
-   if (ctx->is_encoder) {
+   struct hantro_dev *vpu = ctx->dev;
+
+   if (ctx->is_encoder || !vpu->variant->postproc_fmts) {
*num_fmts = 0;
return NULL;
}
-- 
2.25.1



[PATCH v6 06/13] media: hantro: change hantro_codec_ops run prototype to return errors

2021-03-18 Thread Benjamin Gaignard
Change hantro_codec_ops run prototype from 'void' to 'int'.
This allow to cancel the job if an error occur while configuring
the hardware.

Signed-off-by: Benjamin Gaignard 
---
version 5:
 - forward hantro_h264_dec_prepare_run() return value in case
   of error

 drivers/staging/media/hantro/hantro_drv.c |  4 +++-
 .../staging/media/hantro/hantro_g1_h264_dec.c | 10 +++---
 .../media/hantro/hantro_g1_mpeg2_dec.c|  4 +++-
 .../staging/media/hantro/hantro_g1_vp8_dec.c  |  6 --
 .../staging/media/hantro/hantro_h1_jpeg_enc.c |  4 +++-
 drivers/staging/media/hantro/hantro_hw.h  | 19 ++-
 .../media/hantro/rk3399_vpu_hw_jpeg_enc.c |  4 +++-
 .../media/hantro/rk3399_vpu_hw_mpeg2_dec.c|  4 +++-
 .../media/hantro/rk3399_vpu_hw_vp8_dec.c  |  6 --
 9 files changed, 40 insertions(+), 21 deletions(-)

diff --git a/drivers/staging/media/hantro/hantro_drv.c 
b/drivers/staging/media/hantro/hantro_drv.c
index e5f200e64993..ac1429f00b33 100644
--- a/drivers/staging/media/hantro/hantro_drv.c
+++ b/drivers/staging/media/hantro/hantro_drv.c
@@ -161,7 +161,9 @@ static void device_run(void *priv)
 
v4l2_m2m_buf_copy_metadata(src, dst, true);
 
-   ctx->codec_ops->run(ctx);
+   if (ctx->codec_ops->run(ctx))
+   goto err_cancel_job;
+
return;
 
 err_cancel_job:
diff --git a/drivers/staging/media/hantro/hantro_g1_h264_dec.c 
b/drivers/staging/media/hantro/hantro_g1_h264_dec.c
index 845bef73d218..5c792b7bcb79 100644
--- a/drivers/staging/media/hantro/hantro_g1_h264_dec.c
+++ b/drivers/staging/media/hantro/hantro_g1_h264_dec.c
@@ -273,13 +273,15 @@ static void set_buffers(struct hantro_ctx *ctx)
vdpu_write_relaxed(vpu, ctx->h264_dec.priv.dma, G1_REG_ADDR_QTABLE);
 }
 
-void hantro_g1_h264_dec_run(struct hantro_ctx *ctx)
+int hantro_g1_h264_dec_run(struct hantro_ctx *ctx)
 {
struct hantro_dev *vpu = ctx->dev;
+   int ret;
 
/* Prepare the H264 decoder context. */
-   if (hantro_h264_dec_prepare_run(ctx))
-   return;
+   ret = hantro_h264_dec_prepare_run(ctx);
+   if (ret)
+   return ret;
 
/* Configure hardware registers. */
set_params(ctx);
@@ -301,4 +303,6 @@ void hantro_g1_h264_dec_run(struct hantro_ctx *ctx)
   G1_REG_CONFIG_DEC_CLK_GATE_E,
   G1_REG_CONFIG);
vdpu_write(vpu, G1_REG_INTERRUPT_DEC_E, G1_REG_INTERRUPT);
+
+   return 0;
 }
diff --git a/drivers/staging/media/hantro/hantro_g1_mpeg2_dec.c 
b/drivers/staging/media/hantro/hantro_g1_mpeg2_dec.c
index 6386a3989bfe..5e8943d31dc5 100644
--- a/drivers/staging/media/hantro/hantro_g1_mpeg2_dec.c
+++ b/drivers/staging/media/hantro/hantro_g1_mpeg2_dec.c
@@ -155,7 +155,7 @@ hantro_g1_mpeg2_dec_set_buffers(struct hantro_dev *vpu, 
struct hantro_ctx *ctx,
vdpu_write_relaxed(vpu, backward_addr, G1_REG_REFER3_BASE);
 }
 
-void hantro_g1_mpeg2_dec_run(struct hantro_ctx *ctx)
+int hantro_g1_mpeg2_dec_run(struct hantro_ctx *ctx)
 {
struct hantro_dev *vpu = ctx->dev;
struct vb2_v4l2_buffer *src_buf, *dst_buf;
@@ -248,4 +248,6 @@ void hantro_g1_mpeg2_dec_run(struct hantro_ctx *ctx)
 
reg = G1_REG_DEC_E(1);
vdpu_write(vpu, reg, G1_SWREG(1));
+
+   return 0;
 }
diff --git a/drivers/staging/media/hantro/hantro_g1_vp8_dec.c 
b/drivers/staging/media/hantro/hantro_g1_vp8_dec.c
index a5cdf150cd16..d665df026546 100644
--- a/drivers/staging/media/hantro/hantro_g1_vp8_dec.c
+++ b/drivers/staging/media/hantro/hantro_g1_vp8_dec.c
@@ -426,7 +426,7 @@ static void cfg_buffers(struct hantro_ctx *ctx,
vdpu_write_relaxed(vpu, dst_dma, G1_REG_ADDR_DST);
 }
 
-void hantro_g1_vp8_dec_run(struct hantro_ctx *ctx)
+int hantro_g1_vp8_dec_run(struct hantro_ctx *ctx)
 {
const struct v4l2_ctrl_vp8_frame_header *hdr;
struct hantro_dev *vpu = ctx->dev;
@@ -439,7 +439,7 @@ void hantro_g1_vp8_dec_run(struct hantro_ctx *ctx)
 
hdr = hantro_get_ctrl(ctx, V4L2_CID_MPEG_VIDEO_VP8_FRAME_HEADER);
if (WARN_ON(!hdr))
-   return;
+   return -EINVAL;
 
/* Reset segment_map buffer in keyframe */
if (VP8_FRAME_IS_KEY_FRAME(hdr) && ctx->vp8_dec.segment_map.cpu)
@@ -499,4 +499,6 @@ void hantro_g1_vp8_dec_run(struct hantro_ctx *ctx)
hantro_end_prepare_run(ctx);
 
vdpu_write(vpu, G1_REG_INTERRUPT_DEC_E, G1_REG_INTERRUPT);
+
+   return 0;
 }
diff --git a/drivers/staging/media/hantro/hantro_h1_jpeg_enc.c 
b/drivers/staging/media/hantro/hantro_h1_jpeg_enc.c
index b88dc4ed06db..56cf261a8e95 100644
--- a/drivers/staging/media/hantro/hantro_h1_jpeg_enc.c
+++ b/drivers/staging/media/hantro/hantro_h1_jpeg_enc.c
@@ -88,7 +88,7 @@ hantro_h1_jpeg_enc_set_qtable(struct hantro_dev *vpu,
}
 }
 
-void hantro_h1_jpeg_enc_run(struct hantro_ctx *ctx)
+int hantro_h1_jpeg_enc_run(struct hantro_ctx *ctx)
 {
struct hantro_dev *vpu = ctx-&

[PATCH v6 03/13] media: hantro: Use syscon instead of 'ctrl' register

2021-03-18 Thread Benjamin Gaignard
In order to be able to share the control hardware block between
VPUs use a syscon instead a ioremap it in the driver.
To keep the compatibility with older DT if 'nxp,imx8mq-vpu-ctrl'
phandle is not found look at 'ctrl' reg-name.
With the method it becomes useless to provide a list of register
names so remove it.

Signed-off-by: Benjamin Gaignard 
---
version 5:
 - use syscon instead of VPU reset driver.
 - if DT doesn't provide syscon keep backward compatibilty by using
   'ctrl' reg-name.

 drivers/staging/media/hantro/hantro.h   |  5 +-
 drivers/staging/media/hantro/imx8m_vpu_hw.c | 52 -
 2 files changed, 34 insertions(+), 23 deletions(-)

diff --git a/drivers/staging/media/hantro/hantro.h 
b/drivers/staging/media/hantro/hantro.h
index 65f9f7ea7dcf..a99a96b84b5e 100644
--- a/drivers/staging/media/hantro/hantro.h
+++ b/drivers/staging/media/hantro/hantro.h
@@ -13,6 +13,7 @@
 #define HANTRO_H_
 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -167,7 +168,7 @@ hantro_vdev_to_func(struct video_device *vdev)
  * @reg_bases: Mapped addresses of VPU registers.
  * @enc_base:  Mapped address of VPU encoder register for convenience.
  * @dec_base:  Mapped address of VPU decoder register for convenience.
- * @ctrl_base: Mapped address of VPU control block.
+ * @ctrl_base: Regmap of VPU control block.
  * @vpu_mutex: Mutex to synchronize V4L2 calls.
  * @irqlock:   Spinlock to synchronize access to data structures
  * shared with interrupt handlers.
@@ -186,7 +187,7 @@ struct hantro_dev {
void __iomem **reg_bases;
void __iomem *enc_base;
void __iomem *dec_base;
-   void __iomem *ctrl_base;
+   struct regmap *ctrl_base;
 
struct mutex vpu_mutex; /* video_device lock */
spinlock_t irqlock;
diff --git a/drivers/staging/media/hantro/imx8m_vpu_hw.c 
b/drivers/staging/media/hantro/imx8m_vpu_hw.c
index c222de075ef4..bd9d135dd440 100644
--- a/drivers/staging/media/hantro/imx8m_vpu_hw.c
+++ b/drivers/staging/media/hantro/imx8m_vpu_hw.c
@@ -7,6 +7,7 @@
 
 #include 
 #include 
+#include 
 
 #include "hantro.h"
 #include "hantro_jpeg.h"
@@ -24,30 +25,28 @@
 #define CTRL_G1_PP_FUSE0x0c
 #define CTRL_G2_DEC_FUSE   0x10
 
+static const struct regmap_config ctrl_regmap_ctrl = {
+   .reg_bits = 32,
+   .val_bits = 32,
+   .reg_stride = 0x14,
+};
+
 static void imx8m_soft_reset(struct hantro_dev *vpu, u32 reset_bits)
 {
-   u32 val;
-
/* Assert */
-   val = readl(vpu->ctrl_base + CTRL_SOFT_RESET);
-   val &= ~reset_bits;
-   writel(val, vpu->ctrl_base + CTRL_SOFT_RESET);
+   regmap_update_bits(vpu->ctrl_base, CTRL_SOFT_RESET, reset_bits, 0);
 
udelay(2);
 
/* Release */
-   val = readl(vpu->ctrl_base + CTRL_SOFT_RESET);
-   val |= reset_bits;
-   writel(val, vpu->ctrl_base + CTRL_SOFT_RESET);
+   regmap_update_bits(vpu->ctrl_base, CTRL_SOFT_RESET,
+  reset_bits, reset_bits);
 }
 
 static void imx8m_clk_enable(struct hantro_dev *vpu, u32 clock_bits)
 {
-   u32 val;
-
-   val = readl(vpu->ctrl_base + CTRL_CLOCK_ENABLE);
-   val |= clock_bits;
-   writel(val, vpu->ctrl_base + CTRL_CLOCK_ENABLE);
+   regmap_update_bits(vpu->ctrl_base, CTRL_CLOCK_ENABLE,
+  clock_bits, clock_bits);
 }
 
 static int imx8mq_runtime_resume(struct hantro_dev *vpu)
@@ -64,9 +63,9 @@ static int imx8mq_runtime_resume(struct hantro_dev *vpu)
imx8m_clk_enable(vpu, CLOCK_G1 | CLOCK_G2);
 
/* Set values of the fuse registers */
-   writel(0x, vpu->ctrl_base + CTRL_G1_DEC_FUSE);
-   writel(0x, vpu->ctrl_base + CTRL_G1_PP_FUSE);
-   writel(0x, vpu->ctrl_base + CTRL_G2_DEC_FUSE);
+   regmap_write(vpu->ctrl_base, CTRL_G1_DEC_FUSE, 0x);
+   regmap_write(vpu->ctrl_base, CTRL_G1_PP_FUSE, 0x);
+   regmap_write(vpu->ctrl_base, CTRL_G2_DEC_FUSE, 0x);
 
clk_bulk_disable_unprepare(vpu->variant->num_clocks, vpu->clocks);
 
@@ -150,8 +149,22 @@ static irqreturn_t imx8m_vpu_g1_irq(int irq, void *dev_id)
 
 static int imx8mq_vpu_hw_init(struct hantro_dev *vpu)
 {
-   vpu->dec_base = vpu->reg_bases[0];
-   vpu->ctrl_base = vpu->reg_bases[vpu->variant->num_regs - 1];
+   struct device_node *np = vpu->dev->of_node;
+
+   vpu->ctrl_base = syscon_regmap_lookup_by_phandle(np, 
"nxp,imx8mq-vpu-ctrl");
+   if (IS_ERR(vpu->ctrl_base)) {
+   struct resource *res;
+   void __iomem *ctrl;
+
+   res = platform_get_resource_byname(vpu->pdev, IORESOURCE_MEM, 
"ctrl");
+   ctrl = devm_ioremap_resource(vpu->dev, res);
+   if (IS_ERR(ctrl))
+   return 

[PATCH v6 05/13] media: hevc: Add decode params control

2021-03-18 Thread Benjamin Gaignard
Add decode params control and it associated structure to regroup
all the information that are needed to decode a reference frame as
it is describe in ITU-T Rec. H.265 section "8.3.2 Decoding process
for reference picture set".

Adapt Cedrus driver to these changes.

Signed-off-by: Benjamin Gaignard 
---
version 6:
 - fix compilation errors

 .../media/v4l/ext-ctrls-codec.rst | 94 +++
 .../media/v4l/vidioc-queryctrl.rst|  6 ++
 drivers/media/v4l2-core/v4l2-ctrls.c  | 26 +++--
 drivers/staging/media/sunxi/cedrus/cedrus.c   |  6 ++
 drivers/staging/media/sunxi/cedrus/cedrus.h   |  1 +
 .../staging/media/sunxi/cedrus/cedrus_dec.c   |  2 +
 .../staging/media/sunxi/cedrus/cedrus_h265.c  | 12 ++-
 include/media/hevc-ctrls.h| 29 --
 8 files changed, 137 insertions(+), 39 deletions(-)

diff --git a/Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst 
b/Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst
index d62e8e423f3b..8a6d45cb437e 100644
--- a/Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst
+++ b/Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst
@@ -3436,9 +3436,6 @@ enum v4l2_mpeg_video_hevc_size_of_length_field -
 * - __u8
   - ``pic_struct``
   -
-* - __u8
-  - ``num_active_dpb_entries``
-  - The number of entries in ``dpb``.
 * - __u8
   - ``ref_idx_l0[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]``
   - The list of L0 reference elements as indices in the DPB.
@@ -3446,22 +3443,8 @@ enum v4l2_mpeg_video_hevc_size_of_length_field -
   - ``ref_idx_l1[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]``
   - The list of L1 reference elements as indices in the DPB.
 * - __u8
-  - ``num_rps_poc_st_curr_before``
-  - The number of reference pictures in the short-term set that come before
-the current frame.
-* - __u8
-  - ``num_rps_poc_st_curr_after``
-  - The number of reference pictures in the short-term set that come after
-the current frame.
-* - __u8
-  - ``num_rps_poc_lt_curr``
-  - The number of reference pictures in the long-term set.
-* - __u8
-  - ``padding[7]``
+  - ``padding``
   - Applications and drivers must set this to zero.
-* - struct :c:type:`v4l2_hevc_dpb_entry`
-  - ``dpb[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]``
-  - The decoded picture buffer, for meta-data about reference frames.
 * - struct :c:type:`v4l2_hevc_pred_weight_table`
   - ``pred_weight_table``
   - The prediction weight coefficients for inter-picture prediction.
@@ -3660,3 +3643,78 @@ enum v4l2_mpeg_video_hevc_size_of_length_field -
 so this has to come from client.
 This is applicable to H264 and valid Range is from 0 to 63.
 Source Rec. ITU-T H.264 (06/2019); G.7.4.1.1, G.8.8.1.
+
+``V4L2_CID_MPEG_VIDEO_HEVC_DECODE_PARAMS (struct)``
+Specifies various decode parameters, especially the references picture 
order
+count (POC) for all the lists (short, long, before, current, after) and the
+number of entries for each of them.
+These parameters are defined according to :ref:`hevc`.
+They are described in section 8.3 "Slice decoding process" of the
+specification.
+
+.. c:type:: v4l2_ctrl_hevc_decode_params
+
+.. cssclass:: longtable
+
+.. flat-table:: struct v4l2_ctrl_hevc_decode_params
+:header-rows:  0
+:stub-columns: 0
+:widths:   1 1 2
+
+* - __s32
+  - ``pic_order_cnt_val``
+  - PicOrderCntVal as described in section 8.3.1 "Decoding process
+for picture order count" of the specification.
+* - __u8
+  - ``num_active_dpb_entries``
+  - The number of entries in ``dpb``.
+* - struct :c:type:`v4l2_hevc_dpb_entry`
+  - ``dpb[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]``
+  - The decoded picture buffer, for meta-data about reference frames.
+* - __u8
+  - ``num_poc_st_curr_before``
+  - The number of reference pictures in the short-term set that come before
+the current frame.
+* - __u8
+  - ``num_poc_st_curr_after``
+  - The number of reference pictures in the short-term set that come after
+the current frame.
+* - __u8
+  - ``num_poc_lt_curr``
+  - The number of reference pictures in the long-term set.
+* - __u8
+  - ``poc_st_curr_before[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]``
+  - PocStCurrBefore as described in section 8.3.2 "Decoding process for 
reference
+picture set.
+* - __u8
+  - ``poc_st_curr_after[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]``
+  - PocStCurrAfter as described in section 8.3.2 "Decoding process for 
reference
+picture set.
+* - __u8
+  - ``poc_lt_curr[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]``
+  - PocLtCurr as described in section 8.3.2 "Decoding process for reference
+picture set.
+* - __u64
+  - ``flags``
+  - See :ref:`Decode Parameters Flags `
+
+.. _hevc_decode_params_flags:
+
+``Decode 

[PATCH v6 04/13] media: hevc: Add fields and flags for hevc PPS

2021-03-18 Thread Benjamin Gaignard
Add fields and flags as they are defined in
7.4.3.3.1 "General picture parameter set RBSP semantics of the
H.265 ITU specification.

Signed-off-by: Benjamin Gaignard 
---
 .../userspace-api/media/v4l/ext-ctrls-codec.rst| 14 ++
 include/media/hevc-ctrls.h |  4 
 2 files changed, 18 insertions(+)

diff --git a/Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst 
b/Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst
index 00944e97d638..d62e8e423f3b 100644
--- a/Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst
+++ b/Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst
@@ -3234,6 +3234,12 @@ enum v4l2_mpeg_video_hevc_size_of_length_field -
 * - __u8
   - ``num_extra_slice_header_bits``
   -
+* - __u8
+  - ``num_ref_idx_l0_default_active_minus1``
+  - Specifies the inferred value of num_ref_idx_l0_active_minus1
+* - __u8
+  - ``num_ref_idx_l1_default_active_minus1``
+  - Specifies the inferred value of num_ref_idx_l1_active_minus1
 * - __s8
   - ``init_qp_minus26``
   -
@@ -3342,6 +3348,14 @@ enum v4l2_mpeg_video_hevc_size_of_length_field -
 * - ``V4L2_HEVC_PPS_FLAG_SLICE_SEGMENT_HEADER_EXTENSION_PRESENT``
   - 0x0004
   -
+* - ``V4L2_HEVC_PPS_FLAG_DEBLOCKING_FILTER_CONTROL_PRESENT``
+  - 0x0008
+  - Specifies the presence of deblocking filter control syntax elements in
+the PPS
+* - ``V4L2_HEVC_PPS_FLAG_UNIFORM_SPACING``
+  - 0x0010
+  - Specifies that tile column boundaries and likewise tile row boundaries
+are distributed uniformly across the picture
 
 ``V4L2_CID_MPEG_VIDEO_HEVC_SLICE_PARAMS (struct)``
 Specifies various slice-specific parameters, especially from the NAL unit
diff --git a/include/media/hevc-ctrls.h b/include/media/hevc-ctrls.h
index b4cb2ef02f17..003f819ecb26 100644
--- a/include/media/hevc-ctrls.h
+++ b/include/media/hevc-ctrls.h
@@ -100,10 +100,14 @@ struct v4l2_ctrl_hevc_sps {
 #define V4L2_HEVC_PPS_FLAG_PPS_DISABLE_DEBLOCKING_FILTER   (1ULL << 16)
 #define V4L2_HEVC_PPS_FLAG_LISTS_MODIFICATION_PRESENT  (1ULL << 17)
 #define V4L2_HEVC_PPS_FLAG_SLICE_SEGMENT_HEADER_EXTENSION_PRESENT (1ULL << 18)
+#define V4L2_HEVC_PPS_FLAG_DEBLOCKING_FILTER_CONTROL_PRESENT   (1ULL << 19)
+#define V4L2_HEVC_PPS_FLAG_UNIFORM_SPACING (1ULL << 20)
 
 struct v4l2_ctrl_hevc_pps {
/* ISO/IEC 23008-2, ITU-T Rec. H.265: Picture parameter set */
__u8num_extra_slice_header_bits;
+   __u8num_ref_idx_l0_default_active_minus1;
+   __u8num_ref_idx_l1_default_active_minus1;
__s8init_qp_minus26;
__u8diff_cu_qp_delta_depth;
__s8pps_cb_qp_offset;
-- 
2.25.1



[PATCH v6 01/13] dt-bindings: mfd: Add 'nxp,imx8mq-vpu-ctrl' to syscon list

2021-03-18 Thread Benjamin Gaignard
Add 'nxp,imx8mq-vpu-ctrl' in the list of possible syscon.
It will used to access to the VPU control registers.

Signed-off-by: Benjamin Gaignard 
---
 Documentation/devicetree/bindings/mfd/syscon.yaml | 1 +
 1 file changed, 1 insertion(+)

diff --git a/Documentation/devicetree/bindings/mfd/syscon.yaml 
b/Documentation/devicetree/bindings/mfd/syscon.yaml
index f14ae6da0068..ae22c4730613 100644
--- a/Documentation/devicetree/bindings/mfd/syscon.yaml
+++ b/Documentation/devicetree/bindings/mfd/syscon.yaml
@@ -44,6 +44,7 @@ properties:
   - hisilicon,peri-subctrl
   - microchip,sparx5-cpu-syscon
   - mstar,msc313-pmsleep
+  - nxp,imx8mq-vpu-ctrl
   - rockchip,px30-qos
   - rockchip,rk3066-qos
   - rockchip,rk3288-qos
-- 
2.25.1



[PATCH v6 00/13] Add HANTRO G2/HEVC decoder support for IMX8MQ

2021-03-18 Thread Benjamin Gaignard
 VIDIOC_QUERYCAP: OK
test VIDIOC_G/S_PRIORITY: OK
test for unlimited opens: OK

Debug ioctls:
test VIDIOC_DBG_G/S_REGISTER: OK (Not Supported)
test VIDIOC_LOG_STATUS: OK (Not Supported)

Input ioctls:
test VIDIOC_G/S_TUNER/ENUM_FREQ_BANDS: OK (Not Supported)
test VIDIOC_G/S_FREQUENCY: OK (Not Supported)
test VIDIOC_S_HW_FREQ_SEEK: OK (Not Supported)
test VIDIOC_ENUMAUDIO: OK (Not Supported)
test VIDIOC_G/S/ENUMINPUT: OK (Not Supported)
test VIDIOC_G/S_AUDIO: OK (Not Supported)
Inputs: 0 Audio Inputs: 0 Tuners: 0

Output ioctls:
test VIDIOC_G/S_MODULATOR: OK (Not Supported)
test VIDIOC_G/S_FREQUENCY: OK (Not Supported)
test VIDIOC_ENUMAUDOUT: OK (Not Supported)
test VIDIOC_G/S/ENUMOUTPUT: OK (Not Supported)
test VIDIOC_G/S_AUDOUT: OK (Not Supported)
Outputs: 0 Audio Outputs: 0 Modulators: 0

Input/Output configuration ioctls:
test VIDIOC_ENUM/G/S/QUERY_STD: OK (Not Supported)
test VIDIOC_ENUM/G/S/QUERY_DV_TIMINGS: OK (Not Supported)
test VIDIOC_DV_TIMINGS_CAP: OK (Not Supported)
test VIDIOC_G/S_EDID: OK (Not Supported)

Control ioctls:
test VIDIOC_QUERY_EXT_CTRL/QUERYMENU: OK
test VIDIOC_QUERYCTRL: OK
test VIDIOC_G/S_CTRL: OK
test VIDIOC_G/S/TRY_EXT_CTRLS: OK
test VIDIOC_(UN)SUBSCRIBE_EVENT/DQEVENT: OK
test VIDIOC_G/S_JPEGCOMP: OK (Not Supported)
Standard Controls: 8 Private Controls: 1

Format ioctls:
test VIDIOC_ENUM_FMT/FRAMESIZES/FRAMEINTERVALS: OK
test VIDIOC_G/S_PARM: OK (Not Supported)
test VIDIOC_G_FBUF: OK (Not Supported)
test VIDIOC_G_FMT: OK
test VIDIOC_TRY_FMT: OK
test VIDIOC_S_FMT: OK
test VIDIOC_G_SLICED_VBI_CAP: OK (Not Supported)
test Cropping: OK (Not Supported)
test Composing: OK (Not Supported)
test Scaling: OK (Not Supported)

Codec ioctls:
test VIDIOC_(TRY_)ENCODER_CMD: OK (Not Supported)
test VIDIOC_G_ENC_INDEX: OK (Not Supported)
test VIDIOC_(TRY_)DECODER_CMD: OK (Not Supported)

Buffer ioctls:
test VIDIOC_REQBUFS/CREATE_BUFS/QUERYBUF: OK
test VIDIOC_EXPBUF: OK
test Requests: OK

Total for hantro-vpu device /dev/video1: 46, Succeeded: 46, Failed: 0, 
Warnings: 0

Grand Total for hantro-vpu device /dev/media1: 54, Succeeded: 54, Failed: 0, 
Warnings: 0

Benjamin

Benjamin Gaignard (13):
  dt-bindings: mfd: Add 'nxp,imx8mq-vpu-ctrl' to syscon list
  dt-bindings: media: nxp,imx8mq-vpu: Update the bindings for G2 support
  media: hantro: Use syscon instead of 'ctrl' register
  media: hevc: Add fields and flags for hevc PPS
  media: hevc: Add decode params control
  media: hantro: change hantro_codec_ops run prototype to return errors
  media: hantro: Define HEVC codec profiles and supported features
  media: hantro: Only use postproc when post processed formats are
defined
  media: uapi: Add a control for HANTRO driver
  media: hantro: handle V4L2_PIX_FMT_HEVC_SLICE control
  media: hantro: Introduce G2/HEVC decoder
  media: hantro: IMX8M: add variant for G2/HEVC codec
  arm64: dts: imx8mq: Add node to G2 hardware

 .../bindings/media/nxp,imx8mq-vpu.yaml|  53 +-
 .../devicetree/bindings/mfd/syscon.yaml   |   1 +
 .../userspace-api/media/drivers/hantro.rst|  14 +
 .../userspace-api/media/drivers/index.rst |   1 +
 .../media/v4l/ext-ctrls-codec.rst | 108 +++-
 .../media/v4l/vidioc-queryctrl.rst|   6 +
 arch/arm64/boot/dts/freescale/imx8mq.dtsi |  43 +-
 drivers/media/v4l2-core/v4l2-ctrls.c  |  26 +-
 drivers/staging/media/hantro/Makefile |   2 +
 drivers/staging/media/hantro/hantro.h |  18 +-
 drivers/staging/media/hantro/hantro_drv.c |  99 ++-
 .../staging/media/hantro/hantro_g1_h264_dec.c |  10 +-
 .../media/hantro/hantro_g1_mpeg2_dec.c|   4 +-
 .../staging/media/hantro/hantro_g1_vp8_dec.c  |   6 +-
 .../staging/media/hantro/hantro_g2_hevc_dec.c | 587 ++
 drivers/staging/media/hantro/hantro_g2_regs.h | 198 ++
 .../staging/media/hantro/hantro_h1_jpeg_enc.c |   4 +-
 drivers/staging/media/hantro/hantro_hevc.c| 324 ++
 drivers/staging/media/hantro/hantro_hw.h  |  69 +-
 .../staging/media/hantro/hantro_postproc.c|  14 +
 drivers/staging/media/hantro/hantro_v4l2.c|   5 +-
 drivers/staging/media/hantro/imx8m_vpu_hw.c   | 128 +++-
 .../media/hantro/rk3399_vpu_hw_jpeg_enc.c |   4 +-
 .../media/hantro/rk3399_vpu_hw_mpeg2_dec.c|   4 +-
 .../media/hantro/rk3399_vpu_hw_vp8_dec.c  |   6 +-
 drivers/staging/media/sunxi/cedrus/cedrus.c   |   6 +
 drivers/staging/media/sunxi/cedrus/cedrus.h   |   1 +
 .../staging/media/sunxi/cedrus/cedrus_dec.c   |   2 +
 .../staging/media/sunxi/cedrus/cedrus_h265.c  |  12 +-
 include/media/hevc-ctrls.h|  33 +-
 include/uapi/linux/v4l2-controls.h|  13 +
 31 files

[PATCH v6 02/13] dt-bindings: media: nxp,imx8mq-vpu: Update the bindings for G2 support

2021-03-18 Thread Benjamin Gaignard
Introducing G2 hevc video decoder lead to modify the bindings to allow
to get one node per VPUs.
VPUs share one hardware control block which is provided as a phandle on
an syscon.
Each node got now one reg and one interrupt.
Add a compatible for G2 hardware block: nxp,imx8mq-vpu-g2.

To be compatible with older DT the driver is still capable to use 'ctrl'
reg-name even if it is deprecated now.

Signed-off-by: Benjamin Gaignard 
---
version 5:
- This version doesn't break the backward compatibilty between kernel
  and DT.

 .../bindings/media/nxp,imx8mq-vpu.yaml| 53 ---
 1 file changed, 34 insertions(+), 19 deletions(-)

diff --git a/Documentation/devicetree/bindings/media/nxp,imx8mq-vpu.yaml 
b/Documentation/devicetree/bindings/media/nxp,imx8mq-vpu.yaml
index 762be3f96ce9..79502fc8bde5 100644
--- a/Documentation/devicetree/bindings/media/nxp,imx8mq-vpu.yaml
+++ b/Documentation/devicetree/bindings/media/nxp,imx8mq-vpu.yaml
@@ -15,22 +15,18 @@ description:
 
 properties:
   compatible:
-const: nxp,imx8mq-vpu
+oneOf:
+  - const: nxp,imx8mq-vpu
+  - const: nxp,imx8mq-vpu-g2
 
   reg:
-maxItems: 3
-
-  reg-names:
-items:
-  - const: g1
-  - const: g2
-  - const: ctrl
+maxItems: 1
 
   interrupts:
-maxItems: 2
+maxItems: 1
 
   interrupt-names:
-items:
+oneOf:
   - const: g1
   - const: g2
 
@@ -46,14 +42,18 @@ properties:
   power-domains:
 maxItems: 1
 
+  nxp,imx8mq-vpu-ctrl:
+description: Specifies a phandle to syscon VPU hardware control block
+$ref: "/schemas/types.yaml#/definitions/phandle"
+
 required:
   - compatible
   - reg
-  - reg-names
   - interrupts
   - interrupt-names
   - clocks
   - clock-names
+  - nxp,imx8mq-vpu-ctrl
 
 additionalProperties: false
 
@@ -62,18 +62,33 @@ examples:
 #include 
 #include 
 
-vpu: video-codec@3830 {
+vpu_ctrl: syscon@3832 {
+ compatible = "nxp,imx8mq-vpu-ctrl", "syscon";
+ reg = <0x3832 0x1>;
+};
+
+vpu_g1: video-codec@3830 {
 compatible = "nxp,imx8mq-vpu";
-reg = <0x3830 0x1>,
-  <0x3831 0x1>,
-  <0x3832 0x1>;
-reg-names = "g1", "g2", "ctrl";
-interrupts = ,
- ;
-interrupt-names = "g1", "g2";
+reg = <0x3830 0x1>;
+interrupts = ;
+interrupt-names = "g1";
+clocks = < IMX8MQ_CLK_VPU_G1_ROOT>,
+ < IMX8MQ_CLK_VPU_G2_ROOT>,
+ < IMX8MQ_CLK_VPU_DEC_ROOT>;
+clock-names = "g1", "g2", "bus";
+power-domains = <_vpu>;
+nxp,imx8mq-vpu-ctrl = <_ctrl>;
+};
+
+vpu_g2: video-codec@3831 {
+compatible = "nxp,imx8mq-vpu-g2";
+reg = <0x3830 0x1>;
+interrupts = ;
+interrupt-names = "g2";
 clocks = < IMX8MQ_CLK_VPU_G1_ROOT>,
  < IMX8MQ_CLK_VPU_G2_ROOT>,
  < IMX8MQ_CLK_VPU_DEC_ROOT>;
 clock-names = "g1", "g2", "bus";
 power-domains = <_vpu>;
+nxp,imx8mq-vpu-ctrl = <_ctrl>;
 };
-- 
2.25.1



[PATCH v5 07/13] media: hantro: Define HEVC codec profiles and supported features

2021-03-17 Thread Benjamin Gaignard
Define which HEVC profiles (up to level 5.1) and features
(no scaling, no 10 bits) are supported by the driver.

Signed-off-by: Benjamin Gaignard 
---
 drivers/staging/media/hantro/hantro.h |  3 ++
 drivers/staging/media/hantro/hantro_drv.c | 58 +++
 2 files changed, 61 insertions(+)

diff --git a/drivers/staging/media/hantro/hantro.h 
b/drivers/staging/media/hantro/hantro.h
index a99a96b84b5e..4ae2071b3bfe 100644
--- a/drivers/staging/media/hantro/hantro.h
+++ b/drivers/staging/media/hantro/hantro.h
@@ -35,6 +35,7 @@ struct hantro_codec_ops;
 #define HANTRO_MPEG2_DECODER   BIT(16)
 #define HANTRO_VP8_DECODER BIT(17)
 #define HANTRO_H264_DECODERBIT(18)
+#define HANTRO_HEVC_DECODERBIT(19)
 #define HANTRO_DECODERS0x
 
 /**
@@ -100,6 +101,7 @@ struct hantro_variant {
  * @HANTRO_MODE_H264_DEC: H264 decoder.
  * @HANTRO_MODE_MPEG2_DEC: MPEG-2 decoder.
  * @HANTRO_MODE_VP8_DEC: VP8 decoder.
+ * @HANTRO_MODE_HEVC_DEC: HEVC decoder.
  */
 enum hantro_codec_mode {
HANTRO_MODE_NONE = -1,
@@ -107,6 +109,7 @@ enum hantro_codec_mode {
HANTRO_MODE_H264_DEC,
HANTRO_MODE_MPEG2_DEC,
HANTRO_MODE_VP8_DEC,
+   HANTRO_MODE_HEVC_DEC,
 };
 
 /*
diff --git a/drivers/staging/media/hantro/hantro_drv.c 
b/drivers/staging/media/hantro/hantro_drv.c
index ac1429f00b33..f0b68e16fcc0 100644
--- a/drivers/staging/media/hantro/hantro_drv.c
+++ b/drivers/staging/media/hantro/hantro_drv.c
@@ -245,6 +245,18 @@ static int hantro_try_ctrl(struct v4l2_ctrl *ctrl)
if (sps->bit_depth_luma_minus8 != 0)
/* Only 8-bit is supported */
return -EINVAL;
+   } else if (ctrl->id == V4L2_CID_MPEG_VIDEO_HEVC_SPS) {
+   const struct v4l2_ctrl_hevc_sps *sps = ctrl->p_new.p_hevc_sps;
+
+   if (sps->bit_depth_luma_minus8 != sps->bit_depth_chroma_minus8)
+   /* Luma and chroma bit depth mismatch */
+   return -EINVAL;
+   if (sps->bit_depth_luma_minus8 != 0)
+   /* Only 8-bit is supported */
+   return -EINVAL;
+   if (sps->flags & V4L2_HEVC_SPS_FLAG_SCALING_LIST_ENABLED)
+   /* No scaling support */
+   return -EINVAL;
}
return 0;
 }
@@ -351,6 +363,52 @@ static const struct hantro_ctrl controls[] = {
.def = V4L2_MPEG_VIDEO_H264_PROFILE_MAIN,
}
}, {
+   .codec = HANTRO_HEVC_DECODER,
+   .cfg = {
+   .id = V4L2_CID_MPEG_VIDEO_HEVC_DECODE_MODE,
+   .min = V4L2_MPEG_VIDEO_HEVC_DECODE_MODE_FRAME_BASED,
+   .max = V4L2_MPEG_VIDEO_HEVC_DECODE_MODE_FRAME_BASED,
+   .def = V4L2_MPEG_VIDEO_HEVC_DECODE_MODE_FRAME_BASED,
+   },
+   }, {
+   .codec = HANTRO_HEVC_DECODER,
+   .cfg = {
+   .id = V4L2_CID_MPEG_VIDEO_HEVC_START_CODE,
+   .min = V4L2_MPEG_VIDEO_HEVC_START_CODE_ANNEX_B,
+   .max = V4L2_MPEG_VIDEO_HEVC_START_CODE_ANNEX_B,
+   .def = V4L2_MPEG_VIDEO_HEVC_START_CODE_ANNEX_B,
+   },
+   }, {
+   .codec = HANTRO_HEVC_DECODER,
+   .cfg = {
+   .id = V4L2_CID_MPEG_VIDEO_HEVC_PROFILE,
+   .min = V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN,
+   .max = V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN_10,
+   .def = V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN,
+   },
+   }, {
+   .codec = HANTRO_HEVC_DECODER,
+   .cfg = {
+   .id = V4L2_CID_MPEG_VIDEO_HEVC_LEVEL,
+   .min = V4L2_MPEG_VIDEO_HEVC_LEVEL_1,
+   .max = V4L2_MPEG_VIDEO_HEVC_LEVEL_5_1,
+   },
+   }, {
+   .codec = HANTRO_HEVC_DECODER,
+   .cfg = {
+   .id = V4L2_CID_MPEG_VIDEO_HEVC_SPS,
+   .ops = _ctrl_ops,
+   },
+   }, {
+   .codec = HANTRO_HEVC_DECODER,
+   .cfg = {
+   .id = V4L2_CID_MPEG_VIDEO_HEVC_PPS,
+   },
+   }, {
+   .codec = HANTRO_HEVC_DECODER,
+   .cfg = {
+   .id = V4L2_CID_MPEG_VIDEO_HEVC_DECODE_PARAMS,
+   },
},
 };
 
-- 
2.25.1



[PATCH v5 03/13] media: hantro: Use syscon instead of 'ctrl' register

2021-03-17 Thread Benjamin Gaignard
In order to be able to share the control hardware block between
VPUs use a syscon instead a ioremap it in the driver.
To keep the compatibility with older DT if 'nxp,imx8mq-vpu-ctrl'
phandle is not found look at 'ctrl' reg-name.
With the method it becomes useless to provide a list of register
names so remove it.

Signed-off-by: Benjamin Gaignard 
---
version 5:
 - use syscon instead of VPU reset driver.
 - if DT doesn't provide syscon keep backward compatibilty by using
   'ctrl' reg-name.
 drivers/staging/media/hantro/hantro.h   |  5 +-
 drivers/staging/media/hantro/imx8m_vpu_hw.c | 52 -
 2 files changed, 34 insertions(+), 23 deletions(-)

diff --git a/drivers/staging/media/hantro/hantro.h 
b/drivers/staging/media/hantro/hantro.h
index 65f9f7ea7dcf..a99a96b84b5e 100644
--- a/drivers/staging/media/hantro/hantro.h
+++ b/drivers/staging/media/hantro/hantro.h
@@ -13,6 +13,7 @@
 #define HANTRO_H_
 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -167,7 +168,7 @@ hantro_vdev_to_func(struct video_device *vdev)
  * @reg_bases: Mapped addresses of VPU registers.
  * @enc_base:  Mapped address of VPU encoder register for convenience.
  * @dec_base:  Mapped address of VPU decoder register for convenience.
- * @ctrl_base: Mapped address of VPU control block.
+ * @ctrl_base: Regmap of VPU control block.
  * @vpu_mutex: Mutex to synchronize V4L2 calls.
  * @irqlock:   Spinlock to synchronize access to data structures
  * shared with interrupt handlers.
@@ -186,7 +187,7 @@ struct hantro_dev {
void __iomem **reg_bases;
void __iomem *enc_base;
void __iomem *dec_base;
-   void __iomem *ctrl_base;
+   struct regmap *ctrl_base;
 
struct mutex vpu_mutex; /* video_device lock */
spinlock_t irqlock;
diff --git a/drivers/staging/media/hantro/imx8m_vpu_hw.c 
b/drivers/staging/media/hantro/imx8m_vpu_hw.c
index c222de075ef4..bd9d135dd440 100644
--- a/drivers/staging/media/hantro/imx8m_vpu_hw.c
+++ b/drivers/staging/media/hantro/imx8m_vpu_hw.c
@@ -7,6 +7,7 @@
 
 #include 
 #include 
+#include 
 
 #include "hantro.h"
 #include "hantro_jpeg.h"
@@ -24,30 +25,28 @@
 #define CTRL_G1_PP_FUSE0x0c
 #define CTRL_G2_DEC_FUSE   0x10
 
+static const struct regmap_config ctrl_regmap_ctrl = {
+   .reg_bits = 32,
+   .val_bits = 32,
+   .reg_stride = 0x14,
+};
+
 static void imx8m_soft_reset(struct hantro_dev *vpu, u32 reset_bits)
 {
-   u32 val;
-
/* Assert */
-   val = readl(vpu->ctrl_base + CTRL_SOFT_RESET);
-   val &= ~reset_bits;
-   writel(val, vpu->ctrl_base + CTRL_SOFT_RESET);
+   regmap_update_bits(vpu->ctrl_base, CTRL_SOFT_RESET, reset_bits, 0);
 
udelay(2);
 
/* Release */
-   val = readl(vpu->ctrl_base + CTRL_SOFT_RESET);
-   val |= reset_bits;
-   writel(val, vpu->ctrl_base + CTRL_SOFT_RESET);
+   regmap_update_bits(vpu->ctrl_base, CTRL_SOFT_RESET,
+  reset_bits, reset_bits);
 }
 
 static void imx8m_clk_enable(struct hantro_dev *vpu, u32 clock_bits)
 {
-   u32 val;
-
-   val = readl(vpu->ctrl_base + CTRL_CLOCK_ENABLE);
-   val |= clock_bits;
-   writel(val, vpu->ctrl_base + CTRL_CLOCK_ENABLE);
+   regmap_update_bits(vpu->ctrl_base, CTRL_CLOCK_ENABLE,
+  clock_bits, clock_bits);
 }
 
 static int imx8mq_runtime_resume(struct hantro_dev *vpu)
@@ -64,9 +63,9 @@ static int imx8mq_runtime_resume(struct hantro_dev *vpu)
imx8m_clk_enable(vpu, CLOCK_G1 | CLOCK_G2);
 
/* Set values of the fuse registers */
-   writel(0x, vpu->ctrl_base + CTRL_G1_DEC_FUSE);
-   writel(0x, vpu->ctrl_base + CTRL_G1_PP_FUSE);
-   writel(0x, vpu->ctrl_base + CTRL_G2_DEC_FUSE);
+   regmap_write(vpu->ctrl_base, CTRL_G1_DEC_FUSE, 0x);
+   regmap_write(vpu->ctrl_base, CTRL_G1_PP_FUSE, 0x);
+   regmap_write(vpu->ctrl_base, CTRL_G2_DEC_FUSE, 0x);
 
clk_bulk_disable_unprepare(vpu->variant->num_clocks, vpu->clocks);
 
@@ -150,8 +149,22 @@ static irqreturn_t imx8m_vpu_g1_irq(int irq, void *dev_id)
 
 static int imx8mq_vpu_hw_init(struct hantro_dev *vpu)
 {
-   vpu->dec_base = vpu->reg_bases[0];
-   vpu->ctrl_base = vpu->reg_bases[vpu->variant->num_regs - 1];
+   struct device_node *np = vpu->dev->of_node;
+
+   vpu->ctrl_base = syscon_regmap_lookup_by_phandle(np, 
"nxp,imx8mq-vpu-ctrl");
+   if (IS_ERR(vpu->ctrl_base)) {
+   struct resource *res;
+   void __iomem *ctrl;
+
+   res = platform_get_resource_byname(vpu->pdev, IORESOURCE_MEM, 
"ctrl");
+   ctrl = devm_ioremap_resource(vpu->dev, res);
+   if (IS_ERR(ctrl))
+   return PTR_ERR(ctr

[PATCH v5 11/13] media: hantro: Introduce G2/HEVC decoder

2021-03-17 Thread Benjamin Gaignard
Implement all the logic to get G2 hardware decoding HEVC frames.
It support up level 5.1 HEVC stream.
It doesn't support yet 10 bits formats or scaling feature.

Add HANTRO HEVC dedicated control to skip some bits at the beginning
of the slice header. That is very specific to this hardware so can't
go into uapi structures. Compute the needed value is complex and require
information from the stream that only the userland knows so let it
provide the correct value to the driver.

Signed-off-by: Benjamin Gaignard 
Co-developed-by: Adrian Ratiu 
Signed-off-by: Adrian Ratiu 
Co-developed-by: Ezequiel Garcia 
Signed-off-by: Ezequiel Garcia 
---
version 5:
 - Add co-author tags.
 - Fix Ezequiel comments (typo, comments, etc).
 - Remove unused functions.
version 4:
- fix Ezequiel comments
- use dedicated control as an integer
- change hantro_g2_hevc_dec_run prototype to return errors

version 2:
- squash multiple commits in this one.
- fix the comments done by Ezequiel about dma_alloc_coherent usage
- fix Dan's comments about control copy, reverse the test logic
in tile_buffer_reallocate, rework some goto and return cases.

 drivers/staging/media/hantro/Makefile |   2 +
 drivers/staging/media/hantro/hantro.h |   2 +
 drivers/staging/media/hantro/hantro_drv.c |  36 ++
 .../staging/media/hantro/hantro_g2_hevc_dec.c | 587 ++
 drivers/staging/media/hantro/hantro_g2_regs.h | 198 ++
 drivers/staging/media/hantro/hantro_hevc.c| 324 ++
 drivers/staging/media/hantro/hantro_hw.h  |  49 ++
 7 files changed, 1198 insertions(+)
 create mode 100644 drivers/staging/media/hantro/hantro_g2_hevc_dec.c
 create mode 100644 drivers/staging/media/hantro/hantro_g2_regs.h
 create mode 100644 drivers/staging/media/hantro/hantro_hevc.c

diff --git a/drivers/staging/media/hantro/Makefile 
b/drivers/staging/media/hantro/Makefile
index 743ce08eb184..0357f1772267 100644
--- a/drivers/staging/media/hantro/Makefile
+++ b/drivers/staging/media/hantro/Makefile
@@ -9,12 +9,14 @@ hantro-vpu-y += \
hantro_h1_jpeg_enc.o \
hantro_g1_h264_dec.o \
hantro_g1_mpeg2_dec.o \
+   hantro_g2_hevc_dec.o \
hantro_g1_vp8_dec.o \
rk3399_vpu_hw_jpeg_enc.o \
rk3399_vpu_hw_mpeg2_dec.o \
rk3399_vpu_hw_vp8_dec.o \
hantro_jpeg.o \
hantro_h264.o \
+   hantro_hevc.o \
hantro_mpeg2.o \
hantro_vp8.o
 
diff --git a/drivers/staging/media/hantro/hantro.h 
b/drivers/staging/media/hantro/hantro.h
index 83299e8d3a6c..976c1903d9ce 100644
--- a/drivers/staging/media/hantro/hantro.h
+++ b/drivers/staging/media/hantro/hantro.h
@@ -221,6 +221,7 @@ struct hantro_dev {
  * @jpeg_enc:  JPEG-encoding context.
  * @mpeg2_dec: MPEG-2-decoding context.
  * @vp8_dec:   VP8-decoding context.
+ * @hevc_dec:  HEVC-decoding context.
  */
 struct hantro_ctx {
struct hantro_dev *dev;
@@ -247,6 +248,7 @@ struct hantro_ctx {
struct hantro_jpeg_enc_hw_ctx jpeg_enc;
struct hantro_mpeg2_dec_hw_ctx mpeg2_dec;
struct hantro_vp8_dec_hw_ctx vp8_dec;
+   struct hantro_hevc_dec_hw_ctx hevc_dec;
};
 };
 
diff --git a/drivers/staging/media/hantro/hantro_drv.c 
b/drivers/staging/media/hantro/hantro_drv.c
index f0b68e16fcc0..13c197ca9ba3 100644
--- a/drivers/staging/media/hantro/hantro_drv.c
+++ b/drivers/staging/media/hantro/hantro_drv.c
@@ -281,6 +281,26 @@ static int hantro_jpeg_s_ctrl(struct v4l2_ctrl *ctrl)
return 0;
 }
 
+static int hantro_hevc_s_ctrl(struct v4l2_ctrl *ctrl)
+{
+   struct hantro_ctx *ctx;
+
+   ctx = container_of(ctrl->handler,
+  struct hantro_ctx, ctrl_handler);
+
+   vpu_debug(1, "s_ctrl: id = %d, val = %d\n", ctrl->id, ctrl->val);
+
+   switch (ctrl->id) {
+   case V4L2_CID_HANTRO_HEVC_SLICE_HEADER_SKIP:
+   ctx->hevc_dec.ctrls.hevc_hdr_skip_length = ctrl->val;
+   break;
+   default:
+   return -EINVAL;
+   }
+
+   return 0;
+}
+
 static const struct v4l2_ctrl_ops hantro_ctrl_ops = {
.try_ctrl = hantro_try_ctrl,
 };
@@ -289,6 +309,10 @@ static const struct v4l2_ctrl_ops hantro_jpeg_ctrl_ops = {
.s_ctrl = hantro_jpeg_s_ctrl,
 };
 
+static const struct v4l2_ctrl_ops hantro_hevc_ctrl_ops = {
+   .s_ctrl = hantro_hevc_s_ctrl,
+};
+
 static const struct hantro_ctrl controls[] = {
{
.codec = HANTRO_JPEG_ENCODER,
@@ -409,6 +433,18 @@ static const struct hantro_ctrl controls[] = {
.cfg = {
.id = V4L2_CID_MPEG_VIDEO_HEVC_DECODE_PARAMS,
},
+   }, {
+   .codec = HANTRO_HEVC_DECODER,
+   .cfg = {
+   .id = V4L2_CID_HANTRO_HEVC_SLICE_HEADER_SKIP,
+ 

[PATCH v5 04/13] media: hevc: Add fields and flags for hevc PPS

2021-03-17 Thread Benjamin Gaignard
Add fields and flags as they are defined in
7.4.3.3.1 "General picture parameter set RBSP semantics of the
H.265 ITU specification.

Signed-off-by: Benjamin Gaignard 
---
 .../userspace-api/media/v4l/ext-ctrls-codec.rst| 14 ++
 include/media/hevc-ctrls.h |  4 
 2 files changed, 18 insertions(+)

diff --git a/Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst 
b/Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst
index 00944e97d638..d62e8e423f3b 100644
--- a/Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst
+++ b/Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst
@@ -3234,6 +3234,12 @@ enum v4l2_mpeg_video_hevc_size_of_length_field -
 * - __u8
   - ``num_extra_slice_header_bits``
   -
+* - __u8
+  - ``num_ref_idx_l0_default_active_minus1``
+  - Specifies the inferred value of num_ref_idx_l0_active_minus1
+* - __u8
+  - ``num_ref_idx_l1_default_active_minus1``
+  - Specifies the inferred value of num_ref_idx_l1_active_minus1
 * - __s8
   - ``init_qp_minus26``
   -
@@ -3342,6 +3348,14 @@ enum v4l2_mpeg_video_hevc_size_of_length_field -
 * - ``V4L2_HEVC_PPS_FLAG_SLICE_SEGMENT_HEADER_EXTENSION_PRESENT``
   - 0x0004
   -
+* - ``V4L2_HEVC_PPS_FLAG_DEBLOCKING_FILTER_CONTROL_PRESENT``
+  - 0x0008
+  - Specifies the presence of deblocking filter control syntax elements in
+the PPS
+* - ``V4L2_HEVC_PPS_FLAG_UNIFORM_SPACING``
+  - 0x0010
+  - Specifies that tile column boundaries and likewise tile row boundaries
+are distributed uniformly across the picture
 
 ``V4L2_CID_MPEG_VIDEO_HEVC_SLICE_PARAMS (struct)``
 Specifies various slice-specific parameters, especially from the NAL unit
diff --git a/include/media/hevc-ctrls.h b/include/media/hevc-ctrls.h
index b4cb2ef02f17..003f819ecb26 100644
--- a/include/media/hevc-ctrls.h
+++ b/include/media/hevc-ctrls.h
@@ -100,10 +100,14 @@ struct v4l2_ctrl_hevc_sps {
 #define V4L2_HEVC_PPS_FLAG_PPS_DISABLE_DEBLOCKING_FILTER   (1ULL << 16)
 #define V4L2_HEVC_PPS_FLAG_LISTS_MODIFICATION_PRESENT  (1ULL << 17)
 #define V4L2_HEVC_PPS_FLAG_SLICE_SEGMENT_HEADER_EXTENSION_PRESENT (1ULL << 18)
+#define V4L2_HEVC_PPS_FLAG_DEBLOCKING_FILTER_CONTROL_PRESENT   (1ULL << 19)
+#define V4L2_HEVC_PPS_FLAG_UNIFORM_SPACING (1ULL << 20)
 
 struct v4l2_ctrl_hevc_pps {
/* ISO/IEC 23008-2, ITU-T Rec. H.265: Picture parameter set */
__u8num_extra_slice_header_bits;
+   __u8num_ref_idx_l0_default_active_minus1;
+   __u8num_ref_idx_l1_default_active_minus1;
__s8init_qp_minus26;
__u8diff_cu_qp_delta_depth;
__s8pps_cb_qp_offset;
-- 
2.25.1



[PATCH v5 06/13] media: hantro: change hantro_codec_ops run prototype to return errors

2021-03-17 Thread Benjamin Gaignard
Change hantro_codec_ops run prototype from 'void' to 'int'.
This allow to cancel the job if an error occur while configuring
the hardware.

Signed-off-by: Benjamin Gaignard 
---
version 5:
 - forward hantro_h264_dec_prepare_run() return value in case
   of error
 drivers/staging/media/hantro/hantro_drv.c |  4 +++-
 .../staging/media/hantro/hantro_g1_h264_dec.c | 10 +++---
 .../media/hantro/hantro_g1_mpeg2_dec.c|  4 +++-
 .../staging/media/hantro/hantro_g1_vp8_dec.c  |  6 --
 .../staging/media/hantro/hantro_h1_jpeg_enc.c |  4 +++-
 drivers/staging/media/hantro/hantro_hw.h  | 19 ++-
 .../media/hantro/rk3399_vpu_hw_jpeg_enc.c |  4 +++-
 .../media/hantro/rk3399_vpu_hw_mpeg2_dec.c|  4 +++-
 .../media/hantro/rk3399_vpu_hw_vp8_dec.c  |  6 --
 9 files changed, 40 insertions(+), 21 deletions(-)

diff --git a/drivers/staging/media/hantro/hantro_drv.c 
b/drivers/staging/media/hantro/hantro_drv.c
index e5f200e64993..ac1429f00b33 100644
--- a/drivers/staging/media/hantro/hantro_drv.c
+++ b/drivers/staging/media/hantro/hantro_drv.c
@@ -161,7 +161,9 @@ static void device_run(void *priv)
 
v4l2_m2m_buf_copy_metadata(src, dst, true);
 
-   ctx->codec_ops->run(ctx);
+   if (ctx->codec_ops->run(ctx))
+   goto err_cancel_job;
+
return;
 
 err_cancel_job:
diff --git a/drivers/staging/media/hantro/hantro_g1_h264_dec.c 
b/drivers/staging/media/hantro/hantro_g1_h264_dec.c
index 845bef73d218..5c792b7bcb79 100644
--- a/drivers/staging/media/hantro/hantro_g1_h264_dec.c
+++ b/drivers/staging/media/hantro/hantro_g1_h264_dec.c
@@ -273,13 +273,15 @@ static void set_buffers(struct hantro_ctx *ctx)
vdpu_write_relaxed(vpu, ctx->h264_dec.priv.dma, G1_REG_ADDR_QTABLE);
 }
 
-void hantro_g1_h264_dec_run(struct hantro_ctx *ctx)
+int hantro_g1_h264_dec_run(struct hantro_ctx *ctx)
 {
struct hantro_dev *vpu = ctx->dev;
+   int ret;
 
/* Prepare the H264 decoder context. */
-   if (hantro_h264_dec_prepare_run(ctx))
-   return;
+   ret = hantro_h264_dec_prepare_run(ctx);
+   if (ret)
+   return ret;
 
/* Configure hardware registers. */
set_params(ctx);
@@ -301,4 +303,6 @@ void hantro_g1_h264_dec_run(struct hantro_ctx *ctx)
   G1_REG_CONFIG_DEC_CLK_GATE_E,
   G1_REG_CONFIG);
vdpu_write(vpu, G1_REG_INTERRUPT_DEC_E, G1_REG_INTERRUPT);
+
+   return 0;
 }
diff --git a/drivers/staging/media/hantro/hantro_g1_mpeg2_dec.c 
b/drivers/staging/media/hantro/hantro_g1_mpeg2_dec.c
index 6386a3989bfe..5e8943d31dc5 100644
--- a/drivers/staging/media/hantro/hantro_g1_mpeg2_dec.c
+++ b/drivers/staging/media/hantro/hantro_g1_mpeg2_dec.c
@@ -155,7 +155,7 @@ hantro_g1_mpeg2_dec_set_buffers(struct hantro_dev *vpu, 
struct hantro_ctx *ctx,
vdpu_write_relaxed(vpu, backward_addr, G1_REG_REFER3_BASE);
 }
 
-void hantro_g1_mpeg2_dec_run(struct hantro_ctx *ctx)
+int hantro_g1_mpeg2_dec_run(struct hantro_ctx *ctx)
 {
struct hantro_dev *vpu = ctx->dev;
struct vb2_v4l2_buffer *src_buf, *dst_buf;
@@ -248,4 +248,6 @@ void hantro_g1_mpeg2_dec_run(struct hantro_ctx *ctx)
 
reg = G1_REG_DEC_E(1);
vdpu_write(vpu, reg, G1_SWREG(1));
+
+   return 0;
 }
diff --git a/drivers/staging/media/hantro/hantro_g1_vp8_dec.c 
b/drivers/staging/media/hantro/hantro_g1_vp8_dec.c
index a5cdf150cd16..d665df026546 100644
--- a/drivers/staging/media/hantro/hantro_g1_vp8_dec.c
+++ b/drivers/staging/media/hantro/hantro_g1_vp8_dec.c
@@ -426,7 +426,7 @@ static void cfg_buffers(struct hantro_ctx *ctx,
vdpu_write_relaxed(vpu, dst_dma, G1_REG_ADDR_DST);
 }
 
-void hantro_g1_vp8_dec_run(struct hantro_ctx *ctx)
+int hantro_g1_vp8_dec_run(struct hantro_ctx *ctx)
 {
const struct v4l2_ctrl_vp8_frame_header *hdr;
struct hantro_dev *vpu = ctx->dev;
@@ -439,7 +439,7 @@ void hantro_g1_vp8_dec_run(struct hantro_ctx *ctx)
 
hdr = hantro_get_ctrl(ctx, V4L2_CID_MPEG_VIDEO_VP8_FRAME_HEADER);
if (WARN_ON(!hdr))
-   return;
+   return -EINVAL;
 
/* Reset segment_map buffer in keyframe */
if (VP8_FRAME_IS_KEY_FRAME(hdr) && ctx->vp8_dec.segment_map.cpu)
@@ -499,4 +499,6 @@ void hantro_g1_vp8_dec_run(struct hantro_ctx *ctx)
hantro_end_prepare_run(ctx);
 
vdpu_write(vpu, G1_REG_INTERRUPT_DEC_E, G1_REG_INTERRUPT);
+
+   return 0;
 }
diff --git a/drivers/staging/media/hantro/hantro_h1_jpeg_enc.c 
b/drivers/staging/media/hantro/hantro_h1_jpeg_enc.c
index b88dc4ed06db..56cf261a8e95 100644
--- a/drivers/staging/media/hantro/hantro_h1_jpeg_enc.c
+++ b/drivers/staging/media/hantro/hantro_h1_jpeg_enc.c
@@ -88,7 +88,7 @@ hantro_h1_jpeg_enc_set_qtable(struct hantro_dev *vpu,
}
 }
 
-void hantro_h1_jpeg_enc_run(struct hantro_ctx *ctx)
+int hantro_h1_jpeg_enc_run(struct hantro_ctx *ctx)
 {
struct hantro_dev *vpu = ctx-&

[PATCH v5 12/13] media: hantro: IMX8M: add variant for G2/HEVC codec

2021-03-17 Thread Benjamin Gaignard
Add variant to IMX8M to enable G2/HEVC codec.
Define the capabilities for the hardware up to 3840x2160.
G2 doesn't have postprocessor, use the same clocks and got it
own interruption.

Signed-off-by: Benjamin Gaignard 
---
version 5:
 - remove useless postproc fields for G2

version 2:
- remove useless clocks

 drivers/staging/media/hantro/hantro_drv.c   |  1 +
 drivers/staging/media/hantro/hantro_hw.h|  1 +
 drivers/staging/media/hantro/imx8m_vpu_hw.c | 76 -
 3 files changed, 76 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/media/hantro/hantro_drv.c 
b/drivers/staging/media/hantro/hantro_drv.c
index 13c197ca9ba3..659124a52e8a 100644
--- a/drivers/staging/media/hantro/hantro_drv.c
+++ b/drivers/staging/media/hantro/hantro_drv.c
@@ -574,6 +574,7 @@ static const struct of_device_id of_hantro_match[] = {
 #endif
 #ifdef CONFIG_VIDEO_HANTRO_IMX8M
{ .compatible = "nxp,imx8mq-vpu", .data = _vpu_variant, },
+   { .compatible = "nxp,imx8mq-vpu-g2", .data = _vpu_g2_variant },
 #endif
{ /* sentinel */ }
 };
diff --git a/drivers/staging/media/hantro/hantro_hw.h 
b/drivers/staging/media/hantro/hantro_hw.h
index dade3b0769c1..f61f58da05fe 100644
--- a/drivers/staging/media/hantro/hantro_hw.h
+++ b/drivers/staging/media/hantro/hantro_hw.h
@@ -193,6 +193,7 @@ extern const struct hantro_variant rk3399_vpu_variant;
 extern const struct hantro_variant rk3328_vpu_variant;
 extern const struct hantro_variant rk3288_vpu_variant;
 extern const struct hantro_variant imx8mq_vpu_variant;
+extern const struct hantro_variant imx8mq_vpu_g2_variant;
 
 extern const struct hantro_postproc_regs hantro_g1_postproc_regs;
 
diff --git a/drivers/staging/media/hantro/imx8m_vpu_hw.c 
b/drivers/staging/media/hantro/imx8m_vpu_hw.c
index bd9d135dd440..b2ddb1fce0e8 100644
--- a/drivers/staging/media/hantro/imx8m_vpu_hw.c
+++ b/drivers/staging/media/hantro/imx8m_vpu_hw.c
@@ -12,6 +12,7 @@
 #include "hantro.h"
 #include "hantro_jpeg.h"
 #include "hantro_g1_regs.h"
+#include "hantro_g2_regs.h"
 
 #define CTRL_SOFT_RESET0x00
 #define RESET_G1   BIT(1)
@@ -129,6 +130,26 @@ static const struct hantro_fmt imx8m_vpu_dec_fmts[] = {
},
 };
 
+static const struct hantro_fmt imx8m_vpu_g2_dec_fmts[] = {
+   {
+   .fourcc = V4L2_PIX_FMT_NV12,
+   .codec_mode = HANTRO_MODE_NONE,
+   },
+   {
+   .fourcc = V4L2_PIX_FMT_HEVC_SLICE,
+   .codec_mode = HANTRO_MODE_HEVC_DEC,
+   .max_depth = 2,
+   .frmsize = {
+   .min_width = 48,
+   .max_width = 3840,
+   .step_width = MB_DIM,
+   .min_height = 48,
+   .max_height = 2160,
+   .step_height = MB_DIM,
+   },
+   },
+};
+
 static irqreturn_t imx8m_vpu_g1_irq(int irq, void *dev_id)
 {
struct hantro_dev *vpu = dev_id;
@@ -147,6 +168,24 @@ static irqreturn_t imx8m_vpu_g1_irq(int irq, void *dev_id)
return IRQ_HANDLED;
 }
 
+static irqreturn_t imx8m_vpu_g2_irq(int irq, void *dev_id)
+{
+   struct hantro_dev *vpu = dev_id;
+   enum vb2_buffer_state state;
+   u32 status;
+
+   status = vdpu_read(vpu, HEVC_REG_INTERRUPT);
+   state = (status & HEVC_REG_INTERRUPT_DEC_RDY_INT) ?
+VB2_BUF_STATE_DONE : VB2_BUF_STATE_ERROR;
+
+   vdpu_write(vpu, 0, HEVC_REG_INTERRUPT);
+   vdpu_write(vpu, HEVC_REG_CONFIG_DEC_CLK_GATE_E, HEVC_REG_CONFIG);
+
+   hantro_irq_done(vpu, state);
+
+   return IRQ_HANDLED;
+}
+
 static int imx8mq_vpu_hw_init(struct hantro_dev *vpu)
 {
struct device_node *np = vpu->dev->of_node;
@@ -176,6 +215,13 @@ static void imx8m_vpu_g1_reset(struct hantro_ctx *ctx)
imx8m_soft_reset(vpu, RESET_G1);
 }
 
+static void imx8m_vpu_g2_reset(struct hantro_ctx *ctx)
+{
+   struct hantro_dev *vpu = ctx->dev;
+
+   imx8m_soft_reset(vpu, RESET_G2);
+}
+
 /*
  * Supported codec ops.
  */
@@ -201,16 +247,28 @@ static const struct hantro_codec_ops 
imx8mq_vpu_codec_ops[] = {
},
 };
 
+static const struct hantro_codec_ops imx8mq_vpu_g2_codec_ops[] = {
+   [HANTRO_MODE_HEVC_DEC] = {
+   .run = hantro_g2_hevc_dec_run,
+   .reset = imx8m_vpu_g2_reset,
+   .init = hantro_hevc_dec_init,
+   .exit = hantro_hevc_dec_exit,
+   },
+};
+
 /*
  * VPU variants.
  */
 
 static const struct hantro_irq imx8mq_irqs[] = {
{ "g1", imx8m_vpu_g1_irq },
-   { "g2", NULL /* TODO: imx8m_vpu_g2_irq */ },
 };
 
-static const char * const imx8mq_clk_names[] = { "g1", "g2", "bus" };
+static const struct hantro_irq imx8mq_g2_irqs[] = {
+   { "g2", imx8m_vpu_g2_irq },
+};
+
+static const char * const imx8mq_clk_names[] = { "g1", "g2"

[PATCH v5 09/13] media: uapi: Add a control for HANTRO driver

2021-03-17 Thread Benjamin Gaignard
The HEVC HANTRO driver needs to know the number of bits to skip at
the beginning of the slice header.
That is a hardware specific requirement so create a dedicated control
that this purpose.

Signed-off-by: Benjamin Gaignard 
---
version 5:
 - Be even more verbose in control documentation.
 - Do not create class for the control.
version 4:
- The control is now an integer which is enough to provide the numbers
  of bits to skip.
version 3:
- Fix typo in field name

 .../userspace-api/media/drivers/hantro.rst | 14 ++
 .../userspace-api/media/drivers/index.rst  |  1 +
 include/uapi/linux/v4l2-controls.h | 13 +
 3 files changed, 28 insertions(+)
 create mode 100644 Documentation/userspace-api/media/drivers/hantro.rst

diff --git a/Documentation/userspace-api/media/drivers/hantro.rst 
b/Documentation/userspace-api/media/drivers/hantro.rst
new file mode 100644
index ..78dcd2a44a03
--- /dev/null
+++ b/Documentation/userspace-api/media/drivers/hantro.rst
@@ -0,0 +1,14 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+Hantro video decoder driver
+===
+
+The Hantro video decoder driver implements the following driver-specific 
controls:
+
+``V4L2_CID_HANTRO_HEVC_SLICE_HEADER_SKIP (integer)``
+Specifies to Hantro HEVC video decoder driver the number of data (in bits) 
to
+skip in the slice segment header.
+If non-IDR, the bits to be skipped go from syntax element "pic_output_flag"
+to before syntax element "slice_temporal_mvp_enabled_flag".
+If IDR, the skipped bits are just "pic_output_flag"
+(separate_colour_plane_flag is not supported).
diff --git a/Documentation/userspace-api/media/drivers/index.rst 
b/Documentation/userspace-api/media/drivers/index.rst
index 1a9038f5f9fa..12e3c512d718 100644
--- a/Documentation/userspace-api/media/drivers/index.rst
+++ b/Documentation/userspace-api/media/drivers/index.rst
@@ -33,6 +33,7 @@ For more details see the file COPYING in the source 
distribution of Linux.
 
ccs
cx2341x-uapi
+hantro
imx-uapi
max2175
meye-uapi
diff --git a/include/uapi/linux/v4l2-controls.h 
b/include/uapi/linux/v4l2-controls.h
index 039c0d7add1b..cebfb57080ed 100644
--- a/include/uapi/linux/v4l2-controls.h
+++ b/include/uapi/linux/v4l2-controls.h
@@ -865,6 +865,19 @@ enum v4l2_mpeg_mfc51_video_force_frame_type {
 #define V4L2_CID_MPEG_MFC51_VIDEO_H264_ADAPTIVE_RC_STATIC  
(V4L2_CID_CODEC_MFC51_BASE+53)
 #define V4L2_CID_MPEG_MFC51_VIDEO_H264_NUM_REF_PIC_FOR_P   
(V4L2_CID_CODEC_MFC51_BASE+54)
 
+/*  MPEG-class control IDs specific to the Hantro driver as defined by V4L2 */
+#define V4L2_CID_CODEC_HANTRO_BASE 
(V4L2_CTRL_CLASS_CODEC | 0x1200)
+/*
+ * V4L2_CID_HANTRO_HEVC_SLICE_HEADER_SKIP -
+ * the number of data (in bits) to skip in the
+ * slice segment header.
+ * If non-IDR, the bits to be skipped go from syntax element "pic_output_flag"
+ * to before syntax element "slice_temporal_mvp_enabled_flag".
+ * If IDR, the skipped bits are just "pic_output_flag"
+ * (separate_colour_plane_flag is not supported).
+ */
+#define V4L2_CID_HANTRO_HEVC_SLICE_HEADER_SKIP (V4L2_CID_CODEC_HANTRO_BASE + 0)
+
 /*  Camera class control IDs */
 
 #define V4L2_CID_CAMERA_CLASS_BASE (V4L2_CTRL_CLASS_CAMERA | 0x900)
-- 
2.25.1



[PATCH v5 10/13] media: hantro: handle V4L2_PIX_FMT_HEVC_SLICE control

2021-03-17 Thread Benjamin Gaignard
Make sure that V4L2_PIX_FMT_HEVC_SLICE is correctly handle by v4l2
of the driver.

Signed-off-by: Benjamin Gaignard 
---
 drivers/staging/media/hantro/hantro_v4l2.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/staging/media/hantro/hantro_v4l2.c 
b/drivers/staging/media/hantro/hantro_v4l2.c
index 77d7fe62ce81..0655324fd0d4 100644
--- a/drivers/staging/media/hantro/hantro_v4l2.c
+++ b/drivers/staging/media/hantro/hantro_v4l2.c
@@ -392,6 +392,7 @@ hantro_update_requires_request(struct hantro_ctx *ctx, u32 
fourcc)
case V4L2_PIX_FMT_MPEG2_SLICE:
case V4L2_PIX_FMT_VP8_FRAME:
case V4L2_PIX_FMT_H264_SLICE:
+   case V4L2_PIX_FMT_HEVC_SLICE:
ctx->fh.m2m_ctx->out_q_ctx.q.requires_requests = true;
break;
default:
-- 
2.25.1



[PATCH v5 08/13] media: hantro: Only use postproc when post processed formats are defined

2021-03-17 Thread Benjamin Gaignard
If the variant doesn't offert postprocessed formats make sure it will
be ok.

Signed-off-by: Benjamin Gaignard 
---
 drivers/staging/media/hantro/hantro.h  |  8 ++--
 drivers/staging/media/hantro/hantro_postproc.c | 14 ++
 drivers/staging/media/hantro/hantro_v4l2.c |  4 +++-
 3 files changed, 19 insertions(+), 7 deletions(-)

diff --git a/drivers/staging/media/hantro/hantro.h 
b/drivers/staging/media/hantro/hantro.h
index 4ae2071b3bfe..83299e8d3a6c 100644
--- a/drivers/staging/media/hantro/hantro.h
+++ b/drivers/staging/media/hantro/hantro.h
@@ -413,12 +413,8 @@ hantro_get_dst_buf(struct hantro_ctx *ctx)
return v4l2_m2m_next_dst_buf(ctx->fh.m2m_ctx);
 }
 
-static inline bool
-hantro_needs_postproc(const struct hantro_ctx *ctx,
- const struct hantro_fmt *fmt)
-{
-   return !ctx->is_encoder && fmt->fourcc != V4L2_PIX_FMT_NV12;
-}
+bool hantro_needs_postproc(const struct hantro_ctx *ctx,
+  const struct hantro_fmt *fmt);
 
 static inline dma_addr_t
 hantro_get_dec_buf_addr(struct hantro_ctx *ctx, struct vb2_buffer *vb)
diff --git a/drivers/staging/media/hantro/hantro_postproc.c 
b/drivers/staging/media/hantro/hantro_postproc.c
index 6d2a8f2a8f0b..ed8916c950a4 100644
--- a/drivers/staging/media/hantro/hantro_postproc.c
+++ b/drivers/staging/media/hantro/hantro_postproc.c
@@ -50,6 +50,20 @@ const struct hantro_postproc_regs hantro_g1_postproc_regs = {
.display_width = {G1_REG_PP_DISPLAY_WIDTH, 0, 0xfff},
 };
 
+bool hantro_needs_postproc(const struct hantro_ctx *ctx,
+  const struct hantro_fmt *fmt)
+{
+   struct hantro_dev *vpu = ctx->dev;
+
+   if (ctx->is_encoder)
+   return false;
+
+   if (!vpu->variant->postproc_fmts)
+   return false;
+
+   return fmt->fourcc != V4L2_PIX_FMT_NV12;
+}
+
 void hantro_postproc_enable(struct hantro_ctx *ctx)
 {
struct hantro_dev *vpu = ctx->dev;
diff --git a/drivers/staging/media/hantro/hantro_v4l2.c 
b/drivers/staging/media/hantro/hantro_v4l2.c
index 1bc118e375a1..77d7fe62ce81 100644
--- a/drivers/staging/media/hantro/hantro_v4l2.c
+++ b/drivers/staging/media/hantro/hantro_v4l2.c
@@ -55,7 +55,9 @@ static const struct hantro_fmt *
 hantro_get_postproc_formats(const struct hantro_ctx *ctx,
unsigned int *num_fmts)
 {
-   if (ctx->is_encoder) {
+   struct hantro_dev *vpu = ctx->dev;
+
+   if (ctx->is_encoder || !vpu->variant->postproc_fmts) {
*num_fmts = 0;
return NULL;
}
-- 
2.25.1



[PATCH v5 13/13] arm64: dts: imx8mq: Add node to G2 hardware

2021-03-17 Thread Benjamin Gaignard
Split VPU node in two: one for G1 and one for G2 since they are
different hardware blocks.
Add syscon for hardware control block.
Remove reg-names property that is useless.
Each VPU node only need one interrupt.

Signed-off-by: Benjamin Gaignard 
---
version 5:
 - use syscon instead of VPU reset
 arch/arm64/boot/dts/freescale/imx8mq.dtsi | 43 ++-
 1 file changed, 34 insertions(+), 9 deletions(-)

diff --git a/arch/arm64/boot/dts/freescale/imx8mq.dtsi 
b/arch/arm64/boot/dts/freescale/imx8mq.dtsi
index 17c449e12c2e..b537d153ebbd 100644
--- a/arch/arm64/boot/dts/freescale/imx8mq.dtsi
+++ b/arch/arm64/boot/dts/freescale/imx8mq.dtsi
@@ -1329,15 +1329,16 @@ usb3_phy1: usb-phy@382f0040 {
status = "disabled";
};
 
-   vpu: video-codec@3830 {
+   vpu_ctrl: syscon@3832 {
+   compatible = "nxp,imx8mq-vpu-ctrl", "syscon";
+   reg = <0x3832 0x1>;
+   };
+
+   vpu_g1: video-codec@3830 {
compatible = "nxp,imx8mq-vpu";
-   reg = <0x3830 0x1>,
- <0x3831 0x1>,
- <0x3832 0x1>;
-   reg-names = "g1", "g2", "ctrl";
-   interrupts = ,
-;
-   interrupt-names = "g1", "g2";
+   reg = <0x3830 0x1>;
+   interrupts = ;
+   interrupt-names = "g1";
clocks = < IMX8MQ_CLK_VPU_G1_ROOT>,
 < IMX8MQ_CLK_VPU_G2_ROOT>,
 < IMX8MQ_CLK_VPU_DEC_ROOT>;
@@ -1350,9 +1351,33 @@ vpu: video-codec@3830 {
 < IMX8MQ_VPU_PLL_OUT>,
 < IMX8MQ_SYS1_PLL_800M>,
 < IMX8MQ_VPU_PLL>;
-   assigned-clock-rates = <6>, <6>,
+   assigned-clock-rates = <6>, <3>,
+  <8>, <0>;
+   power-domains = <_vpu>;
+   nxp,imx8mq-vpu-ctrl = <_ctrl>;
+   };
+
+   vpu_g2: video-codec@3831 {
+   compatible = "nxp,imx8mq-vpu-g2";
+   reg = <0x3831 0x1>;
+   interrupts = ;
+   interrupt-names = "g2";
+   clocks = < IMX8MQ_CLK_VPU_G1_ROOT>,
+< IMX8MQ_CLK_VPU_G2_ROOT>,
+< IMX8MQ_CLK_VPU_DEC_ROOT>;
+   clock-names = "g1", "g2",  "bus";
+   assigned-clocks = < IMX8MQ_CLK_VPU_G1>,
+ < IMX8MQ_CLK_VPU_G2>,
+ < IMX8MQ_CLK_VPU_BUS>,
+ < IMX8MQ_VPU_PLL_BYPASS>;
+   assigned-clock-parents = < IMX8MQ_VPU_PLL_OUT>,
+< IMX8MQ_VPU_PLL_OUT>,
+< IMX8MQ_SYS1_PLL_800M>,
+< IMX8MQ_VPU_PLL>;
+   assigned-clock-rates = <6>, <3>,
   <8>, <0>;
power-domains = <_vpu>;
+   nxp,imx8mq-vpu-ctrl = <_ctrl>;
};
 
pcie0: pcie@3380 {
-- 
2.25.1



[PATCH v5 05/13] media: hevc: Add decode params control

2021-03-17 Thread Benjamin Gaignard
Add decode params control and it associated structure to regroup
all the information that are needed to decode a reference frame as
it is describe in ITU-T Rec. H.265 section "8.3.2 Decoding process
for reference picture set".

Adapt Cedrus driver to these changes.

Signed-off-by: Benjamin Gaignard 
---
 .../media/v4l/ext-ctrls-codec.rst | 94 +++
 .../media/v4l/vidioc-queryctrl.rst|  6 ++
 drivers/media/v4l2-core/v4l2-ctrls.c  | 26 +++--
 drivers/staging/media/sunxi/cedrus/cedrus.c   |  6 ++
 drivers/staging/media/sunxi/cedrus/cedrus.h   |  1 +
 .../staging/media/sunxi/cedrus/cedrus_dec.c   |  2 +
 .../staging/media/sunxi/cedrus/cedrus_h265.c  |  6 +-
 include/media/hevc-ctrls.h| 29 --
 8 files changed, 134 insertions(+), 36 deletions(-)

diff --git a/Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst 
b/Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst
index d62e8e423f3b..8a6d45cb437e 100644
--- a/Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst
+++ b/Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst
@@ -3436,9 +3436,6 @@ enum v4l2_mpeg_video_hevc_size_of_length_field -
 * - __u8
   - ``pic_struct``
   -
-* - __u8
-  - ``num_active_dpb_entries``
-  - The number of entries in ``dpb``.
 * - __u8
   - ``ref_idx_l0[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]``
   - The list of L0 reference elements as indices in the DPB.
@@ -3446,22 +3443,8 @@ enum v4l2_mpeg_video_hevc_size_of_length_field -
   - ``ref_idx_l1[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]``
   - The list of L1 reference elements as indices in the DPB.
 * - __u8
-  - ``num_rps_poc_st_curr_before``
-  - The number of reference pictures in the short-term set that come before
-the current frame.
-* - __u8
-  - ``num_rps_poc_st_curr_after``
-  - The number of reference pictures in the short-term set that come after
-the current frame.
-* - __u8
-  - ``num_rps_poc_lt_curr``
-  - The number of reference pictures in the long-term set.
-* - __u8
-  - ``padding[7]``
+  - ``padding``
   - Applications and drivers must set this to zero.
-* - struct :c:type:`v4l2_hevc_dpb_entry`
-  - ``dpb[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]``
-  - The decoded picture buffer, for meta-data about reference frames.
 * - struct :c:type:`v4l2_hevc_pred_weight_table`
   - ``pred_weight_table``
   - The prediction weight coefficients for inter-picture prediction.
@@ -3660,3 +3643,78 @@ enum v4l2_mpeg_video_hevc_size_of_length_field -
 so this has to come from client.
 This is applicable to H264 and valid Range is from 0 to 63.
 Source Rec. ITU-T H.264 (06/2019); G.7.4.1.1, G.8.8.1.
+
+``V4L2_CID_MPEG_VIDEO_HEVC_DECODE_PARAMS (struct)``
+Specifies various decode parameters, especially the references picture 
order
+count (POC) for all the lists (short, long, before, current, after) and the
+number of entries for each of them.
+These parameters are defined according to :ref:`hevc`.
+They are described in section 8.3 "Slice decoding process" of the
+specification.
+
+.. c:type:: v4l2_ctrl_hevc_decode_params
+
+.. cssclass:: longtable
+
+.. flat-table:: struct v4l2_ctrl_hevc_decode_params
+:header-rows:  0
+:stub-columns: 0
+:widths:   1 1 2
+
+* - __s32
+  - ``pic_order_cnt_val``
+  - PicOrderCntVal as described in section 8.3.1 "Decoding process
+for picture order count" of the specification.
+* - __u8
+  - ``num_active_dpb_entries``
+  - The number of entries in ``dpb``.
+* - struct :c:type:`v4l2_hevc_dpb_entry`
+  - ``dpb[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]``
+  - The decoded picture buffer, for meta-data about reference frames.
+* - __u8
+  - ``num_poc_st_curr_before``
+  - The number of reference pictures in the short-term set that come before
+the current frame.
+* - __u8
+  - ``num_poc_st_curr_after``
+  - The number of reference pictures in the short-term set that come after
+the current frame.
+* - __u8
+  - ``num_poc_lt_curr``
+  - The number of reference pictures in the long-term set.
+* - __u8
+  - ``poc_st_curr_before[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]``
+  - PocStCurrBefore as described in section 8.3.2 "Decoding process for 
reference
+picture set.
+* - __u8
+  - ``poc_st_curr_after[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]``
+  - PocStCurrAfter as described in section 8.3.2 "Decoding process for 
reference
+picture set.
+* - __u8
+  - ``poc_lt_curr[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]``
+  - PocLtCurr as described in section 8.3.2 "Decoding process for reference
+picture set.
+* - __u64
+  - ``flags``
+  - See :ref:`Decode Parameters Flags `
+
+.. _hevc_decode_params_flags:
+
+``Decode Parameters Flags``
+
+.. cssclass:: longt

[PATCH v5 02/13] dt-bindings: media: nxp,imx8mq-vpu: Update the bindings for G2 support

2021-03-17 Thread Benjamin Gaignard
Introducing G2 hevc video decoder lead to modify the bindings to allow
to get one node per VPUs.
VPUs share one hardware control block which is provided as a phandle on
an syscon.
Each node got now one reg and one interrupt.
Add a compatible for G2 hardware block: nxp,imx8mq-vpu-g2.

To be compatible with older DT the driver is still capable to use 'ctrl'
reg-name even if it is deprecated now.

Signed-off-by: Benjamin Gaignard 
---
version 5:
- This version doesn't break the backward compatibilty between kernel
  and DT.
 .../bindings/media/nxp,imx8mq-vpu.yaml| 53 ---
 1 file changed, 34 insertions(+), 19 deletions(-)

diff --git a/Documentation/devicetree/bindings/media/nxp,imx8mq-vpu.yaml 
b/Documentation/devicetree/bindings/media/nxp,imx8mq-vpu.yaml
index 762be3f96ce9..79502fc8bde5 100644
--- a/Documentation/devicetree/bindings/media/nxp,imx8mq-vpu.yaml
+++ b/Documentation/devicetree/bindings/media/nxp,imx8mq-vpu.yaml
@@ -15,22 +15,18 @@ description:
 
 properties:
   compatible:
-const: nxp,imx8mq-vpu
+oneOf:
+  - const: nxp,imx8mq-vpu
+  - const: nxp,imx8mq-vpu-g2
 
   reg:
-maxItems: 3
-
-  reg-names:
-items:
-  - const: g1
-  - const: g2
-  - const: ctrl
+maxItems: 1
 
   interrupts:
-maxItems: 2
+maxItems: 1
 
   interrupt-names:
-items:
+oneOf:
   - const: g1
   - const: g2
 
@@ -46,14 +42,18 @@ properties:
   power-domains:
 maxItems: 1
 
+  nxp,imx8mq-vpu-ctrl:
+description: Specifies a phandle to syscon VPU hardware control block
+$ref: "/schemas/types.yaml#/definitions/phandle"
+
 required:
   - compatible
   - reg
-  - reg-names
   - interrupts
   - interrupt-names
   - clocks
   - clock-names
+  - nxp,imx8mq-vpu-ctrl
 
 additionalProperties: false
 
@@ -62,18 +62,33 @@ examples:
 #include 
 #include 
 
-vpu: video-codec@3830 {
+vpu_ctrl: syscon@3832 {
+ compatible = "nxp,imx8mq-vpu-ctrl", "syscon";
+ reg = <0x3832 0x1>;
+};
+
+vpu_g1: video-codec@3830 {
 compatible = "nxp,imx8mq-vpu";
-reg = <0x3830 0x1>,
-  <0x3831 0x1>,
-  <0x3832 0x1>;
-reg-names = "g1", "g2", "ctrl";
-interrupts = ,
- ;
-interrupt-names = "g1", "g2";
+reg = <0x3830 0x1>;
+interrupts = ;
+interrupt-names = "g1";
+clocks = < IMX8MQ_CLK_VPU_G1_ROOT>,
+ < IMX8MQ_CLK_VPU_G2_ROOT>,
+ < IMX8MQ_CLK_VPU_DEC_ROOT>;
+clock-names = "g1", "g2", "bus";
+power-domains = <_vpu>;
+nxp,imx8mq-vpu-ctrl = <_ctrl>;
+};
+
+vpu_g2: video-codec@3831 {
+compatible = "nxp,imx8mq-vpu-g2";
+reg = <0x3830 0x1>;
+interrupts = ;
+interrupt-names = "g2";
 clocks = < IMX8MQ_CLK_VPU_G1_ROOT>,
  < IMX8MQ_CLK_VPU_G2_ROOT>,
  < IMX8MQ_CLK_VPU_DEC_ROOT>;
 clock-names = "g1", "g2", "bus";
 power-domains = <_vpu>;
+nxp,imx8mq-vpu-ctrl = <_ctrl>;
 };
-- 
2.25.1



[PATCH v5 01/13] dt-bindings: mfd: Add 'nxp,imx8mq-vpu-ctrl' to syscon list

2021-03-17 Thread Benjamin Gaignard
Add 'nxp,imx8mq-vpu-ctrl' in the list of possible syscon.
It will used to access to the VPU control registers.

Signed-off-by: Benjamin Gaignard 
---
 Documentation/devicetree/bindings/mfd/syscon.yaml | 1 +
 1 file changed, 1 insertion(+)

diff --git a/Documentation/devicetree/bindings/mfd/syscon.yaml 
b/Documentation/devicetree/bindings/mfd/syscon.yaml
index f14ae6da0068..ae22c4730613 100644
--- a/Documentation/devicetree/bindings/mfd/syscon.yaml
+++ b/Documentation/devicetree/bindings/mfd/syscon.yaml
@@ -44,6 +44,7 @@ properties:
   - hisilicon,peri-subctrl
   - microchip,sparx5-cpu-syscon
   - mstar,msc313-pmsleep
+  - nxp,imx8mq-vpu-ctrl
   - rockchip,px30-qos
   - rockchip,rk3066-qos
   - rockchip,rk3288-qos
-- 
2.25.1



[PATCH v5 00/13] Add HANTRO G2/HEVC decoder support for IMX8MQ

2021-03-17 Thread Benjamin Gaignard
 for unlimited opens: OK

Debug ioctls:
test VIDIOC_DBG_G/S_REGISTER: OK (Not Supported)
test VIDIOC_LOG_STATUS: OK (Not Supported)

Input ioctls:
test VIDIOC_G/S_TUNER/ENUM_FREQ_BANDS: OK (Not Supported)
test VIDIOC_G/S_FREQUENCY: OK (Not Supported)
test VIDIOC_S_HW_FREQ_SEEK: OK (Not Supported)
test VIDIOC_ENUMAUDIO: OK (Not Supported)
test VIDIOC_G/S/ENUMINPUT: OK (Not Supported)
test VIDIOC_G/S_AUDIO: OK (Not Supported)
Inputs: 0 Audio Inputs: 0 Tuners: 0

Output ioctls:
test VIDIOC_G/S_MODULATOR: OK (Not Supported)
test VIDIOC_G/S_FREQUENCY: OK (Not Supported)
test VIDIOC_ENUMAUDOUT: OK (Not Supported)
test VIDIOC_G/S/ENUMOUTPUT: OK (Not Supported)
test VIDIOC_G/S_AUDOUT: OK (Not Supported)
Outputs: 0 Audio Outputs: 0 Modulators: 0

Input/Output configuration ioctls:
test VIDIOC_ENUM/G/S/QUERY_STD: OK (Not Supported)
test VIDIOC_ENUM/G/S/QUERY_DV_TIMINGS: OK (Not Supported)
test VIDIOC_DV_TIMINGS_CAP: OK (Not Supported)
test VIDIOC_G/S_EDID: OK (Not Supported)

Control ioctls:
test VIDIOC_QUERY_EXT_CTRL/QUERYMENU: OK
test VIDIOC_QUERYCTRL: OK
test VIDIOC_G/S_CTRL: OK
test VIDIOC_G/S/TRY_EXT_CTRLS: OK
test VIDIOC_(UN)SUBSCRIBE_EVENT/DQEVENT: OK
test VIDIOC_G/S_JPEGCOMP: OK (Not Supported)
Standard Controls: 8 Private Controls: 1

Format ioctls:
test VIDIOC_ENUM_FMT/FRAMESIZES/FRAMEINTERVALS: OK
test VIDIOC_G/S_PARM: OK (Not Supported)
test VIDIOC_G_FBUF: OK (Not Supported)
test VIDIOC_G_FMT: OK
test VIDIOC_TRY_FMT: OK
test VIDIOC_S_FMT: OK
test VIDIOC_G_SLICED_VBI_CAP: OK (Not Supported)
test Cropping: OK (Not Supported)
test Composing: OK (Not Supported)
test Scaling: OK (Not Supported)

Codec ioctls:
test VIDIOC_(TRY_)ENCODER_CMD: OK (Not Supported)
test VIDIOC_G_ENC_INDEX: OK (Not Supported)
test VIDIOC_(TRY_)DECODER_CMD: OK (Not Supported)

Buffer ioctls:
test VIDIOC_REQBUFS/CREATE_BUFS/QUERYBUF: OK
test VIDIOC_EXPBUF: OK
test Requests: OK

Total for hantro-vpu device /dev/video1: 46, Succeeded: 46, Failed: 0, 
Warnings: 0

Grand Total for hantro-vpu device /dev/media1: 54, Succeeded: 54, Failed: 0, 
Warnings: 0

Benjamin

Benjamin Gaignard (13):
  dt-bindings: mfd: Add 'nxp,imx8mq-vpu-ctrl' to syscon list
  dt-bindings: media: nxp,imx8mq-vpu: Update the bindings for G2 support
  media: hantro: Use syscon instead of 'ctrl' register
  media: hevc: Add fields and flags for hevc PPS
  media: hevc: Add decode params control
  media: hantro: change hantro_codec_ops run prototype to return errors
  media: hantro: Define HEVC codec profiles and supported features
  media: hantro: Only use postproc when post processed formats are
defined
  media: uapi: Add a control for HANTRO driver
  media: hantro: handle V4L2_PIX_FMT_HEVC_SLICE control
  media: hantro: Introduce G2/HEVC decoder
  media: hantro: IMX8M: add variant for G2/HEVC codec
  arm64: dts: imx8mq: Add node to G2 hardware

 .../bindings/media/nxp,imx8mq-vpu.yaml|  53 +-
 .../devicetree/bindings/mfd/syscon.yaml   |   1 +
 .../userspace-api/media/drivers/hantro.rst|  14 +
 .../userspace-api/media/drivers/index.rst |   1 +
 .../media/v4l/ext-ctrls-codec.rst | 108 +++-
 .../media/v4l/vidioc-queryctrl.rst|   6 +
 arch/arm64/boot/dts/freescale/imx8mq.dtsi |  43 +-
 drivers/media/v4l2-core/v4l2-ctrls.c  |  26 +-
 drivers/staging/media/hantro/Makefile |   2 +
 drivers/staging/media/hantro/hantro.h |  18 +-
 drivers/staging/media/hantro/hantro_drv.c |  99 ++-
 .../staging/media/hantro/hantro_g1_h264_dec.c |  10 +-
 .../media/hantro/hantro_g1_mpeg2_dec.c|   4 +-
 .../staging/media/hantro/hantro_g1_vp8_dec.c  |   6 +-
 .../staging/media/hantro/hantro_g2_hevc_dec.c | 587 ++
 drivers/staging/media/hantro/hantro_g2_regs.h | 198 ++
 .../staging/media/hantro/hantro_h1_jpeg_enc.c |   4 +-
 drivers/staging/media/hantro/hantro_hevc.c| 324 ++
 drivers/staging/media/hantro/hantro_hw.h  |  69 +-
 .../staging/media/hantro/hantro_postproc.c|  14 +
 drivers/staging/media/hantro/hantro_v4l2.c|   5 +-
 drivers/staging/media/hantro/imx8m_vpu_hw.c   | 128 +++-
 .../media/hantro/rk3399_vpu_hw_jpeg_enc.c |   4 +-
 .../media/hantro/rk3399_vpu_hw_mpeg2_dec.c|   4 +-
 .../media/hantro/rk3399_vpu_hw_vp8_dec.c  |   6 +-
 drivers/staging/media/sunxi/cedrus/cedrus.c   |   6 +
 drivers/staging/media/sunxi/cedrus/cedrus.h   |   1 +
 .../staging/media/sunxi/cedrus/cedrus_dec.c   |   2 +
 .../staging/media/sunxi/cedrus/cedrus_h265.c  |   6 +-
 include/media/hevc-ctrls.h|  33 +-
 include/uapi/linux/v4l2-controls.h|  13 +
 31 files changed, 1678 insertions(+), 117 deletions(-)
 create mode

Re: [PATCH v4 07/11] media: hantro: Introduce G2/HEVC decoder

2021-03-16 Thread Benjamin Gaignard



Le 16/03/2021 à 19:46, Ezequiel Garcia a écrit :

Hi Benjamin,

The series is looking really good. Some comments below.

On Wed, 2021-03-03 at 12:39 +0100, Benjamin Gaignard wrote:

Implement all the logic to get G2 hardware decoding HEVC frames.
It support up level 5.1 HEVC stream.
It doesn't support yet 10 bits formats or scaling feature.

Add HANTRO HEVC dedicated control to skip some bits at the beginning
of the slice header. That is very specific to this hardware so can't
go into uapi structures. Compute the needed value is complex and require
information from the stream that only the userland knows so let it
provide the correct value to the driver.

Signed-off-by: Benjamin Gaignard 
---
version 4:
- fix Ezequiel comments
- use dedicated control as an integer
- change hantro_g2_hevc_dec_run prototype to return errors

version 2:
- squash multiple commits in this one.
- fix the comments done by Ezequiel about dma_alloc_coherent usage
- fix Dan's comments about control copy, reverse the test logic
in tile_buffer_reallocate, rework some goto and return cases.

  drivers/staging/media/hantro/Makefile |   2 +
  drivers/staging/media/hantro/hantro.h |  18 +
  drivers/staging/media/hantro/hantro_drv.c |  53 ++
  .../staging/media/hantro/hantro_g2_hevc_dec.c | 587 ++
  drivers/staging/media/hantro/hantro_g2_regs.h | 198 ++
  drivers/staging/media/hantro/hantro_hevc.c    | 321 ++
  drivers/staging/media/hantro/hantro_hw.h  |  49 ++
  7 files changed, 1228 insertions(+)
  create mode 100644 drivers/staging/media/hantro/hantro_g2_hevc_dec.c
  create mode 100644 drivers/staging/media/hantro/hantro_g2_regs.h
  create mode 100644 drivers/staging/media/hantro/hantro_hevc.c

diff --git a/drivers/staging/media/hantro/Makefile 
b/drivers/staging/media/hantro/Makefile
index 743ce08eb184..0357f1772267 100644
--- a/drivers/staging/media/hantro/Makefile
+++ b/drivers/staging/media/hantro/Makefile
@@ -9,12 +9,14 @@ hantro-vpu-y += \
 hantro_h1_jpeg_enc.o \
 hantro_g1_h264_dec.o \
 hantro_g1_mpeg2_dec.o \
+   hantro_g2_hevc_dec.o \
 hantro_g1_vp8_dec.o \
 rk3399_vpu_hw_jpeg_enc.o \
 rk3399_vpu_hw_mpeg2_dec.o \
 rk3399_vpu_hw_vp8_dec.o \
 hantro_jpeg.o \
 hantro_h264.o \
+   hantro_hevc.o \
 hantro_mpeg2.o \
 hantro_vp8.o
  
diff --git a/drivers/staging/media/hantro/hantro.h b/drivers/staging/media/hantro/hantro.h

index 05876e426419..a9b80b2c9124 100644
--- a/drivers/staging/media/hantro/hantro.h
+++ b/drivers/staging/media/hantro/hantro.h
@@ -225,6 +225,7 @@ struct hantro_dev {
   * @jpeg_enc:  JPEG-encoding context.
   * @mpeg2_dec: MPEG-2-decoding context.
   * @vp8_dec:   VP8-decoding context.
+ * @hevc_dec:  HEVC-decoding context.
   */
  struct hantro_ctx {
 struct hantro_dev *dev;
@@ -251,6 +252,7 @@ struct hantro_ctx {
 struct hantro_jpeg_enc_hw_ctx jpeg_enc;
 struct hantro_mpeg2_dec_hw_ctx mpeg2_dec;
 struct hantro_vp8_dec_hw_ctx vp8_dec;
+   struct hantro_hevc_dec_hw_ctx hevc_dec;
 };
  };
  
@@ -428,6 +430,22 @@ hantro_get_dec_buf_addr(struct hantro_ctx *ctx, struct vb2_buffer *vb)

 return vb2_dma_contig_plane_dma_addr(vb, 0);
  }
  
+static inline size_t

+hantro_get_dec_buf_size(struct hantro_ctx *ctx, struct vb2_buffer *vb)
+{
+   if (hantro_needs_postproc(ctx, ctx->vpu_dst_fmt))
+   return ctx->postproc.dec_q[vb->index].size;
+   return vb2_plane_size(vb, 0);
+}
+
+static inline void *
+hantro_get_dec_buf(struct hantro_ctx *ctx, struct vb2_buffer *vb)
+{
+   if (hantro_needs_postproc(ctx, ctx->vpu_dst_fmt))
+   return ctx->postproc.dec_q[vb->index].cpu;
+   return vb2_plane_vaddr(vb, 0);
+}
+

Seems hantro_get_dec_buf_size and hantro_get_dec_buf are not used?


You are right I will remove them




  void hantro_postproc_disable(struct hantro_ctx *ctx);
  void hantro_postproc_enable(struct hantro_ctx *ctx);
  void hantro_postproc_free(struct hantro_ctx *ctx);
diff --git a/drivers/staging/media/hantro/hantro_drv.c 
b/drivers/staging/media/hantro/hantro_drv.c
index e3e6df28f470..bc90a52f4d3d 100644
--- a/drivers/staging/media/hantro/hantro_drv.c
+++ b/drivers/staging/media/hantro/hantro_drv.c
@@ -30,6 +30,13 @@
  
  #define DRIVER_NAME "hantro-vpu"
  
+/*

+ * V4L2_CID_HANTRO_HEVC_SLICE_HEADER_SKIP -
+ * the number of data (in bits) to skip in the
+ * slice segment header syntax after 'slice type' token
+ */

I think we need to document this better, so applications can
correctly use the control. From i.MX reference code, it seems
this needs to be used as follows:

If non-IDR, the bits to be skipped go from syntax element "pic_output_flag"
to before syntax element &quo

Re: [PATCH v3 0/5] Reset driver for IMX8MQ VPU hardware block

2021-03-05 Thread Benjamin Gaignard



Le 03/03/2021 à 17:25, Philipp Zabel a écrit :

On Wed, 2021-03-03 at 16:20 +0100, Benjamin Gaignard wrote:

Le 03/03/2021 à 15:17, Philipp Zabel a écrit :

Hi Benjamin,

On Mon, 2021-03-01 at 16:17 +0100, Benjamin Gaignard wrote:

The two VPUs inside IMX8MQ share the same control block which can be see
as a reset hardware block.

This isn't a reset controller though. The control block also contains
clock gates of some sort and a filter register for the featureset fuses.
Those shouldn't be manipulated via the reset API.

They are all part of the control block and of the reset process for this
hardware that why I put them here. I guess it is border line :-)

I'm pushing back to keep the reset control framework focused on
controlling reset lines. Every side effect (such as the asymmetric clock
ungating) in a random driver makes it harder to reason about behaviour
at the API level, and to review patches for hardware I am not familiar
with.


In order to be able to add the second VPU (for HECV decoding) it will be
more handy if the both VPU drivers instance don't have to share the
control block registers. This lead to implement it as an independ reset
driver and to change the VPU driver to use it.

Why not switch to a syscon regmap for the control block? That should
also allow to keep backwards compatibility with the old binding with
minimal effort.

I will give a try in this direction.

Thank you.


Please note that this series break the compatibility between the DTB and
kernel. This break is limited to IMX8MQ SoC and is done when the driver
is still in staging directory.

I know in this case we are pretty sure there are no users of this
binding except for a staging driver, but it would still be nice to keep
support for the deprecated binding, to avoid the requirement of updating
kernel and DT in lock-step.

If I want to use a syscon (or a reset) the driver must not ioremap the "ctrl"
registers. It means that "ctrl" has to be removed from the driver requested
reg-names (imx8mq_reg_names[]). Doing that break the kernel/DT compatibility.
Somehow syscon and "ctrl" are exclusive.

The way the driver is set up currently, yes. You could add a bit of
platform specific probe code, though, that would set up the regmap
either by calling
syscon_regmap_lookup_by_phandle();
for the new binding, or, if the phandle is not available, fall back to
platform_get_resource_byname(..., "ctrl");
devm_ioremap_resource();
devm_regmap_init_mmio();
for the old binding.
The actual codec .reset and variant .runtime_resume ops could be
identical then.


I made it works with syscon and your proposal.
The next version of the patches will be without reset and won't break
DT compatibility.

Thanks for your help,
Benjamin



regards
Philipp



Re: [PATCH v4 09/11] media: hantro: IMX8M: add variant for G2/HEVC codec

2021-03-05 Thread Benjamin Gaignard



Le 03/03/2021 à 23:08, Ezequiel Garcia a écrit :

On Wed, 2021-03-03 at 12:39 +0100, Benjamin Gaignard wrote:

Add variant to IMX8M to enable G2/HEVC codec.
Define the capabilities for the hardware up to 3840x2160.
Retrieve the hardware version at init to distinguish G1 from G2.

Signed-off-by: Benjamin Gaignard 
---
version 2:
- remove useless clocks

  drivers/staging/media/hantro/hantro_drv.c   |  1 +
  drivers/staging/media/hantro/hantro_hw.h    |  1 +
  drivers/staging/media/hantro/imx8m_vpu_hw.c | 95 -
  3 files changed, 93 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/media/hantro/hantro_drv.c 
b/drivers/staging/media/hantro/hantro_drv.c
index bc90a52f4d3d..976be7b6ecfb 100644
--- a/drivers/staging/media/hantro/hantro_drv.c
+++ b/drivers/staging/media/hantro/hantro_drv.c
@@ -591,6 +591,7 @@ static const struct of_device_id of_hantro_match[] = {
  #endif
  #ifdef CONFIG_VIDEO_HANTRO_IMX8M
 { .compatible = "nxp,imx8mq-vpu", .data = _vpu_variant, },
+   { .compatible = "nxp,imx8mq-vpu-g2", .data = _vpu_g2_variant },
  #endif
 { /* sentinel */ }
  };
diff --git a/drivers/staging/media/hantro/hantro_hw.h 
b/drivers/staging/media/hantro/hantro_hw.h
index dade3b0769c1..f61f58da05fe 100644
--- a/drivers/staging/media/hantro/hantro_hw.h
+++ b/drivers/staging/media/hantro/hantro_hw.h
@@ -193,6 +193,7 @@ extern const struct hantro_variant rk3399_vpu_variant;
  extern const struct hantro_variant rk3328_vpu_variant;
  extern const struct hantro_variant rk3288_vpu_variant;
  extern const struct hantro_variant imx8mq_vpu_variant;
+extern const struct hantro_variant imx8mq_vpu_g2_variant;
  
  extern const struct hantro_postproc_regs hantro_g1_postproc_regs;
  
diff --git a/drivers/staging/media/hantro/imx8m_vpu_hw.c b/drivers/staging/media/hantro/imx8m_vpu_hw.c

index d5b4312b9391..46b33531be85 100644
--- a/drivers/staging/media/hantro/imx8m_vpu_hw.c
+++ b/drivers/staging/media/hantro/imx8m_vpu_hw.c
@@ -12,6 +12,7 @@
  #include "hantro.h"
  #include "hantro_jpeg.h"
  #include "hantro_g1_regs.h"
+#include "hantro_g2_regs.h"
  
  static int imx8mq_runtime_resume(struct hantro_dev *vpu)

  {
@@ -90,6 +91,26 @@ static const struct hantro_fmt imx8m_vpu_dec_fmts[] = {
 },
  };
  
+static const struct hantro_fmt imx8m_vpu_g2_dec_fmts[] = {

+   {
+   .fourcc = V4L2_PIX_FMT_NV12,
+   .codec_mode = HANTRO_MODE_NONE,
+   },
+   {
+   .fourcc = V4L2_PIX_FMT_HEVC_SLICE,
+   .codec_mode = HANTRO_MODE_HEVC_DEC,
+   .max_depth = 2,
+   .frmsize = {
+   .min_width = 48,
+   .max_width = 3840,
+   .step_width = MB_DIM,
+   .min_height = 48,
+   .max_height = 2160,
+   .step_height = MB_DIM,
+   },
+   },
+};
+
  static irqreturn_t imx8m_vpu_g1_irq(int irq, void *dev_id)
  {
 struct hantro_dev *vpu = dev_id;
@@ -108,9 +129,42 @@ static irqreturn_t imx8m_vpu_g1_irq(int irq, void *dev_id)
 return IRQ_HANDLED;
  }
  
+static irqreturn_t imx8m_vpu_g2_irq(int irq, void *dev_id)

+{
+   struct hantro_dev *vpu = dev_id;
+   enum vb2_buffer_state state;
+   u32 status;
+
+   status = vdpu_read(vpu, HEVC_REG_INTERRUPT);
+   state = (status & HEVC_REG_INTERRUPT_DEC_RDY_INT) ?
+    VB2_BUF_STATE_DONE : VB2_BUF_STATE_ERROR;
+
+   vdpu_write(vpu, 0, HEVC_REG_INTERRUPT);
+   vdpu_write(vpu, HEVC_REG_CONFIG_DEC_CLK_GATE_E, HEVC_REG_CONFIG);

Is this clock gate enable needed on each interrupt?


Yes because if a reset as occur after init, it is the only
platform specific piece of code that is called.




+
+   hantro_irq_done(vpu, state);
+
+   return IRQ_HANDLED;
+}
+
  static int imx8mq_vpu_hw_init(struct hantro_dev *vpu)
  {
-   vpu->dec_base = vpu->reg_bases[0];
+   int ret;
+
+   /* Check variant version */
+   ret = clk_bulk_prepare_enable(vpu->variant->num_clocks, vpu->clocks);
+   if (ret) {
+   dev_err(vpu->dev, "Failed to enable clocks\n");
+   return ret;
+   }
+
+   /* Make that the device has been reset before read it id */
+   ret = device_reset(vpu->dev);
+   if (ret)
+   dev_err(vpu->dev, "Failed to reset Hantro VPU\n");
+
+   vpu->core_hw_dec_rev = (vdpu_read(vpu, HEVC_REG_VERSION) >> 16) & 
0x;
+   clk_bulk_disable_unprepare(vpu->variant->num_clocks, vpu->clocks);
  
 return 0;

  }
@@ -149,17 +203,32 @@ static const struct hantro_codec_ops 
imx8mq_vpu_codec_ops[] = {
 },
  };
  
+static const struct hantro_codec_ops imx8mq_vpu_g2_codec_ops[] = {

+   [HANTRO_MODE_HEVC_DEC] = {
+   .run = hantro_g2_hevc_dec_run,
+  

Re: [PATCH v4 05/11] media: hantro: Add a field to distinguish the hardware versions

2021-03-05 Thread Benjamin Gaignard



Le 03/03/2021 à 23:05, Ezequiel Garcia a écrit :

On Wed, 2021-03-03 at 12:39 +0100, Benjamin Gaignard wrote:

Decoders hardware blocks could exist in multiple versions: add
a field to distinguish them at runtime.
G2 hardware block doesn't have postprocessor hantro_needs_postproc
function should always returns false in for this hardware.
hantro_needs_postproc function becoming to much complex to
stay inline in .h file move it to .c file.


Note that I already questioned this patch before:

https://lkml.org/lkml/2021/2/17/722

I think it's better to rely on of_device_id.data for this
type of thing.

In particular, I was expecting that just using
hantro_variant.postproc_regs would be enough.

Can you try if that works and avoid reading swreg(0)
and probing the hardware core?


I have found a way to remove this: if the variant doesn't define
post processor formats, needs_postproc function will always returns
false and that what the only useful usage of this version field.

Benjamin



Thanks!
Ezequiel


Keep the default behavoir to be G1 hardware.

Signed-off-by: Benjamin Gaignard 
---
  drivers/staging/media/hantro/hantro.h  | 13 +++--
  drivers/staging/media/hantro/hantro_drv.c  |  2 ++
  drivers/staging/media/hantro/hantro_postproc.c | 17 +
  3 files changed, 26 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/media/hantro/hantro.h 
b/drivers/staging/media/hantro/hantro.h
index a76a0d79db9f..05876e426419 100644
--- a/drivers/staging/media/hantro/hantro.h
+++ b/drivers/staging/media/hantro/hantro.h
@@ -37,6 +37,9 @@ struct hantro_codec_ops;
  #define HANTRO_HEVC_DECODERBIT(19)
  #define HANTRO_DECODERS0x
  
+#define HANTRO_G1_REV  0x6731

+#define HANTRO_G2_REV  0x6732
+
  /**
   * struct hantro_irq - irq handler and name
   *
@@ -171,6 +174,7 @@ hantro_vdev_to_func(struct video_device *vdev)
   * @enc_base:  Mapped address of VPU encoder register for convenience.
   * @dec_base:  Mapped address of VPU decoder register for convenience.
   * @ctrl_base: Mapped address of VPU control block.
+ * @core_hw_dec_revRuntime detected HW decoder core revision
   * @vpu_mutex: Mutex to synchronize V4L2 calls.
   * @irqlock:   Spinlock to synchronize access to data structures
   * shared with interrupt handlers.
@@ -190,6 +194,7 @@ struct hantro_dev {
 void __iomem *enc_base;
 void __iomem *dec_base;
 void __iomem *ctrl_base;
+   u32 core_hw_dec_rev;
  
 struct mutex vpu_mutex; /* video_device lock */

 spinlock_t irqlock;
@@ -412,12 +417,8 @@ hantro_get_dst_buf(struct hantro_ctx *ctx)
 return v4l2_m2m_next_dst_buf(ctx->fh.m2m_ctx);
  }
  
-static inline bool

-hantro_needs_postproc(const struct hantro_ctx *ctx,
- const struct hantro_fmt *fmt)
-{
-   return !ctx->is_encoder && fmt->fourcc != V4L2_PIX_FMT_NV12;
-}
+bool hantro_needs_postproc(const struct hantro_ctx *ctx,
+  const struct hantro_fmt *fmt);
  
  static inline dma_addr_t

  hantro_get_dec_buf_addr(struct hantro_ctx *ctx, struct vb2_buffer *vb)
diff --git a/drivers/staging/media/hantro/hantro_drv.c 
b/drivers/staging/media/hantro/hantro_drv.c
index f0b68e16fcc0..e3e6df28f470 100644
--- a/drivers/staging/media/hantro/hantro_drv.c
+++ b/drivers/staging/media/hantro/hantro_drv.c
@@ -836,6 +836,8 @@ static int hantro_probe(struct platform_device *pdev)
 }
 vpu->enc_base = vpu->reg_bases[0] + vpu->variant->enc_offset;
 vpu->dec_base = vpu->reg_bases[0] + vpu->variant->dec_offset;
+   /* by default decoder is G1 */
+   vpu->core_hw_dec_rev = HANTRO_G1_REV;
  
 ret = dma_set_coherent_mask(vpu->dev, DMA_BIT_MASK(32));

 if (ret) {
diff --git a/drivers/staging/media/hantro/hantro_postproc.c 
b/drivers/staging/media/hantro/hantro_postproc.c
index 6d2a8f2a8f0b..050880f720d6 100644
--- a/drivers/staging/media/hantro/hantro_postproc.c
+++ b/drivers/staging/media/hantro/hantro_postproc.c
@@ -50,6 +50,23 @@ const struct hantro_postproc_regs hantro_g1_postproc_regs = {
 .display_width = {G1_REG_PP_DISPLAY_WIDTH, 0, 0xfff},
  };
  
+bool hantro_needs_postproc(const struct hantro_ctx *ctx,

+  const struct hantro_fmt *fmt)
+{
+   struct hantro_dev *vpu = ctx->dev;
+
+   if (ctx->is_encoder)
+   return false;
+
+   if (vpu->core_hw_dec_rev == HANTRO_G1_REV):q
+   return fmt->fourcc != V4L2_PIX_FMT_NV12;
+
+   if (vpu->core_hw_dec_rev == HANTRO_G2_REV)
+   return false;
+
+   return false;
+}
+
  void hantro_postproc_enable(struct hantro_ctx *ctx)
  {
 struct hantro_dev *vpu = ctx->dev;





Re: [PATCH v4 03/11] media: hantro: change hantro_codec_ops run prototype to return errors

2021-03-05 Thread Benjamin Gaignard



Le 03/03/2021 à 22:56, Ezequiel Garcia a écrit :

On Wed, 2021-03-03 at 12:39 +0100, Benjamin Gaignard wrote:

Change hantro_codec_ops run prototype from 'void' to 'int'.
This allow to cancel the job if an error occur while configuring
the hardware.

Signed-off-by: Benjamin Gaignard 
---
  drivers/staging/media/hantro/hantro_drv.c |  4 +++-
  .../staging/media/hantro/hantro_g1_h264_dec.c |  6 --
  .../media/hantro/hantro_g1_mpeg2_dec.c    |  4 +++-
  .../staging/media/hantro/hantro_g1_vp8_dec.c  |  6 --
  .../staging/media/hantro/hantro_h1_jpeg_enc.c |  4 +++-
  drivers/staging/media/hantro/hantro_hw.h  | 19 ++-
  .../media/hantro/rk3399_vpu_hw_jpeg_enc.c |  4 +++-
  .../media/hantro/rk3399_vpu_hw_mpeg2_dec.c    |  4 +++-
  .../media/hantro/rk3399_vpu_hw_vp8_dec.c  |  6 --
  9 files changed, 37 insertions(+), 20 deletions(-)

diff --git a/drivers/staging/media/hantro/hantro_drv.c 
b/drivers/staging/media/hantro/hantro_drv.c
index e5f200e64993..ac1429f00b33 100644
--- a/drivers/staging/media/hantro/hantro_drv.c
+++ b/drivers/staging/media/hantro/hantro_drv.c
@@ -161,7 +161,9 @@ static void device_run(void *priv)
  
 v4l2_m2m_buf_copy_metadata(src, dst, true);
  
-   ctx->codec_ops->run(ctx);

+   if (ctx->codec_ops->run(ctx))
+   goto err_cancel_job;
+
 return;
  
  err_cancel_job:

diff --git a/drivers/staging/media/hantro/hantro_g1_h264_dec.c 
b/drivers/staging/media/hantro/hantro_g1_h264_dec.c
index 845bef73d218..fcd4db13c9fe 100644
--- a/drivers/staging/media/hantro/hantro_g1_h264_dec.c
+++ b/drivers/staging/media/hantro/hantro_g1_h264_dec.c
@@ -273,13 +273,13 @@ static void set_buffers(struct hantro_ctx *ctx)
 vdpu_write_relaxed(vpu, ctx->h264_dec.priv.dma, G1_REG_ADDR_QTABLE);
  }
  
-void hantro_g1_h264_dec_run(struct hantro_ctx *ctx)

+int hantro_g1_h264_dec_run(struct hantro_ctx *ctx)
  {
 struct hantro_dev *vpu = ctx->dev;
  
 /* Prepare the H264 decoder context. */

 if (hantro_h264_dec_prepare_run(ctx))
-   return;
+   return -EINVAL;

This should be returning the value from hantro_h264_dec_prepare_run.


That will be fixed in the next version, thanks

Benjamin



Thanks!
Ezequiel



Re: [PATCH v3 0/5] Reset driver for IMX8MQ VPU hardware block

2021-03-03 Thread Benjamin Gaignard



Le 03/03/2021 à 15:17, Philipp Zabel a écrit :

Hi Benjamin,

On Mon, 2021-03-01 at 16:17 +0100, Benjamin Gaignard wrote:

The two VPUs inside IMX8MQ share the same control block which can be see
as a reset hardware block.

This isn't a reset controller though. The control block also contains
clock gates of some sort and a filter register for the featureset fuses.
Those shouldn't be manipulated via the reset API.


They are all part of the control block and of the reset process for this
hardware that why I put them here. I guess it is border line :-)




In order to be able to add the second VPU (for HECV decoding) it will be
more handy if the both VPU drivers instance don't have to share the
control block registers. This lead to implement it as an independ reset
driver and to change the VPU driver to use it.

Why not switch to a syscon regmap for the control block? That should
also allow to keep backwards compatibility with the old binding with
minimal effort.


I will give a try in this direction.




Please note that this series break the compatibility between the DTB and
kernel. This break is limited to IMX8MQ SoC and is done when the driver
is still in staging directory.

I know in this case we are pretty sure there are no users of this
binding except for a staging driver, but it would still be nice to keep
support for the deprecated binding, to avoid the requirement of updating
kernel and DT in lock-step.


If I want to use a syscon (or a reset) the driver must not ioremap the "ctrl"
registers. It means that "ctrl" has to be removed from the driver requested
reg-names (imx8mq_reg_names[]). Doing that break the kernel/DT compatibility.
Somehow syscon and "ctrl" are exclusive.

Benjamin



regards
Philipp



Re: [PATCH v3 4/5] media: hantro: Use reset driver

2021-03-03 Thread Benjamin Gaignard



Le 03/03/2021 à 15:39, Philipp Zabel a écrit :

On Mon, 2021-03-01 at 16:17 +0100, Benjamin Gaignard wrote:

Rather use a reset like feature inside the driver use the reset
controller API to get the same result.

Signed-off-by: Benjamin Gaignard 
---
  drivers/staging/media/hantro/Kconfig|  1 +
  drivers/staging/media/hantro/imx8m_vpu_hw.c | 61 -
  2 files changed, 12 insertions(+), 50 deletions(-)

diff --git a/drivers/staging/media/hantro/Kconfig 
b/drivers/staging/media/hantro/Kconfig
index 5b6cf9f62b1a..dd1d4dde2658 100644
--- a/drivers/staging/media/hantro/Kconfig
+++ b/drivers/staging/media/hantro/Kconfig
@@ -20,6 +20,7 @@ config VIDEO_HANTRO_IMX8M
bool "Hantro VPU i.MX8M support"
depends on VIDEO_HANTRO
depends on ARCH_MXC || COMPILE_TEST
+   select RESET_VPU_IMX8MQ
default y
help
  Enable support for i.MX8M SoCs.
diff --git a/drivers/staging/media/hantro/imx8m_vpu_hw.c 
b/drivers/staging/media/hantro/imx8m_vpu_hw.c
index c222de075ef4..d5b4312b9391 100644
--- a/drivers/staging/media/hantro/imx8m_vpu_hw.c
+++ b/drivers/staging/media/hantro/imx8m_vpu_hw.c
@@ -7,49 +7,12 @@
  
  #include 

  #include 
+#include 
  
  #include "hantro.h"

  #include "hantro_jpeg.h"
  #include "hantro_g1_regs.h"
  
-#define CTRL_SOFT_RESET		0x00

-#define RESET_G1   BIT(1)
-#define RESET_G2   BIT(0)
-
-#define CTRL_CLOCK_ENABLE  0x04
-#define CLOCK_G1   BIT(1)
-#define CLOCK_G2   BIT(0)
-
-#define CTRL_G1_DEC_FUSE   0x08
-#define CTRL_G1_PP_FUSE0x0c
-#define CTRL_G2_DEC_FUSE   0x10
-
-static void imx8m_soft_reset(struct hantro_dev *vpu, u32 reset_bits)
-{
-   u32 val;
-
-   /* Assert */
-   val = readl(vpu->ctrl_base + CTRL_SOFT_RESET);
-   val &= ~reset_bits;
-   writel(val, vpu->ctrl_base + CTRL_SOFT_RESET);
-
-   udelay(2);
-
-   /* Release */
-   val = readl(vpu->ctrl_base + CTRL_SOFT_RESET);
-   val |= reset_bits;
-   writel(val, vpu->ctrl_base + CTRL_SOFT_RESET);
-}
-
-static void imx8m_clk_enable(struct hantro_dev *vpu, u32 clock_bits)
-{
-   u32 val;
-
-   val = readl(vpu->ctrl_base + CTRL_CLOCK_ENABLE);
-   val |= clock_bits;
-   writel(val, vpu->ctrl_base + CTRL_CLOCK_ENABLE);

The way it is implemented in the reset driver, the clocks are now
ungated between assert and deassert instead of afterwards. Is this on
purpose?


No and that could be changed on next version.

Benjamin



regards
Philipp



[PATCH v4 01/11] media: hevc: Add fields and flags for hevc PPS

2021-03-03 Thread Benjamin Gaignard
Add fields and flags as they are defined in
7.4.3.3.1 "General picture parameter set RBSP semantics of the
H.265 ITU specification.

Signed-off-by: Benjamin Gaignard 
---
 .../userspace-api/media/v4l/ext-ctrls-codec.rst| 14 ++
 include/media/hevc-ctrls.h |  4 
 2 files changed, 18 insertions(+)

diff --git a/Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst 
b/Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst
index 00944e97d638..d62e8e423f3b 100644
--- a/Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst
+++ b/Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst
@@ -3234,6 +3234,12 @@ enum v4l2_mpeg_video_hevc_size_of_length_field -
 * - __u8
   - ``num_extra_slice_header_bits``
   -
+* - __u8
+  - ``num_ref_idx_l0_default_active_minus1``
+  - Specifies the inferred value of num_ref_idx_l0_active_minus1
+* - __u8
+  - ``num_ref_idx_l1_default_active_minus1``
+  - Specifies the inferred value of num_ref_idx_l1_active_minus1
 * - __s8
   - ``init_qp_minus26``
   -
@@ -3342,6 +3348,14 @@ enum v4l2_mpeg_video_hevc_size_of_length_field -
 * - ``V4L2_HEVC_PPS_FLAG_SLICE_SEGMENT_HEADER_EXTENSION_PRESENT``
   - 0x0004
   -
+* - ``V4L2_HEVC_PPS_FLAG_DEBLOCKING_FILTER_CONTROL_PRESENT``
+  - 0x0008
+  - Specifies the presence of deblocking filter control syntax elements in
+the PPS
+* - ``V4L2_HEVC_PPS_FLAG_UNIFORM_SPACING``
+  - 0x0010
+  - Specifies that tile column boundaries and likewise tile row boundaries
+are distributed uniformly across the picture
 
 ``V4L2_CID_MPEG_VIDEO_HEVC_SLICE_PARAMS (struct)``
 Specifies various slice-specific parameters, especially from the NAL unit
diff --git a/include/media/hevc-ctrls.h b/include/media/hevc-ctrls.h
index b4cb2ef02f17..003f819ecb26 100644
--- a/include/media/hevc-ctrls.h
+++ b/include/media/hevc-ctrls.h
@@ -100,10 +100,14 @@ struct v4l2_ctrl_hevc_sps {
 #define V4L2_HEVC_PPS_FLAG_PPS_DISABLE_DEBLOCKING_FILTER   (1ULL << 16)
 #define V4L2_HEVC_PPS_FLAG_LISTS_MODIFICATION_PRESENT  (1ULL << 17)
 #define V4L2_HEVC_PPS_FLAG_SLICE_SEGMENT_HEADER_EXTENSION_PRESENT (1ULL << 18)
+#define V4L2_HEVC_PPS_FLAG_DEBLOCKING_FILTER_CONTROL_PRESENT   (1ULL << 19)
+#define V4L2_HEVC_PPS_FLAG_UNIFORM_SPACING (1ULL << 20)
 
 struct v4l2_ctrl_hevc_pps {
/* ISO/IEC 23008-2, ITU-T Rec. H.265: Picture parameter set */
__u8num_extra_slice_header_bits;
+   __u8num_ref_idx_l0_default_active_minus1;
+   __u8num_ref_idx_l1_default_active_minus1;
__s8init_qp_minus26;
__u8diff_cu_qp_delta_depth;
__s8pps_cb_qp_offset;
-- 
2.25.1



[PATCH v4 00/11] Add HANTRO G2/HEVC decoder support for IMX8MQ

2021-03-03 Thread Benjamin Gaignard
The IMX8MQ got two VPUs but until now only G1 has been enabled.
This series aim to add the second VPU (aka G2) and provide basic 
HEVC decoding support.

To be able to decode HEVC it is needed to add/update some of the
structures in the uapi. In addition of them one HANTRO dedicated
control is required to inform the driver of the numbre of bits to skip
at the beginning of the slice header.
The hardware require to allocate few auxiliary buffers to store the
references frame or tile size data.

The driver has been tested with fluster test suite stream.
For example with this command: ./fluster.py run -ts JCT-VC-HEVC_V1 -d 
GStreamer-H.265-V4L2SL-Gst1.0
 
This series depends of the reset rework posted here: 
https://www.spinics.net/lists/arm-kernel/msg878440.html

Finally the both VPUs will have a node the device-tree and be
independent from v4l2 point of view.

A branch with all the dev is available here:
https://gitlab.collabora.com/benjamin.gaignard/for-upstream/-/commits/upstream_g2_v4

version 4:
- Split the changes in hevc controls in 2 commits to make them easier to
  review.
- Change hantro_codec_ops run() prototype to return errors   
- Hantro v4l2 dedicated control is now only an integer
- rebase on top of VPU reset changes posted here:
  https://www.spinics.net/lists/arm-kernel/msg878440.html
- Various fix from previous remarks
- Limit the modifications in API to what the driver needs

version 3:
- Fix typo in Hantro v4l2 dedicated control
- Add documentation for the new structures and fields
- Rebased on top of media_tree for-linus-5.12-rc1 tag

version 2:
- remove all change related to scaling
- squash commits to a coherent split
- be more verbose about the added fields
- fix the comments done by Ezequiel about dma_alloc_coherent usage
- fix Dan's comments about control copy, reverse the test logic
in tile_buffer_reallocate, rework some goto and return cases.
- be more verbose about why I change the bindings
- remove all sign-off expect mime since it is confusing
- remove useless clocks in VPUs nodes

Benjamin

Benjamin Gaignard (11):
  media: hevc: Add fields and flags for hevc PPS
  media: hevc: Add decode params control
  media: hantro: change hantro_codec_ops run prototype to return errors
  media: hantro: Define HEVC codec profiles and supported features
  media: hantro: Add a field to distinguish the hardware versions
  media: uapi: Add a control for HANTRO driver
  media: hantro: Introduce G2/HEVC decoder
  media: hantro: handle V4L2_PIX_FMT_HEVC_SLICE control
  media: hantro: IMX8M: add variant for G2/HEVC codec
  dt-bindings: media: nxp,imx8mq-vpu: Update bindings
  arm64: dts: imx8mq: Add node to G2 hardware

 .../bindings/media/nxp,imx8mq-vpu.yaml|  46 +-
 .../userspace-api/media/drivers/hantro.rst|  10 +
 .../userspace-api/media/drivers/index.rst |   1 +
 .../media/v4l/ext-ctrls-codec.rst | 108 +++-
 .../media/v4l/vidioc-queryctrl.rst|   6 +
 arch/arm64/boot/dts/freescale/imx8mq.dtsi |  41 +-
 drivers/media/v4l2-core/v4l2-ctrls.c  |  26 +-
 drivers/staging/media/hantro/Makefile |   2 +
 drivers/staging/media/hantro/hantro.h |  34 +-
 drivers/staging/media/hantro/hantro_drv.c | 118 +++-
 .../staging/media/hantro/hantro_g1_h264_dec.c |   6 +-
 .../media/hantro/hantro_g1_mpeg2_dec.c|   4 +-
 .../staging/media/hantro/hantro_g1_vp8_dec.c  |   6 +-
 .../staging/media/hantro/hantro_g2_hevc_dec.c | 587 ++
 drivers/staging/media/hantro/hantro_g2_regs.h | 198 ++
 .../staging/media/hantro/hantro_h1_jpeg_enc.c |   4 +-
 drivers/staging/media/hantro/hantro_hevc.c| 321 ++
 drivers/staging/media/hantro/hantro_hw.h  |  69 +-
 .../staging/media/hantro/hantro_postproc.c|  17 +
 drivers/staging/media/hantro/hantro_v4l2.c|   1 +
 drivers/staging/media/hantro/imx8m_vpu_hw.c   |  95 ++-
 .../media/hantro/rk3399_vpu_hw_jpeg_enc.c |   4 +-
 .../media/hantro/rk3399_vpu_hw_mpeg2_dec.c|   4 +-
 .../media/hantro/rk3399_vpu_hw_vp8_dec.c  |   6 +-
 drivers/staging/media/sunxi/cedrus/cedrus.c   |   6 +
 drivers/staging/media/sunxi/cedrus/cedrus.h   |   1 +
 .../staging/media/sunxi/cedrus/cedrus_dec.c   |   2 +
 .../staging/media/sunxi/cedrus/cedrus_h265.c  |   6 +-
 include/media/hevc-ctrls.h|  33 +-
 include/uapi/linux/v4l2-controls.h|   5 +
 30 files changed, 1675 insertions(+), 92 deletions(-)
 create mode 100644 Documentation/userspace-api/media/drivers/hantro.rst
 create mode 100644 drivers/staging/media/hantro/hantro_g2_hevc_dec.c
 create mode 100644 drivers/staging/media/hantro/hantro_g2_regs.h
 create mode 100644 drivers/staging/media/hantro/hantro_hevc.c

-- 
2.25.1



[PATCH v4 08/11] media: hantro: handle V4L2_PIX_FMT_HEVC_SLICE control

2021-03-03 Thread Benjamin Gaignard
Make sure that V4L2_PIX_FMT_HEVC_SLICE is correctly handle by v4l2
of the driver.

Signed-off-by: Benjamin Gaignard 
---
 drivers/staging/media/hantro/hantro_v4l2.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/staging/media/hantro/hantro_v4l2.c 
b/drivers/staging/media/hantro/hantro_v4l2.c
index 1bc118e375a1..e16d5fd0b9f7 100644
--- a/drivers/staging/media/hantro/hantro_v4l2.c
+++ b/drivers/staging/media/hantro/hantro_v4l2.c
@@ -390,6 +390,7 @@ hantro_update_requires_request(struct hantro_ctx *ctx, u32 
fourcc)
case V4L2_PIX_FMT_MPEG2_SLICE:
case V4L2_PIX_FMT_VP8_FRAME:
case V4L2_PIX_FMT_H264_SLICE:
+   case V4L2_PIX_FMT_HEVC_SLICE:
ctx->fh.m2m_ctx->out_q_ctx.q.requires_requests = true;
break;
default:
-- 
2.25.1



[PATCH v4 11/11] arm64: dts: imx8mq: Add node to G2 hardware

2021-03-03 Thread Benjamin Gaignard
Split VPU node in two: one for G1 and one for G2 since they are
different hardware blocks.

Signed-off-by: Benjamin Gaignard 
---
version 4:
- rebase the change on top of VPU reset patches:
  https://www.spinics.net/lists/arm-kernel/msg878440.html

version 2:
- remove useless clocks in VPUs nodes

 arch/arm64/boot/dts/freescale/imx8mq.dtsi | 41 +--
 1 file changed, 31 insertions(+), 10 deletions(-)

diff --git a/arch/arm64/boot/dts/freescale/imx8mq.dtsi 
b/arch/arm64/boot/dts/freescale/imx8mq.dtsi
index d9d9efc8592d..8358e214d696 100644
--- a/arch/arm64/boot/dts/freescale/imx8mq.dtsi
+++ b/arch/arm64/boot/dts/freescale/imx8mq.dtsi
@@ -1287,17 +1287,15 @@ vpu_reset: vpu-reset@3832 {
#reset-cells = <1>;
};
 
-   vpu: video-codec@3830 {
+   vpu_g1: video-codec@3830 {
compatible = "nxp,imx8mq-vpu";
-   reg = <0x3830 0x1>,
- <0x3831 0x1>;
-   reg-names = "g1", "g2";
-   interrupts = ,
-;
-   interrupt-names = "g1", "g2";
+   reg = <0x3830 0x1>;
+   reg-names = "g1";
+   interrupts = ;
+   interrupt-names = "g1";
clocks = < IMX8MQ_CLK_VPU_G1_ROOT>,
-< IMX8MQ_CLK_VPU_G2_ROOT>;
-   clock-names = "g1", "g2";
+< IMX8MQ_CLK_VPU_DEC_ROOT>;
+   clock-names = "g1", "bus";
assigned-clocks = < IMX8MQ_CLK_VPU_G1>,
  < IMX8MQ_CLK_VPU_G2>,
  < IMX8MQ_CLK_VPU_BUS>,
@@ -1306,12 +1304,35 @@ vpu: video-codec@3830 {
 < IMX8MQ_VPU_PLL_OUT>,
 < IMX8MQ_SYS1_PLL_800M>,
 < IMX8MQ_VPU_PLL>;
-   assigned-clock-rates = <6>, <6>,
+   assigned-clock-rates = <6>, <3>,
   <8>, <0>;
resets = <_reset IMX8MQ_RESET_VPU_RESET_G1>;
power-domains = <_vpu>;
};
 
+   vpu_g2: video-codec@3831 {
+   compatible = "nxp,imx8mq-vpu-g2";
+   reg = <0x3831 0x1>;
+   reg-names = "g2";
+   interrupts = ;
+   interrupt-names = "g2";
+   clocks = < IMX8MQ_CLK_VPU_G2_ROOT>,
+< IMX8MQ_CLK_VPU_DEC_ROOT>;
+   clock-names = "g2",  "bus";
+   assigned-clocks = < IMX8MQ_CLK_VPU_G1>,
+ < IMX8MQ_CLK_VPU_G2>,
+ < IMX8MQ_CLK_VPU_BUS>,
+ < IMX8MQ_VPU_PLL_BYPASS>;
+   assigned-clock-parents = < IMX8MQ_VPU_PLL_OUT>,
+< IMX8MQ_VPU_PLL_OUT>,
+< IMX8MQ_SYS1_PLL_800M>,
+< IMX8MQ_VPU_PLL>;
+   assigned-clock-rates = <6>, <3>,
+  <8>, <0>;
+   resets = <_reset IMX8MQ_RESET_VPU_RESET_G2>;
+   power-domains = <_vpu>;
+   };
+
pcie0: pcie@3380 {
compatible = "fsl,imx8mq-pcie";
reg = <0x3380 0x40>,
-- 
2.25.1



[PATCH v4 07/11] media: hantro: Introduce G2/HEVC decoder

2021-03-03 Thread Benjamin Gaignard
Implement all the logic to get G2 hardware decoding HEVC frames.
It support up level 5.1 HEVC stream.
It doesn't support yet 10 bits formats or scaling feature.

Add HANTRO HEVC dedicated control to skip some bits at the beginning
of the slice header. That is very specific to this hardware so can't
go into uapi structures. Compute the needed value is complex and require
information from the stream that only the userland knows so let it
provide the correct value to the driver.

Signed-off-by: Benjamin Gaignard 
---
version 4:
- fix Ezequiel comments
- use dedicated control as an integer
- change hantro_g2_hevc_dec_run prototype to return errors

version 2:
- squash multiple commits in this one.
- fix the comments done by Ezequiel about dma_alloc_coherent usage
- fix Dan's comments about control copy, reverse the test logic
in tile_buffer_reallocate, rework some goto and return cases.

 drivers/staging/media/hantro/Makefile |   2 +
 drivers/staging/media/hantro/hantro.h |  18 +
 drivers/staging/media/hantro/hantro_drv.c |  53 ++
 .../staging/media/hantro/hantro_g2_hevc_dec.c | 587 ++
 drivers/staging/media/hantro/hantro_g2_regs.h | 198 ++
 drivers/staging/media/hantro/hantro_hevc.c| 321 ++
 drivers/staging/media/hantro/hantro_hw.h  |  49 ++
 7 files changed, 1228 insertions(+)
 create mode 100644 drivers/staging/media/hantro/hantro_g2_hevc_dec.c
 create mode 100644 drivers/staging/media/hantro/hantro_g2_regs.h
 create mode 100644 drivers/staging/media/hantro/hantro_hevc.c

diff --git a/drivers/staging/media/hantro/Makefile 
b/drivers/staging/media/hantro/Makefile
index 743ce08eb184..0357f1772267 100644
--- a/drivers/staging/media/hantro/Makefile
+++ b/drivers/staging/media/hantro/Makefile
@@ -9,12 +9,14 @@ hantro-vpu-y += \
hantro_h1_jpeg_enc.o \
hantro_g1_h264_dec.o \
hantro_g1_mpeg2_dec.o \
+   hantro_g2_hevc_dec.o \
hantro_g1_vp8_dec.o \
rk3399_vpu_hw_jpeg_enc.o \
rk3399_vpu_hw_mpeg2_dec.o \
rk3399_vpu_hw_vp8_dec.o \
hantro_jpeg.o \
hantro_h264.o \
+   hantro_hevc.o \
hantro_mpeg2.o \
hantro_vp8.o
 
diff --git a/drivers/staging/media/hantro/hantro.h 
b/drivers/staging/media/hantro/hantro.h
index 05876e426419..a9b80b2c9124 100644
--- a/drivers/staging/media/hantro/hantro.h
+++ b/drivers/staging/media/hantro/hantro.h
@@ -225,6 +225,7 @@ struct hantro_dev {
  * @jpeg_enc:  JPEG-encoding context.
  * @mpeg2_dec: MPEG-2-decoding context.
  * @vp8_dec:   VP8-decoding context.
+ * @hevc_dec:  HEVC-decoding context.
  */
 struct hantro_ctx {
struct hantro_dev *dev;
@@ -251,6 +252,7 @@ struct hantro_ctx {
struct hantro_jpeg_enc_hw_ctx jpeg_enc;
struct hantro_mpeg2_dec_hw_ctx mpeg2_dec;
struct hantro_vp8_dec_hw_ctx vp8_dec;
+   struct hantro_hevc_dec_hw_ctx hevc_dec;
};
 };
 
@@ -428,6 +430,22 @@ hantro_get_dec_buf_addr(struct hantro_ctx *ctx, struct 
vb2_buffer *vb)
return vb2_dma_contig_plane_dma_addr(vb, 0);
 }
 
+static inline size_t
+hantro_get_dec_buf_size(struct hantro_ctx *ctx, struct vb2_buffer *vb)
+{
+   if (hantro_needs_postproc(ctx, ctx->vpu_dst_fmt))
+   return ctx->postproc.dec_q[vb->index].size;
+   return vb2_plane_size(vb, 0);
+}
+
+static inline void *
+hantro_get_dec_buf(struct hantro_ctx *ctx, struct vb2_buffer *vb)
+{
+   if (hantro_needs_postproc(ctx, ctx->vpu_dst_fmt))
+   return ctx->postproc.dec_q[vb->index].cpu;
+   return vb2_plane_vaddr(vb, 0);
+}
+
 void hantro_postproc_disable(struct hantro_ctx *ctx);
 void hantro_postproc_enable(struct hantro_ctx *ctx);
 void hantro_postproc_free(struct hantro_ctx *ctx);
diff --git a/drivers/staging/media/hantro/hantro_drv.c 
b/drivers/staging/media/hantro/hantro_drv.c
index e3e6df28f470..bc90a52f4d3d 100644
--- a/drivers/staging/media/hantro/hantro_drv.c
+++ b/drivers/staging/media/hantro/hantro_drv.c
@@ -30,6 +30,13 @@
 
 #define DRIVER_NAME "hantro-vpu"
 
+/*
+ * V4L2_CID_HANTRO_HEVC_SLICE_HEADER_SKIP -
+ * the number of data (in bits) to skip in the
+ * slice segment header syntax after 'slice type' token
+ */
+#define V4L2_CID_HANTRO_HEVC_SLICE_HEADER_SKIP (V4L2_CID_USER_HANTRO_BASE + 0)
+
 int hantro_debug;
 module_param_named(debug, hantro_debug, int, 0644);
 MODULE_PARM_DESC(debug,
@@ -281,6 +288,26 @@ static int hantro_jpeg_s_ctrl(struct v4l2_ctrl *ctrl)
return 0;
 }
 
+static int hantro_hevc_s_ctrl(struct v4l2_ctrl *ctrl)
+{
+   struct hantro_ctx *ctx;
+
+   ctx = container_of(ctrl->handler,
+  struct hantro_ctx, ctrl_handler);
+
+   vpu_debug(1, "s_ctrl: id = %d, val = %d\n", ctrl->id, ctrl->val);
+
+   switch (ctrl->id) {
+

[PATCH v4 10/11] dt-bindings: media: nxp,imx8mq-vpu: Update bindings

2021-03-03 Thread Benjamin Gaignard
The current bindings seem to make the assumption that the
two VPUs hardware blocks (G1 and G2) are only one set of
registers.
After implementing the VPU reset driver and G2 decoder driver
it shows that all the VPUs are independent and don't need to
know about the registers of the other blocks.
Remove from the bindings the need to set all blocks register
but keep reg-names property because removing it from the driver
may affect other variants.

Signed-off-by: Benjamin Gaignard 
---
version 4:
- rebase the change on top of VPU reset patches:
  https://www.spinics.net/lists/arm-kernel/msg878440.html

version 2:
- be more verbose about why I change the bindings
Keep in mind that series comes after: 
https://www.spinics.net/lists/arm-kernel/msg875766.html
without that review and ack it won't work

 .../bindings/media/nxp,imx8mq-vpu.yaml| 46 ---
 1 file changed, 30 insertions(+), 16 deletions(-)

diff --git a/Documentation/devicetree/bindings/media/nxp,imx8mq-vpu.yaml 
b/Documentation/devicetree/bindings/media/nxp,imx8mq-vpu.yaml
index fd53a4e43572..468435c70eef 100644
--- a/Documentation/devicetree/bindings/media/nxp,imx8mq-vpu.yaml
+++ b/Documentation/devicetree/bindings/media/nxp,imx8mq-vpu.yaml
@@ -15,23 +15,25 @@ description:
 
 properties:
   compatible:
-const: nxp,imx8mq-vpu
+enum:
+  - nxp,imx8mq-vpu
+  - nxp,imx8mq-vpu-g2
 
   reg:
-maxItems: 2
+maxItems: 1
 
   reg-names:
-items:
-  - const: g1
-  - const: g2
+enum:
+  - g1
+  - g2
 
   interrupts:
-maxItems: 2
+maxItems: 1
 
   interrupt-names:
-items:
-  - const: g1
-  - const: g2
+enum:
+  - g1
+  - g2
 
   clocks:
 maxItems: 3
@@ -66,14 +68,12 @@ examples:
 #include 
 #include 
 
-vpu: video-codec@3830 {
+vpu_g1: video-codec@3830 {
 compatible = "nxp,imx8mq-vpu";
-reg = <0x3830 0x1>,
-  <0x3831 0x1>;
-reg-names = "g1", "g2";
-interrupts = ,
- ;
-interrupt-names = "g1", "g2";
+reg = <0x3830 0x1>;
+reg-names = "g1";
+interrupts = ;
+interrupt-names = "g1";
 clocks = < IMX8MQ_CLK_VPU_G1_ROOT>,
  < IMX8MQ_CLK_VPU_G2_ROOT>,
  < IMX8MQ_CLK_VPU_DEC_ROOT>;
@@ -81,3 +81,17 @@ examples:
 power-domains = <_vpu>;
 resets = <_reset IMX8MQ_RESET_VPU_RESET_G1>;
 };
+
+vpu_g2: video-codec@3831 {
+compatible = "nxp,imx8mq-vpu-g2";
+reg = <0x3831 0x1>;
+reg-names = "g2";
+interrupts = ;
+interrupt-names = "g2";
+clocks = < IMX8MQ_CLK_VPU_G1_ROOT>,
+ < IMX8MQ_CLK_VPU_G2_ROOT>,
+ < IMX8MQ_CLK_VPU_DEC_ROOT>;
+clock-names = "g1", "g2", "bus";
+power-domains = <_vpu>;
+resets = <_reset IMX8MQ_RESET_VPU_RESET_G2>;
+};
-- 
2.25.1



[PATCH v4 03/11] media: hantro: change hantro_codec_ops run prototype to return errors

2021-03-03 Thread Benjamin Gaignard
Change hantro_codec_ops run prototype from 'void' to 'int'.
This allow to cancel the job if an error occur while configuring
the hardware.

Signed-off-by: Benjamin Gaignard 
---
 drivers/staging/media/hantro/hantro_drv.c |  4 +++-
 .../staging/media/hantro/hantro_g1_h264_dec.c |  6 --
 .../media/hantro/hantro_g1_mpeg2_dec.c|  4 +++-
 .../staging/media/hantro/hantro_g1_vp8_dec.c  |  6 --
 .../staging/media/hantro/hantro_h1_jpeg_enc.c |  4 +++-
 drivers/staging/media/hantro/hantro_hw.h  | 19 ++-
 .../media/hantro/rk3399_vpu_hw_jpeg_enc.c |  4 +++-
 .../media/hantro/rk3399_vpu_hw_mpeg2_dec.c|  4 +++-
 .../media/hantro/rk3399_vpu_hw_vp8_dec.c  |  6 --
 9 files changed, 37 insertions(+), 20 deletions(-)

diff --git a/drivers/staging/media/hantro/hantro_drv.c 
b/drivers/staging/media/hantro/hantro_drv.c
index e5f200e64993..ac1429f00b33 100644
--- a/drivers/staging/media/hantro/hantro_drv.c
+++ b/drivers/staging/media/hantro/hantro_drv.c
@@ -161,7 +161,9 @@ static void device_run(void *priv)
 
v4l2_m2m_buf_copy_metadata(src, dst, true);
 
-   ctx->codec_ops->run(ctx);
+   if (ctx->codec_ops->run(ctx))
+   goto err_cancel_job;
+
return;
 
 err_cancel_job:
diff --git a/drivers/staging/media/hantro/hantro_g1_h264_dec.c 
b/drivers/staging/media/hantro/hantro_g1_h264_dec.c
index 845bef73d218..fcd4db13c9fe 100644
--- a/drivers/staging/media/hantro/hantro_g1_h264_dec.c
+++ b/drivers/staging/media/hantro/hantro_g1_h264_dec.c
@@ -273,13 +273,13 @@ static void set_buffers(struct hantro_ctx *ctx)
vdpu_write_relaxed(vpu, ctx->h264_dec.priv.dma, G1_REG_ADDR_QTABLE);
 }
 
-void hantro_g1_h264_dec_run(struct hantro_ctx *ctx)
+int hantro_g1_h264_dec_run(struct hantro_ctx *ctx)
 {
struct hantro_dev *vpu = ctx->dev;
 
/* Prepare the H264 decoder context. */
if (hantro_h264_dec_prepare_run(ctx))
-   return;
+   return -EINVAL;
 
/* Configure hardware registers. */
set_params(ctx);
@@ -301,4 +301,6 @@ void hantro_g1_h264_dec_run(struct hantro_ctx *ctx)
   G1_REG_CONFIG_DEC_CLK_GATE_E,
   G1_REG_CONFIG);
vdpu_write(vpu, G1_REG_INTERRUPT_DEC_E, G1_REG_INTERRUPT);
+
+   return 0;
 }
diff --git a/drivers/staging/media/hantro/hantro_g1_mpeg2_dec.c 
b/drivers/staging/media/hantro/hantro_g1_mpeg2_dec.c
index 6386a3989bfe..5e8943d31dc5 100644
--- a/drivers/staging/media/hantro/hantro_g1_mpeg2_dec.c
+++ b/drivers/staging/media/hantro/hantro_g1_mpeg2_dec.c
@@ -155,7 +155,7 @@ hantro_g1_mpeg2_dec_set_buffers(struct hantro_dev *vpu, 
struct hantro_ctx *ctx,
vdpu_write_relaxed(vpu, backward_addr, G1_REG_REFER3_BASE);
 }
 
-void hantro_g1_mpeg2_dec_run(struct hantro_ctx *ctx)
+int hantro_g1_mpeg2_dec_run(struct hantro_ctx *ctx)
 {
struct hantro_dev *vpu = ctx->dev;
struct vb2_v4l2_buffer *src_buf, *dst_buf;
@@ -248,4 +248,6 @@ void hantro_g1_mpeg2_dec_run(struct hantro_ctx *ctx)
 
reg = G1_REG_DEC_E(1);
vdpu_write(vpu, reg, G1_SWREG(1));
+
+   return 0;
 }
diff --git a/drivers/staging/media/hantro/hantro_g1_vp8_dec.c 
b/drivers/staging/media/hantro/hantro_g1_vp8_dec.c
index a5cdf150cd16..d665df026546 100644
--- a/drivers/staging/media/hantro/hantro_g1_vp8_dec.c
+++ b/drivers/staging/media/hantro/hantro_g1_vp8_dec.c
@@ -426,7 +426,7 @@ static void cfg_buffers(struct hantro_ctx *ctx,
vdpu_write_relaxed(vpu, dst_dma, G1_REG_ADDR_DST);
 }
 
-void hantro_g1_vp8_dec_run(struct hantro_ctx *ctx)
+int hantro_g1_vp8_dec_run(struct hantro_ctx *ctx)
 {
const struct v4l2_ctrl_vp8_frame_header *hdr;
struct hantro_dev *vpu = ctx->dev;
@@ -439,7 +439,7 @@ void hantro_g1_vp8_dec_run(struct hantro_ctx *ctx)
 
hdr = hantro_get_ctrl(ctx, V4L2_CID_MPEG_VIDEO_VP8_FRAME_HEADER);
if (WARN_ON(!hdr))
-   return;
+   return -EINVAL;
 
/* Reset segment_map buffer in keyframe */
if (VP8_FRAME_IS_KEY_FRAME(hdr) && ctx->vp8_dec.segment_map.cpu)
@@ -499,4 +499,6 @@ void hantro_g1_vp8_dec_run(struct hantro_ctx *ctx)
hantro_end_prepare_run(ctx);
 
vdpu_write(vpu, G1_REG_INTERRUPT_DEC_E, G1_REG_INTERRUPT);
+
+   return 0;
 }
diff --git a/drivers/staging/media/hantro/hantro_h1_jpeg_enc.c 
b/drivers/staging/media/hantro/hantro_h1_jpeg_enc.c
index b88dc4ed06db..56cf261a8e95 100644
--- a/drivers/staging/media/hantro/hantro_h1_jpeg_enc.c
+++ b/drivers/staging/media/hantro/hantro_h1_jpeg_enc.c
@@ -88,7 +88,7 @@ hantro_h1_jpeg_enc_set_qtable(struct hantro_dev *vpu,
}
 }
 
-void hantro_h1_jpeg_enc_run(struct hantro_ctx *ctx)
+int hantro_h1_jpeg_enc_run(struct hantro_ctx *ctx)
 {
struct hantro_dev *vpu = ctx->dev;
struct vb2_v4l2_buffer *src_buf, *dst_buf;
@@ -136,6 +136,8 @@ void hantro_h1_jpeg_enc_run(struct hantro_ctx *ctx)
hantro_end_prepare_r

[PATCH v4 05/11] media: hantro: Add a field to distinguish the hardware versions

2021-03-03 Thread Benjamin Gaignard
Decoders hardware blocks could exist in multiple versions: add
a field to distinguish them at runtime.
G2 hardware block doesn't have postprocessor hantro_needs_postproc
function should always returns false in for this hardware.
hantro_needs_postproc function becoming to much complex to
stay inline in .h file move it to .c file.

Keep the default behavoir to be G1 hardware.

Signed-off-by: Benjamin Gaignard 
---
 drivers/staging/media/hantro/hantro.h  | 13 +++--
 drivers/staging/media/hantro/hantro_drv.c  |  2 ++
 drivers/staging/media/hantro/hantro_postproc.c | 17 +
 3 files changed, 26 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/media/hantro/hantro.h 
b/drivers/staging/media/hantro/hantro.h
index a76a0d79db9f..05876e426419 100644
--- a/drivers/staging/media/hantro/hantro.h
+++ b/drivers/staging/media/hantro/hantro.h
@@ -37,6 +37,9 @@ struct hantro_codec_ops;
 #define HANTRO_HEVC_DECODERBIT(19)
 #define HANTRO_DECODERS0x
 
+#define HANTRO_G1_REV  0x6731
+#define HANTRO_G2_REV  0x6732
+
 /**
  * struct hantro_irq - irq handler and name
  *
@@ -171,6 +174,7 @@ hantro_vdev_to_func(struct video_device *vdev)
  * @enc_base:  Mapped address of VPU encoder register for convenience.
  * @dec_base:  Mapped address of VPU decoder register for convenience.
  * @ctrl_base: Mapped address of VPU control block.
+ * @core_hw_dec_revRuntime detected HW decoder core revision
  * @vpu_mutex: Mutex to synchronize V4L2 calls.
  * @irqlock:   Spinlock to synchronize access to data structures
  * shared with interrupt handlers.
@@ -190,6 +194,7 @@ struct hantro_dev {
void __iomem *enc_base;
void __iomem *dec_base;
void __iomem *ctrl_base;
+   u32 core_hw_dec_rev;
 
struct mutex vpu_mutex; /* video_device lock */
spinlock_t irqlock;
@@ -412,12 +417,8 @@ hantro_get_dst_buf(struct hantro_ctx *ctx)
return v4l2_m2m_next_dst_buf(ctx->fh.m2m_ctx);
 }
 
-static inline bool
-hantro_needs_postproc(const struct hantro_ctx *ctx,
- const struct hantro_fmt *fmt)
-{
-   return !ctx->is_encoder && fmt->fourcc != V4L2_PIX_FMT_NV12;
-}
+bool hantro_needs_postproc(const struct hantro_ctx *ctx,
+  const struct hantro_fmt *fmt);
 
 static inline dma_addr_t
 hantro_get_dec_buf_addr(struct hantro_ctx *ctx, struct vb2_buffer *vb)
diff --git a/drivers/staging/media/hantro/hantro_drv.c 
b/drivers/staging/media/hantro/hantro_drv.c
index f0b68e16fcc0..e3e6df28f470 100644
--- a/drivers/staging/media/hantro/hantro_drv.c
+++ b/drivers/staging/media/hantro/hantro_drv.c
@@ -836,6 +836,8 @@ static int hantro_probe(struct platform_device *pdev)
}
vpu->enc_base = vpu->reg_bases[0] + vpu->variant->enc_offset;
vpu->dec_base = vpu->reg_bases[0] + vpu->variant->dec_offset;
+   /* by default decoder is G1 */
+   vpu->core_hw_dec_rev = HANTRO_G1_REV;
 
ret = dma_set_coherent_mask(vpu->dev, DMA_BIT_MASK(32));
if (ret) {
diff --git a/drivers/staging/media/hantro/hantro_postproc.c 
b/drivers/staging/media/hantro/hantro_postproc.c
index 6d2a8f2a8f0b..050880f720d6 100644
--- a/drivers/staging/media/hantro/hantro_postproc.c
+++ b/drivers/staging/media/hantro/hantro_postproc.c
@@ -50,6 +50,23 @@ const struct hantro_postproc_regs hantro_g1_postproc_regs = {
.display_width = {G1_REG_PP_DISPLAY_WIDTH, 0, 0xfff},
 };
 
+bool hantro_needs_postproc(const struct hantro_ctx *ctx,
+  const struct hantro_fmt *fmt)
+{
+   struct hantro_dev *vpu = ctx->dev;
+
+   if (ctx->is_encoder)
+   return false;
+
+   if (vpu->core_hw_dec_rev == HANTRO_G1_REV)
+   return fmt->fourcc != V4L2_PIX_FMT_NV12;
+
+   if (vpu->core_hw_dec_rev == HANTRO_G2_REV)
+   return false;
+
+   return false;
+}
+
 void hantro_postproc_enable(struct hantro_ctx *ctx)
 {
struct hantro_dev *vpu = ctx->dev;
-- 
2.25.1



  1   2   3   4   5   6   7   8   9   10   >