]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blame - include/linux/pm_domain.h
cpuidle: Export the next timer expiration for CPUs
[mirror_ubuntu-jammy-kernel.git] / include / linux / pm_domain.h
CommitLineData
f721889f
RW
1/*
2 * pm_domain.h - Definitions and headers related to device power domains.
3 *
4 * Copyright (C) 2011 Rafael J. Wysocki <rjw@sisk.pl>, Renesas Electronics Corp.
5 *
6 * This file is released under the GPLv2.
7 */
8
9#ifndef _LINUX_PM_DOMAIN_H
10#define _LINUX_PM_DOMAIN_H
11
12#include <linux/device.h>
313162d0
PG
13#include <linux/mutex.h>
14#include <linux/pm.h>
4f042cda 15#include <linux/err.h>
c8aa130b 16#include <linux/of.h>
6ff7bb0d 17#include <linux/notifier.h>
d716f479 18#include <linux/spinlock.h>
eb594b73 19#include <linux/cpumask.h>
f721889f 20
e5089c2c
UH
21/*
22 * Flags to control the behaviour of a genpd.
23 *
24 * These flags may be set in the struct generic_pm_domain's flags field by a
25 * genpd backend driver. The flags must be set before it calls pm_genpd_init(),
26 * which initializes a genpd.
27 *
28 * GENPD_FLAG_PM_CLK: Instructs genpd to use the PM clk framework,
29 * while powering on/off attached devices.
30 *
31 * GENPD_FLAG_IRQ_SAFE: This informs genpd that its backend callbacks,
32 * ->power_on|off(), doesn't sleep. Hence, these
33 * can be invoked from within atomic context, which
34 * enables genpd to power on/off the PM domain,
35 * even when pm_runtime_is_irq_safe() returns true,
36 * for any of its attached devices. Note that, a
37 * genpd having this flag set, requires its
38 * masterdomains to also have it set.
39 *
40 * GENPD_FLAG_ALWAYS_ON: Instructs genpd to always keep the PM domain
41 * powered on.
42 *
43 * GENPD_FLAG_ACTIVE_WAKEUP: Instructs genpd to keep the PM domain powered
44 * on, in case any of its attached devices is used
45 * in the wakeup path to serve system wakeups.
eb594b73
UH
46 *
47 * GENPD_FLAG_CPU_DOMAIN: Instructs genpd that it should expect to get
48 * devices attached, which may belong to CPUs or
49 * possibly have subdomains with CPUs attached.
50 * This flag enables the genpd backend driver to
51 * deploy idle power management support for CPUs
52 * and groups of CPUs. Note that, the backend
53 * driver must then comply with the so called,
54 * last-man-standing algorithm, for the CPUs in the
55 * PM domain.
e5089c2c
UH
56 */
57#define GENPD_FLAG_PM_CLK (1U << 0)
58#define GENPD_FLAG_IRQ_SAFE (1U << 1)
59#define GENPD_FLAG_ALWAYS_ON (1U << 2)
60#define GENPD_FLAG_ACTIVE_WAKEUP (1U << 3)
eb594b73 61#define GENPD_FLAG_CPU_DOMAIN (1U << 4)
c11f6f5b 62
17b75eca
RW
63enum gpd_status {
64 GPD_STATE_ACTIVE = 0, /* PM domain is active */
17b75eca
RW
65 GPD_STATE_POWER_OFF, /* PM domain is off */
66};
596ba34b 67
f721889f
RW
68struct dev_power_governor {
69 bool (*power_down_ok)(struct dev_pm_domain *domain);
9df3921e 70 bool (*suspend_ok)(struct device *dev);
f721889f
RW
71};
72
d5e4cbfe
RW
73struct gpd_dev_ops {
74 int (*start)(struct device *dev);
75 int (*stop)(struct device *dev);
d5e4cbfe
RW
76};
77
fc5cbf0c
AH
78struct genpd_power_state {
79 s64 power_off_latency_ns;
80 s64 power_on_latency_ns;
405f7226 81 s64 residency_ns;
0c9b694a 82 struct fwnode_handle *fwnode;
afece3ab 83 ktime_t idle_time;
49a27e27 84 void *data;
fc5cbf0c
AH
85};
86
35241d12 87struct genpd_lock_ops;
6e41766a 88struct dev_pm_opp;
1067ae3e 89struct opp_table;
35241d12 90
f721889f 91struct generic_pm_domain {
401ea157 92 struct device dev;
f721889f 93 struct dev_pm_domain domain; /* PM domain operations */
5125bbf3 94 struct list_head gpd_list_node; /* Node in the global PM domains list */
5063ce15
RW
95 struct list_head master_links; /* Links with PM domain as a master */
96 struct list_head slave_links; /* Links with PM domain as a slave */
f721889f 97 struct list_head dev_list; /* List of devices */
f721889f
RW
98 struct dev_power_governor *gov;
99 struct work_struct power_off_work;
de0aa06d
JH
100 struct fwnode_handle *provider; /* Identity of the domain provider */
101 bool has_provider;
d07e9c17 102 const char *name;
c4bb3160 103 atomic_t sd_count; /* Number of subdomains with power "on" */
17b75eca 104 enum gpd_status status; /* Current state of the domain */
596ba34b
RW
105 unsigned int device_count; /* Number of devices */
106 unsigned int suspended_count; /* System suspend device counter */
107 unsigned int prepared_count; /* Suspend counter of prepared devices */
42f6284a 108 unsigned int performance_state; /* Aggregated max performance state */
eb594b73 109 cpumask_var_t cpus; /* A cpumask of the attached CPUs */
f721889f
RW
110 int (*power_off)(struct generic_pm_domain *domain);
111 int (*power_on)(struct generic_pm_domain *domain);
1067ae3e 112 struct opp_table *opp_table; /* OPP table of the genpd */
6e41766a
VK
113 unsigned int (*opp_to_performance_state)(struct generic_pm_domain *genpd,
114 struct dev_pm_opp *opp);
42f6284a
VK
115 int (*set_performance_state)(struct generic_pm_domain *genpd,
116 unsigned int state);
d5e4cbfe 117 struct gpd_dev_ops dev_ops;
221e9b58 118 s64 max_off_time_ns; /* Maximum allowed "suspended" time. */
6ff7bb0d
RW
119 bool max_off_time_changed;
120 bool cached_power_down_ok;
c16561e8
UH
121 int (*attach_dev)(struct generic_pm_domain *domain,
122 struct device *dev);
123 void (*detach_dev)(struct generic_pm_domain *domain,
124 struct device *dev);
c11f6f5b 125 unsigned int flags; /* Bit field of configs for genpd */
59d65b73 126 struct genpd_power_state *states;
49a27e27
UH
127 void (*free_states)(struct genpd_power_state *states,
128 unsigned int state_count);
fc5cbf0c
AH
129 unsigned int state_count; /* number of states */
130 unsigned int state_idx; /* state that genpd will go to when off */
afece3ab
TG
131 ktime_t on_time;
132 ktime_t accounting_time;
35241d12 133 const struct genpd_lock_ops *lock_ops;
d716f479
LI
134 union {
135 struct mutex mlock;
136 struct {
137 spinlock_t slock;
138 unsigned long lock_flags;
139 };
140 };
fc5cbf0c 141
f721889f
RW
142};
143
596ba34b
RW
144static inline struct generic_pm_domain *pd_to_genpd(struct dev_pm_domain *pd)
145{
146 return container_of(pd, struct generic_pm_domain, domain);
147}
148
5063ce15
RW
149struct gpd_link {
150 struct generic_pm_domain *master;
151 struct list_head master_node;
152 struct generic_pm_domain *slave;
153 struct list_head slave_node;
18edf49c
VK
154
155 /* Sub-domain's per-master domain performance state */
156 unsigned int performance_state;
157 unsigned int prev_performance_state;
5063ce15
RW
158};
159
b02c999a 160struct gpd_timing_data {
2b1d88cd
UH
161 s64 suspend_latency_ns;
162 s64 resume_latency_ns;
a5bef810 163 s64 effective_constraint_ns;
6ff7bb0d 164 bool constraint_changed;
9df3921e 165 bool cached_suspend_ok;
b02c999a
RW
166};
167
00e7c295
UH
168struct pm_domain_data {
169 struct list_head list_node;
170 struct device *dev;
171};
172
cd0ea672
RW
173struct generic_pm_domain_data {
174 struct pm_domain_data base;
b02c999a 175 struct gpd_timing_data td;
6ff7bb0d 176 struct notifier_block nb;
42f6284a 177 unsigned int performance_state;
a5ea7a0f 178 void *data;
cd0ea672
RW
179};
180
9b4f617b 181#ifdef CONFIG_PM_GENERIC_DOMAINS
cd0ea672
RW
182static inline struct generic_pm_domain_data *to_gpd_data(struct pm_domain_data *pdd)
183{
184 return container_of(pdd, struct generic_pm_domain_data, base);
185}
186
d5e4cbfe
RW
187static inline struct generic_pm_domain_data *dev_gpd_data(struct device *dev)
188{
189 return to_gpd_data(dev->power.subsys_data->domain_data);
190}
191
1a7a6707 192int pm_genpd_add_device(struct generic_pm_domain *genpd, struct device *dev);
924f4486 193int pm_genpd_remove_device(struct device *dev);
781b9d6b
UH
194int pm_genpd_add_subdomain(struct generic_pm_domain *genpd,
195 struct generic_pm_domain *new_subdomain);
196int pm_genpd_remove_subdomain(struct generic_pm_domain *genpd,
197 struct generic_pm_domain *target);
198int pm_genpd_init(struct generic_pm_domain *genpd,
199 struct dev_power_governor *gov, bool is_off);
200int pm_genpd_remove(struct generic_pm_domain *genpd);
201int dev_pm_genpd_set_performance_state(struct device *dev, unsigned int state);
b02c999a 202
ae3c511c 203extern struct dev_power_governor simple_qos_governor;
925b44a2 204extern struct dev_power_governor pm_domain_always_on_gov;
f721889f 205#else
b02c999a 206
b642631d
MD
207static inline struct generic_pm_domain_data *dev_gpd_data(struct device *dev)
208{
209 return ERR_PTR(-ENOSYS);
210}
1a7a6707
UH
211static inline int pm_genpd_add_device(struct generic_pm_domain *genpd,
212 struct device *dev)
b02c999a
RW
213{
214 return -ENOSYS;
215}
924f4486 216static inline int pm_genpd_remove_device(struct device *dev)
f721889f
RW
217{
218 return -ENOSYS;
219}
220static inline int pm_genpd_add_subdomain(struct generic_pm_domain *genpd,
221 struct generic_pm_domain *new_sd)
222{
223 return -ENOSYS;
224}
225static inline int pm_genpd_remove_subdomain(struct generic_pm_domain *genpd,
226 struct generic_pm_domain *target)
227{
228 return -ENOSYS;
229}
7eb231c3
UH
230static inline int pm_genpd_init(struct generic_pm_domain *genpd,
231 struct dev_power_governor *gov, bool is_off)
b02c999a 232{
7eb231c3 233 return -ENOSYS;
b02c999a 234}
3fe57710
JH
235static inline int pm_genpd_remove(struct generic_pm_domain *genpd)
236{
237 return -ENOTSUPP;
238}
16d0bf18 239
42f6284a
VK
240static inline int dev_pm_genpd_set_performance_state(struct device *dev,
241 unsigned int state)
242{
243 return -ENOTSUPP;
244}
245
16d0bf18
GU
246#define simple_qos_governor (*(struct dev_power_governor *)(NULL))
247#define pm_domain_always_on_gov (*(struct dev_power_governor *)(NULL))
17f2ae7f
RW
248#endif
249
77f827de 250#ifdef CONFIG_PM_GENERIC_DOMAINS_SLEEP
781b9d6b
UH
251void pm_genpd_syscore_poweroff(struct device *dev);
252void pm_genpd_syscore_poweron(struct device *dev);
77f827de 253#else
d47e6464
UH
254static inline void pm_genpd_syscore_poweroff(struct device *dev) {}
255static inline void pm_genpd_syscore_poweron(struct device *dev) {}
77f827de
RW
256#endif
257
aa42240a
TF
258/* OF PM domain providers */
259struct of_device_id;
260
40845524
TR
261typedef struct generic_pm_domain *(*genpd_xlate_t)(struct of_phandle_args *args,
262 void *data);
263
aa42240a
TF
264struct genpd_onecell_data {
265 struct generic_pm_domain **domains;
266 unsigned int num_domains;
40845524 267 genpd_xlate_t xlate;
aa42240a
TF
268};
269
aa42240a 270#ifdef CONFIG_PM_GENERIC_DOMAINS_OF
892ebdcc
JH
271int of_genpd_add_provider_simple(struct device_node *np,
272 struct generic_pm_domain *genpd);
273int of_genpd_add_provider_onecell(struct device_node *np,
274 struct genpd_onecell_data *data);
aa42240a 275void of_genpd_del_provider(struct device_node *np);
781b9d6b
UH
276int of_genpd_add_device(struct of_phandle_args *args, struct device *dev);
277int of_genpd_add_subdomain(struct of_phandle_args *parent,
278 struct of_phandle_args *new_subdomain);
279struct generic_pm_domain *of_genpd_remove_last(struct device_node *np);
280int of_genpd_parse_idle_states(struct device_node *dn,
281 struct genpd_power_state **states, int *n);
e38f89d3
VK
282unsigned int pm_genpd_opp_to_performance_state(struct device *genpd_dev,
283 struct dev_pm_opp *opp);
aa42240a
TF
284
285int genpd_dev_pm_attach(struct device *dev);
3c095f32
UH
286struct device *genpd_dev_pm_attach_by_id(struct device *dev,
287 unsigned int index);
5d6be70a 288struct device *genpd_dev_pm_attach_by_name(struct device *dev,
7416f1f2 289 const char *name);
aa42240a 290#else /* !CONFIG_PM_GENERIC_DOMAINS_OF */
892ebdcc
JH
291static inline int of_genpd_add_provider_simple(struct device_node *np,
292 struct generic_pm_domain *genpd)
aa42240a 293{
892ebdcc
JH
294 return -ENOTSUPP;
295}
296
297static inline int of_genpd_add_provider_onecell(struct device_node *np,
298 struct genpd_onecell_data *data)
299{
300 return -ENOTSUPP;
aa42240a 301}
aa42240a 302
892ebdcc 303static inline void of_genpd_del_provider(struct device_node *np) {}
aa42240a 304
ec69572b
JH
305static inline int of_genpd_add_device(struct of_phandle_args *args,
306 struct device *dev)
307{
308 return -ENODEV;
309}
310
311static inline int of_genpd_add_subdomain(struct of_phandle_args *parent,
312 struct of_phandle_args *new_subdomain)
313{
314 return -ENODEV;
315}
316
30f60428
LI
317static inline int of_genpd_parse_idle_states(struct device_node *dn,
318 struct genpd_power_state **states, int *n)
319{
320 return -ENODEV;
321}
322
e38f89d3
VK
323static inline unsigned int
324pm_genpd_opp_to_performance_state(struct device *genpd_dev,
325 struct dev_pm_opp *opp)
326{
327 return 0;
328}
329
aa42240a
TF
330static inline int genpd_dev_pm_attach(struct device *dev)
331{
919b7308 332 return 0;
aa42240a 333}
17926551 334
3c095f32
UH
335static inline struct device *genpd_dev_pm_attach_by_id(struct device *dev,
336 unsigned int index)
337{
338 return NULL;
339}
340
5d6be70a 341static inline struct device *genpd_dev_pm_attach_by_name(struct device *dev,
7416f1f2 342 const char *name)
5d6be70a
UH
343{
344 return NULL;
345}
346
17926551
JH
347static inline
348struct generic_pm_domain *of_genpd_remove_last(struct device_node *np)
349{
350 return ERR_PTR(-ENOTSUPP);
351}
aa42240a
TF
352#endif /* CONFIG_PM_GENERIC_DOMAINS_OF */
353
f48c767c 354#ifdef CONFIG_PM
781b9d6b 355int dev_pm_domain_attach(struct device *dev, bool power_on);
82e12d9e
UH
356struct device *dev_pm_domain_attach_by_id(struct device *dev,
357 unsigned int index);
27dceb81 358struct device *dev_pm_domain_attach_by_name(struct device *dev,
eeb35df0 359 const char *name);
781b9d6b
UH
360void dev_pm_domain_detach(struct device *dev, bool power_off);
361void dev_pm_domain_set(struct device *dev, struct dev_pm_domain *pd);
f48c767c
UH
362#else
363static inline int dev_pm_domain_attach(struct device *dev, bool power_on)
364{
919b7308 365 return 0;
f48c767c 366}
82e12d9e
UH
367static inline struct device *dev_pm_domain_attach_by_id(struct device *dev,
368 unsigned int index)
369{
370 return NULL;
371}
27dceb81 372static inline struct device *dev_pm_domain_attach_by_name(struct device *dev,
eeb35df0 373 const char *name)
27dceb81
UH
374{
375 return NULL;
376}
f48c767c 377static inline void dev_pm_domain_detach(struct device *dev, bool power_off) {}
989561de
TV
378static inline void dev_pm_domain_set(struct device *dev,
379 struct dev_pm_domain *pd) {}
f48c767c
UH
380#endif
381
f721889f 382#endif /* _LINUX_PM_DOMAIN_H */