From: Ezequiel Garcia <ezequiel@collabora.com>
To: Benjamin Gaignard <benjamin.gaignard@collabora.com>,
p.zabel@pengutronix.de, mchehab@kernel.org, robh+dt@kernel.org,
shawnguo@kernel.org, s.hauer@pengutronix.de,
kernel@pengutronix.de, festevam@gmail.com, linux-imx@nxp.com,
gregkh@linuxfoundation.org, mripard@kernel.org,
paul.kocialkowski@bootlin.com, wens@csie.org,
jernej.skrabec@siol.net, peng.fan@nxp.com,
hverkuil-cisco@xs4all.nl, dan.carpenter@oracle.com
Cc: linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org,
devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, kernel@collabora.com
Subject: Re: [PATCH v3 5/9] media: hantro: Introduce G2/HEVC decoder
Date: Fri, 26 Feb 2021 18:08:12 -0300 [thread overview]
Message-ID: <75696dd2ae8c78f626db4e59300d3f04e348f341.camel@collabora.com> (raw)
In-Reply-To: <6f3c23a6-4b74-c7b4-f6b2-2fb983a8bbb8@collabora.com>
On Fri, 2021-02-26 at 10:47 +0100, Benjamin Gaignard wrote:
>
> Le 25/02/2021 à 18:55, Ezequiel Garcia a écrit :
> > Hi Benjamin,
> >
> > Thanks for the good work!
> > I mostly have two concerns with this implementation,
> > the tiled output and the allocation path.
> >
> > More below.
> >
> > On Mon, 2021-02-22 at 13:24 +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 <benjamin.gaignard@collabora.com>
> > > ---
> > > 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 | 19 +
> > > drivers/staging/media/hantro/hantro_drv.c | 42 ++
> > > .../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 | 47 ++
> > > 7 files changed, 1216 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
> > >
> > >
> > [snip]
> > > +
> > > +static void set_buffers(struct hantro_ctx *ctx)
> > > +{
> > > + struct vb2_v4l2_buffer *src_buf, *dst_buf;
> > > + struct hantro_dev *vpu = ctx->dev;
> > > + const struct hantro_hevc_dec_ctrls *ctrls = &ctx->hevc_dec.ctrls;
> > > + const struct v4l2_ctrl_hevc_sps *sps = ctrls->sps;
> > > + size_t cr_offset = hantro_hevc_chroma_offset(sps);
> > > + dma_addr_t src_dma, dst_dma;
> > > + u32 src_len, src_buf_len;
> > > +
> > > + src_buf = hantro_get_src_buf(ctx);
> > > + dst_buf = hantro_get_dst_buf(ctx);
> > > +
> > > + /* Source (stream) buffer. */
> > > + src_dma = vb2_dma_contig_plane_dma_addr(&src_buf->vb2_buf, 0);
> > > + src_len = vb2_get_plane_payload(&src_buf->vb2_buf, 0);
> > > + src_buf_len = vb2_plane_size(&src_buf->vb2_buf, 0);
> > > +
> > > + hantro_write_addr(vpu, HEVC_ADDR_STR, src_dma);
> > > + hantro_reg_write(vpu, hevc_stream_len, src_len);
> > > + hantro_reg_write(vpu, hevc_strm_buffer_len, src_buf_len);
> > > + hantro_reg_write(vpu, hevc_strm_start_offset, 0);
> > > + hantro_reg_write(vpu, hevc_write_mvs_e, 1);
> > > +
> > > + /* Destination (decoded frame) buffer. */
> > > + dst_dma = hantro_get_dec_buf_addr(ctx, &dst_buf->vb2_buf);
> > > +
> > > + hantro_write_addr(vpu, HEVC_RASTER_SCAN, dst_dma);
> > > + hantro_write_addr(vpu, HEVC_RASTER_SCAN_CHR, dst_dma + cr_offset);
> > The way this is done the raster-scan output is the only
> > output, and the tiled ouput it kept entirely internal, in hantro_hevc_dec_hw_ctx.ref_bufs.
> >
> > This means there's no way to expose tiled NV12 in i.MX8M VPU tiled format
> > to userspace, which could be desirable for some use cases.
> >
> > I'm not suggesting to actually expose tiled NV12 in this patch, but to prepare
> > the driver to be able to support that easily in the future.
> >
> > It should be possible to consider this detiling as
> > post-processing, adding some code in hantro_postproc.c
> > leveraging the existing post-proc support.
> >
> > IOW, hantro_postproc_ctx.dec_q would hold the tiled output,
> > hantro_postproc_enable() writes the raster-scan
> > buffer destination address, and so on.
>
> Well the G2 can't use the post-processor so I'm reluctant to do as if it was the case.
>
I don't really see a big difference between G1 post-processing, and G2 raster-scan
detiling. As a user of the device, both features offer a post-processing.
In any case, it's not a big deal, it's fine as-is if you are inclined to this implementation.
> To support tiled NV12 for me the solution is to create a hantro_hevc_add_ref_buf() function
> to add the destination buffer in hevc_dec->ref_bufs.
> We can test destination format to set hevc_out_rs_e bit and HEVC_RASTER_SCAN register.
>
Is it worth adding some boilerplate and/or refactoring things a bit, so it's
easier to expose tiled NV12 once that format is exposable?
> >
> > > + hantro_write_addr(vpu, HEVC_ADDR_TILE_SIZE, ctx->hevc_dec.tile_sizes.dma);
> > > + hantro_write_addr(vpu, HEVC_TILE_FILTER, ctx->hevc_dec.tile_filter.dma);
> > > + hantro_write_addr(vpu, HEVC_TILE_SAO, ctx->hevc_dec.tile_sao.dma);
> > > + hantro_write_addr(vpu, HEVC_TILE_BSD, ctx->hevc_dec.tile_bsd.dma);
> > > +}
> > > +
> > > +void hantro_g2_check_idle(struct hantro_dev *vpu)
> > > +{
> > > + int i;
> > > +
> > > + for (i = 0; i < 3; i++) {
> > > + u32 status;
> > > +
> > > + /* Make sure the VPU is idle */
> > > + status = vdpu_read(vpu, HEVC_REG_INTERRUPT);
> > > + if (status & HEVC_REG_INTERRUPT_DEC_E) {
> > > + pr_warn("%s: still enabled!!! resetting.\n", __func__);
> > > + status |= HEVC_REG_INTERRUPT_DEC_ABORT_E | HEVC_REG_INTERRUPT_DEC_IRQ_DIS;
> > > + vdpu_write(vpu, status, HEVC_REG_INTERRUPT);
> > > + }
> > > + }
> > > +}
> > > +
> > > +void hantro_g2_hevc_dec_run(struct hantro_ctx *ctx)
> > > +{
> > > + struct hantro_dev *vpu = ctx->dev;
> > > +
> > > + hantro_g2_check_idle(vpu);
> > > +
> > > + /* Prepare HEVC decoder context. */
> > > + if (hantro_hevc_dec_prepare_run(ctx))
> > > + return;
> > > +
> > > + /* Configure hardware registers. */
> > > + set_params(ctx);
> > > +
> > > + /* set reference pictures */
> > > + if (set_ref(ctx))
> > > + /* something goes wrong */
> > > + hantro_irq_done(vpu, VB2_BUF_STATE_ERROR);
> > > +
> > I don't think we want to allow the _run() operation to fail like this.
> > In other words, I would avoid allocating buffers in the _run() path,
> > and doing all allocation at start() time.
> >
> > That's why hantro_start_streaming() calls hantro_postproc_alloc() if needed.
>
> The error could also be that the reference picture isn't found in the list so
> we can't perform the decode operation.
> If we do the allocation at start time we will allocate all the reference frames
> buffers even if we don't know if we will use them. That could increase a lot
> memory usage. Note that buffers allocated once and re-used until the end of the
> session.
>
Improving memory usage is a good point. I wonder if it makes sense to release
some buffers under some condition, instead of keeping then allocated (and unused)
until the end of the session.
(BTW, the same can be done with the post-processor, as it's basically
the same process. It would be interesting to explore.)
I'm still unsure why we'd call hantro_irq_done() (which cancels the timeout
handler and returns buffers to userspace), but we would keep programming
the operation.
Thanks,
Ezequiel
next prev parent reply other threads:[~2021-02-26 21:09 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-22 12:23 [PATCH v3 0/9] Add HANTRO G2/HEVC decoder support for IMX8MQ Benjamin Gaignard
2021-02-22 12:23 ` [PATCH v3 1/9] media: hevc: Modify structures to follow H265 ITU spec Benjamin Gaignard
2021-02-25 13:09 ` Ezequiel Garcia
2021-02-25 17:01 ` Jernej Škrabec
2021-02-25 17:34 ` Ezequiel Garcia
2021-02-25 18:05 ` Jernej Škrabec
2021-02-25 18:34 ` John Cox
2021-02-25 19:11 ` Nicolas Dufresne
2021-02-25 18:35 ` Nicolas Dufresne
2021-02-22 12:23 ` [PATCH v3 2/9] media: hantro: Define HEVC codec profiles and supported features Benjamin Gaignard
2021-02-24 20:39 ` Ezequiel Garcia
2021-02-22 12:24 ` [PATCH v3 3/9] media: hantro: Add a field to distinguish the hardware versions Benjamin Gaignard
2021-02-22 12:24 ` [PATCH v3 4/9] media: uapi: Add a control for HANTRO driver Benjamin Gaignard
2021-02-25 14:05 ` Ezequiel Garcia
2021-02-22 12:24 ` [PATCH v3 5/9] media: hantro: Introduce G2/HEVC decoder Benjamin Gaignard
2021-02-25 17:55 ` Ezequiel Garcia
2021-02-26 9:47 ` Benjamin Gaignard
2021-02-26 21:08 ` Ezequiel Garcia [this message]
2021-02-22 12:24 ` [PATCH v3 6/9] media: hantro: handle V4L2_PIX_FMT_HEVC_SLICE control Benjamin Gaignard
2021-02-22 12:24 ` [PATCH v3 7/9] media: hantro: IMX8M: add variant for G2/HEVC codec Benjamin Gaignard
2021-02-22 12:24 ` [PATCH v3 8/9] dt-bindings: media: nxp,imx8mq-vpu: Update bindings Benjamin Gaignard
2021-02-23 0:34 ` Rob Herring
2021-02-23 8:04 ` Benjamin Gaignard
2021-02-23 14:31 ` Rob Herring
2021-02-23 14:48 ` Ezequiel Garcia
2021-02-22 12:24 ` [PATCH v3 9/9] arm64: dts: imx8mq: Add node to G2 hardware Benjamin Gaignard
2021-02-24 20:31 ` [PATCH v3 0/9] Add HANTRO G2/HEVC decoder support for IMX8MQ Ezequiel Garcia
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=75696dd2ae8c78f626db4e59300d3f04e348f341.camel@collabora.com \
--to=ezequiel@collabora.com \
--cc=benjamin.gaignard@collabora.com \
--cc=dan.carpenter@oracle.com \
--cc=devicetree@vger.kernel.org \
--cc=festevam@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=hverkuil-cisco@xs4all.nl \
--cc=jernej.skrabec@siol.net \
--cc=kernel@collabora.com \
--cc=kernel@pengutronix.de \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-imx@nxp.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=linux-rockchip@lists.infradead.org \
--cc=mchehab@kernel.org \
--cc=mripard@kernel.org \
--cc=p.zabel@pengutronix.de \
--cc=paul.kocialkowski@bootlin.com \
--cc=peng.fan@nxp.com \
--cc=robh+dt@kernel.org \
--cc=s.hauer@pengutronix.de \
--cc=shawnguo@kernel.org \
--cc=wens@csie.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).