.. | .. |
---|
| 1 | +/* SPDX-License-Identifier: GPL-2.0-only */ |
---|
1 | 2 | /* |
---|
2 | 3 | * pm_domain.h - Definitions and headers related to device power domains. |
---|
3 | 4 | * |
---|
4 | 5 | * Copyright (C) 2011 Rafael J. Wysocki <rjw@sisk.pl>, Renesas Electronics Corp. |
---|
5 | | - * |
---|
6 | | - * This file is released under the GPLv2. |
---|
7 | 6 | */ |
---|
8 | 7 | |
---|
9 | 8 | #ifndef _LINUX_PM_DOMAIN_H |
---|
10 | 9 | #define _LINUX_PM_DOMAIN_H |
---|
11 | 10 | |
---|
12 | 11 | #include <linux/device.h> |
---|
| 12 | +#include <linux/ktime.h> |
---|
13 | 13 | #include <linux/mutex.h> |
---|
14 | 14 | #include <linux/pm.h> |
---|
15 | 15 | #include <linux/err.h> |
---|
16 | 16 | #include <linux/of.h> |
---|
17 | 17 | #include <linux/notifier.h> |
---|
18 | 18 | #include <linux/spinlock.h> |
---|
| 19 | +#include <linux/cpumask.h> |
---|
19 | 20 | |
---|
20 | | -/* Defines used for the flags field in the struct generic_pm_domain */ |
---|
21 | | -#define GENPD_FLAG_PM_CLK (1U << 0) /* PM domain uses PM clk */ |
---|
22 | | -#define GENPD_FLAG_IRQ_SAFE (1U << 1) /* PM domain operates in atomic */ |
---|
23 | | -#define GENPD_FLAG_ALWAYS_ON (1U << 2) /* PM domain is always powered on */ |
---|
24 | | -#define GENPD_FLAG_ACTIVE_WAKEUP (1U << 3) /* Keep devices active if wakeup */ |
---|
| 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. |
---|
| 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. |
---|
| 56 | + * |
---|
| 57 | + * GENPD_FLAG_RPM_ALWAYS_ON: Instructs genpd to always keep the PM domain |
---|
| 58 | + * powered on except for system suspend. |
---|
| 59 | + * |
---|
| 60 | + * GENPD_FLAG_MIN_RESIDENCY: Enable the genpd governor to consider its |
---|
| 61 | + * components' next wakeup when determining the |
---|
| 62 | + * optimal idle state. |
---|
| 63 | + */ |
---|
| 64 | +#define GENPD_FLAG_PM_CLK (1U << 0) |
---|
| 65 | +#define GENPD_FLAG_IRQ_SAFE (1U << 1) |
---|
| 66 | +#define GENPD_FLAG_ALWAYS_ON (1U << 2) |
---|
| 67 | +#define GENPD_FLAG_ACTIVE_WAKEUP (1U << 3) |
---|
| 68 | +#define GENPD_FLAG_CPU_DOMAIN (1U << 4) |
---|
| 69 | +#define GENPD_FLAG_RPM_ALWAYS_ON (1U << 5) |
---|
| 70 | +#define GENPD_FLAG_MIN_RESIDENCY (1U << 6) |
---|
25 | 71 | |
---|
26 | 72 | enum gpd_status { |
---|
27 | | - GPD_STATE_ACTIVE = 0, /* PM domain is active */ |
---|
28 | | - GPD_STATE_POWER_OFF, /* PM domain is off */ |
---|
| 73 | + GENPD_STATE_ON = 0, /* PM domain is on */ |
---|
| 74 | + GENPD_STATE_OFF, /* PM domain is off */ |
---|
| 75 | +}; |
---|
| 76 | + |
---|
| 77 | +enum genpd_notication { |
---|
| 78 | + GENPD_NOTIFY_PRE_OFF = 0, |
---|
| 79 | + GENPD_NOTIFY_OFF, |
---|
| 80 | + GENPD_NOTIFY_PRE_ON, |
---|
| 81 | + GENPD_NOTIFY_ON, |
---|
29 | 82 | }; |
---|
30 | 83 | |
---|
31 | 84 | struct dev_power_governor { |
---|
.. | .. |
---|
42 | 95 | s64 power_off_latency_ns; |
---|
43 | 96 | s64 power_on_latency_ns; |
---|
44 | 97 | s64 residency_ns; |
---|
| 98 | + u64 usage; |
---|
| 99 | + u64 rejected; |
---|
45 | 100 | struct fwnode_handle *fwnode; |
---|
46 | 101 | ktime_t idle_time; |
---|
| 102 | + void *data; |
---|
47 | 103 | }; |
---|
48 | 104 | |
---|
49 | 105 | struct genpd_lock_ops; |
---|
50 | 106 | struct dev_pm_opp; |
---|
| 107 | +struct opp_table; |
---|
51 | 108 | |
---|
52 | 109 | struct generic_pm_domain { |
---|
53 | 110 | struct device dev; |
---|
54 | 111 | struct dev_pm_domain domain; /* PM domain operations */ |
---|
55 | 112 | struct list_head gpd_list_node; /* Node in the global PM domains list */ |
---|
56 | | - struct list_head master_links; /* Links with PM domain as a master */ |
---|
57 | | - struct list_head slave_links; /* Links with PM domain as a slave */ |
---|
| 113 | + struct list_head parent_links; /* Links with PM domain as a parent */ |
---|
| 114 | + struct list_head child_links; /* Links with PM domain as a child */ |
---|
58 | 115 | struct list_head dev_list; /* List of devices */ |
---|
59 | 116 | struct dev_power_governor *gov; |
---|
60 | 117 | struct work_struct power_off_work; |
---|
.. | .. |
---|
67 | 124 | unsigned int suspended_count; /* System suspend device counter */ |
---|
68 | 125 | unsigned int prepared_count; /* Suspend counter of prepared devices */ |
---|
69 | 126 | unsigned int performance_state; /* Aggregated max performance state */ |
---|
70 | | - bool suspend_power_off; /* Power status before system suspend */ |
---|
| 127 | + cpumask_var_t cpus; /* A cpumask of the attached CPUs */ |
---|
71 | 128 | int (*power_off)(struct generic_pm_domain *domain); |
---|
72 | 129 | int (*power_on)(struct generic_pm_domain *domain); |
---|
| 130 | + struct raw_notifier_head power_notifiers; /* Power on/off notifiers */ |
---|
| 131 | + struct opp_table *opp_table; /* OPP table of the genpd */ |
---|
73 | 132 | unsigned int (*opp_to_performance_state)(struct generic_pm_domain *genpd, |
---|
74 | 133 | struct dev_pm_opp *opp); |
---|
75 | 134 | int (*set_performance_state)(struct generic_pm_domain *genpd, |
---|
76 | 135 | unsigned int state); |
---|
77 | 136 | struct gpd_dev_ops dev_ops; |
---|
78 | 137 | s64 max_off_time_ns; /* Maximum allowed "suspended" time. */ |
---|
| 138 | + ktime_t next_wakeup; /* Maintained by the domain governor */ |
---|
79 | 139 | bool max_off_time_changed; |
---|
80 | 140 | bool cached_power_down_ok; |
---|
| 141 | + bool cached_power_down_state_idx; |
---|
81 | 142 | int (*attach_dev)(struct generic_pm_domain *domain, |
---|
82 | 143 | struct device *dev); |
---|
83 | 144 | void (*detach_dev)(struct generic_pm_domain *domain, |
---|
84 | 145 | struct device *dev); |
---|
85 | 146 | unsigned int flags; /* Bit field of configs for genpd */ |
---|
86 | 147 | struct genpd_power_state *states; |
---|
| 148 | + void (*free_states)(struct genpd_power_state *states, |
---|
| 149 | + unsigned int state_count); |
---|
87 | 150 | unsigned int state_count; /* number of states */ |
---|
88 | 151 | unsigned int state_idx; /* state that genpd will go to when off */ |
---|
89 | | - void *free; /* Free the state that was allocated for default */ |
---|
90 | 152 | ktime_t on_time; |
---|
91 | 153 | ktime_t accounting_time; |
---|
92 | 154 | const struct genpd_lock_ops *lock_ops; |
---|
.. | .. |
---|
106 | 168 | } |
---|
107 | 169 | |
---|
108 | 170 | struct gpd_link { |
---|
109 | | - struct generic_pm_domain *master; |
---|
110 | | - struct list_head master_node; |
---|
111 | | - struct generic_pm_domain *slave; |
---|
112 | | - struct list_head slave_node; |
---|
| 171 | + struct generic_pm_domain *parent; |
---|
| 172 | + struct list_head parent_node; |
---|
| 173 | + struct generic_pm_domain *child; |
---|
| 174 | + struct list_head child_node; |
---|
| 175 | + |
---|
| 176 | + /* Sub-domain's per-master domain performance state */ |
---|
| 177 | + unsigned int performance_state; |
---|
| 178 | + unsigned int prev_performance_state; |
---|
113 | 179 | }; |
---|
114 | 180 | |
---|
115 | 181 | struct gpd_timing_data { |
---|
.. | .. |
---|
129 | 195 | struct pm_domain_data base; |
---|
130 | 196 | struct gpd_timing_data td; |
---|
131 | 197 | struct notifier_block nb; |
---|
| 198 | + struct notifier_block *power_nb; |
---|
| 199 | + int cpu; |
---|
132 | 200 | unsigned int performance_state; |
---|
| 201 | + ktime_t next_wakeup; |
---|
133 | 202 | void *data; |
---|
134 | 203 | }; |
---|
135 | 204 | |
---|
.. | .. |
---|
147 | 216 | int pm_genpd_add_device(struct generic_pm_domain *genpd, struct device *dev); |
---|
148 | 217 | int pm_genpd_remove_device(struct device *dev); |
---|
149 | 218 | int pm_genpd_add_subdomain(struct generic_pm_domain *genpd, |
---|
150 | | - struct generic_pm_domain *new_subdomain); |
---|
| 219 | + struct generic_pm_domain *subdomain); |
---|
151 | 220 | int pm_genpd_remove_subdomain(struct generic_pm_domain *genpd, |
---|
152 | | - struct generic_pm_domain *target); |
---|
| 221 | + struct generic_pm_domain *subdomain); |
---|
153 | 222 | int pm_genpd_init(struct generic_pm_domain *genpd, |
---|
154 | 223 | struct dev_power_governor *gov, bool is_off); |
---|
155 | 224 | int pm_genpd_remove(struct generic_pm_domain *genpd); |
---|
156 | 225 | int dev_pm_genpd_set_performance_state(struct device *dev, unsigned int state); |
---|
| 226 | +int dev_pm_genpd_add_notifier(struct device *dev, struct notifier_block *nb); |
---|
| 227 | +int dev_pm_genpd_remove_notifier(struct device *dev); |
---|
| 228 | +void dev_pm_genpd_set_next_wakeup(struct device *dev, ktime_t next); |
---|
157 | 229 | |
---|
158 | 230 | extern struct dev_power_governor simple_qos_governor; |
---|
159 | 231 | extern struct dev_power_governor pm_domain_always_on_gov; |
---|
| 232 | +#ifdef CONFIG_CPU_IDLE |
---|
| 233 | +extern struct dev_power_governor pm_domain_cpu_gov; |
---|
| 234 | +#endif |
---|
160 | 235 | #else |
---|
161 | 236 | |
---|
162 | 237 | static inline struct generic_pm_domain_data *dev_gpd_data(struct device *dev) |
---|
.. | .. |
---|
173 | 248 | return -ENOSYS; |
---|
174 | 249 | } |
---|
175 | 250 | static inline int pm_genpd_add_subdomain(struct generic_pm_domain *genpd, |
---|
176 | | - struct generic_pm_domain *new_sd) |
---|
| 251 | + struct generic_pm_domain *subdomain) |
---|
177 | 252 | { |
---|
178 | 253 | return -ENOSYS; |
---|
179 | 254 | } |
---|
180 | 255 | static inline int pm_genpd_remove_subdomain(struct generic_pm_domain *genpd, |
---|
181 | | - struct generic_pm_domain *target) |
---|
| 256 | + struct generic_pm_domain *subdomain) |
---|
182 | 257 | { |
---|
183 | 258 | return -ENOSYS; |
---|
184 | 259 | } |
---|
.. | .. |
---|
198 | 273 | return -ENOTSUPP; |
---|
199 | 274 | } |
---|
200 | 275 | |
---|
| 276 | +static inline int dev_pm_genpd_add_notifier(struct device *dev, |
---|
| 277 | + struct notifier_block *nb) |
---|
| 278 | +{ |
---|
| 279 | + return -ENOTSUPP; |
---|
| 280 | +} |
---|
| 281 | + |
---|
| 282 | +static inline int dev_pm_genpd_remove_notifier(struct device *dev) |
---|
| 283 | +{ |
---|
| 284 | + return -ENOTSUPP; |
---|
| 285 | +} |
---|
| 286 | + |
---|
| 287 | +static inline void dev_pm_genpd_set_next_wakeup(struct device *dev, ktime_t next) |
---|
| 288 | +{ } |
---|
| 289 | + |
---|
201 | 290 | #define simple_qos_governor (*(struct dev_power_governor *)(NULL)) |
---|
202 | 291 | #define pm_domain_always_on_gov (*(struct dev_power_governor *)(NULL)) |
---|
203 | 292 | #endif |
---|
204 | 293 | |
---|
205 | 294 | #ifdef CONFIG_PM_GENERIC_DOMAINS_SLEEP |
---|
206 | | -void pm_genpd_syscore_poweroff(struct device *dev); |
---|
207 | | -void pm_genpd_syscore_poweron(struct device *dev); |
---|
| 295 | +void dev_pm_genpd_suspend(struct device *dev); |
---|
| 296 | +void dev_pm_genpd_resume(struct device *dev); |
---|
208 | 297 | #else |
---|
209 | | -static inline void pm_genpd_syscore_poweroff(struct device *dev) {} |
---|
210 | | -static inline void pm_genpd_syscore_poweron(struct device *dev) {} |
---|
| 298 | +static inline void dev_pm_genpd_suspend(struct device *dev) {} |
---|
| 299 | +static inline void dev_pm_genpd_resume(struct device *dev) {} |
---|
211 | 300 | #endif |
---|
212 | 301 | |
---|
213 | 302 | /* OF PM domain providers */ |
---|
.. | .. |
---|
229 | 318 | struct genpd_onecell_data *data); |
---|
230 | 319 | void of_genpd_del_provider(struct device_node *np); |
---|
231 | 320 | int of_genpd_add_device(struct of_phandle_args *args, struct device *dev); |
---|
232 | | -int of_genpd_add_subdomain(struct of_phandle_args *parent, |
---|
233 | | - struct of_phandle_args *new_subdomain); |
---|
| 321 | +int of_genpd_add_subdomain(struct of_phandle_args *parent_spec, |
---|
| 322 | + struct of_phandle_args *subdomain_spec); |
---|
| 323 | +int of_genpd_remove_subdomain(struct of_phandle_args *parent_spec, |
---|
| 324 | + struct of_phandle_args *subdomain_spec); |
---|
234 | 325 | struct generic_pm_domain *of_genpd_remove_last(struct device_node *np); |
---|
235 | 326 | int of_genpd_parse_idle_states(struct device_node *dn, |
---|
236 | 327 | struct genpd_power_state **states, int *n); |
---|
237 | | -unsigned int of_genpd_opp_to_performance_state(struct device *dev, |
---|
238 | | - struct device_node *np); |
---|
| 328 | +unsigned int pm_genpd_opp_to_performance_state(struct device *genpd_dev, |
---|
| 329 | + struct dev_pm_opp *opp); |
---|
239 | 330 | |
---|
240 | 331 | int genpd_dev_pm_attach(struct device *dev); |
---|
241 | 332 | struct device *genpd_dev_pm_attach_by_id(struct device *dev, |
---|
242 | 333 | unsigned int index); |
---|
243 | 334 | struct device *genpd_dev_pm_attach_by_name(struct device *dev, |
---|
244 | | - char *name); |
---|
| 335 | + const char *name); |
---|
245 | 336 | #else /* !CONFIG_PM_GENERIC_DOMAINS_OF */ |
---|
246 | 337 | static inline int of_genpd_add_provider_simple(struct device_node *np, |
---|
247 | 338 | struct generic_pm_domain *genpd) |
---|
.. | .. |
---|
263 | 354 | return -ENODEV; |
---|
264 | 355 | } |
---|
265 | 356 | |
---|
266 | | -static inline int of_genpd_add_subdomain(struct of_phandle_args *parent, |
---|
267 | | - struct of_phandle_args *new_subdomain) |
---|
| 357 | +static inline int of_genpd_add_subdomain(struct of_phandle_args *parent_spec, |
---|
| 358 | + struct of_phandle_args *subdomain_spec) |
---|
| 359 | +{ |
---|
| 360 | + return -ENODEV; |
---|
| 361 | +} |
---|
| 362 | + |
---|
| 363 | +static inline int of_genpd_remove_subdomain(struct of_phandle_args *parent_spec, |
---|
| 364 | + struct of_phandle_args *subdomain_spec) |
---|
268 | 365 | { |
---|
269 | 366 | return -ENODEV; |
---|
270 | 367 | } |
---|
.. | .. |
---|
276 | 373 | } |
---|
277 | 374 | |
---|
278 | 375 | static inline unsigned int |
---|
279 | | -of_genpd_opp_to_performance_state(struct device *dev, |
---|
280 | | - struct device_node *np) |
---|
| 376 | +pm_genpd_opp_to_performance_state(struct device *genpd_dev, |
---|
| 377 | + struct dev_pm_opp *opp) |
---|
281 | 378 | { |
---|
282 | 379 | return 0; |
---|
283 | 380 | } |
---|
.. | .. |
---|
294 | 391 | } |
---|
295 | 392 | |
---|
296 | 393 | static inline struct device *genpd_dev_pm_attach_by_name(struct device *dev, |
---|
297 | | - char *name) |
---|
| 394 | + const char *name) |
---|
298 | 395 | { |
---|
299 | 396 | return NULL; |
---|
300 | 397 | } |
---|
.. | .. |
---|
311 | 408 | struct device *dev_pm_domain_attach_by_id(struct device *dev, |
---|
312 | 409 | unsigned int index); |
---|
313 | 410 | struct device *dev_pm_domain_attach_by_name(struct device *dev, |
---|
314 | | - char *name); |
---|
| 411 | + const char *name); |
---|
315 | 412 | void dev_pm_domain_detach(struct device *dev, bool power_off); |
---|
| 413 | +int dev_pm_domain_start(struct device *dev); |
---|
316 | 414 | void dev_pm_domain_set(struct device *dev, struct dev_pm_domain *pd); |
---|
317 | 415 | #else |
---|
318 | 416 | static inline int dev_pm_domain_attach(struct device *dev, bool power_on) |
---|
.. | .. |
---|
325 | 423 | return NULL; |
---|
326 | 424 | } |
---|
327 | 425 | static inline struct device *dev_pm_domain_attach_by_name(struct device *dev, |
---|
328 | | - char *name) |
---|
| 426 | + const char *name) |
---|
329 | 427 | { |
---|
330 | 428 | return NULL; |
---|
331 | 429 | } |
---|
332 | 430 | static inline void dev_pm_domain_detach(struct device *dev, bool power_off) {} |
---|
| 431 | +static inline int dev_pm_domain_start(struct device *dev) |
---|
| 432 | +{ |
---|
| 433 | + return 0; |
---|
| 434 | +} |
---|
333 | 435 | static inline void dev_pm_domain_set(struct device *dev, |
---|
334 | 436 | struct dev_pm_domain *pd) {} |
---|
335 | 437 | #endif |
---|