From: Kevin Hilman <khilman@baylibre.com>
To: Ulf Hansson <ulf.hansson@linaro.org>
Cc: Rob Herring <robh@kernel.org>,
Geert Uytterhoeven <geert@linux-m68k.org>,
linux-pm@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org, arm-scmi@vger.kernel.org,
linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH 2/3] pmdomain: core: add support for power-domains-child-ids
Date: Thu, 09 Apr 2026 17:45:52 -0700 [thread overview]
Message-ID: <7h4iljskvz.fsf@baylibre.com> (raw)
In-Reply-To: <CAPDyKFquJ7K4NcWuKMr1sjrnFVVPGAeLCiSF_FhvJf9Frbn1uA@mail.gmail.com>
Ulf Hansson <ulf.hansson@linaro.org> writes:
> On Wed, 11 Mar 2026 at 01:19, Kevin Hilman (TI) <khilman@baylibre.com> wrote:
>>
>> Currently, PM domains can only support hierarchy for simple
>> providers (e.g. ones with #power-domain-cells = 0).
>>
>> Add support for oncell providers as well by adding a new property
>> `power-domains-child-ids` to describe the parent/child relationship.
>>
>> For example, an SCMI PM domain provider has multiple domains, each of
>> which might be a child of diffeent parent domains. In this example,
>> the parent domains are MAIN_PD and WKUP_PD:
>>
>> scmi_pds: protocol@11 {
>> reg = <0x11>;
>> #power-domain-cells = <1>;
>> power-domains = <&MAIN_PD>, <&WKUP_PD>;
>> power-domains-child-ids = <15>, <19>;
>> };
>>
>> With this example using the new property, SCMI PM domain 15 becomes a
>> child domain of MAIN_PD, and SCMI domain 19 becomes a child domain of
>> WKUP_PD.
>>
>> To support this feature, add two new core functions
>>
>> - of_genpd_add_child_ids()
>> - of_genpd_remove_child_ids()
>>
>> which can be called by pmdomain providers to add/remove child domains
>> if they support the new property power-domains-child-ids.
>>
>> Signed-off-by: Kevin Hilman (TI) <khilman@baylibre.com>
>
> Thanks for working on this! It certainly is a missing feature!
You're welcome, thanks for the detailed review.
>> ---
>> drivers/pmdomain/core.c | 169 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>> include/linux/pm_domain.h | 16 ++++++++++++++++
>> 2 files changed, 185 insertions(+)
>>
>> diff --git a/drivers/pmdomain/core.c b/drivers/pmdomain/core.c
>> index 61c2277c9ce3..acb45dd540b7 100644
>> --- a/drivers/pmdomain/core.c
>> +++ b/drivers/pmdomain/core.c
>> @@ -2909,6 +2909,175 @@ static struct generic_pm_domain *genpd_get_from_provider(
>> return genpd;
>> }
>>
>> +/**
>> + * of_genpd_add_child_ids() - Parse power-domains-child-ids property
>> + * @np: Device node pointer associated with the PM domain provider.
>> + * @data: Pointer to the onecell data associated with the PM domain provider.
>> + *
>> + * Parse the power-domains and power-domains-child-ids properties to establish
>> + * parent-child relationships for PM domains. The power-domains property lists
>> + * parent domains, and power-domains-child-ids lists which child domain IDs
>> + * should be associated with each parent.
>> + *
>> + * Returns 0 on success, -ENOENT if properties don't exist, or negative error code.
>
> I think we should avoid returning specific error codes for specific
> errors, simply because it usually becomes messy.
>
> If I understand correctly the intent here is to allow the caller to
> check for -ENOENT and potentially avoid bailing out as it may not
> really be an error, right?
Right, -ENOENT is not an error of parsing, it's to indicate that there
are no child-ids to be parsed.
> Perhaps a better option is to return the number of children for whom
> we successfully assigned parents. Hence 0 or a positive value allows
> the caller to understand what happened. More importantly, a negative
> error code then really becomes an error for the caller to consider.
I explored this a bit, but it gets messy quick. It means we have to
track cases where only some of the children were added as well as when
all children were added. Personally, I think this should be an "all or
nothing" thing. If all the children cannot be parsed/added, then none
of them should be added.
This also allows the remove to not have to care about how many were
added, and just remove them all, with the additional benefit of not
having to track the state of how many children were successfully added.
>> + */
>> +int of_genpd_add_child_ids(struct device_node *np,
>> + struct genpd_onecell_data *data)
>> +{
>> + struct of_phandle_args parent_args;
>> + struct generic_pm_domain *parent_genpd, *child_genpd;
>> + struct of_phandle_iterator it;
>> + const struct property *prop;
>> + const __be32 *item;
>> + u32 child_id;
>> + int ret;
>> +
>> + /* Check if both properties exist */
>> + if (of_count_phandle_with_args(np, "power-domains", "#power-domain-cells") <= 0)
>> + return -ENOENT;
>> +
>> + prop = of_find_property(np, "power-domains-child-ids", NULL);
>> + if (!prop)
>> + return -ENOENT;
>> +
>> + item = of_prop_next_u32(prop, NULL, &child_id);
>
> Perhaps it's easier to check if of_property_count_u32_elems() returns
> the same number as of_count_phandle_with_args() above? If it doesn't,
> something is wrong, and there is no need to continue.
Agreed. Will add.
> This way you also know the number of loops upfront that must iterate
> through all indexes. This should allow us to use a simpler for-loop
> below, I think. In this case you can also use
> of_property_read_u32_index() instead.
OK.
>> +
>> + /* Iterate over power-domains phandles and power-domains-child-ids in lockstep */
>> + of_for_each_phandle(&it, ret, np, "power-domains", "#power-domain-cells", 0) {
>> + if (!item) {
>> + pr_err("power-domains-child-ids shorter than power-domains for %pOF\n", np);
>> + ret = -EINVAL;
>> + goto err_put_node;
>> + }
>> +
>> + /*
>> + * Fill parent_args from the iterator. it.node is released by
>> + * the next of_phandle_iterator_next() call at the top of the
>> + * loop, or by the of_node_put() on the error path below.
>> + */
>> + parent_args.np = it.node;
>> + parent_args.args_count = of_phandle_iterator_args(&it, parent_args.args,
>> + MAX_PHANDLE_ARGS);
>> +
>> + /* Get the parent domain */
>> + parent_genpd = genpd_get_from_provider(&parent_args);
>
> Before getting the parent_genpd like this, we need to take the
> gpd_list_lock. The lock must be held when genpd_add_subdomain() is
> being called.
Good catch, thanks.
>> + if (IS_ERR(parent_genpd)) {
>> + pr_err("Failed to get parent domain for %pOF: %ld\n",
>> + np, PTR_ERR(parent_genpd));
>> + ret = PTR_ERR(parent_genpd);
>> + goto err_put_node;
>> + }
>> +
>> + /* Validate child ID is within bounds */
>> + if (child_id >= data->num_domains) {
>> + pr_err("Child ID %u out of bounds (max %u) for %pOF\n",
>> + child_id, data->num_domains - 1, np);
>> + ret = -EINVAL;
>> + goto err_put_node;
>> + }
>> +
>> + /* Get the child domain */
>> + child_genpd = data->domains[child_id];
>> + if (!child_genpd) {
>> + pr_err("Child domain %u is NULL for %pOF\n", child_id, np);
>> + ret = -EINVAL;
>> + goto err_put_node;
>> + }
>> +
>> + /* Establish parent-child relationship */
>> + ret = genpd_add_subdomain(parent_genpd, child_genpd);
>> + if (ret) {
>> + pr_err("Failed to add child domain %u to parent in %pOF: %d\n",
>> + child_id, np, ret);
>> + goto err_put_node;
>> + }
>> +
>> + pr_debug("Added child domain %u (%s) to parent %s for %pOF\n",
>> + child_id, child_genpd->name, parent_genpd->name, np);
>> +
>> + item = of_prop_next_u32(prop, item, &child_id);
>> + }
>> +
>> + /* of_for_each_phandle returns -ENOENT at natural end-of-list */
>> + if (ret && ret != -ENOENT)
>> + return ret;
>> +
>> + /* All power-domains phandles were consumed; check for trailing child IDs */
>> + if (item) {
>> + pr_err("power-domains-child-ids longer than power-domains for %pOF\n", np);
>> + return -EINVAL;
>> + }
>> +
>> + return 0;
>> +
>> +err_put_node:
>
> This isn't a suffient error handling.
>
> If we successfully added child domains using genpd_add_subdomain(), we
> must remove them here, by calling pm_genpd_remove_subdomain() in the
> reverse order as we just added them.
OK, I was relying on the remove function to cleanup, but you're right,
if there's a falure during the add, it should be unwound before
returning.
>> + of_node_put(it.node);
>> + return ret;
>> +}
>> +EXPORT_SYMBOL_GPL(of_genpd_add_child_ids);
>> +
>> +/**
>> + * of_genpd_remove_child_ids() - Remove parent-child PM domain relationships
>> + * @np: Device node pointer associated with the PM domain provider.
>> + * @data: Pointer to the onecell data associated with the PM domain provider.
>> + *
>> + * Reverses the effect of of_genpd_add_child_ids() by parsing the same
>> + * power-domains and power-domains-child-ids properties and calling
>> + * pm_genpd_remove_subdomain() for each established relationship.
>> + *
>> + * Returns 0 on success, -ENOENT if properties don't exist, or negative error
>> + * code on failure.
>> + */
>> +int of_genpd_remove_child_ids(struct device_node *np,
>> + struct genpd_onecell_data *data)
>> +{
>> + struct of_phandle_args parent_args;
>> + struct generic_pm_domain *parent_genpd, *child_genpd;
>> + struct of_phandle_iterator it;
>> + const struct property *prop;
>> + const __be32 *item;
>> + u32 child_id;
>> + int ret;
>> +
>> + /* Check if both properties exist */
>> + if (of_count_phandle_with_args(np, "power-domains", "#power-domain-cells") <= 0)
>> + return -ENOENT;
>> +
>> + prop = of_find_property(np, "power-domains-child-ids", NULL);
>> + if (!prop)
>> + return -ENOENT;
>> +
>> + item = of_prop_next_u32(prop, NULL, &child_id);
>
> Similar comments as for of_genpd_add_child_ids().
>
> Moreover, I think we should remove the children in the reverse order
> of how we added them.
I'm curious why does the order matter? The children are all siblings
(no hierarchy), so why would the order be important?
I'm not ware of a phandle iterator/helper to parse in the reverse, so
that would mean iterating once to create a list, and then walking it in
reverse. Seems unnecessary.
Thanks again for the detailed review,
Kevin
next prev parent reply other threads:[~2026-04-10 0:46 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-11 0:19 [PATCH 0/3] pmdomain: core: add support for domain hierarchies in DT Kevin Hilman (TI)
2026-03-11 0:19 ` [PATCH 1/3] dt-bindings: power: Add power-domains-child-ids property Kevin Hilman (TI)
2026-03-11 1:38 ` Rob Herring (Arm)
2026-03-11 21:34 ` Kevin Hilman
2026-03-24 23:25 ` Rob Herring
2026-03-11 0:19 ` [PATCH 2/3] pmdomain: core: add support for power-domains-child-ids Kevin Hilman (TI)
2026-03-13 11:55 ` Dhruva Gole
2026-03-25 10:22 ` Ulf Hansson
2026-04-10 0:45 ` Kevin Hilman [this message]
2026-04-10 8:57 ` Ulf Hansson
2026-03-11 0:19 ` [PATCH 3/3] pmdomain: arm_scmi: add support for domain hierarchies Kevin Hilman (TI)
2026-03-13 12:07 ` Dhruva Gole
2026-04-10 1:01 ` Kevin Hilman
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=7h4iljskvz.fsf@baylibre.com \
--to=khilman@baylibre.com \
--cc=arm-scmi@vger.kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=geert@linux-m68k.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=robh@kernel.org \
--cc=ulf.hansson@linaro.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