From: "Kyrie Wu (吴晗)" <Kyrie.Wu@mediatek.com>
To: "matthias.bgg@gmail.com" <matthias.bgg@gmail.com>,
"mchehab@kernel.org" <mchehab@kernel.org>,
AngeloGioacchino Del Regno
<angelogioacchino.delregno@collabora.com>,
"robh+dt@kernel.org" <robh+dt@kernel.org>,
"hverkuil-cisco@xs4all.nl" <hverkuil-cisco@xs4all.nl>,
"tzungbi@chromium.org" <tzungbi@chromium.org>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"linux-mediatek@lists.infradead.org"
<linux-mediatek@lists.infradead.org>,
"linux-media@vger.kernel.org" <linux-media@vger.kernel.org>,
"devicetree@vger.kernel.org" <devicetree@vger.kernel.org>,
"kyrie.wu@mediatek.corp-partner.google.com"
<kyrie.wu@mediatek.corp-partner.google.com>,
"Bin Liu (刘彬)" <bin.liu@mediatek.com>,
"conor+dt@kernel.org" <conor+dt@kernel.org>,
"robh@kernel.org" <robh@kernel.org>,
"linux-arm-kernel@lists.infradead.org"
<linux-arm-kernel@lists.infradead.org>,
"krzk+dt@kernel.org" <krzk+dt@kernel.org>
Subject: Re: [V1,04/12] media: mediatek: jpeg: add jpeg smmu sid setting
Date: Mon, 7 Apr 2025 07:21:29 +0000 [thread overview]
Message-ID: <c5dcf1c5b8cbf5f18a578446f18c34e7049d18d9.camel@mediatek.com> (raw)
In-Reply-To: <73144187-7f7f-4f68-aa5a-5fc019e646ec@collabora.com>
On Fri, 2025-01-10 at 10:39 +0100, AngeloGioacchino Del Regno wrote:
> External email : Please do not click links or open attachments until
> you have verified the sender or the content.
>
>
> Il 09/01/25 14:35, kyrie.wu ha scritto:
> > Add a configuration to set jpeg dec & enc smmu sid
> >
> > Signed-off-by: kyrie.wu <kyrie.wu@mediatek.com>
> > ---
> > .../platform/mediatek/jpeg/mtk_jpeg_core.c | 6 ++++
> > .../platform/mediatek/jpeg/mtk_jpeg_core.h | 11 +++++++
> > .../platform/mediatek/jpeg/mtk_jpeg_dec_hw.c | 30
> > +++++++++++++++++--
> > .../platform/mediatek/jpeg/mtk_jpeg_dec_hw.h | 4 +++
> > .../platform/mediatek/jpeg/mtk_jpeg_enc_hw.c | 26
> > ++++++++++++++++
> > .../platform/mediatek/jpeg/mtk_jpeg_enc_hw.h | 4 +++
> > 6 files changed, 78 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c
> > b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c
> > index c3ccc525d9fd..77b3bd6c4d3f 100644
> > --- a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c
> > +++ b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c
> > @@ -1655,6 +1655,9 @@ static void mtk_jpegenc_worker(struct
> > work_struct *work)
> > jpeg_dst_buf->frame_num = ctx->total_frame_num;
> > ctx->total_frame_num++;
> > mtk_jpeg_enc_reset(comp_jpeg[hw_id]->reg_base);
> > +#if IS_ENABLED(CONFIG_ARM_SMMU_V3)
> > + mtk_jpeg_enc_set_smmu_sid(hw_id);
> > +#endif
> > mtk_jpeg_set_enc_dst(ctx,
> > comp_jpeg[hw_id]->reg_base,
> > &dst_buf->vb2_buf);
> > @@ -1771,6 +1774,9 @@ static void mtk_jpegdec_worker(struct
> > work_struct *work)
> > spin_lock_irqsave(&comp_jpeg[hw_id]->hw_lock, flags);
> > ctx->total_frame_num++;
> > mtk_jpeg_dec_reset(comp_jpeg[hw_id]->reg_base);
> > +#if IS_ENABLED(CONFIG_ARM_SMMU_V3)
>
> You can avoid using preprocessor conditionals - and then, this
> doesn't look like an
> ARM SMMUv3 configuration, but rather a JPEG dec/enc HW config, so in
> that case the
> enclosing of this in the proposed config option would even be wrong.
>
> Use platform data for that.
>
> > + mtk_jpeg_dec_set_smmu_sid(hw_id);
> > +#endif
> > mtk_jpeg_dec_set_config(comp_jpeg[hw_id]->reg_base,
> > jpeg->variant->support_34bit,
> > &jpeg_src_buf->dec_param,
> > diff --git a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.h
> > b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.h
> > index 8fddc133c46c..d3aba1e6cae8 100644
> > --- a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.h
> > +++ b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.h
> > @@ -36,6 +36,17 @@
> >
> > #define MTK_JPEG_ADDR_MASK GENMASK(1, 0)
> >
> > +#if IS_ENABLED(CONFIG_ARM_SMMU_V3)
> > +#define JPG_REG_CORE0_GUSER_ID 0x380d0000
> > +#define JPG_REG_CORE1_GUSER_ID 0x388d0000
>
> At least these two definitions shall go in the devicetree reg node.
>
> > +#define JPG_REG_GUSER_ID_MASK 0x7
> > +#define JPG_REG_GUSER_ID_DEC_SID 0x4
> > +#define JPG_REG_GUSER_ID_ENC_SID 0x5
> > +#define JPG_REG_DEC_GUSER_ID_SHIFT 8
> > +#define JPG_REG_ENC_GUSER_ID_SHIFT 4
>
> If this is setting an IOMMU SID, then you can just use the "iommus"
> property
> to pass a handle to the IOMMU that this device is using plus the
> streamid,
> which you can retrieve and write to the guser_id_{dec,enc}_sid
> register.
>
> There's no reason to hardcode that in this header, and actually
> hardcoding
> will give you a number of issues (example: unpowered/unclocked access
> to the
> IOMMU, and many others).
>
> > +#define GUSER_ID_MAPRANGE 4
> > +#endif
> > +
> > /**
> > * enum mtk_jpeg_ctx_state - states of the context state machine
> > * @MTK_JPEG_INIT: current state is initialized
> > diff --git a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.c
> > b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.c
> > index d868e46aaf37..fadfc4b5e366 100644
> > --- a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.c
> > +++ b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.c
> > @@ -274,6 +274,32 @@ void mtk_jpeg_dec_reset(void __iomem *base)
> > }
> > EXPORT_SYMBOL_GPL(mtk_jpeg_dec_reset);
> >
> > +#if IS_ENABLED(CONFIG_ARM_SMMU_V3)
> > +void mtk_jpeg_dec_set_smmu_sid(int hwid)
> > +{
> > + void __iomem *dec_reg_base;
> > + u32 val, mask;
> > +
> > + if (hwid)
> > + dec_reg_base = ioremap(JPG_REG_CORE1_GUSER_ID,
> > GUSER_ID_MAPRANGE);
> > + else
> > + dec_reg_base = ioremap(JPG_REG_CORE0_GUSER_ID,
> > GUSER_ID_MAPRANGE);
> > + if (!dec_reg_base) {
> > + dev_err(jpeg->dev, "Failed to map jpgdec
> > JPG_REG_GUSER_ID\n");
> > + return;
> > + }
> > +
> > + val = ioread32(dec_reg_base);
> > + mask = ~(JPG_REG_GUSER_ID_MASK <<
> > JPG_REG_DEC_GUSER_ID_SHIFT);
> > + val &= mask;
> > + val |= (JPG_REG_GUSER_ID_DEC_SID <<
> > JPG_REG_DEC_GUSER_ID_SHIFT);
> > +
> > + iowrite32(val, dec_reg_base);
> > + iounmap(dec_reg_base);
> > +}
> > +EXPORT_SYMBOL_GPL(mtk_jpeg_dec_set_smmu_sid);
> > +#endif
> > +
> > static void mtk_jpeg_dec_set_brz_factor(void __iomem *base, u8
> > yscale_w,
> > u8 yscale_h, u8 uvscale_w, u8
> > uvscale_h)
> > {
> > @@ -552,7 +578,6 @@ static irqreturn_t
> > mtk_jpegdec_hw_irq_handler(int irq, void *priv)
> > struct vb2_v4l2_buffer *src_buf, *dst_buf;
> > struct mtk_jpeg_src_buf *jpeg_src_buf;
> > enum vb2_buffer_state buf_state;
> > - struct mtk_jpeg_ctx *ctx;
> > u32 dec_irq_ret;
> > u32 irq_status;
> > int i;
> > @@ -562,7 +587,6 @@ static irqreturn_t
> > mtk_jpegdec_hw_irq_handler(int irq, void *priv)
> >
> > cancel_delayed_work(&jpeg->job_timeout_work);
> >
> > - ctx = jpeg->hw_param.curr_ctx;
> > src_buf = jpeg->hw_param.src_buffer;
> > dst_buf = jpeg->hw_param.dst_buffer;
> > v4l2_m2m_buf_copy_metadata(src_buf, dst_buf, true);
> > @@ -585,7 +609,7 @@ static irqreturn_t
> > mtk_jpegdec_hw_irq_handler(int irq, void *priv)
> > buf_state = VB2_BUF_STATE_DONE;
> > v4l2_m2m_buf_done(src_buf, buf_state);
> > mtk_jpegdec_put_buf(jpeg);
> > - pm_runtime_put(ctx->jpeg->dev);
> > + pm_runtime_put(jpeg->dev);
>
> You're doing more than what you're describing in the commit title and
> description.
>
> If this change was intentional, please move it to a diffrent commit.
>
> Regards,
> Angelo
Dear Angelo,
Thanks for your comments, let's have a summary for them:
1. add smmu config enalbing flag in platform data.
2. move the hw smmu setting to devicetree and get it in probe func.
3. refine the patch.
I will fix ithem.
Thanks.
Regards,
Kyrie.
next prev parent reply other threads:[~2025-04-07 7:21 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-09 13:35 [V1,00/12] Enable jpeg enc & dec multi-hardwares for MT8196 kyrie.wu
2025-01-09 13:35 ` [V1,01/12] dt-bindings: mediatek: Add mediatek, mt8196-jpgdec compatible kyrie.wu
2025-01-09 13:54 ` Krzysztof Kozlowski
2025-04-07 7:13 ` Kyrie Wu (吴晗)
2025-04-07 7:19 ` Krzysztof Kozlowski
2025-04-07 9:39 ` Kyrie Wu (吴晗)
2025-01-09 13:35 ` [V1,02/12] dt-bindings: mediatek: Add mediatek, mt8196-jpgenc compatible kyrie.wu
2025-01-09 13:35 ` [V1,03/12] media: mediatek: jpeg: add jpeg compatible kyrie.wu
2025-01-10 9:46 ` AngeloGioacchino Del Regno
2025-04-07 7:15 ` Kyrie Wu (吴晗)
2025-01-09 13:35 ` [V1,04/12] media: mediatek: jpeg: add jpeg smmu sid setting kyrie.wu
2025-01-10 9:39 ` AngeloGioacchino Del Regno
2025-04-07 7:21 ` Kyrie Wu (吴晗) [this message]
2025-01-09 13:35 ` [V1,05/12] media: mediatek: jpeg: fix jpeg hw count setting kyrie.wu
2025-01-10 9:45 ` AngeloGioacchino Del Regno
2025-04-07 7:23 ` Kyrie Wu (吴晗)
2025-01-09 13:35 ` [V1,06/12] media: mediatek: jpeg: refactor jpeg buffer payload setting kyrie.wu
2025-01-09 13:35 ` [V1,07/12] media: mediatek: jpeg: refactor jpeg dst buffer layout kyrie.wu
2025-01-09 13:35 ` [V1,08/12] media: mediatek: jpeg: fix stop streaming flow for multi-core kyrie.wu
2025-01-09 13:35 ` [V1,09/12] media: mediatek: jpeg: refactor multi-core clk suspend and resume setting kyrie.wu
2025-01-09 13:35 ` [V1,10/12] media: mediatek: jpeg: fix decoding buffer number setting timing issue kyrie.wu
2025-01-09 13:35 ` [V1,11/12] media: mediatek: jpeg: refactor decoding resolution change operation kyrie.wu
2025-01-09 13:35 ` [V1,12/12] media: mediatek: jpeg: fix remove buffer operation for multi-core kyrie.wu
2025-01-09 14:06 ` [V1,00/12] Enable jpeg enc & dec multi-hardwares for MT8196 Nicolas Dufresne
2025-01-10 5:31 ` Kyrie Wu (吴晗)
2025-04-07 6:27 ` Kyrie Wu (吴晗)
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=c5dcf1c5b8cbf5f18a578446f18c34e7049d18d9.camel@mediatek.com \
--to=kyrie.wu@mediatek.com \
--cc=angelogioacchino.delregno@collabora.com \
--cc=bin.liu@mediatek.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=hverkuil-cisco@xs4all.nl \
--cc=krzk+dt@kernel.org \
--cc=kyrie.wu@mediatek.corp-partner.google.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=matthias.bgg@gmail.com \
--cc=mchehab@kernel.org \
--cc=robh+dt@kernel.org \
--cc=robh@kernel.org \
--cc=tzungbi@chromium.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
all inboxes | Powered by JetHome®