Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at d986ba0329dcca102e227995371135c9bbcefb6b 602 lines 19 kB view raw
1/* SPDX-License-Identifier: GPL-2.0-only */ 2/* 3 * pm_domain.h - Definitions and headers related to device power domains. 4 * 5 * Copyright (C) 2011 Rafael J. Wysocki <rjw@sisk.pl>, Renesas Electronics Corp. 6 */ 7 8#ifndef _LINUX_PM_DOMAIN_H 9#define _LINUX_PM_DOMAIN_H 10 11#include <linux/device.h> 12#include <linux/ktime.h> 13#include <linux/mutex.h> 14#include <linux/pm.h> 15#include <linux/err.h> 16#include <linux/of.h> 17#include <linux/notifier.h> 18#include <linux/spinlock.h> 19#include <linux/cpumask_types.h> 20#include <linux/time64.h> 21 22/* 23 * Flags to control the behaviour when attaching a device to its PM domains. 24 * 25 * PD_FLAG_NO_DEV_LINK: As the default behaviour creates a device-link 26 * for every PM domain that gets attached, this 27 * flag can be used to skip that. 28 * 29 * PD_FLAG_DEV_LINK_ON: Add the DL_FLAG_RPM_ACTIVE to power-on the 30 * supplier and its PM domain when creating the 31 * device-links. 32 * 33 * PD_FLAG_REQUIRED_OPP: Assign required_devs for the required OPPs. The 34 * index of the required OPP must correspond to the 35 * index in the array of the pd_names. If pd_names 36 * isn't specified, the index just follows the 37 * index for the attached PM domain. 38 * 39 * PD_FLAG_ATTACH_POWER_ON: Power on the domain during attach. 40 * 41 * PD_FLAG_DETACH_POWER_OFF: Power off the domain during detach. 42 * 43 */ 44#define PD_FLAG_NO_DEV_LINK BIT(0) 45#define PD_FLAG_DEV_LINK_ON BIT(1) 46#define PD_FLAG_REQUIRED_OPP BIT(2) 47#define PD_FLAG_ATTACH_POWER_ON BIT(3) 48#define PD_FLAG_DETACH_POWER_OFF BIT(4) 49 50struct dev_pm_domain_attach_data { 51 const char * const *pd_names; 52 u32 num_pd_names; 53 u32 pd_flags; 54}; 55 56struct dev_pm_domain_list { 57 struct device **pd_devs; 58 struct device_link **pd_links; 59 u32 *opp_tokens; 60 u32 num_pds; 61}; 62 63/* 64 * Flags to control the behaviour of a genpd. 65 * 66 * These flags may be set in the struct generic_pm_domain's flags field by a 67 * genpd backend driver. The flags must be set before it calls pm_genpd_init(), 68 * which initializes a genpd. 69 * 70 * GENPD_FLAG_PM_CLK: Instructs genpd to use the PM clk framework, 71 * while powering on/off attached devices. 72 * 73 * GENPD_FLAG_IRQ_SAFE: This informs genpd that its backend callbacks, 74 * ->power_on|off(), doesn't sleep. Hence, these 75 * can be invoked from within atomic context, which 76 * enables genpd to power on/off the PM domain, 77 * even when pm_runtime_is_irq_safe() returns true, 78 * for any of its attached devices. Note that, a 79 * genpd having this flag set, requires its 80 * masterdomains to also have it set. 81 * 82 * GENPD_FLAG_ALWAYS_ON: Instructs genpd to always keep the PM domain 83 * powered on. 84 * 85 * GENPD_FLAG_ACTIVE_WAKEUP: Instructs genpd to keep the PM domain powered 86 * on, in case any of its attached devices is used 87 * in the wakeup path to serve system wakeups. 88 * 89 * GENPD_FLAG_CPU_DOMAIN: Instructs genpd that it should expect to get 90 * devices attached, which may belong to CPUs or 91 * possibly have subdomains with CPUs attached. 92 * This flag enables the genpd backend driver to 93 * deploy idle power management support for CPUs 94 * and groups of CPUs. Note that, the backend 95 * driver must then comply with the so called, 96 * last-man-standing algorithm, for the CPUs in the 97 * PM domain. 98 * 99 * GENPD_FLAG_RPM_ALWAYS_ON: Instructs genpd to always keep the PM domain 100 * powered on except for system suspend. 101 * 102 * GENPD_FLAG_MIN_RESIDENCY: Enable the genpd governor to consider its 103 * components' next wakeup when determining the 104 * optimal idle state. 105 * 106 * GENPD_FLAG_OPP_TABLE_FW: The genpd provider supports performance states, 107 * but its corresponding OPP tables are not 108 * described in DT, but are given directly by FW. 109 * 110 * GENPD_FLAG_DEV_NAME_FW: Instructs genpd to generate an unique device name 111 * using ida. It is used by genpd providers which 112 * get their genpd-names directly from FW. 113 * 114 * GENPD_FLAG_NO_SYNC_STATE: The ->sync_state() support is implemented in a 115 * genpd provider specific way, likely through a 116 * parent device node. This flag makes genpd to 117 * skip its internal support for this. 118 * 119 * GENPD_FLAG_NO_STAY_ON: For genpd OF providers a powered-on PM domain at 120 * initialization is prevented from being 121 * powered-off until the ->sync_state() callback is 122 * invoked. This flag informs genpd to allow a 123 * power-off without waiting for ->sync_state(). 124 */ 125#define GENPD_FLAG_PM_CLK (1U << 0) 126#define GENPD_FLAG_IRQ_SAFE (1U << 1) 127#define GENPD_FLAG_ALWAYS_ON (1U << 2) 128#define GENPD_FLAG_ACTIVE_WAKEUP (1U << 3) 129#define GENPD_FLAG_CPU_DOMAIN (1U << 4) 130#define GENPD_FLAG_RPM_ALWAYS_ON (1U << 5) 131#define GENPD_FLAG_MIN_RESIDENCY (1U << 6) 132#define GENPD_FLAG_OPP_TABLE_FW (1U << 7) 133#define GENPD_FLAG_DEV_NAME_FW (1U << 8) 134#define GENPD_FLAG_NO_SYNC_STATE (1U << 9) 135#define GENPD_FLAG_NO_STAY_ON (1U << 10) 136 137enum gpd_status { 138 GENPD_STATE_ON = 0, /* PM domain is on */ 139 GENPD_STATE_OFF, /* PM domain is off */ 140}; 141 142enum genpd_notication { 143 GENPD_NOTIFY_PRE_OFF = 0, 144 GENPD_NOTIFY_OFF, 145 GENPD_NOTIFY_PRE_ON, 146 GENPD_NOTIFY_ON, 147}; 148 149enum genpd_sync_state { 150 GENPD_SYNC_STATE_OFF = 0, 151 GENPD_SYNC_STATE_SIMPLE, 152 GENPD_SYNC_STATE_ONECELL, 153}; 154 155struct dev_power_governor { 156 bool (*system_power_down_ok)(struct dev_pm_domain *domain); 157 bool (*power_down_ok)(struct dev_pm_domain *domain); 158 bool (*suspend_ok)(struct device *dev); 159}; 160 161struct gpd_dev_ops { 162 int (*start)(struct device *dev); 163 int (*stop)(struct device *dev); 164}; 165 166struct genpd_governor_data { 167 s64 max_off_time_ns; 168 bool max_off_time_changed; 169 ktime_t next_wakeup; 170 ktime_t next_hrtimer; 171 ktime_t last_enter; 172 bool reflect_residency; 173 bool cached_power_down_ok; 174 bool cached_power_down_state_idx; 175}; 176 177struct genpd_power_state { 178 const char *name; 179 s64 power_off_latency_ns; 180 s64 power_on_latency_ns; 181 s64 residency_ns; 182 u64 usage; 183 u64 rejected; 184 u64 above; 185 u64 below; 186 u64 usage_s2idle; 187 struct fwnode_handle *fwnode; 188 u64 idle_time; 189 void *data; 190}; 191 192struct genpd_lock_ops; 193struct opp_table; 194 195struct generic_pm_domain { 196 struct device dev; 197 struct dev_pm_domain domain; /* PM domain operations */ 198 struct list_head gpd_list_node; /* Node in the global PM domains list */ 199 struct list_head parent_links; /* Links with PM domain as a parent */ 200 struct list_head child_links; /* Links with PM domain as a child */ 201 struct list_head dev_list; /* List of devices */ 202 struct dev_power_governor *gov; 203 struct genpd_governor_data *gd; /* Data used by a genpd governor. */ 204 struct work_struct power_off_work; 205 struct fwnode_handle *provider; /* Identity of the domain provider */ 206 bool has_provider; 207 const char *name; 208 atomic_t sd_count; /* Number of subdomains with power "on" */ 209 enum gpd_status status; /* Current state of the domain */ 210 unsigned int device_count; /* Number of devices */ 211 unsigned int device_id; /* unique device id */ 212 unsigned int suspended_count; /* System suspend device counter */ 213 unsigned int prepared_count; /* Suspend counter of prepared devices */ 214 unsigned int performance_state; /* Aggregated max performance state */ 215 cpumask_var_t cpus; /* A cpumask of the attached CPUs */ 216 bool synced_poweroff; /* A consumer needs a synced poweroff */ 217 bool stay_on; /* Stay powered-on during boot. */ 218 enum genpd_sync_state sync_state; /* How sync_state is managed. */ 219 int (*power_off)(struct generic_pm_domain *domain); 220 int (*power_on)(struct generic_pm_domain *domain); 221 struct raw_notifier_head power_notifiers; /* Power on/off notifiers */ 222 struct opp_table *opp_table; /* OPP table of the genpd */ 223 int (*set_performance_state)(struct generic_pm_domain *genpd, 224 unsigned int state); 225 struct gpd_dev_ops dev_ops; 226 int (*set_hwmode_dev)(struct generic_pm_domain *domain, 227 struct device *dev, bool enable); 228 bool (*get_hwmode_dev)(struct generic_pm_domain *domain, 229 struct device *dev); 230 int (*attach_dev)(struct generic_pm_domain *domain, 231 struct device *dev); 232 void (*detach_dev)(struct generic_pm_domain *domain, 233 struct device *dev); 234 unsigned int flags; /* Bit field of configs for genpd */ 235 struct genpd_power_state *states; 236 void (*free_states)(struct genpd_power_state *states, 237 unsigned int state_count); 238 unsigned int state_count; /* number of states */ 239 unsigned int state_idx; /* state that genpd will go to when off */ 240 u64 on_time; 241 u64 accounting_time; 242 const struct genpd_lock_ops *lock_ops; 243 union { 244 struct mutex mlock; 245 struct { 246 spinlock_t slock; 247 unsigned long lock_flags; 248 }; 249 struct { 250 raw_spinlock_t raw_slock; 251 unsigned long raw_lock_flags; 252 }; 253 }; 254}; 255 256static inline struct generic_pm_domain *pd_to_genpd(struct dev_pm_domain *pd) 257{ 258 return container_of(pd, struct generic_pm_domain, domain); 259} 260 261struct gpd_link { 262 struct generic_pm_domain *parent; 263 struct list_head parent_node; 264 struct generic_pm_domain *child; 265 struct list_head child_node; 266 267 /* Sub-domain's per-master domain performance state */ 268 unsigned int performance_state; 269 unsigned int prev_performance_state; 270}; 271 272struct gpd_timing_data { 273 s64 suspend_latency_ns; 274 s64 resume_latency_ns; 275 s64 effective_constraint_ns; 276 ktime_t next_wakeup; 277 bool constraint_changed; 278 bool cached_suspend_ok; 279}; 280 281struct pm_domain_data { 282 struct list_head list_node; 283 struct device *dev; 284}; 285 286struct generic_pm_domain_data { 287 struct pm_domain_data base; 288 struct gpd_timing_data *td; 289 struct notifier_block nb; 290 struct notifier_block *power_nb; 291 int cpu; 292 unsigned int performance_state; 293 unsigned int default_pstate; 294 unsigned int rpm_pstate; 295 unsigned int opp_token; 296 bool hw_mode; 297 bool rpm_always_on; 298 void *data; 299}; 300 301#ifdef CONFIG_PM_GENERIC_DOMAINS 302static inline struct generic_pm_domain_data *to_gpd_data(struct pm_domain_data *pdd) 303{ 304 return container_of(pdd, struct generic_pm_domain_data, base); 305} 306 307static inline struct generic_pm_domain_data *dev_gpd_data(struct device *dev) 308{ 309 return to_gpd_data(dev->power.subsys_data->domain_data); 310} 311 312int pm_genpd_add_device(struct generic_pm_domain *genpd, struct device *dev); 313int pm_genpd_remove_device(struct device *dev); 314int pm_genpd_add_subdomain(struct generic_pm_domain *genpd, 315 struct generic_pm_domain *subdomain); 316int pm_genpd_remove_subdomain(struct generic_pm_domain *genpd, 317 struct generic_pm_domain *subdomain); 318int pm_genpd_init(struct generic_pm_domain *genpd, 319 struct dev_power_governor *gov, bool is_off); 320int pm_genpd_remove(struct generic_pm_domain *genpd); 321void pm_genpd_inc_rejected(struct generic_pm_domain *genpd, 322 unsigned int state_idx); 323struct device *dev_to_genpd_dev(struct device *dev); 324int dev_pm_genpd_set_performance_state(struct device *dev, unsigned int state); 325int dev_pm_genpd_add_notifier(struct device *dev, struct notifier_block *nb); 326int dev_pm_genpd_remove_notifier(struct device *dev); 327void dev_pm_genpd_set_next_wakeup(struct device *dev, ktime_t next); 328ktime_t dev_pm_genpd_get_next_hrtimer(struct device *dev); 329void dev_pm_genpd_synced_poweroff(struct device *dev); 330int dev_pm_genpd_set_hwmode(struct device *dev, bool enable); 331bool dev_pm_genpd_get_hwmode(struct device *dev); 332int dev_pm_genpd_rpm_always_on(struct device *dev, bool on); 333bool dev_pm_genpd_is_on(struct device *dev); 334 335extern struct dev_power_governor simple_qos_governor; 336extern struct dev_power_governor pm_domain_always_on_gov; 337#ifdef CONFIG_CPU_IDLE 338extern struct dev_power_governor pm_domain_cpu_gov; 339#endif 340#else 341 342static inline struct generic_pm_domain_data *dev_gpd_data(struct device *dev) 343{ 344 return ERR_PTR(-ENOSYS); 345} 346static inline int pm_genpd_add_device(struct generic_pm_domain *genpd, 347 struct device *dev) 348{ 349 return -ENOSYS; 350} 351static inline int pm_genpd_remove_device(struct device *dev) 352{ 353 return -ENOSYS; 354} 355static inline int pm_genpd_add_subdomain(struct generic_pm_domain *genpd, 356 struct generic_pm_domain *subdomain) 357{ 358 return -ENOSYS; 359} 360static inline int pm_genpd_remove_subdomain(struct generic_pm_domain *genpd, 361 struct generic_pm_domain *subdomain) 362{ 363 return -ENOSYS; 364} 365static inline int pm_genpd_init(struct generic_pm_domain *genpd, 366 struct dev_power_governor *gov, bool is_off) 367{ 368 return -ENOSYS; 369} 370static inline int pm_genpd_remove(struct generic_pm_domain *genpd) 371{ 372 return -EOPNOTSUPP; 373} 374 375static inline void pm_genpd_inc_rejected(struct generic_pm_domain *genpd, 376 unsigned int state_idx) 377{ } 378 379static inline struct device *dev_to_genpd_dev(struct device *dev) 380{ 381 return ERR_PTR(-EOPNOTSUPP); 382} 383 384static inline int dev_pm_genpd_set_performance_state(struct device *dev, 385 unsigned int state) 386{ 387 return -EOPNOTSUPP; 388} 389 390static inline int dev_pm_genpd_add_notifier(struct device *dev, 391 struct notifier_block *nb) 392{ 393 return -EOPNOTSUPP; 394} 395 396static inline int dev_pm_genpd_remove_notifier(struct device *dev) 397{ 398 return -EOPNOTSUPP; 399} 400 401static inline void dev_pm_genpd_set_next_wakeup(struct device *dev, ktime_t next) 402{ } 403 404static inline ktime_t dev_pm_genpd_get_next_hrtimer(struct device *dev) 405{ 406 return KTIME_MAX; 407} 408static inline void dev_pm_genpd_synced_poweroff(struct device *dev) 409{ } 410 411static inline int dev_pm_genpd_set_hwmode(struct device *dev, bool enable) 412{ 413 return -EOPNOTSUPP; 414} 415 416static inline bool dev_pm_genpd_get_hwmode(struct device *dev) 417{ 418 return false; 419} 420 421static inline int dev_pm_genpd_rpm_always_on(struct device *dev, bool on) 422{ 423 return -EOPNOTSUPP; 424} 425 426static inline bool dev_pm_genpd_is_on(struct device *dev) 427{ 428 return false; 429} 430 431#define simple_qos_governor (*(struct dev_power_governor *)(NULL)) 432#define pm_domain_always_on_gov (*(struct dev_power_governor *)(NULL)) 433#endif 434 435#ifdef CONFIG_PM_GENERIC_DOMAINS_SLEEP 436void dev_pm_genpd_suspend(struct device *dev); 437void dev_pm_genpd_resume(struct device *dev); 438#else 439static inline void dev_pm_genpd_suspend(struct device *dev) {} 440static inline void dev_pm_genpd_resume(struct device *dev) {} 441#endif 442 443/* OF PM domain providers */ 444struct of_device_id; 445 446typedef struct generic_pm_domain *(*genpd_xlate_t)(const struct of_phandle_args *args, 447 void *data); 448 449struct genpd_onecell_data { 450 struct generic_pm_domain **domains; 451 unsigned int num_domains; 452 genpd_xlate_t xlate; 453}; 454 455#ifdef CONFIG_PM_GENERIC_DOMAINS_OF 456int of_genpd_add_provider_simple(struct device_node *np, 457 struct generic_pm_domain *genpd); 458int of_genpd_add_provider_onecell(struct device_node *np, 459 struct genpd_onecell_data *data); 460void of_genpd_del_provider(struct device_node *np); 461int of_genpd_add_device(const struct of_phandle_args *args, struct device *dev); 462int of_genpd_add_subdomain(const struct of_phandle_args *parent_spec, 463 const struct of_phandle_args *subdomain_spec); 464int of_genpd_remove_subdomain(const struct of_phandle_args *parent_spec, 465 const struct of_phandle_args *subdomain_spec); 466struct generic_pm_domain *of_genpd_remove_last(struct device_node *np); 467int of_genpd_parse_idle_states(struct device_node *dn, 468 struct genpd_power_state **states, int *n); 469void of_genpd_sync_state(struct device_node *np); 470 471int genpd_dev_pm_attach(struct device *dev); 472struct device *genpd_dev_pm_attach_by_id(struct device *dev, 473 unsigned int index); 474struct device *genpd_dev_pm_attach_by_name(struct device *dev, 475 const char *name); 476#else /* !CONFIG_PM_GENERIC_DOMAINS_OF */ 477static inline int of_genpd_add_provider_simple(struct device_node *np, 478 struct generic_pm_domain *genpd) 479{ 480 return -EOPNOTSUPP; 481} 482 483static inline int of_genpd_add_provider_onecell(struct device_node *np, 484 struct genpd_onecell_data *data) 485{ 486 return -EOPNOTSUPP; 487} 488 489static inline void of_genpd_del_provider(struct device_node *np) {} 490 491static inline int of_genpd_add_device(const struct of_phandle_args *args, 492 struct device *dev) 493{ 494 return -ENODEV; 495} 496 497static inline int of_genpd_add_subdomain(const struct of_phandle_args *parent_spec, 498 const struct of_phandle_args *subdomain_spec) 499{ 500 return -ENODEV; 501} 502 503static inline int of_genpd_remove_subdomain(const struct of_phandle_args *parent_spec, 504 const struct of_phandle_args *subdomain_spec) 505{ 506 return -ENODEV; 507} 508 509static inline int of_genpd_parse_idle_states(struct device_node *dn, 510 struct genpd_power_state **states, int *n) 511{ 512 return -ENODEV; 513} 514 515static inline void of_genpd_sync_state(struct device_node *np) {} 516 517static inline int genpd_dev_pm_attach(struct device *dev) 518{ 519 return 0; 520} 521 522static inline struct device *genpd_dev_pm_attach_by_id(struct device *dev, 523 unsigned int index) 524{ 525 return NULL; 526} 527 528static inline struct device *genpd_dev_pm_attach_by_name(struct device *dev, 529 const char *name) 530{ 531 return NULL; 532} 533 534static inline 535struct generic_pm_domain *of_genpd_remove_last(struct device_node *np) 536{ 537 return ERR_PTR(-EOPNOTSUPP); 538} 539#endif /* CONFIG_PM_GENERIC_DOMAINS_OF */ 540 541#ifdef CONFIG_PM 542int dev_pm_domain_attach(struct device *dev, u32 flags); 543struct device *dev_pm_domain_attach_by_id(struct device *dev, 544 unsigned int index); 545struct device *dev_pm_domain_attach_by_name(struct device *dev, 546 const char *name); 547int dev_pm_domain_attach_list(struct device *dev, 548 const struct dev_pm_domain_attach_data *data, 549 struct dev_pm_domain_list **list); 550int devm_pm_domain_attach_list(struct device *dev, 551 const struct dev_pm_domain_attach_data *data, 552 struct dev_pm_domain_list **list); 553void dev_pm_domain_detach(struct device *dev, bool power_off); 554void dev_pm_domain_detach_list(struct dev_pm_domain_list *list); 555int dev_pm_domain_start(struct device *dev); 556void dev_pm_domain_set(struct device *dev, struct dev_pm_domain *pd); 557int dev_pm_domain_set_performance_state(struct device *dev, unsigned int state); 558#else 559static inline int dev_pm_domain_attach(struct device *dev, u32 flags) 560{ 561 return 0; 562} 563static inline struct device *dev_pm_domain_attach_by_id(struct device *dev, 564 unsigned int index) 565{ 566 return NULL; 567} 568static inline struct device *dev_pm_domain_attach_by_name(struct device *dev, 569 const char *name) 570{ 571 return NULL; 572} 573static inline int dev_pm_domain_attach_list(struct device *dev, 574 const struct dev_pm_domain_attach_data *data, 575 struct dev_pm_domain_list **list) 576{ 577 return 0; 578} 579 580static inline int devm_pm_domain_attach_list(struct device *dev, 581 const struct dev_pm_domain_attach_data *data, 582 struct dev_pm_domain_list **list) 583{ 584 return 0; 585} 586 587static inline void dev_pm_domain_detach(struct device *dev, bool power_off) {} 588static inline void dev_pm_domain_detach_list(struct dev_pm_domain_list *list) {} 589static inline int dev_pm_domain_start(struct device *dev) 590{ 591 return 0; 592} 593static inline void dev_pm_domain_set(struct device *dev, 594 struct dev_pm_domain *pd) {} 595static inline int dev_pm_domain_set_performance_state(struct device *dev, 596 unsigned int state) 597{ 598 return 0; 599} 600#endif 601 602#endif /* _LINUX_PM_DOMAIN_H */