[PATCH RFC 04/16] pmdomain: core: Support named indexed virtual attachments

From: Konrad Dybcio

Date: Wed Oct 14 2026 - 08:26:17 EST


From: Konrad Dybcio <konrad.dybcio@xxxxxxxxxxxxxxxx>

A device may need separate virtual GenPD attachments to the same
power-domain index for distinct purposes. dev_pm_domain_attach_list()
can make indexed attachments, but cannot give the resulting virtual
devices distinct names.

genpd_dev_pm_attach_by_id() derives a virtual-device name from only
the consumer device and power-domain index. Repeating the attachment
therefore collides with the existing virtual device.

Add an optional suffix to indexed virtual attachments and let
dev_pm_domain_attach_list() pass it through.

Assisted-by: LLM
Signed-off-by: Konrad Dybcio <konrad.dybcio@xxxxxxxxxxxxxxxx>
---
drivers/base/power/common.c | 4 +++-
drivers/pmdomain/core.c | 28 +++++++++++++++++++++++++---
include/linux/pm_domain.h | 11 +++++++++++
3 files changed, 39 insertions(+), 4 deletions(-)

diff --git a/drivers/base/power/common.c b/drivers/base/power/common.c
index 9bef9248a705..8beedde6dba7 100644
--- a/drivers/base/power/common.c
+++ b/drivers/base/power/common.c
@@ -241,7 +241,9 @@ int dev_pm_domain_attach_list(struct device *dev,

for (i = 0; i < num_pds; i++) {
if (by_id)
- pd_dev = dev_pm_domain_attach_by_id(dev, i);
+ pd_dev = data && data->pd_suffix ?
+ genpd_dev_pm_attach_by_id_suffix(dev, i, data->pd_suffix) :
+ dev_pm_domain_attach_by_id(dev, i);
else
pd_dev = dev_pm_domain_attach_by_name(dev,
data->pd_names[i]);
diff --git a/drivers/pmdomain/core.c b/drivers/pmdomain/core.c
index 964e44c2f78f..76ff0d9a229c 100644
--- a/drivers/pmdomain/core.c
+++ b/drivers/pmdomain/core.c
@@ -3596,8 +3596,9 @@ EXPORT_SYMBOL_GPL(genpd_dev_pm_attach);
* turned on, then ERR_PTR(-EPROBE_DEFER) is returned to ensure that the device
* is not probed and to re-try again later.
*/
-struct device *genpd_dev_pm_attach_by_id(struct device *dev,
- unsigned int index)
+static struct device *__genpd_dev_pm_attach_by_id(struct device *dev,
+ unsigned int index,
+ const char *suffix)
{
struct device *virt_dev;
int num_domains;
@@ -3620,7 +3621,11 @@ struct device *genpd_dev_pm_attach_by_id(struct device *dev,
if (!virt_dev)
return ERR_PTR(-ENOMEM);

- dev_set_name(virt_dev, "genpd:%u:%s", index, dev_name(dev));
+ if (suffix)
+ dev_set_name(virt_dev, "genpd:%u:%s:%s", index, dev_name(dev),
+ suffix);
+ else
+ dev_set_name(virt_dev, "genpd:%u:%s", index, dev_name(dev));
virt_dev->bus = &genpd_bus_type;
virt_dev->release = genpd_release_dev;
virt_dev->of_node = of_node_get(dev->of_node);
@@ -3643,8 +3648,25 @@ struct device *genpd_dev_pm_attach_by_id(struct device *dev,

return virt_dev;
}
+
+struct device *genpd_dev_pm_attach_by_id(struct device *dev,
+ unsigned int index)
+{
+ return __genpd_dev_pm_attach_by_id(dev, index, NULL);
+}
EXPORT_SYMBOL_GPL(genpd_dev_pm_attach_by_id);

+struct device *genpd_dev_pm_attach_by_id_suffix(struct device *dev,
+ unsigned int index,
+ const char *suffix)
+{
+ if (!suffix || !*suffix)
+ return ERR_PTR(-EINVAL);
+
+ return __genpd_dev_pm_attach_by_id(dev, index, suffix);
+}
+EXPORT_SYMBOL_GPL(genpd_dev_pm_attach_by_id_suffix);
+
/**
* genpd_dev_pm_attach_by_name - Associate a device with one of its PM domains.
* @dev: The device used to lookup the PM domain.
diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
index 14e0e346c610..98aca4a4aede 100644
--- a/include/linux/pm_domain.h
+++ b/include/linux/pm_domain.h
@@ -50,6 +50,7 @@
struct dev_pm_domain_attach_data {
const char * const *pd_names;
u32 num_pd_names;
+ const char *pd_suffix;
u32 pd_flags;
};

@@ -484,6 +485,9 @@ int of_genpd_remove_child_ids(struct device_node *np,
int genpd_dev_pm_attach(struct device *dev);
struct device *genpd_dev_pm_attach_by_id(struct device *dev,
unsigned int index);
+struct device *genpd_dev_pm_attach_by_id_suffix(struct device *dev,
+ unsigned int index,
+ const char *suffix);
struct device *genpd_dev_pm_attach_by_name(struct device *dev,
const char *name);
#else /* !CONFIG_PM_GENERIC_DOMAINS_OF */
@@ -538,6 +542,13 @@ static inline struct device *genpd_dev_pm_attach_by_id(struct device *dev,
return NULL;
}

+static inline struct device *
+genpd_dev_pm_attach_by_id_suffix(struct device *dev, unsigned int index,
+ const char *suffix)
+{
+ return NULL;
+}
+
static inline struct device *genpd_dev_pm_attach_by_name(struct device *dev,
const char *name)
{

--
2.56.0