* [PATCH 1/3] pmdomain: imx: gpcv2: Keep the domains left on by the bootloader
2026-11-21 13:06 [PATCH 0/3] pmdomain: imx: Keep the domains left on by the bootloader Dario Binacchi
@ 2026-11-21 13:06 ` Dario Binacchi
2026-11-21 13:06 ` [PATCH 2/3] pmdomain: imx8m-blk-ctrl: " Dario Binacchi
2026-11-21 13:06 ` [PATCH 3/3] pmdomain: imx8m-blk-ctrl: Hold boot-on domain clocks until sync_state Dario Binacchi
2 siblings, 0 replies; 5+ messages in thread
From: Dario Binacchi @ 2026-11-21 13:06 UTC (permalink / raw)
To: Ulf Hansson
Cc: Peng Fan, linux-amarula, Lucas Stach, michael, Dario Binacchi,
Fabio Estevam, Frank Li, Jacky Bai, Pengutronix Kernel Team,
Rafael J. Wysocki, Sascha Hauer, bui duc phuc, imx,
linux-arm-kernel, linux-pm
The PGC domains are all registered as off, so a domain left on by the
bootloader, e.g. DISPMIX to show a splash screen, is powered up again
by its first consumer. On the i.MX8MN this turns the display off and
hangs the system.
The GPC does not report the power state of a domain, but the ADB400
bridge acknowledges the power-up handshake only while the domain is
powered. Use it to register as on the domains left on by the
bootloader.
Co-developed-by: Michael Trimarchi <michael@amarulasolutions.com>
Signed-off-by: Michael Trimarchi <michael@amarulasolutions.com>
Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com>
---
drivers/pmdomain/imx/gpcv2.c | 61 ++++++++++++++++++++++++++++++++++--
1 file changed, 59 insertions(+), 2 deletions(-)
diff --git a/drivers/pmdomain/imx/gpcv2.c b/drivers/pmdomain/imx/gpcv2.c
index 6a54ee734514..23159b0489d4 100644
--- a/drivers/pmdomain/imx/gpcv2.c
+++ b/drivers/pmdomain/imx/gpcv2.c
@@ -1315,9 +1315,27 @@ static const struct imx_pgc_domain_data imx8mn_pgc_domain_data = {
.pgc_regs = &imx7_pgc_regs,
};
+/*
+ * The GPC does not report the power state of a domain, but the ADB400
+ * acknowledges the power-up handshake only while the domain is powered.
+ */
+static bool imx_pgc_domain_is_on(struct imx_pgc_domain *domain)
+{
+ u32 val;
+
+ if (!domain->bits.hskack)
+ return false;
+
+ if (regmap_read(domain->regmap, domain->regs->hsk, &val))
+ return false;
+
+ return (val & domain->bits.hskack) == domain->bits.hskack;
+}
+
static int imx_pgc_domain_probe(struct platform_device *pdev)
{
struct imx_pgc_domain *domain = pdev->dev.platform_data;
+ bool init_off;
int ret;
domain->dev = &pdev->dev;
@@ -1348,12 +1366,42 @@ static int imx_pgc_domain_probe(struct platform_device *pdev)
regmap_update_bits(domain->regmap, domain->regs->map,
domain->bits.map, domain->bits.map);
- ret = pm_genpd_init(&domain->genpd, NULL, true);
+ init_off = !imx_pgc_domain_is_on(domain);
+ ret = pm_genpd_init(&domain->genpd, NULL, init_off);
if (ret) {
dev_err_probe(domain->dev, ret, "Failed to init power domain\n");
goto out_domain_unmap;
}
+ /* Balance the first imx_pgc_power_down() */
+ if (!init_off) {
+ ret = pm_runtime_resume_and_get(domain->dev);
+ if (ret < 0) {
+ dev_err_probe(domain->dev, ret,
+ "Failed to resume domain\n");
+ goto out_genpd_remove;
+ }
+
+ if (!IS_ERR(domain->regulator)) {
+ ret = regulator_enable(domain->regulator);
+ if (ret) {
+ dev_err_probe(domain->dev, ret,
+ "Failed to enable domain's regulator\n");
+ goto out_put_pm;
+ }
+ }
+
+ if (domain->keep_clocks) {
+ ret = clk_bulk_prepare_enable(domain->num_clks,
+ domain->clks);
+ if (ret) {
+ dev_err_probe(domain->dev, ret,
+ "Failed to enable domain's clocks\n");
+ goto out_regulator_disable;
+ }
+ }
+ }
+
if (IS_ENABLED(CONFIG_LOCKDEP) &&
of_property_present(domain->dev->of_node, "power-domains"))
lockdep_set_subclass(&domain->genpd.mlock, 1);
@@ -1362,11 +1410,20 @@ static int imx_pgc_domain_probe(struct platform_device *pdev)
&domain->genpd);
if (ret) {
dev_err_probe(domain->dev, ret, "Failed to add genpd provider\n");
- goto out_genpd_remove;
+ goto out_clk_disable;
}
return 0;
+out_clk_disable:
+ if (!init_off && domain->keep_clocks)
+ clk_bulk_disable_unprepare(domain->num_clks, domain->clks);
+out_regulator_disable:
+ if (!init_off && !IS_ERR(domain->regulator))
+ regulator_disable(domain->regulator);
+out_put_pm:
+ if (!init_off)
+ pm_runtime_put(domain->dev);
out_genpd_remove:
pm_genpd_remove(&domain->genpd);
out_domain_unmap:
--
2.43.0
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCH 2/3] pmdomain: imx8m-blk-ctrl: Keep the domains left on by the bootloader
2026-11-21 13:06 [PATCH 0/3] pmdomain: imx: Keep the domains left on by the bootloader Dario Binacchi
2026-11-21 13:06 ` [PATCH 1/3] pmdomain: imx: gpcv2: " Dario Binacchi
@ 2026-11-21 13:06 ` Dario Binacchi
2026-11-21 13:29 ` sashiko-bot
2026-11-21 13:06 ` [PATCH 3/3] pmdomain: imx8m-blk-ctrl: Hold boot-on domain clocks until sync_state Dario Binacchi
2 siblings, 1 reply; 5+ messages in thread
From: Dario Binacchi @ 2026-11-21 13:06 UTC (permalink / raw)
To: Ulf Hansson
Cc: Peng Fan, linux-amarula, Lucas Stach, michael, Dario Binacchi,
Fabio Estevam, Frank Li, Kees Cook, Ming Qian,
Pengutronix Kernel Team, Sascha Hauer, Uwe Kleine-König,
Xu Yang, bui duc phuc, imx, linux-arm-kernel, linux-pm
The blk-ctrl domains are all registered as off, so a domain left on by
the bootloader is powered up again by its first consumer. On the
i.MX8MN this resets the display pipeline set up by U-Boot to show a
splash screen.
Read the state of the domains from the blk-ctrl registers and register
as on the ones left on by the bootloader.
Enable this only for the i.MX8MN DISP blk-ctrl, as on other blk-ctrls
(e.g. the i.MX8MP VPUMIX) the registers do not reset to 0.
Co-developed-by: Michael Trimarchi <michael@amarulasolutions.com>
Signed-off-by: Michael Trimarchi <michael@amarulasolutions.com>
Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com>
---
drivers/pmdomain/imx/imx8m-blk-ctrl.c | 83 ++++++++++++++++++++++++++-
1 file changed, 82 insertions(+), 1 deletion(-)
diff --git a/drivers/pmdomain/imx/imx8m-blk-ctrl.c b/drivers/pmdomain/imx/imx8m-blk-ctrl.c
index 9df933a7a238..35087da43dd7 100644
--- a/drivers/pmdomain/imx/imx8m-blk-ctrl.c
+++ b/drivers/pmdomain/imx/imx8m-blk-ctrl.c
@@ -83,10 +83,13 @@ struct imx8m_blk_ctrl_domain {
struct device *power_dev;
struct imx8m_blk_ctrl *bc;
int num_paths;
+ bool boot_on; /* Left on by the bootloader */
};
struct imx8m_blk_ctrl_data {
int max_reg;
+ /* SFT_RSTN and CLK_EN reset to 0, so a domain left on can be detected */
+ bool boot_state_readable;
notifier_fn_t power_notifier_fn;
const struct imx8m_blk_ctrl_domain_data *domains;
int num_domains;
@@ -192,6 +195,71 @@ static int imx8m_blk_ctrl_power_off(struct generic_pm_domain *genpd)
static struct lock_class_key blk_ctrl_genpd_lock_class;
+/*
+ * A domain left on by the bootloader has its resets deasserted and its
+ * clocks enabled. The registers can only be read if the bus domain is
+ * on, so a domain is considered off whenever the bus domain is off.
+ */
+static bool imx8m_blk_ctrl_is_off(struct imx8m_blk_ctrl *bc,
+ const struct imx8m_blk_ctrl_data *bc_data,
+ const struct imx8m_blk_ctrl_domain_data *data)
+{
+ u32 rst, clk, mipi = 0;
+
+ if (!bc_data->boot_state_readable ||
+ !dev_pm_genpd_is_on(bc->bus_power_dev))
+ return true;
+
+ if (regmap_read(bc->regmap, BLK_SFT_RSTN, &rst) ||
+ regmap_read(bc->regmap, BLK_CLK_EN, &clk))
+ return true;
+
+ if (data->mipi_phy_rst_mask &&
+ regmap_read(bc->regmap, BLK_MIPI_RESET_DIV, &mipi))
+ return true;
+
+ return (rst & data->rst_mask) != data->rst_mask ||
+ (clk & data->clk_mask) != data->clk_mask ||
+ (mipi & data->mipi_phy_rst_mask) != data->mipi_phy_rst_mask;
+}
+
+/* Take the references of imx8m_blk_ctrl_power_on() for a domain left on */
+static int imx8m_blk_ctrl_get_boot_on(struct imx8m_blk_ctrl_domain *domain)
+{
+ struct imx8m_blk_ctrl *bc = domain->bc;
+ int ret;
+
+ ret = pm_runtime_resume_and_get(bc->bus_power_dev);
+ if (ret < 0) {
+ dev_err(bc->dev, "failed to power up bus domain\n");
+ return ret;
+ }
+
+ ret = pm_runtime_resume_and_get(domain->power_dev);
+ if (ret < 0) {
+ dev_err(bc->dev, "failed to power up peripheral domain\n");
+ pm_runtime_put(bc->bus_power_dev);
+ return ret;
+ }
+
+ if (icc_bulk_set_bw(domain->num_paths, domain->paths))
+ dev_err(bc->dev, "failed to set icc bw\n");
+
+ domain->boot_on = true;
+
+ return 0;
+}
+
+static void imx8m_blk_ctrl_put_boot_on(struct imx8m_blk_ctrl_domain *domain)
+{
+ if (!domain->boot_on)
+ return;
+
+ pm_runtime_put(domain->power_dev);
+ pm_runtime_put(domain->bc->bus_power_dev);
+ domain->boot_on = false;
+}
+
static int imx8m_blk_ctrl_probe(struct platform_device *pdev)
{
const struct imx8m_blk_ctrl_data *bc_data;
@@ -199,6 +267,7 @@ static int imx8m_blk_ctrl_probe(struct platform_device *pdev)
struct imx8m_blk_ctrl *bc;
void __iomem *base;
int i, ret;
+ bool init_off;
struct regmap_config regmap_config = {
.reg_bits = 32,
@@ -303,7 +372,8 @@ static int imx8m_blk_ctrl_probe(struct platform_device *pdev)
domain->genpd.power_off = imx8m_blk_ctrl_power_off;
domain->bc = bc;
- ret = pm_genpd_init(&domain->genpd, NULL, true);
+ init_off = imx8m_blk_ctrl_is_off(bc, bc_data, data);
+ ret = pm_genpd_init(&domain->genpd, NULL, init_off);
if (ret) {
dev_err_probe(dev, ret,
"failed to init power domain \"%s\"\n",
@@ -312,6 +382,15 @@ static int imx8m_blk_ctrl_probe(struct platform_device *pdev)
goto cleanup_pds;
}
+ if (!init_off) {
+ ret = imx8m_blk_ctrl_get_boot_on(domain);
+ if (ret) {
+ pm_genpd_remove(&domain->genpd);
+ dev_pm_domain_detach(domain->power_dev, true);
+ goto cleanup_pds;
+ }
+ }
+
/*
* We use runtime PM to trigger power on/off of the upstream GPC
* domain, as a strict hierarchical parent/child power domain
@@ -353,6 +432,7 @@ static int imx8m_blk_ctrl_probe(struct platform_device *pdev)
of_genpd_del_provider(dev->of_node);
cleanup_pds:
for (i--; i >= 0; i--) {
+ imx8m_blk_ctrl_put_boot_on(&bc->domains[i]);
pm_genpd_remove(&bc->domains[i].genpd);
dev_pm_domain_detach(bc->domains[i].power_dev, true);
}
@@ -707,6 +787,7 @@ static const struct imx8m_blk_ctrl_domain_data imx8mn_disp_blk_ctl_domain_data[]
static const struct imx8m_blk_ctrl_data imx8mn_disp_blk_ctl_dev_data = {
.max_reg = 0x84,
+ .boot_state_readable = true,
.power_notifier_fn = imx8mn_disp_power_notifier,
.domains = imx8mn_disp_blk_ctl_domain_data,
.num_domains = ARRAY_SIZE(imx8mn_disp_blk_ctl_domain_data),
--
2.43.0
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH 2/3] pmdomain: imx8m-blk-ctrl: Keep the domains left on by the bootloader
2026-11-21 13:06 ` [PATCH 2/3] pmdomain: imx8m-blk-ctrl: " Dario Binacchi
@ 2026-11-21 13:29 ` sashiko-bot
0 siblings, 0 replies; 5+ messages in thread
From: sashiko-bot @ 2026-11-21 13:29 UTC (permalink / raw)
To: Dario Binacchi; +Cc: imx, Frank.Li
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] pmdomain: imx8m-blk-ctrl: unbalanced boot_on state in remove
and probe unwind
It also noticed 1 related pre-existing issue this patch does not
introduce:
- [Critical] pmdomain: imx: imx8m-blk-ctrl: use-after-free in
imx8m_blk_ctrl_probe() [1]
--
commit 68404e36f0b266cabfa06ab2dfb79d11fc9d8d3f
Author: Dario Binacchi <dario.binacchi@amarulasolutions.com>
pmdomain: imx8m-blk-ctrl: Keep the domains left on by the bootloader
This commit reads the blk-ctrl registers during probe on i.MX8MN DISP
blk-ctrl to detect domains left on by the bootloader, initializes those
domains as powered on, and takes the corresponding runtime PM and
interconnect references.
> diff --git a/drivers/pmdomain/imx/imx8m-blk-ctrl.c b/drivers/pmdomain/imx/imx8m-blk-ctrl.c
> index 9df933a7a2380..35087da43dd72 100644
> --- a/drivers/pmdomain/imx/imx8m-blk-ctrl.c
> +++ b/drivers/pmdomain/imx/imx8m-blk-ctrl.c
[ ... ]
> @@ -192,6 +195,71 @@ static int imx8m_blk_ctrl_power_off(struct generic_pm_domain *genpd)
[ ... ]
> +/* Take the references of imx8m_blk_ctrl_power_on() for a domain left on */
> +static int imx8m_blk_ctrl_get_boot_on(struct imx8m_blk_ctrl_domain *domain)
> +{
> + struct imx8m_blk_ctrl *bc = domain->bc;
> + int ret;
> +
> + ret = pm_runtime_resume_and_get(bc->bus_power_dev);
> + if (ret < 0) {
> + dev_err(bc->dev, "failed to power up bus domain\n");
> + return ret;
> + }
> +
> + ret = pm_runtime_resume_and_get(domain->power_dev);
> + if (ret < 0) {
> + dev_err(bc->dev, "failed to power up peripheral domain\n");
> + pm_runtime_put(bc->bus_power_dev);
> + return ret;
> + }
> +
> + if (icc_bulk_set_bw(domain->num_paths, domain->paths))
> + dev_err(bc->dev, "failed to set icc bw\n");
> +
> + domain->boot_on = true;
> +
> + return 0;
> +}
> +
> +static void imx8m_blk_ctrl_put_boot_on(struct imx8m_blk_ctrl_domain *domain)
> +{
> + if (!domain->boot_on)
> + return;
> +
> + pm_runtime_put(domain->power_dev);
> + pm_runtime_put(domain->bc->bus_power_dev);
> + domain->boot_on = false;
> +}
[Severity: Medium]
Can this power down the MIPI PHY domain on probe deferral or leave
domain->boot_on stale across power-off and driver removal?
On i.MX8MN DISP blk-ctrl, domain 0 (IMX8MN_DISPBLK_PD_MIPI_DSI) attaches
domain->power_dev to pgc_mipi, which has no hskack bit in gpcv2.c and is
therefore initialized as GENPD_STATE_OFF with stay_on = false. Calling
pm_runtime_resume_and_get(domain->power_dev) in
imx8m_blk_ctrl_get_boot_on() transitions pgc_mipi to GENPD_STATE_ON. If a
later domain in the probe loop returns -EPROBE_DEFER, cleanup_pds calls
imx8m_blk_ctrl_put_boot_on() and dev_pm_domain_detach(), which queues
power_off_work on pgc_mipi and shuts down the MIPI PHY domain in hardware
while the bootloader splash screen is running.
In addition, imx8m_blk_ctrl_power_off() drops the runtime PM references
taken by imx8m_blk_ctrl_get_boot_on() without clearing domain->boot_on,
and imx8m_blk_ctrl_remove() never releases active boot_on references
before dev_pm_genpd_remove_notifier(bc->bus_power_dev). If
imx8m_blk_ctrl_remove() runs while a boot-on domain is still on without
attached consumers, pm_genpd_remove() does not invoke
imx8m_blk_ctrl_power_off(), so bc->bus_power_dev stays active until
dev_pm_domain_detach(bc->bus_power_dev, true) powers down pgc_dispmix
after imx8mn_disp_power_notifier() has already been unregistered.
[ ... ]
> @@ -353,6 +432,7 @@ static int imx8m_blk_ctrl_probe(struct platform_device *pdev)
> of_genpd_del_provider(dev->of_node);
> cleanup_pds:
> for (i--; i >= 0; i--) {
> + imx8m_blk_ctrl_put_boot_on(&bc->domains[i]);
> pm_genpd_remove(&bc->domains[i].genpd);
> dev_pm_domain_detach(bc->domains[i].power_dev, true);
> }
[Severity: Critical]
This problem wasn't introduced by this patch, but if
devm_of_platform_populate() fails in imx8m_blk_ctrl_probe() [1],
does jumping to cleanup_provider leave bc->power_nb registered on
bc->bus_power_dev after devres frees bc?
When dev_pm_genpd_add_notifier() succeeds and devm_of_platform_populate()
then fails, cleanup_provider does not call
dev_pm_genpd_remove_notifier(bc->bus_power_dev), leaving a dangling
notifier block in the bus power domain's notifier list that causes a
use-after-free on the next bus domain power transition.
[1] https://sashiko.dev/#/bug/linux-61d2c7f1-47af-4d61-8d2d-423ac38bf002
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261121130614.2482656-1-dario.binacchi@amarulasolutions.com?part=2
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 3/3] pmdomain: imx8m-blk-ctrl: Hold boot-on domain clocks until sync_state
2026-11-21 13:06 [PATCH 0/3] pmdomain: imx: Keep the domains left on by the bootloader Dario Binacchi
2026-11-21 13:06 ` [PATCH 1/3] pmdomain: imx: gpcv2: " Dario Binacchi
2026-11-21 13:06 ` [PATCH 2/3] pmdomain: imx8m-blk-ctrl: " Dario Binacchi
@ 2026-11-21 13:06 ` Dario Binacchi
2 siblings, 0 replies; 5+ messages in thread
From: Dario Binacchi @ 2026-11-21 13:06 UTC (permalink / raw)
To: Ulf Hansson
Cc: Peng Fan, linux-amarula, Lucas Stach, michael, Dario Binacchi,
Fabio Estevam, Frank Li, Kees Cook, Ming Qian,
Pengutronix Kernel Team, Sascha Hauer, Xu Yang, bui duc phuc, imx,
linux-arm-kernel, linux-pm
The clocks of a domain left on by the bootloader have no user until
its consumers probe, so they are gated when the unused clocks are
disabled. On the i.MX8MN, with the LCDIF driver built as a module,
this stops the pixel clock of the U-Boot splash screen long before
the DRM driver probes.
Keep the clocks of these domains enabled until sync_state, i.e. until
all the consumers of the blk-ctrl have probed.
Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com>
---
drivers/pmdomain/imx/imx8m-blk-ctrl.c | 32 +++++++++++++++++++++++++++
1 file changed, 32 insertions(+)
diff --git a/drivers/pmdomain/imx/imx8m-blk-ctrl.c b/drivers/pmdomain/imx/imx8m-blk-ctrl.c
index 35087da43dd7..95b010505ded 100644
--- a/drivers/pmdomain/imx/imx8m-blk-ctrl.c
+++ b/drivers/pmdomain/imx/imx8m-blk-ctrl.c
@@ -84,6 +84,7 @@ struct imx8m_blk_ctrl_domain {
struct imx8m_blk_ctrl *bc;
int num_paths;
bool boot_on; /* Left on by the bootloader */
+ bool boot_clks_held; /* Until sync_state */
};
struct imx8m_blk_ctrl_data {
@@ -245,16 +246,33 @@ static int imx8m_blk_ctrl_get_boot_on(struct imx8m_blk_ctrl_domain *domain)
if (icc_bulk_set_bw(domain->num_paths, domain->paths))
dev_err(bc->dev, "failed to set icc bw\n");
+ /* Nobody else holds the clocks until the consumers probe */
+ if (clk_bulk_prepare_enable(domain->data->num_clks, domain->clks))
+ dev_warn(bc->dev, "failed to enable clocks of \"%s\"\n",
+ domain->data->name);
+ else
+ domain->boot_clks_held = true;
+
domain->boot_on = true;
return 0;
}
+static void imx8m_blk_ctrl_put_boot_clks(struct imx8m_blk_ctrl_domain *domain)
+{
+ if (!domain->boot_clks_held)
+ return;
+
+ clk_bulk_disable_unprepare(domain->data->num_clks, domain->clks);
+ domain->boot_clks_held = false;
+}
+
static void imx8m_blk_ctrl_put_boot_on(struct imx8m_blk_ctrl_domain *domain)
{
if (!domain->boot_on)
return;
+ imx8m_blk_ctrl_put_boot_clks(domain);
pm_runtime_put(domain->power_dev);
pm_runtime_put(domain->bc->bus_power_dev);
domain->boot_on = false;
@@ -452,6 +470,7 @@ static void imx8m_blk_ctrl_remove(struct platform_device *pdev)
for (i = 0; i < bc->onecell_data.num_domains; i++) {
struct imx8m_blk_ctrl_domain *domain = &bc->domains[i];
+ imx8m_blk_ctrl_put_boot_clks(domain);
pm_genpd_remove(&domain->genpd);
dev_pm_domain_detach(domain->power_dev, true);
}
@@ -1032,11 +1051,24 @@ static const struct of_device_id imx8m_blk_ctrl_of_match[] = {
};
MODULE_DEVICE_TABLE(of, imx8m_blk_ctrl_of_match);
+static void imx8m_blk_ctrl_sync_state(struct device *dev)
+{
+ struct imx8m_blk_ctrl *bc = dev_get_drvdata(dev);
+ int i;
+
+ /* This replaces the genpd provider sync_state */
+ of_genpd_sync_state(dev->of_node);
+
+ for (i = 0; i < bc->onecell_data.num_domains; i++)
+ imx8m_blk_ctrl_put_boot_clks(&bc->domains[i]);
+}
+
static struct platform_driver imx8m_blk_ctrl_driver = {
.probe = imx8m_blk_ctrl_probe,
.remove = imx8m_blk_ctrl_remove,
.driver = {
.name = "imx8m-blk-ctrl",
+ .sync_state = imx8m_blk_ctrl_sync_state,
.pm = &imx8m_blk_ctrl_pm_ops,
.of_match_table = imx8m_blk_ctrl_of_match,
.suppress_bind_attrs = true,
--
2.43.0
^ permalink raw reply related [flat|nested] 5+ messages in thread