Message ID | 20220610125215.240539-5-nicolas.dufresne@collabora.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | media: rkvdec: Fix H.264 error resilience | expand |
On Fri, Jun 10, 2022 at 08:52:14AM -0400, Nicolas Dufresne wrote: > This re-enables H.264 error detection, but using the other error mode. > In that mode, the decoder will skip over the error macro-block or > slices and complete the decoding. As a side effect, the error status > is not set in the interrupt status register, and instead errors are > detected per format. Using this mode workaround the issue that the > HW get stuck in error stated and allow reporting that some corruption > may be present in the buffer returned to userland. > > Signed-off-by: Nicolas Dufresne <nicolas.dufresne@collabora.com> > --- > drivers/staging/media/rkvdec/rkvdec-h264.c | 23 +++++++++++++++++++--- > 1 file changed, 20 insertions(+), 3 deletions(-) > > diff --git a/drivers/staging/media/rkvdec/rkvdec-h264.c b/drivers/staging/media/rkvdec/rkvdec-h264.c > index 55596ce6bb6e..60a89918e2c1 100644 > --- a/drivers/staging/media/rkvdec/rkvdec-h264.c > +++ b/drivers/staging/media/rkvdec/rkvdec-h264.c > @@ -1175,14 +1175,15 @@ static int rkvdec_h264_run(struct rkvdec_ctx *ctx) > > schedule_delayed_work(&rkvdec->watchdog_work, msecs_to_jiffies(2000)); > > - writel(0, rkvdec->regs + RKVDEC_REG_STRMD_ERR_EN); > - writel(0, rkvdec->regs + RKVDEC_REG_H264_ERR_E); > + writel(0xffffffff, rkvdec->regs + RKVDEC_REG_STRMD_ERR_EN); > + writel(0xffffffff, rkvdec->regs + RKVDEC_REG_H264_ERR_E); This reverts the changes in patch 1/5. Could we just skip patch 1/5 instead? regards, dan carpenter
On 6/10/22 16:20, Dan Carpenter wrote: > On Fri, Jun 10, 2022 at 08:52:14AM -0400, Nicolas Dufresne wrote: >> This re-enables H.264 error detection, but using the other error mode. >> In that mode, the decoder will skip over the error macro-block or >> slices and complete the decoding. As a side effect, the error status >> is not set in the interrupt status register, and instead errors are >> detected per format. Using this mode workaround the issue that the >> HW get stuck in error stated and allow reporting that some corruption >> may be present in the buffer returned to userland. >> >> Signed-off-by: Nicolas Dufresne <nicolas.dufresne@collabora.com> >> --- >> drivers/staging/media/rkvdec/rkvdec-h264.c | 23 +++++++++++++++++++--- >> 1 file changed, 20 insertions(+), 3 deletions(-) >> >> diff --git a/drivers/staging/media/rkvdec/rkvdec-h264.c b/drivers/staging/media/rkvdec/rkvdec-h264.c >> index 55596ce6bb6e..60a89918e2c1 100644 >> --- a/drivers/staging/media/rkvdec/rkvdec-h264.c >> +++ b/drivers/staging/media/rkvdec/rkvdec-h264.c >> @@ -1175,14 +1175,15 @@ static int rkvdec_h264_run(struct rkvdec_ctx *ctx) >> >> schedule_delayed_work(&rkvdec->watchdog_work, msecs_to_jiffies(2000)); >> >> - writel(0, rkvdec->regs + RKVDEC_REG_STRMD_ERR_EN); >> - writel(0, rkvdec->regs + RKVDEC_REG_H264_ERR_E); >> + writel(0xffffffff, rkvdec->regs + RKVDEC_REG_STRMD_ERR_EN); >> + writel(0xffffffff, rkvdec->regs + RKVDEC_REG_H264_ERR_E); > > This reverts the changes in patch 1/5. Could we just skip patch 1/5 > instead? The first patch must go to the stable kernels, hence we couldn't skip it.
Hi Nicolas, Great stuff! See below for some ideas how to expose errors. On Fri, Jun 10, 2022 at 9:52 AM Nicolas Dufresne <nicolas.dufresne@collabora.com> wrote: > > This re-enables H.264 error detection, but using the other error mode. > In that mode, the decoder will skip over the error macro-block or > slices and complete the decoding. As a side effect, the error status > is not set in the interrupt status register, and instead errors are > detected per format. Using this mode workaround the issue that the > HW get stuck in error stated and allow reporting that some corruption > may be present in the buffer returned to userland. > > Signed-off-by: Nicolas Dufresne <nicolas.dufresne@collabora.com> > --- > drivers/staging/media/rkvdec/rkvdec-h264.c | 23 +++++++++++++++++++--- > 1 file changed, 20 insertions(+), 3 deletions(-) > > diff --git a/drivers/staging/media/rkvdec/rkvdec-h264.c b/drivers/staging/media/rkvdec/rkvdec-h264.c > index 55596ce6bb6e..60a89918e2c1 100644 > --- a/drivers/staging/media/rkvdec/rkvdec-h264.c > +++ b/drivers/staging/media/rkvdec/rkvdec-h264.c > @@ -1175,14 +1175,15 @@ static int rkvdec_h264_run(struct rkvdec_ctx *ctx) > > schedule_delayed_work(&rkvdec->watchdog_work, msecs_to_jiffies(2000)); > > - writel(0, rkvdec->regs + RKVDEC_REG_STRMD_ERR_EN); > - writel(0, rkvdec->regs + RKVDEC_REG_H264_ERR_E); > + writel(0xffffffff, rkvdec->regs + RKVDEC_REG_STRMD_ERR_EN); > + writel(0xffffffff, rkvdec->regs + RKVDEC_REG_H264_ERR_E); > writel(1, rkvdec->regs + RKVDEC_REG_PREF_LUMA_CACHE_COMMAND); > writel(1, rkvdec->regs + RKVDEC_REG_PREF_CHR_CACHE_COMMAND); > > /* Start decoding! */ > writel(RKVDEC_INTERRUPT_DEC_E | RKVDEC_CONFIG_DEC_CLK_GATE_E | > - RKVDEC_TIMEOUT_E | RKVDEC_BUF_EMPTY_E, > + RKVDEC_TIMEOUT_E | RKVDEC_BUF_EMPTY_E | > + RKVDEC_H264ORVP9_ERR_MODE, > rkvdec->regs + RKVDEC_REG_INTERRUPT); > > return 0; > @@ -1196,10 +1197,26 @@ static int rkvdec_h264_try_ctrl(struct rkvdec_ctx *ctx, struct v4l2_ctrl *ctrl) > return 0; > } > > +static int rkvdec_h264_check_error_info(struct rkvdec_ctx *ctx) > +{ > + struct rkvdec_dev *rkvdec = ctx->dev; > + int err; > + > + err = readl(rkvdec->regs + RKVDEC_REG_H264_ERRINFO_NUM); > + if (err & RKVDEC_STRMD_DECT_ERR_FLAG) { > + pr_debug("Decoded picture have %i/%i slices with errors.\n", > + RKVDEC_ERR_PKT_NUM(err), RKVDEC_SLICEDEC_NUM(err)); It's more useful friendly to just keep a counter somewhere. In the past, we've created a user control, which has the advantage of leveraging an existing mechanism, and already being per-fd. See: commit b2d3bef1aa7858b2ae5e0d01adb214121ba00b9f "media: coda: Add a V4L2 user for control error macroblocks count". I would drop the pr_debug, or if you think it's really useful for users and developers, go with v4l2_dbg. In which case, how do you ensure a corrupted stream won't flood the logs? Thanks, Ezequiel > + return VB2_BUF_STATE_ERROR; > + } > + > + return VB2_BUF_STATE_DONE; > +} > + > const struct rkvdec_coded_fmt_ops rkvdec_h264_fmt_ops = { > .adjust_fmt = rkvdec_h264_adjust_fmt, > .start = rkvdec_h264_start, > .stop = rkvdec_h264_stop, > .run = rkvdec_h264_run, > .try_ctrl = rkvdec_h264_try_ctrl, > + .check_error_info = rkvdec_h264_check_error_info, > }; > -- > 2.36.1 >
Le vendredi 10 juin 2022 à 16:20 +0300, Dan Carpenter a écrit : > On Fri, Jun 10, 2022 at 08:52:14AM -0400, Nicolas Dufresne wrote: > > This re-enables H.264 error detection, but using the other error mode. > > In that mode, the decoder will skip over the error macro-block or > > slices and complete the decoding. As a side effect, the error status > > is not set in the interrupt status register, and instead errors are > > detected per format. Using this mode workaround the issue that the > > HW get stuck in error stated and allow reporting that some corruption > > may be present in the buffer returned to userland. > > > > Signed-off-by: Nicolas Dufresne <nicolas.dufresne@collabora.com> > > --- > > drivers/staging/media/rkvdec/rkvdec-h264.c | 23 +++++++++++++++++++--- > > 1 file changed, 20 insertions(+), 3 deletions(-) > > > > diff --git a/drivers/staging/media/rkvdec/rkvdec-h264.c b/drivers/staging/media/rkvdec/rkvdec-h264.c > > index 55596ce6bb6e..60a89918e2c1 100644 > > --- a/drivers/staging/media/rkvdec/rkvdec-h264.c > > +++ b/drivers/staging/media/rkvdec/rkvdec-h264.c > > @@ -1175,14 +1175,15 @@ static int rkvdec_h264_run(struct rkvdec_ctx *ctx) > > > > schedule_delayed_work(&rkvdec->watchdog_work, msecs_to_jiffies(2000)); > > > > - writel(0, rkvdec->regs + RKVDEC_REG_STRMD_ERR_EN); > > - writel(0, rkvdec->regs + RKVDEC_REG_H264_ERR_E); > > + writel(0xffffffff, rkvdec->regs + RKVDEC_REG_STRMD_ERR_EN); > > + writel(0xffffffff, rkvdec->regs + RKVDEC_REG_H264_ERR_E); > > This reverts the changes in patch 1/5. Could we just skip patch 1/5 > instead? As documented, this is for back-porting purpose. The first patch is what has been running for 7 years in Chromebook, so I'm fully confident it is safe to backport it into our stable kernel. The second is like a new feature, which I'm confident works, but didn't get as much testing as I just wrote it. So what I'm doing here is giving a same thing to backport, and a better fix for the next kernel. You are otherwise right that this will revert it. Nicolas
Le vendredi 10 juin 2022 à 12:01 -0300, Ezequiel Garcia a écrit : > Hi Nicolas, > > Great stuff! See below for some ideas how to expose errors. > > On Fri, Jun 10, 2022 at 9:52 AM Nicolas Dufresne > <nicolas.dufresne@collabora.com> wrote: > > > > This re-enables H.264 error detection, but using the other error mode. > > In that mode, the decoder will skip over the error macro-block or > > slices and complete the decoding. As a side effect, the error status > > is not set in the interrupt status register, and instead errors are > > detected per format. Using this mode workaround the issue that the > > HW get stuck in error stated and allow reporting that some corruption > > may be present in the buffer returned to userland. > > > > Signed-off-by: Nicolas Dufresne <nicolas.dufresne@collabora.com> > > --- > > drivers/staging/media/rkvdec/rkvdec-h264.c | 23 +++++++++++++++++++--- > > 1 file changed, 20 insertions(+), 3 deletions(-) > > > > diff --git a/drivers/staging/media/rkvdec/rkvdec-h264.c b/drivers/staging/media/rkvdec/rkvdec-h264.c > > index 55596ce6bb6e..60a89918e2c1 100644 > > --- a/drivers/staging/media/rkvdec/rkvdec-h264.c > > +++ b/drivers/staging/media/rkvdec/rkvdec-h264.c > > @@ -1175,14 +1175,15 @@ static int rkvdec_h264_run(struct rkvdec_ctx *ctx) > > > > schedule_delayed_work(&rkvdec->watchdog_work, msecs_to_jiffies(2000)); > > > > - writel(0, rkvdec->regs + RKVDEC_REG_STRMD_ERR_EN); > > - writel(0, rkvdec->regs + RKVDEC_REG_H264_ERR_E); > > + writel(0xffffffff, rkvdec->regs + RKVDEC_REG_STRMD_ERR_EN); > > + writel(0xffffffff, rkvdec->regs + RKVDEC_REG_H264_ERR_E); > > writel(1, rkvdec->regs + RKVDEC_REG_PREF_LUMA_CACHE_COMMAND); > > writel(1, rkvdec->regs + RKVDEC_REG_PREF_CHR_CACHE_COMMAND); > > > > /* Start decoding! */ > > writel(RKVDEC_INTERRUPT_DEC_E | RKVDEC_CONFIG_DEC_CLK_GATE_E | > > - RKVDEC_TIMEOUT_E | RKVDEC_BUF_EMPTY_E, > > + RKVDEC_TIMEOUT_E | RKVDEC_BUF_EMPTY_E | > > + RKVDEC_H264ORVP9_ERR_MODE, > > rkvdec->regs + RKVDEC_REG_INTERRUPT); > > > > return 0; > > @@ -1196,10 +1197,26 @@ static int rkvdec_h264_try_ctrl(struct rkvdec_ctx *ctx, struct v4l2_ctrl *ctrl) > > return 0; > > } > > > > +static int rkvdec_h264_check_error_info(struct rkvdec_ctx *ctx) > > +{ > > + struct rkvdec_dev *rkvdec = ctx->dev; > > + int err; > > + > > + err = readl(rkvdec->regs + RKVDEC_REG_H264_ERRINFO_NUM); > > + if (err & RKVDEC_STRMD_DECT_ERR_FLAG) { > > + pr_debug("Decoded picture have %i/%i slices with errors.\n", > > + RKVDEC_ERR_PKT_NUM(err), RKVDEC_SLICEDEC_NUM(err)); > > It's more useful friendly to just keep a counter somewhere. In the past, > we've created a user control, which has the advantage of leveraging > an existing mechanism, and already being per-fd. > > See: > > commit b2d3bef1aa7858b2ae5e0d01adb214121ba00b9f > "media: coda: Add a V4L2 user for control error macroblocks count". > > I would drop the pr_debug, or if you think it's really useful for users > and developers, go with v4l2_dbg. In which case, how do you ensure > a corrupted stream won't flood the logs? There is no use case to make this a control, but yes, a corrupted stream can flood, but isn't the point of pr_debug() that it won't show if you don't enabled it ? As for v4l2_dbg I'm not familiar with that and its not used in this driver for traces. I've use pr_debug for reference list tracing previously and flooding was not considered a problem despite being a per-frame trace. You can even out- compile these if you need to. Let me know if you have further rationale in the suggestion direction. The rationale in my coding for such trace is that if I read 1 bit of a register, and trace the surrounding value, I can validate (as a human) that the rest of the register isn't complete garbage, and that I'm not basically reading a random bit. Leaving the trace there, allow other developer on other variant of these SoC to also notice if that register becomes garbage. This is in contrast of just telling others "trust me, I tested it". Nicolas > > Thanks, > Ezequiel > > > > + return VB2_BUF_STATE_ERROR; > > + } > > + > > + return VB2_BUF_STATE_DONE; > > +} > > + > > const struct rkvdec_coded_fmt_ops rkvdec_h264_fmt_ops = { > > .adjust_fmt = rkvdec_h264_adjust_fmt, > > .start = rkvdec_h264_start, > > .stop = rkvdec_h264_stop, > > .run = rkvdec_h264_run, > > .try_ctrl = rkvdec_h264_try_ctrl, > > + .check_error_info = rkvdec_h264_check_error_info, > > }; > > -- > > 2.36.1 > >
Am 10.06.22 um 14:52 schrieb Nicolas Dufresne: > This re-enables H.264 error detection, but using the other error mode. > In that mode, the decoder will skip over the error macro-block or > slices and complete the decoding. As a side effect, the error status > is not set in the interrupt status register, and instead errors are > detected per format. Using this mode workaround the issue that the > HW get stuck in error stated and allow reporting that some corruption > may be present in the buffer returned to userland. > > Signed-off-by: Nicolas Dufresne <nicolas.dufresne@collabora.com> > --- > drivers/staging/media/rkvdec/rkvdec-h264.c | 23 +++++++++++++++++++--- > 1 file changed, 20 insertions(+), 3 deletions(-) > > diff --git a/drivers/staging/media/rkvdec/rkvdec-h264.c b/drivers/staging/media/rkvdec/rkvdec-h264.c > index 55596ce6bb6e..60a89918e2c1 100644 > --- a/drivers/staging/media/rkvdec/rkvdec-h264.c > +++ b/drivers/staging/media/rkvdec/rkvdec-h264.c > @@ -1175,14 +1175,15 @@ static int rkvdec_h264_run(struct rkvdec_ctx *ctx) > > schedule_delayed_work(&rkvdec->watchdog_work, msecs_to_jiffies(2000)); > > - writel(0, rkvdec->regs + RKVDEC_REG_STRMD_ERR_EN); > - writel(0, rkvdec->regs + RKVDEC_REG_H264_ERR_E); > + writel(0xffffffff, rkvdec->regs + RKVDEC_REG_STRMD_ERR_EN); > + writel(0xffffffff, rkvdec->regs + RKVDEC_REG_H264_ERR_E); > writel(1, rkvdec->regs + RKVDEC_REG_PREF_LUMA_CACHE_COMMAND); > writel(1, rkvdec->regs + RKVDEC_REG_PREF_CHR_CACHE_COMMAND); > > /* Start decoding! */ > writel(RKVDEC_INTERRUPT_DEC_E | RKVDEC_CONFIG_DEC_CLK_GATE_E | > - RKVDEC_TIMEOUT_E | RKVDEC_BUF_EMPTY_E, > + RKVDEC_TIMEOUT_E | RKVDEC_BUF_EMPTY_E | > + RKVDEC_H264ORVP9_ERR_MODE, > rkvdec->regs + RKVDEC_REG_INTERRUPT); > > return 0; > @@ -1196,10 +1197,26 @@ static int rkvdec_h264_try_ctrl(struct rkvdec_ctx *ctx, struct v4l2_ctrl *ctrl) > return 0; > } > > +static int rkvdec_h264_check_error_info(struct rkvdec_ctx *ctx) > +{ > + struct rkvdec_dev *rkvdec = ctx->dev; > + int err; > + > + err = readl(rkvdec->regs + RKVDEC_REG_H264_ERRINFO_NUM); > + if (err & RKVDEC_STRMD_DECT_ERR_FLAG) { > + pr_debug("Decoded picture have %i/%i slices with errors.\n", > + RKVDEC_ERR_PKT_NUM(err), RKVDEC_SLICEDEC_NUM(err)); > + return VB2_BUF_STATE_ERROR; > + } > + > + return VB2_BUF_STATE_DONE; > +} > + > const struct rkvdec_coded_fmt_ops rkvdec_h264_fmt_ops = { > .adjust_fmt = rkvdec_h264_adjust_fmt, > .start = rkvdec_h264_start, > .stop = rkvdec_h264_stop, > .run = rkvdec_h264_run, > .try_ctrl = rkvdec_h264_try_ctrl, > + .check_error_info = rkvdec_h264_check_error_info, > }; Actually I'm not sure I fully understand what you are expecting the userspace to do with the information that there was an (HW!) error, which might or might not be bitstrean related. Resending the corrupted(?) frame until the HW fully hangs? As the interrupt reports an HW error it should (at least also) be handled driver-side and the HW is known not to be able to fully reset itself in case of an error. I think this will make behavior worse than it is now (for real-life users) where errors are eventually just ignored. Alex
Le samedi 11 juin 2022 à 14:08 +0200, Alex Bee a écrit : > Am 10.06.22 um 14:52 schrieb Nicolas Dufresne: > > This re-enables H.264 error detection, but using the other error mode. > > In that mode, the decoder will skip over the error macro-block or > > slices and complete the decoding. As a side effect, the error status > > is not set in the interrupt status register, and instead errors are > > detected per format. Using this mode workaround the issue that the > > HW get stuck in error stated and allow reporting that some corruption > > may be present in the buffer returned to userland. > > > > Signed-off-by: Nicolas Dufresne <nicolas.dufresne@collabora.com> > > --- > > drivers/staging/media/rkvdec/rkvdec-h264.c | 23 +++++++++++++++++++--- > > 1 file changed, 20 insertions(+), 3 deletions(-) > > > > diff --git a/drivers/staging/media/rkvdec/rkvdec-h264.c b/drivers/staging/media/rkvdec/rkvdec-h264.c > > index 55596ce6bb6e..60a89918e2c1 100644 > > --- a/drivers/staging/media/rkvdec/rkvdec-h264.c > > +++ b/drivers/staging/media/rkvdec/rkvdec-h264.c > > @@ -1175,14 +1175,15 @@ static int rkvdec_h264_run(struct rkvdec_ctx *ctx) > > > > schedule_delayed_work(&rkvdec->watchdog_work, msecs_to_jiffies(2000)); > > > > - writel(0, rkvdec->regs + RKVDEC_REG_STRMD_ERR_EN); > > - writel(0, rkvdec->regs + RKVDEC_REG_H264_ERR_E); > > + writel(0xffffffff, rkvdec->regs + RKVDEC_REG_STRMD_ERR_EN); > > + writel(0xffffffff, rkvdec->regs + RKVDEC_REG_H264_ERR_E); > > writel(1, rkvdec->regs + RKVDEC_REG_PREF_LUMA_CACHE_COMMAND); > > writel(1, rkvdec->regs + RKVDEC_REG_PREF_CHR_CACHE_COMMAND); > > > > /* Start decoding! */ > > writel(RKVDEC_INTERRUPT_DEC_E | RKVDEC_CONFIG_DEC_CLK_GATE_E | > > - RKVDEC_TIMEOUT_E | RKVDEC_BUF_EMPTY_E, > > + RKVDEC_TIMEOUT_E | RKVDEC_BUF_EMPTY_E | > > + RKVDEC_H264ORVP9_ERR_MODE, > > rkvdec->regs + RKVDEC_REG_INTERRUPT); > > > > return 0; > > @@ -1196,10 +1197,26 @@ static int rkvdec_h264_try_ctrl(struct rkvdec_ctx *ctx, struct v4l2_ctrl *ctrl) > > return 0; > > } > > > > +static int rkvdec_h264_check_error_info(struct rkvdec_ctx *ctx) > > +{ > > + struct rkvdec_dev *rkvdec = ctx->dev; > > + int err; > > + > > + err = readl(rkvdec->regs + RKVDEC_REG_H264_ERRINFO_NUM); > > + if (err & RKVDEC_STRMD_DECT_ERR_FLAG) { > > + pr_debug("Decoded picture have %i/%i slices with errors.\n", > > + RKVDEC_ERR_PKT_NUM(err), RKVDEC_SLICEDEC_NUM(err)); > > + return VB2_BUF_STATE_ERROR; > > + } > > + > > + return VB2_BUF_STATE_DONE; > > +} > > + > > const struct rkvdec_coded_fmt_ops rkvdec_h264_fmt_ops = { > > .adjust_fmt = rkvdec_h264_adjust_fmt, > > .start = rkvdec_h264_start, > > .stop = rkvdec_h264_stop, > > .run = rkvdec_h264_run, > > .try_ctrl = rkvdec_h264_try_ctrl, > > + .check_error_info = rkvdec_h264_check_error_info, > > }; > > Actually I'm not sure I fully understand what you are expecting the > userspace to do with the information that there was an (HW!) error, > which might or might not be bitstrean related. Resending the > corrupted(?) frame until the HW fully hangs? > As the interrupt reports an HW error it should (at least also) be > handled driver-side and the HW is known not to be able to fully reset > itself in case of an error. > I think this will make behavior worse than it is now (for real-life > users) where errors are eventually just ignored. I've changed the decoding mode, see bit 19 or swreg1. In that mode, the decoder will behave just like if error detection was off. It will just keep going and produce "something". With the set of corrupted streams we had, we found that the decoder no longer get stuck, and we are aware of the possibly corrupted buffers. In current mode, the decoder tries to stop as soon as an error is met, which most of the time means nothing is every written to the buffer. And as you mention, it often fail at "self reset". In streaming there is two style of handling corrupted buffers, one is to skip until valid state, and the other is to show them even if corrupted. In stack like GStreamer we just flag the corrupted frames based on the ERROR flag (unless payload size is 0) and let the user chose to drop them or not. > I think this will make behavior worse than it is now (for real-life users) where errors are eventually just ignored. Just ignoring the errors is way better then an infinite row of errors. At the moment, FFMPEG/Chromium and GStreamer ignores errors indeed. I got some work in progress patch in GStreamer I've used to test this, but its not ready yet. In the current behaviour, if you hit an error, you basically have 9 chances out of 10 to keep replaying ancient buffers in loop till the end of time. This is because the self reset never completes, and you get the same error over and over regardless what you pass to the decoder. regards, Nicolas p.s. the tests should land (if not already) in ChromeOS taste suite. > > Alex
diff --git a/drivers/staging/media/rkvdec/rkvdec-h264.c b/drivers/staging/media/rkvdec/rkvdec-h264.c index 55596ce6bb6e..60a89918e2c1 100644 --- a/drivers/staging/media/rkvdec/rkvdec-h264.c +++ b/drivers/staging/media/rkvdec/rkvdec-h264.c @@ -1175,14 +1175,15 @@ static int rkvdec_h264_run(struct rkvdec_ctx *ctx) schedule_delayed_work(&rkvdec->watchdog_work, msecs_to_jiffies(2000)); - writel(0, rkvdec->regs + RKVDEC_REG_STRMD_ERR_EN); - writel(0, rkvdec->regs + RKVDEC_REG_H264_ERR_E); + writel(0xffffffff, rkvdec->regs + RKVDEC_REG_STRMD_ERR_EN); + writel(0xffffffff, rkvdec->regs + RKVDEC_REG_H264_ERR_E); writel(1, rkvdec->regs + RKVDEC_REG_PREF_LUMA_CACHE_COMMAND); writel(1, rkvdec->regs + RKVDEC_REG_PREF_CHR_CACHE_COMMAND); /* Start decoding! */ writel(RKVDEC_INTERRUPT_DEC_E | RKVDEC_CONFIG_DEC_CLK_GATE_E | - RKVDEC_TIMEOUT_E | RKVDEC_BUF_EMPTY_E, + RKVDEC_TIMEOUT_E | RKVDEC_BUF_EMPTY_E | + RKVDEC_H264ORVP9_ERR_MODE, rkvdec->regs + RKVDEC_REG_INTERRUPT); return 0; @@ -1196,10 +1197,26 @@ static int rkvdec_h264_try_ctrl(struct rkvdec_ctx *ctx, struct v4l2_ctrl *ctrl) return 0; } +static int rkvdec_h264_check_error_info(struct rkvdec_ctx *ctx) +{ + struct rkvdec_dev *rkvdec = ctx->dev; + int err; + + err = readl(rkvdec->regs + RKVDEC_REG_H264_ERRINFO_NUM); + if (err & RKVDEC_STRMD_DECT_ERR_FLAG) { + pr_debug("Decoded picture have %i/%i slices with errors.\n", + RKVDEC_ERR_PKT_NUM(err), RKVDEC_SLICEDEC_NUM(err)); + return VB2_BUF_STATE_ERROR; + } + + return VB2_BUF_STATE_DONE; +} + const struct rkvdec_coded_fmt_ops rkvdec_h264_fmt_ops = { .adjust_fmt = rkvdec_h264_adjust_fmt, .start = rkvdec_h264_start, .stop = rkvdec_h264_stop, .run = rkvdec_h264_run, .try_ctrl = rkvdec_h264_try_ctrl, + .check_error_info = rkvdec_h264_check_error_info, };
This re-enables H.264 error detection, but using the other error mode. In that mode, the decoder will skip over the error macro-block or slices and complete the decoding. As a side effect, the error status is not set in the interrupt status register, and instead errors are detected per format. Using this mode workaround the issue that the HW get stuck in error stated and allow reporting that some corruption may be present in the buffer returned to userland. Signed-off-by: Nicolas Dufresne <nicolas.dufresne@collabora.com> --- drivers/staging/media/rkvdec/rkvdec-h264.c | 23 +++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-)