public inbox for linux-arm-kernel@lists.infradead.org
 help / color / mirror / Atom feed
From: Nicolas Frattaroli <nicolas.frattaroli@collabora.com>
To: Boris Brezillon <boris.brezillon@collabora.com>,
	Steven Price <steven.price@arm.com>,
	Liviu Dudau <liviu.dudau@arm.com>,
	Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
	Maxime Ripard <mripard@kernel.org>,
	Thomas Zimmermann <tzimmermann@suse.de>,
	David Airlie <airlied@gmail.com>, Simona Vetter <simona@ffwll.ch>,
	Rob Herring <robh@kernel.org>,
	Krzysztof Kozlowski <krzk+dt@kernel.org>,
	Conor Dooley <conor+dt@kernel.org>,
	Matthias Brugger <matthias.bgg@gmail.com>,
	MyungJoo Ham <myungjoo.ham@samsung.com>,
	Kyungmin Park <kyungmin.park@samsung.com>,
	Chanwoo Choi <cw00.choi@samsung.com>,
	Jassi Brar <jassisinghbrar@gmail.com>,
	Kees Cook <kees@kernel.org>,
	"Gustavo A. R. Silva" <gustavoars@kernel.org>,
	AngeloGioacchino Del Regno
	<angelogioacchino.delregno@collabora.com>
Cc: Chia-I Wu <olvaffe@gmail.com>, Chen-Yu Tsai <wenst@chromium.org>,
	kernel@collabora.com, dri-devel@lists.freedesktop.org,
	devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-mediatek@lists.infradead.org, linux-pm@vger.kernel.org,
	linux-hardening@vger.kernel.org
Subject: Re: [PATCH RFC 05/10] mailbox: add MediaTek GPUEB IPI mailbox
Date: Mon, 08 Sep 2025 14:05:05 +0200	[thread overview]
Message-ID: <7865698.EvYhyI6sBW@workhorse> (raw)
In-Reply-To: <27159dc0-96f1-4d99-bf5e-cda0f9c7d307@collabora.com>

