[PATCH 12/18] drivers: firmware: psci: Add a helper to attach a CPU to its PM domain
From: Ulf Hansson
Date: Mon May 13 2019 - 15:31:19 EST
Introduce a new PSCI DT helper function, psci_dt_attach_cpu(), which takes
a CPU number as an in-parameter and tries to attach the CPU's struct device
to its corresponding PM domain. Let's use dev_pm_domain_attach_by_name(),
as to be able to specify "psci" as the required "power-domain-names".
Additionally, let the helper prepare the CPU to be power managed via
runtime PM.
Signed-off-by: Ulf Hansson <ulf.hansson@xxxxxxxxxx>
---
Changes:
- Take into account whether the CPU is online/offline.
- Convert from dev_pm_domain_attach() into using the more future proof
dev_pm_domain_attach_by_name().
---
drivers/firmware/psci/psci.h | 3 +++
drivers/firmware/psci/psci_pm_domain.c | 17 +++++++++++++++++
2 files changed, 20 insertions(+)
diff --git a/drivers/firmware/psci/psci.h b/drivers/firmware/psci/psci.h
index c36e0e6649e9..b4254405b8ef 100644
--- a/drivers/firmware/psci/psci.h
+++ b/drivers/firmware/psci/psci.h
@@ -4,6 +4,7 @@
#define __PSCI_H
struct cpuidle_driver;
+struct device;
struct device_node;
int psci_set_osi_mode(void);
@@ -16,10 +17,12 @@ int psci_dt_parse_state_node(struct device_node *np, u32 *state);
int psci_dt_init_pm_domains(struct device_node *np);
int psci_dt_pm_domains_parse_states(struct cpuidle_driver *drv,
struct device_node *cpu_node, u32 *psci_states);
+struct device *psci_dt_attach_cpu(int cpu);
#else
static inline int psci_dt_init_pm_domains(struct device_node *np) { return 0; }
static inline int psci_dt_pm_domains_parse_states(struct cpuidle_driver *drv,
struct device_node *cpu_node, u32 *psci_states) { return 0; }
+static inline struct device *psci_dt_attach_cpu(int cpu) { return NULL; }
#endif
#endif
diff --git a/drivers/firmware/psci/psci_pm_domain.c b/drivers/firmware/psci/psci_pm_domain.c
index 3aa645dba81b..1cbe745ee001 100644
--- a/drivers/firmware/psci/psci_pm_domain.c
+++ b/drivers/firmware/psci/psci_pm_domain.c
@@ -12,8 +12,10 @@
#include <linux/device.h>
#include <linux/kernel.h>
#include <linux/pm_domain.h>
+#include <linux/pm_runtime.h>
#include <linux/slab.h>
#include <linux/string.h>
+#include <linux/cpu.h>
#include <linux/cpuidle.h>
#include <linux/cpu_pm.h>
@@ -383,4 +385,19 @@ int psci_dt_pm_domains_parse_states(struct cpuidle_driver *drv,
return 0;
}
+
+struct device *psci_dt_attach_cpu(int cpu)
+{
+ struct device *dev, *cpu_dev = get_cpu_device(cpu);
+
+ dev = dev_pm_domain_attach_by_name(cpu_dev, "psci");
+ if (IS_ERR_OR_NULL(dev))
+ return dev;
+
+ pm_runtime_irq_safe(dev);
+ if (cpu_online(cpu))
+ pm_runtime_get_sync(dev);
+
+ return dev;
+}
#endif
--
2.17.1