Message ID | 20180613140714.1686-8-maxime.ripard@bootlin.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Hi, On Wed, 2018-06-13 at 16:07 +0200, Maxime Ripard wrote: > The IRQ handler up until now was hardcoding the use of the MPEG engine to > read the interrupt status, clear it and disable the interrupts. > > Obviously, that won't work really well with the introduction of new codecs > that use a separate engine with a separate register set. > > In order to make this more future proof, introduce new decodec operations > to deal with the interrupt management. The only one missing is the one to > enable the interrupts in the first place, but that's taken care of by the > trigger hook for now. Acked-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com> > Signed-off-by: Maxime Ripard <maxime.ripard@bootlin.com> > --- > .../sunxi/cedrus/sunxi_cedrus_common.h | 9 +++++ > .../platform/sunxi/cedrus/sunxi_cedrus_hw.c | 21 ++++++------ > .../sunxi/cedrus/sunxi_cedrus_mpeg2.c | 33 +++++++++++++++++++ > 3 files changed, 53 insertions(+), 10 deletions(-) > > diff --git a/drivers/media/platform/sunxi/cedrus/sunxi_cedrus_common.h b/drivers/media/platform/sunxi/cedrus/sunxi_cedrus_common.h > index c2e2c92d103b..a2a507eb9fc9 100644 > --- a/drivers/media/platform/sunxi/cedrus/sunxi_cedrus_common.h > +++ b/drivers/media/platform/sunxi/cedrus/sunxi_cedrus_common.h > @@ -108,7 +108,16 @@ struct sunxi_cedrus_buffer *vb2_to_cedrus_buffer(const struct vb2_buffer *p) > return vb2_v4l2_to_cedrus_buffer(to_vb2_v4l2_buffer(p)); > } > > +enum sunxi_cedrus_irq_status { > + SUNXI_CEDRUS_IRQ_NONE, > + SUNXI_CEDRUS_IRQ_ERROR, > + SUNXI_CEDRUS_IRQ_OK, > +}; > + > struct sunxi_cedrus_dec_ops { > + void (*irq_clear)(struct sunxi_cedrus_ctx *ctx); > + void (*irq_disable)(struct sunxi_cedrus_ctx *ctx); > + enum sunxi_cedrus_irq_status (*irq_status)(struct sunxi_cedrus_ctx *ctx); > void (*setup)(struct sunxi_cedrus_ctx *ctx, > struct sunxi_cedrus_run *run); > void (*trigger)(struct sunxi_cedrus_ctx *ctx); > diff --git a/drivers/media/platform/sunxi/cedrus/sunxi_cedrus_hw.c b/drivers/media/platform/sunxi/cedrus/sunxi_cedrus_hw.c > index bb46a01214e0..6b97cbd2834e 100644 > --- a/drivers/media/platform/sunxi/cedrus/sunxi_cedrus_hw.c > +++ b/drivers/media/platform/sunxi/cedrus/sunxi_cedrus_hw.c > @@ -77,27 +77,28 @@ static irqreturn_t sunxi_cedrus_ve_irq(int irq, void *dev_id) > struct sunxi_cedrus_ctx *ctx; > struct sunxi_cedrus_buffer *src_buffer, *dst_buffer; > struct vb2_v4l2_buffer *src_vb, *dst_vb; > + enum sunxi_cedrus_irq_status status; > unsigned long flags; > - unsigned int value, status; > > spin_lock_irqsave(&dev->irq_lock, flags); > > - /* Disable MPEG interrupts and stop the MPEG engine */ > - value = sunxi_cedrus_read(dev, VE_MPEG_CTRL); > - sunxi_cedrus_write(dev, value & (~0xf), VE_MPEG_CTRL); > - > - status = sunxi_cedrus_read(dev, VE_MPEG_STATUS); > - sunxi_cedrus_write(dev, 0x0000c00f, VE_MPEG_STATUS); > - sunxi_cedrus_engine_disable(dev); > - > ctx = v4l2_m2m_get_curr_priv(dev->m2m_dev); > if (!ctx) { > pr_err("Instance released before the end of transaction\n"); > spin_unlock_irqrestore(&dev->irq_lock, flags); > > - return IRQ_HANDLED; > + return IRQ_NONE; > } > > + status = dev->dec_ops[ctx->current_codec]->irq_status(ctx); > + if (status == SUNXI_CEDRUS_IRQ_NONE) { > + spin_unlock_irqrestore(&dev->irq_lock, flags); > + return IRQ_NONE; > + } > + > + dev->dec_ops[ctx->current_codec]->irq_disable(ctx); > + dev->dec_ops[ctx->current_codec]->irq_clear(ctx); > + > src_vb = v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx); > dst_vb = v4l2_m2m_dst_buf_remove(ctx->fh.m2m_ctx); > > diff --git a/drivers/media/platform/sunxi/cedrus/sunxi_cedrus_mpeg2.c b/drivers/media/platform/sunxi/cedrus/sunxi_cedrus_mpeg2.c > index e25075bb5779..51fa0c0f9bf2 100644 > --- a/drivers/media/platform/sunxi/cedrus/sunxi_cedrus_mpeg2.c > +++ b/drivers/media/platform/sunxi/cedrus/sunxi_cedrus_mpeg2.c > @@ -52,6 +52,36 @@ static const u8 mpeg_default_non_intra_quant[64] = { > > #define m_niq(i) ((i << 8) | mpeg_default_non_intra_quant[i]) > > +static enum sunxi_cedrus_irq_status > +sunxi_cedrus_mpeg2_irq_status(struct sunxi_cedrus_ctx *ctx) > +{ > + struct sunxi_cedrus_dev *dev = ctx->dev; > + u32 reg = sunxi_cedrus_read(dev, VE_MPEG_STATUS) & 0x7; > + > + if (!reg) > + return SUNXI_CEDRUS_IRQ_NONE; > + > + if (reg & (BIT(1) | BIT(2))) > + return SUNXI_CEDRUS_IRQ_ERROR; > + > + return SUNXI_CEDRUS_IRQ_OK; > +} > + > +static void sunxi_cedrus_mpeg2_irq_clear(struct sunxi_cedrus_ctx *ctx) > +{ > + struct sunxi_cedrus_dev *dev = ctx->dev; > + > + sunxi_cedrus_write(dev, GENMASK(2, 0), VE_MPEG_STATUS); > +} > + > +static void sunxi_cedrus_mpeg2_irq_disable(struct sunxi_cedrus_ctx *ctx) > +{ > + struct sunxi_cedrus_dev *dev = ctx->dev; > + u32 reg = sunxi_cedrus_read(dev, VE_MPEG_CTRL) & ~BIT(3); > + > + sunxi_cedrus_write(dev, reg, VE_MPEG_CTRL); > +} > + > static void sunxi_cedrus_mpeg2_setup(struct sunxi_cedrus_ctx *ctx, > struct sunxi_cedrus_run *run) > { > @@ -156,6 +186,9 @@ static void sunxi_cedrus_mpeg2_trigger(struct sunxi_cedrus_ctx *ctx) > } > > struct sunxi_cedrus_dec_ops sunxi_cedrus_dec_ops_mpeg2 = { > + .irq_clear = sunxi_cedrus_mpeg2_irq_clear, > + .irq_disable = sunxi_cedrus_mpeg2_irq_disable, > + .irq_status = sunxi_cedrus_mpeg2_irq_status, > .setup = sunxi_cedrus_mpeg2_setup, > .trigger = sunxi_cedrus_mpeg2_trigger, > };
Hi, On Thu, 2018-06-21 at 17:35 +0200, Paul Kocialkowski wrote: > Hi, > > On Wed, 2018-06-13 at 16:07 +0200, Maxime Ripard wrote: > > The IRQ handler up until now was hardcoding the use of the MPEG engine to > > read the interrupt status, clear it and disable the interrupts. > > > > Obviously, that won't work really well with the introduction of new codecs > > that use a separate engine with a separate register set. > > > > In order to make this more future proof, introduce new decodec operations > > to deal with the interrupt management. The only one missing is the one to > > enable the interrupts in the first place, but that's taken care of by the > > trigger hook for now. > > Acked-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com> Scratch that for now, I just thought of something here (see below). > > Signed-off-by: Maxime Ripard <maxime.ripard@bootlin.com> > > --- > > .../sunxi/cedrus/sunxi_cedrus_common.h | 9 +++++ > > .../platform/sunxi/cedrus/sunxi_cedrus_hw.c | 21 ++++++------ > > .../sunxi/cedrus/sunxi_cedrus_mpeg2.c | 33 +++++++++++++++++++ > > 3 files changed, 53 insertions(+), 10 deletions(-) > > > > diff --git a/drivers/media/platform/sunxi/cedrus/sunxi_cedrus_common.h b/drivers/media/platform/sunxi/cedrus/sunxi_cedrus_common.h > > index c2e2c92d103b..a2a507eb9fc9 100644 > > --- a/drivers/media/platform/sunxi/cedrus/sunxi_cedrus_common.h > > +++ b/drivers/media/platform/sunxi/cedrus/sunxi_cedrus_common.h > > @@ -108,7 +108,16 @@ struct sunxi_cedrus_buffer *vb2_to_cedrus_buffer(const struct vb2_buffer *p) > > return vb2_v4l2_to_cedrus_buffer(to_vb2_v4l2_buffer(p)); > > } > > > > +enum sunxi_cedrus_irq_status { > > + SUNXI_CEDRUS_IRQ_NONE, > > + SUNXI_CEDRUS_IRQ_ERROR, > > + SUNXI_CEDRUS_IRQ_OK, > > +}; > > + > > struct sunxi_cedrus_dec_ops { > > + void (*irq_clear)(struct sunxi_cedrus_ctx *ctx); > > + void (*irq_disable)(struct sunxi_cedrus_ctx *ctx); > > + enum sunxi_cedrus_irq_status (*irq_status)(struct sunxi_cedrus_ctx *ctx); > > void (*setup)(struct sunxi_cedrus_ctx *ctx, > > struct sunxi_cedrus_run *run); > > void (*trigger)(struct sunxi_cedrus_ctx *ctx); > > diff --git a/drivers/media/platform/sunxi/cedrus/sunxi_cedrus_hw.c b/drivers/media/platform/sunxi/cedrus/sunxi_cedrus_hw.c > > index bb46a01214e0..6b97cbd2834e 100644 > > --- a/drivers/media/platform/sunxi/cedrus/sunxi_cedrus_hw.c > > +++ b/drivers/media/platform/sunxi/cedrus/sunxi_cedrus_hw.c > > @@ -77,27 +77,28 @@ static irqreturn_t sunxi_cedrus_ve_irq(int irq, void *dev_id) > > struct sunxi_cedrus_ctx *ctx; > > struct sunxi_cedrus_buffer *src_buffer, *dst_buffer; > > struct vb2_v4l2_buffer *src_vb, *dst_vb; > > + enum sunxi_cedrus_irq_status status; > > unsigned long flags; > > - unsigned int value, status; > > > > spin_lock_irqsave(&dev->irq_lock, flags); > > > > - /* Disable MPEG interrupts and stop the MPEG engine */ > > - value = sunxi_cedrus_read(dev, VE_MPEG_CTRL); > > - sunxi_cedrus_write(dev, value & (~0xf), VE_MPEG_CTRL); > > - > > - status = sunxi_cedrus_read(dev, VE_MPEG_STATUS); > > - sunxi_cedrus_write(dev, 0x0000c00f, VE_MPEG_STATUS); > > - sunxi_cedrus_engine_disable(dev); > > - > > ctx = v4l2_m2m_get_curr_priv(dev->m2m_dev); > > if (!ctx) { > > pr_err("Instance released before the end of transaction\n"); > > spin_unlock_irqrestore(&dev->irq_lock, flags); > > > > - return IRQ_HANDLED; > > + return IRQ_NONE; > > } > > > > + status = dev->dec_ops[ctx->current_codec]->irq_status(ctx); > > + if (status == SUNXI_CEDRUS_IRQ_NONE) { > > + spin_unlock_irqrestore(&dev->irq_lock, flags); > > + return IRQ_NONE; > > + } > > + > > + dev->dec_ops[ctx->current_codec]->irq_disable(ctx); > > + dev->dec_ops[ctx->current_codec]->irq_clear(ctx); > > + > > src_vb = v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx); > > dst_vb = v4l2_m2m_dst_buf_remove(ctx->fh.m2m_ctx); Later in that file, there is still some checking that the first bit of status is set: /* First bit of MPEG_STATUS indicates success. */ if (ctx->job_abort || !(status & 0x01)) So !(status & 0x01) must be replaced with status != CEDRUS_IRQ_OK. It seems that was working "by accident", with CEDRUS_IRQ_OK probably being set by the compiler to 0x03. Cheers, Paul
Hi, On Wed, 2018-06-13 at 16:07 +0200, Maxime Ripard wrote: > The IRQ handler up until now was hardcoding the use of the MPEG engine to > read the interrupt status, clear it and disable the interrupts. > > Obviously, that won't work really well with the introduction of new codecs > that use a separate engine with a separate register set. > > In order to make this more future proof, introduce new decodec operations > to deal with the interrupt management. The only one missing is the one to > enable the interrupts in the first place, but that's taken care of by the > trigger hook for now. Here's another comment about an issue I just figured out. > Signed-off-by: Maxime Ripard <maxime.ripard@bootlin.com> > --- > .../sunxi/cedrus/sunxi_cedrus_common.h | 9 +++++ > .../platform/sunxi/cedrus/sunxi_cedrus_hw.c | 21 ++++++------ > .../sunxi/cedrus/sunxi_cedrus_mpeg2.c | 33 +++++++++++++++++++ > 3 files changed, 53 insertions(+), 10 deletions(-) > > diff --git a/drivers/media/platform/sunxi/cedrus/sunxi_cedrus_common.h b/drivers/media/platform/sunxi/cedrus/sunxi_cedrus_common.h > index c2e2c92d103b..a2a507eb9fc9 100644 > --- a/drivers/media/platform/sunxi/cedrus/sunxi_cedrus_common.h > +++ b/drivers/media/platform/sunxi/cedrus/sunxi_cedrus_common.h > @@ -108,7 +108,16 @@ struct sunxi_cedrus_buffer *vb2_to_cedrus_buffer(const struct vb2_buffer *p) > return vb2_v4l2_to_cedrus_buffer(to_vb2_v4l2_buffer(p)); > } > > +enum sunxi_cedrus_irq_status { > + SUNXI_CEDRUS_IRQ_NONE, > + SUNXI_CEDRUS_IRQ_ERROR, > + SUNXI_CEDRUS_IRQ_OK, > +}; > + > struct sunxi_cedrus_dec_ops { > + void (*irq_clear)(struct sunxi_cedrus_ctx *ctx); > + void (*irq_disable)(struct sunxi_cedrus_ctx *ctx); > + enum sunxi_cedrus_irq_status (*irq_status)(struct sunxi_cedrus_ctx *ctx); > void (*setup)(struct sunxi_cedrus_ctx *ctx, > struct sunxi_cedrus_run *run); > void (*trigger)(struct sunxi_cedrus_ctx *ctx); > diff --git a/drivers/media/platform/sunxi/cedrus/sunxi_cedrus_hw.c b/drivers/media/platform/sunxi/cedrus/sunxi_cedrus_hw.c > index bb46a01214e0..6b97cbd2834e 100644 > --- a/drivers/media/platform/sunxi/cedrus/sunxi_cedrus_hw.c > +++ b/drivers/media/platform/sunxi/cedrus/sunxi_cedrus_hw.c > @@ -77,27 +77,28 @@ static irqreturn_t sunxi_cedrus_ve_irq(int irq, void *dev_id) > struct sunxi_cedrus_ctx *ctx; > struct sunxi_cedrus_buffer *src_buffer, *dst_buffer; > struct vb2_v4l2_buffer *src_vb, *dst_vb; > + enum sunxi_cedrus_irq_status status; > unsigned long flags; > - unsigned int value, status; > > spin_lock_irqsave(&dev->irq_lock, flags); > > - /* Disable MPEG interrupts and stop the MPEG engine */ > - value = sunxi_cedrus_read(dev, VE_MPEG_CTRL); > - sunxi_cedrus_write(dev, value & (~0xf), VE_MPEG_CTRL); > - > - status = sunxi_cedrus_read(dev, VE_MPEG_STATUS); > - sunxi_cedrus_write(dev, 0x0000c00f, VE_MPEG_STATUS); > - sunxi_cedrus_engine_disable(dev); This call was dropped from the code reorganization. What it intentional? IMO, it should be brought back to the irq_disable ops for MPEG2 (and the same probably applies to H264). Things still seem to work without it, though, but there might be a difference in terms of standby VPU power consumption. Cheers, Paul
On Mon, 2018-06-25 at 17:38 +0200, Paul Kocialkowski wrote: > Hi, > > On Wed, 2018-06-13 at 16:07 +0200, Maxime Ripard wrote: > > The IRQ handler up until now was hardcoding the use of the MPEG engine to > > read the interrupt status, clear it and disable the interrupts. > > > > Obviously, that won't work really well with the introduction of new codecs > > that use a separate engine with a separate register set. > > > > In order to make this more future proof, introduce new decodec operations > > to deal with the interrupt management. The only one missing is the one to > > enable the interrupts in the first place, but that's taken care of by the > > trigger hook for now. > > Here's another comment about an issue I just figured out. > > > Signed-off-by: Maxime Ripard <maxime.ripard@bootlin.com> > > --- > > .../sunxi/cedrus/sunxi_cedrus_common.h | 9 +++++ > > .../platform/sunxi/cedrus/sunxi_cedrus_hw.c | 21 ++++++------ > > .../sunxi/cedrus/sunxi_cedrus_mpeg2.c | 33 +++++++++++++++++++ > > 3 files changed, 53 insertions(+), 10 deletions(-) > > > > diff --git a/drivers/media/platform/sunxi/cedrus/sunxi_cedrus_common.h b/drivers/media/platform/sunxi/cedrus/sunxi_cedrus_common.h > > index c2e2c92d103b..a2a507eb9fc9 100644 > > --- a/drivers/media/platform/sunxi/cedrus/sunxi_cedrus_common.h > > +++ b/drivers/media/platform/sunxi/cedrus/sunxi_cedrus_common.h > > @@ -108,7 +108,16 @@ struct sunxi_cedrus_buffer *vb2_to_cedrus_buffer(const struct vb2_buffer *p) > > return vb2_v4l2_to_cedrus_buffer(to_vb2_v4l2_buffer(p)); > > } > > > > +enum sunxi_cedrus_irq_status { > > + SUNXI_CEDRUS_IRQ_NONE, > > + SUNXI_CEDRUS_IRQ_ERROR, > > + SUNXI_CEDRUS_IRQ_OK, > > +}; > > + > > struct sunxi_cedrus_dec_ops { > > + void (*irq_clear)(struct sunxi_cedrus_ctx *ctx); > > + void (*irq_disable)(struct sunxi_cedrus_ctx *ctx); > > + enum sunxi_cedrus_irq_status (*irq_status)(struct sunxi_cedrus_ctx *ctx); > > void (*setup)(struct sunxi_cedrus_ctx *ctx, > > struct sunxi_cedrus_run *run); > > void (*trigger)(struct sunxi_cedrus_ctx *ctx); > > diff --git a/drivers/media/platform/sunxi/cedrus/sunxi_cedrus_hw.c b/drivers/media/platform/sunxi/cedrus/sunxi_cedrus_hw.c > > index bb46a01214e0..6b97cbd2834e 100644 > > --- a/drivers/media/platform/sunxi/cedrus/sunxi_cedrus_hw.c > > +++ b/drivers/media/platform/sunxi/cedrus/sunxi_cedrus_hw.c > > @@ -77,27 +77,28 @@ static irqreturn_t sunxi_cedrus_ve_irq(int irq, void *dev_id) > > struct sunxi_cedrus_ctx *ctx; > > struct sunxi_cedrus_buffer *src_buffer, *dst_buffer; > > struct vb2_v4l2_buffer *src_vb, *dst_vb; > > + enum sunxi_cedrus_irq_status status; > > unsigned long flags; > > - unsigned int value, status; > > > > spin_lock_irqsave(&dev->irq_lock, flags); > > > > - /* Disable MPEG interrupts and stop the MPEG engine */ > > - value = sunxi_cedrus_read(dev, VE_MPEG_CTRL); > > - sunxi_cedrus_write(dev, value & (~0xf), VE_MPEG_CTRL); > > - > > - status = sunxi_cedrus_read(dev, VE_MPEG_STATUS); > > - sunxi_cedrus_write(dev, 0x0000c00f, VE_MPEG_STATUS); > > - sunxi_cedrus_engine_disable(dev); > > This call was dropped from the code reorganization. What it intentional? > > IMO, it should be brought back to the irq_disable ops for MPEG2 (and the > same probably applies to H264). Actually, this doesn't seem like the right place to put it. Looking at the sunxi_engine_enable function, explicitly passing the codec as an argument and calling that function from each codec's code feels strange. We should probably break down these functions (sunxi_engine_enable/sunxi_engine_disable) into codec ops. The start/stop couple seems like a good fit, but it brings up the following question: do we want to disable the engine between each frame or not? I really don't know how significant the power saving benefits are and what downsides there might be. What do you think? > Things still seem to work without it, > though, but there might be a difference in terms of standby VPU power > consumption. > > Cheers, > > Paul >
On Mon, Jun 25, 2018 at 04:18:51PM +0200, Paul Kocialkowski wrote: > Hi, > > On Thu, 2018-06-21 at 17:35 +0200, Paul Kocialkowski wrote: > > Hi, > > > > On Wed, 2018-06-13 at 16:07 +0200, Maxime Ripard wrote: > > > The IRQ handler up until now was hardcoding the use of the MPEG engine to > > > read the interrupt status, clear it and disable the interrupts. > > > > > > Obviously, that won't work really well with the introduction of new codecs > > > that use a separate engine with a separate register set. > > > > > > In order to make this more future proof, introduce new decodec operations > > > to deal with the interrupt management. The only one missing is the one to > > > enable the interrupts in the first place, but that's taken care of by the > > > trigger hook for now. > > > > Acked-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com> > > Scratch that for now, I just thought of something here (see below). > > > > Signed-off-by: Maxime Ripard <maxime.ripard@bootlin.com> > > > --- > > > .../sunxi/cedrus/sunxi_cedrus_common.h | 9 +++++ > > > .../platform/sunxi/cedrus/sunxi_cedrus_hw.c | 21 ++++++------ > > > .../sunxi/cedrus/sunxi_cedrus_mpeg2.c | 33 +++++++++++++++++++ > > > 3 files changed, 53 insertions(+), 10 deletions(-) > > > > > > diff --git a/drivers/media/platform/sunxi/cedrus/sunxi_cedrus_common.h b/drivers/media/platform/sunxi/cedrus/sunxi_cedrus_common.h > > > index c2e2c92d103b..a2a507eb9fc9 100644 > > > --- a/drivers/media/platform/sunxi/cedrus/sunxi_cedrus_common.h > > > +++ b/drivers/media/platform/sunxi/cedrus/sunxi_cedrus_common.h > > > @@ -108,7 +108,16 @@ struct sunxi_cedrus_buffer *vb2_to_cedrus_buffer(const struct vb2_buffer *p) > > > return vb2_v4l2_to_cedrus_buffer(to_vb2_v4l2_buffer(p)); > > > } > > > > > > +enum sunxi_cedrus_irq_status { > > > + SUNXI_CEDRUS_IRQ_NONE, > > > + SUNXI_CEDRUS_IRQ_ERROR, > > > + SUNXI_CEDRUS_IRQ_OK, > > > +}; > > > + > > > struct sunxi_cedrus_dec_ops { > > > + void (*irq_clear)(struct sunxi_cedrus_ctx *ctx); > > > + void (*irq_disable)(struct sunxi_cedrus_ctx *ctx); > > > + enum sunxi_cedrus_irq_status (*irq_status)(struct sunxi_cedrus_ctx *ctx); > > > void (*setup)(struct sunxi_cedrus_ctx *ctx, > > > struct sunxi_cedrus_run *run); > > > void (*trigger)(struct sunxi_cedrus_ctx *ctx); > > > diff --git a/drivers/media/platform/sunxi/cedrus/sunxi_cedrus_hw.c b/drivers/media/platform/sunxi/cedrus/sunxi_cedrus_hw.c > > > index bb46a01214e0..6b97cbd2834e 100644 > > > --- a/drivers/media/platform/sunxi/cedrus/sunxi_cedrus_hw.c > > > +++ b/drivers/media/platform/sunxi/cedrus/sunxi_cedrus_hw.c > > > @@ -77,27 +77,28 @@ static irqreturn_t sunxi_cedrus_ve_irq(int irq, void *dev_id) > > > struct sunxi_cedrus_ctx *ctx; > > > struct sunxi_cedrus_buffer *src_buffer, *dst_buffer; > > > struct vb2_v4l2_buffer *src_vb, *dst_vb; > > > + enum sunxi_cedrus_irq_status status; > > > unsigned long flags; > > > - unsigned int value, status; > > > > > > spin_lock_irqsave(&dev->irq_lock, flags); > > > > > > - /* Disable MPEG interrupts and stop the MPEG engine */ > > > - value = sunxi_cedrus_read(dev, VE_MPEG_CTRL); > > > - sunxi_cedrus_write(dev, value & (~0xf), VE_MPEG_CTRL); > > > - > > > - status = sunxi_cedrus_read(dev, VE_MPEG_STATUS); > > > - sunxi_cedrus_write(dev, 0x0000c00f, VE_MPEG_STATUS); > > > - sunxi_cedrus_engine_disable(dev); > > > - > > > ctx = v4l2_m2m_get_curr_priv(dev->m2m_dev); > > > if (!ctx) { > > > pr_err("Instance released before the end of transaction\n"); > > > spin_unlock_irqrestore(&dev->irq_lock, flags); > > > > > > - return IRQ_HANDLED; > > > + return IRQ_NONE; > > > } > > > > > > + status = dev->dec_ops[ctx->current_codec]->irq_status(ctx); > > > + if (status == SUNXI_CEDRUS_IRQ_NONE) { > > > + spin_unlock_irqrestore(&dev->irq_lock, flags); > > > + return IRQ_NONE; > > > + } > > > + > > > + dev->dec_ops[ctx->current_codec]->irq_disable(ctx); > > > + dev->dec_ops[ctx->current_codec]->irq_clear(ctx); > > > + > > > src_vb = v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx); > > > dst_vb = v4l2_m2m_dst_buf_remove(ctx->fh.m2m_ctx); > > Later in that file, there is still some checking that the first bit of > status is set: > > /* First bit of MPEG_STATUS indicates success. */ > if (ctx->job_abort || !(status & 0x01)) > > So !(status & 0x01) must be replaced with status != CEDRUS_IRQ_OK. > > It seems that was working "by accident", with CEDRUS_IRQ_OK probably > being set by the compiler to 0x03. Yeah, I noticed this already and this was fixed for the v2 :) Maxime
On Mon, Jun 25, 2018 at 05:49:58PM +0200, Paul Kocialkowski wrote: > On Mon, 2018-06-25 at 17:38 +0200, Paul Kocialkowski wrote: > > Hi, > > > > On Wed, 2018-06-13 at 16:07 +0200, Maxime Ripard wrote: > > > The IRQ handler up until now was hardcoding the use of the MPEG engine to > > > read the interrupt status, clear it and disable the interrupts. > > > > > > Obviously, that won't work really well with the introduction of new codecs > > > that use a separate engine with a separate register set. > > > > > > In order to make this more future proof, introduce new decodec operations > > > to deal with the interrupt management. The only one missing is the one to > > > enable the interrupts in the first place, but that's taken care of by the > > > trigger hook for now. > > > > Here's another comment about an issue I just figured out. > > > > > Signed-off-by: Maxime Ripard <maxime.ripard@bootlin.com> > > > --- > > > .../sunxi/cedrus/sunxi_cedrus_common.h | 9 +++++ > > > .../platform/sunxi/cedrus/sunxi_cedrus_hw.c | 21 ++++++------ > > > .../sunxi/cedrus/sunxi_cedrus_mpeg2.c | 33 +++++++++++++++++++ > > > 3 files changed, 53 insertions(+), 10 deletions(-) > > > > > > diff --git a/drivers/media/platform/sunxi/cedrus/sunxi_cedrus_common.h b/drivers/media/platform/sunxi/cedrus/sunxi_cedrus_common.h > > > index c2e2c92d103b..a2a507eb9fc9 100644 > > > --- a/drivers/media/platform/sunxi/cedrus/sunxi_cedrus_common.h > > > +++ b/drivers/media/platform/sunxi/cedrus/sunxi_cedrus_common.h > > > @@ -108,7 +108,16 @@ struct sunxi_cedrus_buffer *vb2_to_cedrus_buffer(const struct vb2_buffer *p) > > > return vb2_v4l2_to_cedrus_buffer(to_vb2_v4l2_buffer(p)); > > > } > > > > > > +enum sunxi_cedrus_irq_status { > > > + SUNXI_CEDRUS_IRQ_NONE, > > > + SUNXI_CEDRUS_IRQ_ERROR, > > > + SUNXI_CEDRUS_IRQ_OK, > > > +}; > > > + > > > struct sunxi_cedrus_dec_ops { > > > + void (*irq_clear)(struct sunxi_cedrus_ctx *ctx); > > > + void (*irq_disable)(struct sunxi_cedrus_ctx *ctx); > > > + enum sunxi_cedrus_irq_status (*irq_status)(struct sunxi_cedrus_ctx *ctx); > > > void (*setup)(struct sunxi_cedrus_ctx *ctx, > > > struct sunxi_cedrus_run *run); > > > void (*trigger)(struct sunxi_cedrus_ctx *ctx); > > > diff --git a/drivers/media/platform/sunxi/cedrus/sunxi_cedrus_hw.c b/drivers/media/platform/sunxi/cedrus/sunxi_cedrus_hw.c > > > index bb46a01214e0..6b97cbd2834e 100644 > > > --- a/drivers/media/platform/sunxi/cedrus/sunxi_cedrus_hw.c > > > +++ b/drivers/media/platform/sunxi/cedrus/sunxi_cedrus_hw.c > > > @@ -77,27 +77,28 @@ static irqreturn_t sunxi_cedrus_ve_irq(int irq, void *dev_id) > > > struct sunxi_cedrus_ctx *ctx; > > > struct sunxi_cedrus_buffer *src_buffer, *dst_buffer; > > > struct vb2_v4l2_buffer *src_vb, *dst_vb; > > > + enum sunxi_cedrus_irq_status status; > > > unsigned long flags; > > > - unsigned int value, status; > > > > > > spin_lock_irqsave(&dev->irq_lock, flags); > > > > > > - /* Disable MPEG interrupts and stop the MPEG engine */ > > > - value = sunxi_cedrus_read(dev, VE_MPEG_CTRL); > > > - sunxi_cedrus_write(dev, value & (~0xf), VE_MPEG_CTRL); > > > - > > > - status = sunxi_cedrus_read(dev, VE_MPEG_STATUS); > > > - sunxi_cedrus_write(dev, 0x0000c00f, VE_MPEG_STATUS); > > > - sunxi_cedrus_engine_disable(dev); > > > > This call was dropped from the code reorganization. What it intentional? > > > > IMO, it should be brought back to the irq_disable ops for MPEG2 (and the > > same probably applies to H264). > > Actually, this doesn't seem like the right place to put it. > > Looking at the sunxi_engine_enable function, explicitly passing the > codec as an argument and calling that function from each codec's code > feels strange. > > We should probably break down these functions > (sunxi_engine_enable/sunxi_engine_disable) into codec ops. The > start/stop couple seems like a good fit, but it brings up the following > question: do we want to disable the engine between each frame or not? > > I really don't know how significant the power saving benefits are and > what downsides there might be. > > What do you think? If we don't need to disable it between each frames, then let's keep it enabled. Without any number, and considering the current state of power management (which is inexistent on this driver, and close to for the whole platform), wasting a bit of power if we do isn't really a big deal. Maxime
On Mon, Jun 25, 2018 at 05:49:58PM +0200, Paul Kocialkowski wrote: > On Mon, 2018-06-25 at 17:38 +0200, Paul Kocialkowski wrote: > > Hi, > > > > On Wed, 2018-06-13 at 16:07 +0200, Maxime Ripard wrote: > > > The IRQ handler up until now was hardcoding the use of the MPEG engine to > > > read the interrupt status, clear it and disable the interrupts. > > > > > > Obviously, that won't work really well with the introduction of new codecs > > > that use a separate engine with a separate register set. > > > > > > In order to make this more future proof, introduce new decodec operations > > > to deal with the interrupt management. The only one missing is the one to > > > enable the interrupts in the first place, but that's taken care of by the > > > trigger hook for now. > > > > Here's another comment about an issue I just figured out. > > > > > Signed-off-by: Maxime Ripard <maxime.ripard@bootlin.com> > > > --- > > > .../sunxi/cedrus/sunxi_cedrus_common.h | 9 +++++ > > > .../platform/sunxi/cedrus/sunxi_cedrus_hw.c | 21 ++++++------ > > > .../sunxi/cedrus/sunxi_cedrus_mpeg2.c | 33 +++++++++++++++++++ > > > 3 files changed, 53 insertions(+), 10 deletions(-) > > > > > > diff --git a/drivers/media/platform/sunxi/cedrus/sunxi_cedrus_common.h b/drivers/media/platform/sunxi/cedrus/sunxi_cedrus_common.h > > > index c2e2c92d103b..a2a507eb9fc9 100644 > > > --- a/drivers/media/platform/sunxi/cedrus/sunxi_cedrus_common.h > > > +++ b/drivers/media/platform/sunxi/cedrus/sunxi_cedrus_common.h > > > @@ -108,7 +108,16 @@ struct sunxi_cedrus_buffer *vb2_to_cedrus_buffer(const struct vb2_buffer *p) > > > return vb2_v4l2_to_cedrus_buffer(to_vb2_v4l2_buffer(p)); > > > } > > > > > > +enum sunxi_cedrus_irq_status { > > > + SUNXI_CEDRUS_IRQ_NONE, > > > + SUNXI_CEDRUS_IRQ_ERROR, > > > + SUNXI_CEDRUS_IRQ_OK, > > > +}; > > > + > > > struct sunxi_cedrus_dec_ops { > > > + void (*irq_clear)(struct sunxi_cedrus_ctx *ctx); > > > + void (*irq_disable)(struct sunxi_cedrus_ctx *ctx); > > > + enum sunxi_cedrus_irq_status (*irq_status)(struct sunxi_cedrus_ctx *ctx); > > > void (*setup)(struct sunxi_cedrus_ctx *ctx, > > > struct sunxi_cedrus_run *run); > > > void (*trigger)(struct sunxi_cedrus_ctx *ctx); > > > diff --git a/drivers/media/platform/sunxi/cedrus/sunxi_cedrus_hw.c b/drivers/media/platform/sunxi/cedrus/sunxi_cedrus_hw.c > > > index bb46a01214e0..6b97cbd2834e 100644 > > > --- a/drivers/media/platform/sunxi/cedrus/sunxi_cedrus_hw.c > > > +++ b/drivers/media/platform/sunxi/cedrus/sunxi_cedrus_hw.c > > > @@ -77,27 +77,28 @@ static irqreturn_t sunxi_cedrus_ve_irq(int irq, void *dev_id) > > > struct sunxi_cedrus_ctx *ctx; > > > struct sunxi_cedrus_buffer *src_buffer, *dst_buffer; > > > struct vb2_v4l2_buffer *src_vb, *dst_vb; > > > + enum sunxi_cedrus_irq_status status; > > > unsigned long flags; > > > - unsigned int value, status; > > > > > > spin_lock_irqsave(&dev->irq_lock, flags); > > > > > > - /* Disable MPEG interrupts and stop the MPEG engine */ > > > - value = sunxi_cedrus_read(dev, VE_MPEG_CTRL); > > > - sunxi_cedrus_write(dev, value & (~0xf), VE_MPEG_CTRL); > > > - > > > - status = sunxi_cedrus_read(dev, VE_MPEG_STATUS); > > > - sunxi_cedrus_write(dev, 0x0000c00f, VE_MPEG_STATUS); > > > - sunxi_cedrus_engine_disable(dev); > > > > This call was dropped from the code reorganization. What it intentional? > > > > IMO, it should be brought back to the irq_disable ops for MPEG2 (and the > > same probably applies to H264). > > Actually, this doesn't seem like the right place to put it. > > Looking at the sunxi_engine_enable function, explicitly passing the > codec as an argument and calling that function from each codec's code > feels strange. This isn't what this code is doing. You have three engines, each of them implementing a different set of codec. The JPEG engine implements MPEG1, MPEG2 and MPEG4, the H264 engine H264 and VP8, and the H265 H265 and VP9. So there is no direct match between a codec and an engine. Maxime
diff --git a/drivers/media/platform/sunxi/cedrus/sunxi_cedrus_common.h b/drivers/media/platform/sunxi/cedrus/sunxi_cedrus_common.h index c2e2c92d103b..a2a507eb9fc9 100644 --- a/drivers/media/platform/sunxi/cedrus/sunxi_cedrus_common.h +++ b/drivers/media/platform/sunxi/cedrus/sunxi_cedrus_common.h @@ -108,7 +108,16 @@ struct sunxi_cedrus_buffer *vb2_to_cedrus_buffer(const struct vb2_buffer *p) return vb2_v4l2_to_cedrus_buffer(to_vb2_v4l2_buffer(p)); } +enum sunxi_cedrus_irq_status { + SUNXI_CEDRUS_IRQ_NONE, + SUNXI_CEDRUS_IRQ_ERROR, + SUNXI_CEDRUS_IRQ_OK, +}; + struct sunxi_cedrus_dec_ops { + void (*irq_clear)(struct sunxi_cedrus_ctx *ctx); + void (*irq_disable)(struct sunxi_cedrus_ctx *ctx); + enum sunxi_cedrus_irq_status (*irq_status)(struct sunxi_cedrus_ctx *ctx); void (*setup)(struct sunxi_cedrus_ctx *ctx, struct sunxi_cedrus_run *run); void (*trigger)(struct sunxi_cedrus_ctx *ctx); diff --git a/drivers/media/platform/sunxi/cedrus/sunxi_cedrus_hw.c b/drivers/media/platform/sunxi/cedrus/sunxi_cedrus_hw.c index bb46a01214e0..6b97cbd2834e 100644 --- a/drivers/media/platform/sunxi/cedrus/sunxi_cedrus_hw.c +++ b/drivers/media/platform/sunxi/cedrus/sunxi_cedrus_hw.c @@ -77,27 +77,28 @@ static irqreturn_t sunxi_cedrus_ve_irq(int irq, void *dev_id) struct sunxi_cedrus_ctx *ctx; struct sunxi_cedrus_buffer *src_buffer, *dst_buffer; struct vb2_v4l2_buffer *src_vb, *dst_vb; + enum sunxi_cedrus_irq_status status; unsigned long flags; - unsigned int value, status; spin_lock_irqsave(&dev->irq_lock, flags); - /* Disable MPEG interrupts and stop the MPEG engine */ - value = sunxi_cedrus_read(dev, VE_MPEG_CTRL); - sunxi_cedrus_write(dev, value & (~0xf), VE_MPEG_CTRL); - - status = sunxi_cedrus_read(dev, VE_MPEG_STATUS); - sunxi_cedrus_write(dev, 0x0000c00f, VE_MPEG_STATUS); - sunxi_cedrus_engine_disable(dev); - ctx = v4l2_m2m_get_curr_priv(dev->m2m_dev); if (!ctx) { pr_err("Instance released before the end of transaction\n"); spin_unlock_irqrestore(&dev->irq_lock, flags); - return IRQ_HANDLED; + return IRQ_NONE; } + status = dev->dec_ops[ctx->current_codec]->irq_status(ctx); + if (status == SUNXI_CEDRUS_IRQ_NONE) { + spin_unlock_irqrestore(&dev->irq_lock, flags); + return IRQ_NONE; + } + + dev->dec_ops[ctx->current_codec]->irq_disable(ctx); + dev->dec_ops[ctx->current_codec]->irq_clear(ctx); + src_vb = v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx); dst_vb = v4l2_m2m_dst_buf_remove(ctx->fh.m2m_ctx); diff --git a/drivers/media/platform/sunxi/cedrus/sunxi_cedrus_mpeg2.c b/drivers/media/platform/sunxi/cedrus/sunxi_cedrus_mpeg2.c index e25075bb5779..51fa0c0f9bf2 100644 --- a/drivers/media/platform/sunxi/cedrus/sunxi_cedrus_mpeg2.c +++ b/drivers/media/platform/sunxi/cedrus/sunxi_cedrus_mpeg2.c @@ -52,6 +52,36 @@ static const u8 mpeg_default_non_intra_quant[64] = { #define m_niq(i) ((i << 8) | mpeg_default_non_intra_quant[i]) +static enum sunxi_cedrus_irq_status +sunxi_cedrus_mpeg2_irq_status(struct sunxi_cedrus_ctx *ctx) +{ + struct sunxi_cedrus_dev *dev = ctx->dev; + u32 reg = sunxi_cedrus_read(dev, VE_MPEG_STATUS) & 0x7; + + if (!reg) + return SUNXI_CEDRUS_IRQ_NONE; + + if (reg & (BIT(1) | BIT(2))) + return SUNXI_CEDRUS_IRQ_ERROR; + + return SUNXI_CEDRUS_IRQ_OK; +} + +static void sunxi_cedrus_mpeg2_irq_clear(struct sunxi_cedrus_ctx *ctx) +{ + struct sunxi_cedrus_dev *dev = ctx->dev; + + sunxi_cedrus_write(dev, GENMASK(2, 0), VE_MPEG_STATUS); +} + +static void sunxi_cedrus_mpeg2_irq_disable(struct sunxi_cedrus_ctx *ctx) +{ + struct sunxi_cedrus_dev *dev = ctx->dev; + u32 reg = sunxi_cedrus_read(dev, VE_MPEG_CTRL) & ~BIT(3); + + sunxi_cedrus_write(dev, reg, VE_MPEG_CTRL); +} + static void sunxi_cedrus_mpeg2_setup(struct sunxi_cedrus_ctx *ctx, struct sunxi_cedrus_run *run) { @@ -156,6 +186,9 @@ static void sunxi_cedrus_mpeg2_trigger(struct sunxi_cedrus_ctx *ctx) } struct sunxi_cedrus_dec_ops sunxi_cedrus_dec_ops_mpeg2 = { + .irq_clear = sunxi_cedrus_mpeg2_irq_clear, + .irq_disable = sunxi_cedrus_mpeg2_irq_disable, + .irq_status = sunxi_cedrus_mpeg2_irq_status, .setup = sunxi_cedrus_mpeg2_setup, .trigger = sunxi_cedrus_mpeg2_trigger, };
The IRQ handler up until now was hardcoding the use of the MPEG engine to read the interrupt status, clear it and disable the interrupts. Obviously, that won't work really well with the introduction of new codecs that use a separate engine with a separate register set. In order to make this more future proof, introduce new decodec operations to deal with the interrupt management. The only one missing is the one to enable the interrupts in the first place, but that's taken care of by the trigger hook for now. Signed-off-by: Maxime Ripard <maxime.ripard@bootlin.com> --- .../sunxi/cedrus/sunxi_cedrus_common.h | 9 +++++ .../platform/sunxi/cedrus/sunxi_cedrus_hw.c | 21 ++++++------ .../sunxi/cedrus/sunxi_cedrus_mpeg2.c | 33 +++++++++++++++++++ 3 files changed, 53 insertions(+), 10 deletions(-)