On Monday, 8 September 2025 12:06:01 Central European Summer Time AngeloGioacchino Del Regno wrote:
> Il 05/09/25 12:23, Nicolas Frattaroli ha scritto:
> > The MT8196 SoC uses an embedded MCU to control frequencies and power of
> > the GPU. This controller is referred to as "GPUEB".
> > 
> > It communicates to the application processor, among other ways, through
> > a mailbox.
> > 
> > The mailbox exposes one interrupt, which appears to only be fired when a
> > response is received, rather than a transaction is completed. For us,
> > this means we unfortunately need to poll for txdone.
> > 
> > The mailbox also requires the EB clock to be on when touching any of the
> > mailbox registers.
> > 
> > Add a simple driver for it based on the common mailbox framework.
> > 
> > Signed-off-by: Nicolas Frattaroli <nicolas.frattaroli@collabora.com>
> 
> Only a few nits in this, check below.
> 
> [...]
> > +
> > +static int mtk_gpueb_mbox_send_data(struct mbox_chan *chan, void *data)
> > +{
> > +	struct mtk_gpueb_mbox *ebm = dev_get_drvdata(chan->mbox->dev);
> > +	unsigned int *num = chan->con_priv;
> > +	int i;
> 
> int i, j;
> 
> > +	u32 *values = data;
> > +
> > +	if (*num >= ebm->v->num_channels)
> > +		return -ECHRNG;
> > +
> > +	if (!ebm->v->channels[*num].no_response &&
> > +	    atomic_read(&ebm->rx_status[*num]))
> > +		return -EBUSY;
> > +
> > +	writel(BIT(*num), ebm->mbox_ctl + MBOX_CTL_IRQ_CLR);
> > +
> > +	/*
> > +	 * We don't want any fancy nonsense, just write the 32-bit values in
> > +	 * order. memcpy_toio/__iowrite32_copy don't work here, because fancy.
> > +	 */
> > +	for (i = 0; i < ebm->v->channels[*num].tx_len; i += 4) {
> 
> Just use an additional `j` index, so that you can avoid division.

The `/ 4` division here is equivalent to a `>> 2` which comes free with
almost every instruction on arm64, I don't think having two separate
indices makes the code any clearer? Unless I misunderstand how you'd
want me to use j here.

Like this?

  j = 0;
  for (i = 0; i < ebm->v->channels[*num].tx_len; i += 4) {
    writel(values[j++], ebm->mbox_mmio + ebm->v->channels[*num].tx_offset + i);
  }

This makes the relationship between the values index and i less clear. (And
in my rendition, assumes the reader knows how postincrement works, but I
think assuming people know C is fine.)

> [...]
>
> > +
> > +	ebm->clk = devm_clk_get_enabled(ebm->dev, NULL);
> > +	if (IS_ERR(ebm->clk))
> > +		return dev_err_probe(ebm->dev, PTR_ERR(ebm->clk),
> > +				     "Failed to get 'eb' clock\n");
> > +
> > +	ebm->mbox_mmio = devm_platform_ioremap_resource_byname(pdev, "mbox");
> 
> I'd say that "chan" and "ctl" are more descriptive as resource names, but then,
> do we really need to search by name?

In the binding, it was proposed to change "mbox" to something like "data",
which is fine by me, and to drop the "mbox" prefix of "ctl".

> 
> Doing that by index is also an option, as you can write the MMIO names and their
> full description in the bindings instead.

Yeah in the driver I think I'll switch to doing indices until some second
compatible forces us to actually rely on names because it adds a bunch of
other ranges.

> [...]

thanks for the feedback, assume that anything I didn't directly respond
to will be fixed in the next revision.

Kind regards,
Nicolas Frattaroli




  reply	other threads:[~2025-09-08 13:10 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-05 10:22 [PATCH RFC 00/10] MT8196 GPU Frequency/Power Control Support Nicolas Frattaroli
2025-09-05 10:22 ` [PATCH RFC 01/10] dt-bindings: gpu: mali-valhall-csf: add mediatek,mt8196-mali variant Nicolas Frattaroli
2025-09-05 23:26   ` Rob Herring
2025-09-06 17:54     ` Nicolas Frattaroli
2025-09-08 19:51   ` Liviu Dudau
2025-09-05 10:22 ` [PATCH RFC 02/10] dt-bindings: devfreq: add mt8196-gpufreq binding Nicolas Frattaroli
2025-09-08 11:15   ` AngeloGioacchino Del Regno
2025-09-08 11:39     ` Nicolas Frattaroli
2025-09-08 12:49       ` AngeloGioacchino Del Regno
2025-09-05 10:22 ` [PATCH RFC 03/10] dt-bindings: sram: Add compatible for mediatek,mt8196-gpufreq-sram Nicolas Frattaroli
2025-09-05 23:28   ` Rob Herring (Arm)
2025-09-05 10:23 ` [PATCH RFC 04/10] dt-bindings: mailbox: Add MT8196 GPUEB Mailbox Nicolas Frattaroli
2025-09-05 23:31   ` Rob Herring
2025-09-05 10:23 ` [PATCH RFC 05/10] mailbox: add MediaTek GPUEB IPI mailbox Nicolas Frattaroli
2025-09-08 10:06   ` AngeloGioacchino Del Regno
2025-09-08 12:05     ` Nicolas Frattaroli [this message]
2025-09-08 12:34       ` AngeloGioacchino Del Regno
2025-09-12  4:48   ` Chia-I Wu
2025-09-12  6:11     ` Chen-Yu Tsai
2025-09-12 10:59     ` Nicolas Frattaroli
2025-09-12 17:30       ` Chia-I Wu
2025-09-05 10:23 ` [PATCH RFC 06/10] drm/panthor: call into devfreq for current frequency Nicolas Frattaroli
2025-09-10 13:59   ` Steven Price
2025-09-05 10:23 ` [PATCH RFC 07/10] drm/panthor: move panthor_devfreq struct to header Nicolas Frattaroli
2025-09-10 13:59   ` Steven Price
2025-09-05 10:23 ` [PATCH RFC 08/10] drm/panthor: devfreq: expose get_dev_status and make it more generic Nicolas Frattaroli
2025-09-10 13:59   ` Steven Price
2025-09-05 10:23 ` [PATCH RFC 09/10] drm/panthor: devfreq: add pluggable devfreq providers Nicolas Frattaroli
2025-09-10 13:59   ` Steven Price
2025-09-05 10:23 ` [PATCH RFC 10/10] drm/panthor: add support for MediaTek MFlexGraphics Nicolas Frattaroli

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=7865698.EvYhyI6sBW@workhorse \
    --to=nicolas.frattaroli@collabora.com \
    --cc=airlied@gmail.com \
    --cc=angelogioacchino.delregno@collabora.com \
    --cc=boris.brezillon@collabora.com \
    --cc=conor+dt@kernel.org \
    --cc=cw00.choi@samsung.com \
    --cc=devicetree@vger.kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=gustavoars@kernel.org \
    --cc=jassisinghbrar@gmail.com \
    --cc=kees@kernel.org \
    --cc=kernel@collabora.com \
    --cc=krzk+dt@kernel.org \
    --cc=kyungmin.park@samsung.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=liviu.dudau@arm.com \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=matthias.bgg@gmail.com \
    --cc=mripard@kernel.org \
    --cc=myungjoo.ham@samsung.com \
    --cc=olvaffe@gmail.com \
    --cc=robh@kernel.org \
    --cc=simona@ffwll.ch \
    --cc=steven.price@arm.com \
    --cc=tzimmermann@suse.de \
    --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