From: Nicolas Frattaroli <nicolas.frattaroli@collabora.com>
To: Ulf Hansson <ulf.hansson@linaro.org>
Cc: AngeloGioacchino Del Regno
<angelogioacchino.delregno@collabora.com>,
Boris Brezillon <boris.brezillon@collabora.com>,
Jassi Brar <jassisinghbrar@gmail.com>,
Chia-I Wu <olvaffe@gmail.com>, Chen-Yu Tsai <wenst@chromium.org>,
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>,
Kees Cook <kees@kernel.org>,
"Gustavo A. R. Silva" <gustavoars@kernel.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-hardening@vger.kernel.org, linux-pm@vger.kernel.org
Subject: Re: [PATCH v4 8/8] pmdomain: mediatek: Add support for MFlexGraphics
Date: Thu, 25 Sep 2025 16:04:59 +0200 [thread overview]
Message-ID: <2015216.PYKUYFuaPT@workhorse> (raw)
In-Reply-To: <CAPDyKFpLNJRRxWPm2Eye+Fs8go-LNwWGzPUPPKmNVJkyK5N3Dw@mail.gmail.com>
On Tuesday, 23 September 2025 16:24:13 Central European Summer Time Ulf Hansson wrote:
> On Tue, 23 Sept 2025 at 13:41, Nicolas Frattaroli
> <nicolas.frattaroli@collabora.com> wrote:
> >
> > Various MediaTek SoCs use GPU integration silicon named "MFlexGraphics"
> > by MediaTek. On the MT8196 and MT6991 SoCs, interacting with this
> > integration silicon is required to power on the GPU.
> >
> > This glue silicon is in the form of an embedded microcontroller running
> > special-purpose firmware, which autonomously adjusts clocks and
> > regulators.
> >
> > Implement a driver, modelled as a pmdomain driver with a
> > set_performance_state operation, to support these SoCs.
> >
> > The driver also exposes the actual achieved clock rate, as read back
> > from the MCU, as common clock framework clocks, by acting as a clock
> > provider as well.
> >
> > Signed-off-by: Nicolas Frattaroli <nicolas.frattaroli@collabora.com>
> > ---
> > drivers/pmdomain/mediatek/Kconfig | 16 +
> > drivers/pmdomain/mediatek/Makefile | 1 +
> > drivers/pmdomain/mediatek/mtk-mfg-pmdomain.c | 928 +++++++++++++++++++++++++++
> > 3 files changed, 945 insertions(+)
>
> [...]
>
> > +
> > +static int mtk_mfg_set_performance(struct generic_pm_domain *pd,
> > + unsigned int state)
> > +{
> > + struct mtk_mfg *mfg = mtk_mfg_from_genpd(pd);
> > +
> > + /*
> > + * Occasionally, we're asked to set OPPs when we're off. This will fail,
> > + * so don't do it at all. We do foo != GENPD_STATE_ON instead of !foo
> > + * as to not depend on the actual value of the enum.
> > + */
> > + if (mfg->pd.status != GENPD_STATE_ON)
> > + return 0;
>
> Returning 0 here, means that we may end up never restoring the
> performance state for a device and its genpd, when the device is
> getting runtime resumed. In genpd_runtime_resume() we are calling
> genpd_restore_performance_state() before calling genpd_power_on().
> This is deliberate, see commit ae8ac19655e0.
>
> That said, I think we need to manage the restore in the ->power_on()
> callback. In principle, it means we should call
> mtk_mfg_set_oppidx(mfg, genpd->performance_state) from there.
>
Thanks for pointing this out, yeah setting the oppidx in power_on
does look like the right choice.
> > +
> > + return mtk_mfg_set_oppidx(mfg, state);
> > +}
> > +
> > +static int mtk_mfg_power_on(struct generic_pm_domain *pd)
> > +{
> > + struct mtk_mfg *mfg = mtk_mfg_from_genpd(pd);
> > + int ret;
> > +
> > + ret = regulator_bulk_enable(mfg->variant->num_regulators,
> > + mfg->gpu_regs);
> > + if (ret)
> > + return ret;
> > +
> > + ret = clk_prepare_enable(mfg->clk_eb);
> > + if (ret)
> > + goto err_disable_regulators;
> > +
> > + ret = clk_bulk_prepare_enable(mfg->variant->num_clks, mfg->gpu_clks);
> > + if (ret)
> > + goto err_disable_eb_clk;
> > +
> > + ret = mtk_mfg_eb_on(mfg);
> > + if (ret)
> > + goto err_disable_clks;
> > +
> > + ret = mtk_mfg_power_control(mfg, true);
> > + if (ret)
> > + goto err_eb_off;
> > +
> > + return 0;
> > +
> > +err_eb_off:
> > + mtk_mfg_eb_off(mfg);
> > +err_disable_clks:
> > + clk_bulk_disable_unprepare(mfg->variant->num_clks, mfg->gpu_clks);
> > +err_disable_eb_clk:
> > + clk_disable_unprepare(mfg->clk_eb);
> > +err_disable_regulators:
> > + regulator_bulk_disable(mfg->variant->num_regulators, mfg->gpu_regs);
> > +
> > + return ret;
> > +}
>
> [...]
>
> Note, I intend to have a bit closer look at this soon, but I just
> observed the issue I pointed out above from my first quick look.
I actually have a question about a mystery that has been puzzling
me as I work on v5: when unloading the driver that uses the PD
(panthor) and my driver using `modprobe -r panthor mtk_mfg_pmdomain`,
I see that sometimes detach_dev is called with the pd status
reportedly being off, but according to my own power-on/power-off
counting I hacked in, it actually being on. It then proceeds to
call my remove, which results in three splats from the regulator
subsystem as the regulators weren't balanced with disables before
they were freed, which isn't the main problem but more a symptom
of the bigger problem that power_off and power_on calls don't
appear to be balanced by the pmdomain subsystem when a driver is
removed under certain circumstances.
Did I run into a core pmdomain bug here, or do I have to balance
the power_on/off myself somehow in detach_dev? If the latter, I'm
struggling to figure out how I can determine that the PD is still
on without doing my own bookkeeping, as pmdomain core seems to clear
these fields before my detach_dev gets to them :(
>
> Kind regards
> Uffe
>
Kind regards,
Nicolas Frattaroli
next prev parent reply other threads:[~2025-09-25 14:05 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-23 11:39 [PATCH v4 0/8] MT8196 GPU Frequency/Power Control Support Nicolas Frattaroli
2025-09-23 11:39 ` [PATCH v4 1/8] dt-bindings: gpu: mali-valhall-csf: add mediatek,mt8196-mali variant Nicolas Frattaroli
2025-09-23 11:39 ` [PATCH v4 2/8] dt-bindings: power: Add MT8196 GPU frequency control binding Nicolas Frattaroli
2025-09-24 11:30 ` AngeloGioacchino Del Regno
2025-09-23 11:39 ` [PATCH v4 3/8] dt-bindings: sram: Add compatible for mediatek,mt8196-gpufreq-sram Nicolas Frattaroli
2025-09-23 11:39 ` [PATCH v4 4/8] dt-bindings: mailbox: Add MT8196 GPUEB Mailbox Nicolas Frattaroli
2025-09-23 14:39 ` Rob Herring (Arm)
2025-09-23 11:39 ` [PATCH v4 5/8] mailbox: add MediaTek GPUEB IPI mailbox Nicolas Frattaroli
2025-09-24 11:35 ` AngeloGioacchino Del Regno
2025-09-23 11:39 ` [PATCH v4 6/8] drm/panthor: call into devfreq for current frequency Nicolas Frattaroli
2025-09-23 11:40 ` [PATCH v4 7/8] drm/panthor: Use existing OPP table if present Nicolas Frattaroli
2025-09-23 11:40 ` [PATCH v4 8/8] pmdomain: mediatek: Add support for MFlexGraphics Nicolas Frattaroli
2025-09-23 14:24 ` Ulf Hansson
2025-09-25 14:04 ` Nicolas Frattaroli [this message]
2025-09-29 9:58 ` Ulf Hansson
2025-09-23 16:25 ` AngeloGioacchino Del Regno
2025-09-24 19:11 ` Nicolas Frattaroli
2025-09-25 13:56 ` AngeloGioacchino Del Regno
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=2015216.PYKUYFuaPT@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=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=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=olvaffe@gmail.com \
--cc=robh@kernel.org \
--cc=simona@ffwll.ch \
--cc=steven.price@arm.com \
--cc=tzimmermann@suse.de \
--cc=ulf.hansson@linaro.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