On 22/01/2026 16:08, Geert Uytterhoeven wrote: > Call the dev_pm_domain_attach_list() and dev_pm_domain_detach_list() > helpers instead of open-coding multi PM Domain handling. > > This changes behavior slightly: > - The new handling is also applied in case of a single PM Domain, > - PM Domains are now referred to by index instead of by name, but > "make dtbs_check" enforces the actual naming and ordering anyway, > - There are no longer device links created between virtual domain > devices, only between virtual devices and the parent device.
We still need this guarantee, both at start and end of day. In the current implementation dev_pm_domain_attach_list() iterates forwards, but so does dev_pm_domain_detach_list(). Even if we changed that, I'd prefer not to rely on the implementation details when we can declare the dependencies explicitly. We had/have a patch (attached) kicking around internally to use the *_list() functions but keep the inter-domain links in place; it got held up by discussions as to whether we actually need those dependencies for the hardware to behave correctly. Your patch spurred me to run around the office and nag people a bit, and it seems we really do need to care about the ordering. Can you add the links back in for a V2 or I can properly send the attached patch instead, I don't mind either way. Cheers, Matt > None of this should have an actual impact on functionality. > > Signed-off-by: Geert Uytterhoeven <[email protected]> > --- > Tested lightly on R-Car M3-W: driver probes and firmware is loaded. > --- > drivers/gpu/drm/imagination/pvr_device.h | 13 +-- > drivers/gpu/drm/imagination/pvr_power.c | 105 ++--------------------- > 2 files changed, 9 insertions(+), 109 deletions(-) > > diff --git a/drivers/gpu/drm/imagination/pvr_device.h > b/drivers/gpu/drm/imagination/pvr_device.h > index 491718fb87a1b608..a823f6f7e0b659c6 100644 > --- a/drivers/gpu/drm/imagination/pvr_device.h > +++ b/drivers/gpu/drm/imagination/pvr_device.h > @@ -148,19 +148,12 @@ struct pvr_device { > struct clk *mem_clk; > > /** > - * @power: Optional power domain devices. > + * @pds: Optional power domain devices. > * > * On platforms with more than one power domain for the GPU, they are > - * stored here in @domain_devs, along with links between them in > - * @domain_links. The size of @domain_devs is given by @domain_count, > - * while the size of @domain_links is (2 * @domain_count) - 1. > + * stored here, along with links between them. > */ > - struct pvr_device_power { > - struct device **domain_devs; > - struct device_link **domain_links; > - > - u32 domain_count; > - } power; > + struct dev_pm_domain_list *pds; > > /** > * @reset: Optional reset line. > diff --git a/drivers/gpu/drm/imagination/pvr_power.c > b/drivers/gpu/drm/imagination/pvr_power.c > index b9f801c63260cb81..cc6efab3c8b015ce 100644 > --- a/drivers/gpu/drm/imagination/pvr_power.c > +++ b/drivers/gpu/drm/imagination/pvr_power.c > @@ -594,110 +594,17 @@ pvr_watchdog_fini(struct pvr_device *pvr_dev) > int pvr_power_domains_init(struct pvr_device *pvr_dev) > { > struct device *dev = from_pvr_device(pvr_dev)->dev; > + int ret; > > - struct device_link **domain_links __free(kfree) = NULL; > - struct device **domain_devs __free(kfree) = NULL; > - int domain_count; > - int link_count; > - > - char dev_name[2] = "a"; > - int err; > - int i; > - > - domain_count = of_count_phandle_with_args(dev->of_node, "power-domains", > - "#power-domain-cells"); > - if (domain_count < 0) > - return domain_count; > - > - if (domain_count <= 1) > - return 0; > - > - link_count = domain_count + (domain_count - 1); > - > - domain_devs = kcalloc(domain_count, sizeof(*domain_devs), GFP_KERNEL); > - if (!domain_devs) > - return -ENOMEM; > - > - domain_links = kcalloc(link_count, sizeof(*domain_links), GFP_KERNEL); > - if (!domain_links) > - return -ENOMEM; > - > - for (i = 0; i < domain_count; i++) { > - struct device *domain_dev; > - > - dev_name[0] = 'a' + i; > - domain_dev = dev_pm_domain_attach_by_name(dev, dev_name); > - if (IS_ERR_OR_NULL(domain_dev)) { > - err = domain_dev ? PTR_ERR(domain_dev) : -ENODEV; > - goto err_detach; > - } > - > - domain_devs[i] = domain_dev; > - } > - > - for (i = 0; i < domain_count; i++) { > - struct device_link *link; > - > - link = device_link_add(dev, domain_devs[i], DL_FLAG_STATELESS | > DL_FLAG_PM_RUNTIME); > - if (!link) { > - err = -ENODEV; > - goto err_unlink; > - } > - > - domain_links[i] = link; > - } > - > - for (i = domain_count; i < link_count; i++) { > - struct device_link *link; > - > - link = device_link_add(domain_devs[i - domain_count + 1], > - domain_devs[i - domain_count], > - DL_FLAG_STATELESS | DL_FLAG_PM_RUNTIME); > - if (!link) { > - err = -ENODEV; > - goto err_unlink; > - } > - > - domain_links[i] = link; > - } > - > - pvr_dev->power = (struct pvr_device_power){ > - .domain_devs = no_free_ptr(domain_devs), > - .domain_links = no_free_ptr(domain_links), > - .domain_count = domain_count, > - }; > + ret = dev_pm_domain_attach_list(dev, NULL, &pvr_dev->pds); > + if (ret < 0) > + return ret; > > return 0; > - > -err_unlink: > - while (--i >= 0) > - device_link_del(domain_links[i]); > - > - i = domain_count; > - > -err_detach: > - while (--i >= 0) > - dev_pm_domain_detach(domain_devs[i], true); > - > - return err; > } > > void pvr_power_domains_fini(struct pvr_device *pvr_dev) > { > - const int domain_count = pvr_dev->power.domain_count; > - > - int i = domain_count + (domain_count - 1); > - > - while (--i >= 0) > - device_link_del(pvr_dev->power.domain_links[i]); > - > - i = domain_count; > - > - while (--i >= 0) > - dev_pm_domain_detach(pvr_dev->power.domain_devs[i], true); > - > - kfree(pvr_dev->power.domain_links); > - kfree(pvr_dev->power.domain_devs); > - > - pvr_dev->power = (struct pvr_device_power){ 0 }; > + dev_pm_domain_detach_list(pvr_dev->pds); > + pvr_dev->pds = NULL; > } -- Matt Coster E: [email protected]
From 0ff3dc3a8c8364574e6bdbeeb3067e70bd0e8c0a Mon Sep 17 00:00:00 2001 From: Matt Coster <[email protected]> Date: Tue, 25 Nov 2025 09:51:51 +0000 Subject: [PATCH] drm/imagination: Use dev_pm_domain_attach_list() This helper handles the attaching and linking of the entire list of power domains. Besides making pvr_power_domains_init() simpler, this also lays the groundwork to simplify supporting the varied power domain names used in Volcanic GPU cores. Note that we still need to create the links between power domains to ensure they're brought up in a valid sequence. Signed-off-by: Matt Coster <[email protected]> --- drivers/gpu/drm/imagination/pvr_device.h | 10 ++- drivers/gpu/drm/imagination/pvr_power.c | 80 +++++++++--------------- 2 files changed, 33 insertions(+), 57 deletions(-) diff --git a/drivers/gpu/drm/imagination/pvr_device.h b/drivers/gpu/drm/imagination/pvr_device.h index ec53ff2755418..759c639aafa2d 100644 --- a/drivers/gpu/drm/imagination/pvr_device.h +++ b/drivers/gpu/drm/imagination/pvr_device.h @@ -150,15 +150,13 @@ struct pvr_device { * @power: Optional power domain devices. * * On platforms with more than one power domain for the GPU, they are - * stored here in @domain_devs, along with links between them in - * @domain_links. The size of @domain_devs is given by @domain_count, - * while the size of @domain_links is (2 * @domain_count) - 1. + * stored here in @domains, along with links between them in + * @domain_links. The size of @domain_links is one less than + * struct dev_pm_domain_list->num_pds in @domains. */ struct pvr_device_power { - struct device **domain_devs; + struct dev_pm_domain_list *domains; struct device_link **domain_links; - - u32 domain_count; } power; /** diff --git a/drivers/gpu/drm/imagination/pvr_power.c b/drivers/gpu/drm/imagination/pvr_power.c index b9f801c63260c..a0834c550a852 100644 --- a/drivers/gpu/drm/imagination/pvr_power.c +++ b/drivers/gpu/drm/imagination/pvr_power.c @@ -593,14 +593,16 @@ pvr_watchdog_fini(struct pvr_device *pvr_dev) int pvr_power_domains_init(struct pvr_device *pvr_dev) { - struct device *dev = from_pvr_device(pvr_dev)->dev; + static const char *const ROGUE_PD_NAMES[] = { "a", "b", "c", "d", "e" }; + + struct drm_device *drm_dev = from_pvr_device(pvr_dev); + struct device *dev = drm_dev->dev; struct device_link **domain_links __free(kfree) = NULL; - struct device **domain_devs __free(kfree) = NULL; + struct dev_pm_domain_list *domains = NULL; int domain_count; int link_count; - char dev_name[2] = "a"; int err; int i; @@ -612,46 +614,33 @@ int pvr_power_domains_init(struct pvr_device *pvr_dev) if (domain_count <= 1) return 0; - link_count = domain_count + (domain_count - 1); + if (domain_count > ARRAY_SIZE(ROGUE_PD_NAMES)) { + drm_err(drm_dev, "%s() only supports %zu domains on Rogue", + __func__, ARRAY_SIZE(ROGUE_PD_NAMES)); + return -EOPNOTSUPP; + } - domain_devs = kcalloc(domain_count, sizeof(*domain_devs), GFP_KERNEL); - if (!domain_devs) - return -ENOMEM; + link_count = domain_count - 1; domain_links = kcalloc(link_count, sizeof(*domain_links), GFP_KERNEL); if (!domain_links) return -ENOMEM; - for (i = 0; i < domain_count; i++) { - struct device *domain_dev; - - dev_name[0] = 'a' + i; - domain_dev = dev_pm_domain_attach_by_name(dev, dev_name); - if (IS_ERR_OR_NULL(domain_dev)) { - err = domain_dev ? PTR_ERR(domain_dev) : -ENODEV; - goto err_detach; - } - - domain_devs[i] = domain_dev; - } - - for (i = 0; i < domain_count; i++) { - struct device_link *link; - - link = device_link_add(dev, domain_devs[i], DL_FLAG_STATELESS | DL_FLAG_PM_RUNTIME); - if (!link) { - err = -ENODEV; - goto err_unlink; - } + const struct dev_pm_domain_attach_data pd_attach_data = { + .pd_names = ROGUE_PD_NAMES, + .num_pd_names = domain_count, + .pd_flags = 0, + }; - domain_links[i] = link; - } + err = dev_pm_domain_attach_list(dev, &pd_attach_data, &domains); + if (err < 0) + return err; - for (i = domain_count; i < link_count; i++) { + for (i = 0; i < link_count; i++) { struct device_link *link; - link = device_link_add(domain_devs[i - domain_count + 1], - domain_devs[i - domain_count], + link = device_link_add(domains->pd_devs[i + 1], + domains->pd_devs[i], DL_FLAG_STATELESS | DL_FLAG_PM_RUNTIME); if (!link) { err = -ENODEV; @@ -662,9 +651,8 @@ int pvr_power_domains_init(struct pvr_device *pvr_dev) } pvr_dev->power = (struct pvr_device_power){ - .domain_devs = no_free_ptr(domain_devs), + .domains = domains, .domain_links = no_free_ptr(domain_links), - .domain_count = domain_count, }; return 0; @@ -673,31 +661,21 @@ int pvr_power_domains_init(struct pvr_device *pvr_dev) while (--i >= 0) device_link_del(domain_links[i]); - i = domain_count; - -err_detach: - while (--i >= 0) - dev_pm_domain_detach(domain_devs[i], true); - return err; } void pvr_power_domains_fini(struct pvr_device *pvr_dev) { - const int domain_count = pvr_dev->power.domain_count; + struct pvr_device_power *pvr_power = &pvr_dev->power; - int i = domain_count + (domain_count - 1); + int i = (int)pvr_power->domains->num_pds - 1; while (--i >= 0) - device_link_del(pvr_dev->power.domain_links[i]); - - i = domain_count; + device_link_del(pvr_power->domain_links[i]); - while (--i >= 0) - dev_pm_domain_detach(pvr_dev->power.domain_devs[i], true); + dev_pm_domain_detach_list(pvr_power->domains); - kfree(pvr_dev->power.domain_links); - kfree(pvr_dev->power.domain_devs); + kfree(pvr_power->domain_links); - pvr_dev->power = (struct pvr_device_power){ 0 }; + *pvr_power = (struct pvr_device_power){ 0 }; } -- 2.52.0
OpenPGP_signature.asc
Description: OpenPGP digital signature
