From: "Jason-JH Lin (林睿祥)" <Jason-JH.Lin@mediatek.com>
To: "rva333@protonmail.com" <rva333@protonmail.com>
Cc: "stable@vger.kernel.org" <stable@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"chunkuang.hu@kernel.org" <chunkuang.hu@kernel.org>,
Project_Global_Chrome_Upstream_Group
<Project_Global_Chrome_Upstream_Group@mediatek.com>,
"AngeloGioacchino Del Regno"
<angelogioacchino.delregno@collabora.com>,
"Paul-pl Chen (陳柏霖)" <Paul-pl.Chen@mediatek.com>,
"Zi-hao Huang (黃梓豪)" <Zi-hao.Huang@mediatek.com>,
"jassisinghbrar@gmail.com" <jassisinghbrar@gmail.com>,
"Olivia Wen (温倩苓)" <Olivia.Wen@mediatek.com>,
"matthias.bgg@gmail.com" <matthias.bgg@gmail.com>,
"fshao@chromium.org" <fshao@chromium.org>,
"wenst@chromium.org" <wenst@chromium.org>,
"linux-mediatek@lists.infradead.org"
<linux-mediatek@lists.infradead.org>,
"linux-arm-kernel@lists.infradead.org"
<linux-arm-kernel@lists.infradead.org>
Subject: Re: [PATCH v2] soc: mediatek: mtk-cmdq: Keep the low address in client_reg->offset
Date: Thu, 3 Dec 2026 09:37:58 +0000 [thread overview]
Message-ID: <d10950c20e1ccbb58a18c2de8c64f496343ee684.camel@mediatek.com> (raw)
In-Reply-To: <OHOcNBeqt_gfai_K4MMvFlfBr9SkhkKkQrxrRHuLfVV3av4Rs4yUoiHbSiG0dLlEI6ElouiLa9kaBfkHC2uT2YR_WGIL6X9hw7SJbM2IzwM=@protonmail.com>
Hi Roman,
Thanks for the review.
On Wed, 2026-12-02 at 16:45 +0000, Roman Vivchar wrote:
>
> External email : Please do not click links or open attachments until
> you have verified the sender or the content.
>
>
> Hi,
>
> On Wednesday, December 2nd, 2026 at 5:14 PM, Jason-JH Lin
> <jason-jh.lin@mediatek.com> wrote:
>
> > From: Jason-jh Lin <jason-jh.lin@mediatek.com>
> >
> > The subsys ID of a GCE client stands for bits [31:16] of its
> > register
> > address, and the write instruction carries the low 16 bits as the
> > offset. cmdq_dev_get_client_reg() parses both from the DT:
> > the subsys ID, and the low 16 bits into client_reg->offset, which
> > clients add their register offset to before they call pkt_write().
> >
> > cmdq_pkt_write_pa() and cmdq_pkt_write_mask_pa() work the same way
> > for
> > a client without a subsys ID: pa_base replaces the subsys ID and
> > gives
> > bits [31:16], and offset gives the low 16 bits.
>
> Nit: it might be clearer to mention that under the hood
> pa_base[31:16]
> is loaded into an SPR and GCE uses that SPR as the high-address
> source
> in indirect WRITE_S encoding. 'pa_base replaces the subsys ID' is a
> bit incorrect, because subsys ID encoding has only 5 bits.
>
Agreed, "replaces" is not accurate. I'll describe it that way in v3:
pa_base[31:16] is loaded into an SPR, which WRITE_S uses as the
high address, and offset gives the low 16 bits.
> >
> > But the no-subsys path of cmdq_dev_get_client_reg() leaves
> > client_reg->offset at 0, so a client that passes
> > client_reg->offset + reg_offset like it does with a subsys loses
> > the low
> > 16 bits of its base. When the base isn't 64K aligned, as the OVLSYS
> > display components of some SoCs, the packet writes to
> > (base & ~0xffff) + reg_offset and still runs to EOC without error.
> >
> > Set client_reg->offset to the low 16 bits of the base there, which
> > is
> > what the DT holds for a subsys, so that clients can use both paths
> > the
> > same way. Document pa_base and offset of the _pa helpers and of
> > struct
> > cmdq_client_reg accordingly.
> >
> > Fixes: 4bf783d8415c ("soc: mediatek: mtk-cmdq: Add pa_base parsing
> > for hardware without subsys ID support")
> > Cc: stable@vger.kernel.org
> > Signed-off-by: Jason-jh Lin <jason-jh.lin@mediatek.com>
> > ---
> > Changes in v2:
> > - Drop the fold of pa_base + offset in cmdq_pkt_write_pa() and
> > cmdq_pkt_write_mask_pa(), which would break callers that already
> > pass
> > the low 16 bits of the address in offset. Fix the cause in
> > cmdq_dev_get_client_reg() instead, so the title changes as well.
> > - Drop the Reviewed-by tags of v1, as the patch is different.
> >
> > v1:
> > https://lore.kernel.org/all/20261201112523.643035-1-jason-jh.lin@mediatek.com/
> >
> > drivers/soc/mediatek/mtk-cmdq-helper.c | 7 +++++++
> > include/linux/soc/mediatek/mtk-cmdq.h | 23 +++++++++++++++++++---
> > -
> > 2 files changed, 26 insertions(+), 4 deletions(-)
> >
> > diff --git a/drivers/soc/mediatek/mtk-cmdq-helper.c
> > b/drivers/soc/mediatek/mtk-cmdq-helper.c
> > index fb82f2a85a21..22f179b37b6b 100644
> > --- a/drivers/soc/mediatek/mtk-cmdq-helper.c
> > +++ b/drivers/soc/mediatek/mtk-cmdq-helper.c
> > @@ -9,6 +9,7 @@
> > #include <linux/mailbox_controller.h>
> > #include <linux/of.h>
> > #include <linux/of_address.h>
> > +#include <linux/wordpart.h>
> > #include <linux/soc/mediatek/mtk-cmdq.h>
> >
> > #define CMDQ_WRITE_ENABLE_MASK BIT(0)
> > @@ -104,6 +105,12 @@ int cmdq_dev_get_client_reg(struct device
> > *dev,
> > client_reg->pkt_write = cmdq_pkt_write_pa;
> > client_reg->pkt_write_mask = cmdq_pkt_write_mask_pa;
> >
> > + /*
> > + * Keep the low 16 bits of the base, as the DT does
> > for a
> > + * subsys, because the base isn't always 64K aligned.
> > + */
> > + client_reg->offset = lower_16_bits(res.start);
> > +
> > return 0;
> > }
> >
> > diff --git a/include/linux/soc/mediatek/mtk-cmdq.h
> > b/include/linux/soc/mediatek/mtk-cmdq.h
> > index 03bb85462566..73024fd705bc 100644
> > --- a/include/linux/soc/mediatek/mtk-cmdq.h
> > +++ b/include/linux/soc/mediatek/mtk-cmdq.h
> > @@ -52,6 +52,17 @@ struct cmdq_operand {
> > };
> > };
> >
> > +/**
> > + * struct cmdq_client_reg - GCE client register information from
> > the DT
> > + * @subsys: the CMDQ sub system code, CMDQ_SUBSYS_INVALID if
> > there is none
> > + * @pa_base: the physical address of the client registers, only
> > its bits [31:16]
> > + * are used, as the subsys ID stands for them
>
> I'd also briefly mention that pa_base applies only to GCEv2* and v3.
> Legacy (used in mt65xx and early mt81xx) have no PA writes at all.
>
> * - I believe that mt6595 is GCEv2, which has PA write in the
> hardware.
> Feel free to correct me if it's only GCEv3, since I'm familiar only
> with
> the latter.
Thanks for checking. PA write is only supported on GCEv3, since it
relies on the SPRs and the WRITE_S instruction. The PA helpers are
only a fallback, though: cmdq_dev_get_client_reg() picks the subsys
helpers whenever the DT gives a subsys ID in mediatek,gce-client-reg,
and only falls back to the PA helpers when it doesn't. GCEv2 has no
SPRs, but the GCEv2 DTs all give a subsys ID, so their clients never
take the PA path.
I'll add a note to the struct cmdq_client_reg kernel-doc that pa_base
is only used by the PA helpers, for clients without a subsys ID,
and that those need GCEv3.
>
> > + * @offset: the low 16 bits of @pa_base. Add the register offset
> > to it to
> > + * get the offset argument of @pkt_write and
> > @pkt_write_mask
> > + * @size: the size of the client registers
> > + * @pkt_write: cmdq_pkt_write_subsys() or
> > cmdq_pkt_write_pa()
> > + * @pkt_write_mask: cmdq_pkt_write_mask_subsys() or
> > cmdq_pkt_write_mask_pa()
> > + */
> > struct cmdq_client_reg {
> > u8 subsys;
> > phys_addr_t pa_base;
> > @@ -139,8 +150,10 @@ int cmdq_pkt_write(struct cmdq_pkt *pkt, u8
> > subsys, u16 offset, u32 value);
> > * cmdq_pkt_write_pa() - append write command to the CMDQ packet
> > with pa_base
> > * @pkt: the CMDQ packet
> > * @subsys: unused parameter
> > - * @pa_base: the physical address base of the hardware register
> > - * @offset: register offset from CMDQ sub system
> > + * @pa_base: the physical address of the hardware register, only
> > its bits
> > + * [31:16] are used, as the subsys ID stands for them
>
> Nit: this is a bit hard to read. Maybe reword it to make the high/low
> 16-bit split explicit? For example: 'the physical address of the
> hardware
> register, only bits [31:16] are used, while bits [15:0] must be
> supplied
> in @offset'. This also applies to the change below.
>
Will do, for both cmdq_pkt_write_pa() and cmdq_pkt_write_mask_pa().
> > + * @offset: the low 16 bits of the register address, as for the
> > subsys
> > + * variant
> > * @value: the specified target register value
> > *
> > * Return: 0 for success; else the error code is returned
> > @@ -178,8 +191,10 @@ int cmdq_pkt_write_mask(struct cmdq_pkt *pkt,
> > u8 subsys,
> > * cmdq_pkt_write_mask_pa() - append write command with mask to
> > the CMDQ packet with pa
> > * @pkt: the CMDQ packet
> > * @subsys: unused parameter
> > - * @pa_base: the physical address base of the hardware register
> > - * @offset: register offset from CMDQ sub system
> > + * @pa_base: the physical address of the hardware register, only
> > its bits
> > + * [31:16] are used, as the subsys ID stands for them
> > + * @offset: the low 16 bits of the register address, as for the
> > subsys
> > + * variant
> > * @value: the specified target register value
> > * @mask: the specified target register mask
> > *
>
> Other than these doc nits, this looks fine to me.
>
> Reviewed-by: Roman Vivchar <rva333@protonmail.com>
>
Since v3 only changes the commit message and the kernel-doc, I'll
keep your Reviewed-by tag, unless you'd rather check v3 first.
Regards,
Jason-JH Lin
> Best regards,
> Roman
prev parent reply other threads:[~2026-12-03 9:38 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 15:11 Jason-JH Lin
2026-12-02 16:45 ` Roman Vivchar
2026-12-03 9:37 ` Jason-JH Lin (林睿祥) [this message]
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=d10950c20e1ccbb58a18c2de8c64f496343ee684.camel@mediatek.com \
--to=jason-jh.lin@mediatek.com \
--cc=Olivia.Wen@mediatek.com \
--cc=Paul-pl.Chen@mediatek.com \
--cc=Project_Global_Chrome_Upstream_Group@mediatek.com \
--cc=Zi-hao.Huang@mediatek.com \
--cc=angelogioacchino.delregno@collabora.com \
--cc=chunkuang.hu@kernel.org \
--cc=fshao@chromium.org \
--cc=jassisinghbrar@gmail.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=matthias.bgg@gmail.com \
--cc=rva333@protonmail.com \
--cc=stable@vger.kernel.org \
--cc=wenst@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®