mbox series

[v3,0/2] add device managed version of dev_pm_domain_attach|detach_list()

Message ID 1724048566-5035-1-git-send-email-quic_dikshita@quicinc.com
Headers show
Series add device managed version of dev_pm_domain_attach|detach_list() | expand

Message

Dikshita Agarwal Aug. 19, 2024, 6:22 a.m. UTC
These patches add the devres-enabled version of
dev_pm_domain_attach|detach_list in pm domain framework and
use the same APIs in venus driver.

If any client drivers use devm_pm_domain_attach_list() to
attach the PM domains, devm_pm_domain_detach_list() will be
invoked implicitly during remove phase.

Changes since v2:
 - made devm_pm_domain_detach_list as static and no
   longer export this API.
 - added null checks for num_pds to avoid adding a 
   devres callback for the same.
 - added bryan's reviewed-by from v1.

Changes since v1:
 - fixed the warnings reported by kernel test robot.
 - added stub functions for !CONFIG_PM case.
 - removed un-necessasry type casting.
 - fixed the issue with remove sequence.

Dikshita Agarwal (2):
  PM: domains: add device managed version of
    dev_pm_domain_attach|detach_list()
  media: venus: use device managed APIs for power domains

 drivers/base/power/common.c                    | 45 ++++++++++++++++++++++++++
 drivers/media/platform/qcom/venus/pm_helpers.c |  5 +--
 include/linux/pm_domain.h                      | 11 +++++++
 3 files changed, 57 insertions(+), 4 deletions(-)

Comments

Ulf Hansson Aug. 19, 2024, 10:04 a.m. UTC | #1
On Mon, 19 Aug 2024 at 08:23, Dikshita Agarwal
<quic_dikshita@quicinc.com> wrote:
>
> Add the devres-enabled version of dev_pm_domain_attach|detach_list.
> If client drivers use devm_pm_domain_attach_list() to attach the PM domains,
> devm_pm_domain_detach_list() will be invoked implicitly during remove phase.
>
> Signed-off-by: Dikshita Agarwal <quic_dikshita@quicinc.com>
> ---
>  drivers/base/power/common.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
>  include/linux/pm_domain.h   | 11 +++++++++++
>  2 files changed, 56 insertions(+)
>
> diff --git a/drivers/base/power/common.c b/drivers/base/power/common.c
> index 327d168..c8431de 100644
> --- a/drivers/base/power/common.c
> +++ b/drivers/base/power/common.c
> @@ -277,6 +277,51 @@ int dev_pm_domain_attach_list(struct device *dev,
>  EXPORT_SYMBOL_GPL(dev_pm_domain_attach_list);
>
>  /**
> + * devm_pm_domain_detach_list - devres-enabled version of dev_pm_domain_detach_list.
> + * @_list: The list of PM domains to detach.
> + *
> + * This function reverse the actions from devm_pm_domain_attach_list().
> + * it will be invoked during the remove phase from drivers implicitly if driver
> + * uses devm_pm_domain_attach_list() to attach the PM domains.
> + */
> +static void devm_pm_domain_detach_list(void *_list)
> +{
> +       struct dev_pm_domain_list *list = _list;
> +
> +       dev_pm_domain_detach_list(list);
> +}
> +
> +/**
> + * devm_pm_domain_attach_list - devres-enabled version of dev_pm_domain_attach_list
> + * @dev: The device used to lookup the PM domains for.
> + * @data: The data used for attaching to the PM domains.
> + * @list: An out-parameter with an allocated list of attached PM domains.
> + *
> + * NOTE: this will also handle calling devm_pm_domain_detach_list() for
> + * you during remove phase.
> + *
> + * Returns the number of attached PM domains or a negative error code in case of
> + * a failure.
> + */
> +int devm_pm_domain_attach_list(struct device *dev,
> +                              const struct dev_pm_domain_attach_data *data,
> +                              struct dev_pm_domain_list **list)
> +{
> +       int ret, num_pds;
> +
> +       num_pds = dev_pm_domain_attach_list(dev, data, list);
> +       if (!num_pds)
> +               return 0;

This should be:
if (num_pds <= 0)
      return num_pds;

> +
> +       ret = devm_add_action_or_reset(dev, devm_pm_domain_detach_list, *list);
> +       if (ret)
> +               return ret;
> +
> +       return num_pds;
> +}
> +EXPORT_SYMBOL_GPL(devm_pm_domain_attach_list);
> +
> +/**
>   * dev_pm_domain_detach - Detach a device from its PM domain.
>   * @dev: Device to detach.
>   * @power_off: Used to indicate whether we should power off the device.
> diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
> index 772d328..b01e127 100644
> --- a/include/linux/pm_domain.h
> +++ b/include/linux/pm_domain.h
> @@ -450,6 +450,9 @@ struct device *dev_pm_domain_attach_by_name(struct device *dev,
>  int dev_pm_domain_attach_list(struct device *dev,
>                               const struct dev_pm_domain_attach_data *data,
>                               struct dev_pm_domain_list **list);
> +int devm_pm_domain_attach_list(struct device *dev,
> +                              const struct dev_pm_domain_attach_data *data,
> +                              struct dev_pm_domain_list **list);
>  void dev_pm_domain_detach(struct device *dev, bool power_off);
>  void dev_pm_domain_detach_list(struct dev_pm_domain_list *list);
>  int dev_pm_domain_start(struct device *dev);
> @@ -476,6 +479,14 @@ static inline int dev_pm_domain_attach_list(struct device *dev,
>  {
>         return 0;
>  }
> +
> +static inline int devm_pm_domain_attach_list(struct device *dev,
> +                                            const struct dev_pm_domain_attach_data *data,
> +                                            struct dev_pm_domain_list **list)
> +{
> +       return 0;
> +}
> +
>  static inline void dev_pm_domain_detach(struct device *dev, bool power_off) {}
>  static inline void dev_pm_domain_detach_list(struct dev_pm_domain_list *list) {}
>  static inline int dev_pm_domain_start(struct device *dev)
> --
> 2.7.4
>

Kind regards
Uffe