blob: fe247b33652d13cbb30faed2e8e9b7628d71a167 [file] [log] [blame]
Jean Pihete8db0be2011-08-25 15:35:03 +02001#ifndef _LINUX_PM_QOS_H
2#define _LINUX_PM_QOS_H
3/* interface for the pm_qos_power infrastructure of the linux kernel.
4 *
5 * Mark Gross <mgross@linux.intel.com>
6 */
7#include <linux/plist.h>
8#include <linux/notifier.h>
9#include <linux/miscdevice.h>
Rafael J. Wysocki1a9a9152011-09-29 22:29:44 +020010#include <linux/device.h>
Jean Pihete8db0be2011-08-25 15:35:03 +020011
12#define PM_QOS_RESERVED 0
13#define PM_QOS_CPU_DMA_LATENCY 1
14#define PM_QOS_NETWORK_LATENCY 2
15#define PM_QOS_NETWORK_THROUGHPUT 3
16
17#define PM_QOS_NUM_CLASSES 4
18#define PM_QOS_DEFAULT_VALUE -1
19
20#define PM_QOS_CPU_DMA_LAT_DEFAULT_VALUE (2000 * USEC_PER_SEC)
21#define PM_QOS_NETWORK_LAT_DEFAULT_VALUE (2000 * USEC_PER_SEC)
22#define PM_QOS_NETWORK_THROUGHPUT_DEFAULT_VALUE 0
Jean Pihet91ff4cb2011-08-25 15:35:41 +020023#define PM_QOS_DEV_LAT_DEFAULT_VALUE 0
Jean Pihete8db0be2011-08-25 15:35:03 +020024
Jean Pihetcc749982011-08-25 15:35:12 +020025struct pm_qos_request {
26 struct plist_node node;
Jean Pihete8db0be2011-08-25 15:35:03 +020027 int pm_qos_class;
28};
29
Jean Pihet91ff4cb2011-08-25 15:35:41 +020030struct dev_pm_qos_request {
31 struct plist_node node;
32 struct device *dev;
33};
34
Jean Pihet4e1779b2011-08-25 15:35:27 +020035enum pm_qos_type {
36 PM_QOS_UNITIALIZED,
37 PM_QOS_MAX, /* return the largest value */
38 PM_QOS_MIN /* return the smallest value */
39};
40
41/*
42 * Note: The lockless read path depends on the CPU accessing
43 * target_value atomically. Atomic access is only guaranteed on all CPU
44 * types linux supports for 32 bit quantites
45 */
46struct pm_qos_constraints {
47 struct plist_head list;
48 s32 target_value; /* Do not change to 64 bit */
49 s32 default_value;
50 enum pm_qos_type type;
51 struct blocking_notifier_head *notifiers;
52};
53
Jean Pihetabe98ec2011-08-25 15:35:34 +020054/* Action requested to pm_qos_update_target */
55enum pm_qos_req_action {
56 PM_QOS_ADD_REQ, /* Add a new request */
57 PM_QOS_UPDATE_REQ, /* Update an existing request */
58 PM_QOS_REMOVE_REQ /* Remove an existing request */
59};
60
Jean Pihet91ff4cb2011-08-25 15:35:41 +020061static inline int dev_pm_qos_request_active(struct dev_pm_qos_request *req)
62{
63 return req->dev != 0;
64}
65
Jean Pihete8db0be2011-08-25 15:35:03 +020066#ifdef CONFIG_PM
Jean Pihetabe98ec2011-08-25 15:35:34 +020067int pm_qos_update_target(struct pm_qos_constraints *c, struct plist_node *node,
68 enum pm_qos_req_action action, int value);
Jean Pihetcc749982011-08-25 15:35:12 +020069void pm_qos_add_request(struct pm_qos_request *req, int pm_qos_class,
70 s32 value);
71void pm_qos_update_request(struct pm_qos_request *req,
Jean Pihete8db0be2011-08-25 15:35:03 +020072 s32 new_value);
Jean Pihetcc749982011-08-25 15:35:12 +020073void pm_qos_remove_request(struct pm_qos_request *req);
Jean Pihete8db0be2011-08-25 15:35:03 +020074
75int pm_qos_request(int pm_qos_class);
76int pm_qos_add_notifier(int pm_qos_class, struct notifier_block *notifier);
77int pm_qos_remove_notifier(int pm_qos_class, struct notifier_block *notifier);
Jean Pihetcc749982011-08-25 15:35:12 +020078int pm_qos_request_active(struct pm_qos_request *req);
Jean Pihetb66213c2011-08-25 15:35:47 +020079s32 pm_qos_read_value(struct pm_qos_constraints *c);
Jean Pihet91ff4cb2011-08-25 15:35:41 +020080
Rafael J. Wysocki1a9a9152011-09-29 22:29:44 +020081s32 dev_pm_qos_read_value(struct device *dev);
Jean Pihet91ff4cb2011-08-25 15:35:41 +020082int dev_pm_qos_add_request(struct device *dev, struct dev_pm_qos_request *req,
83 s32 value);
84int dev_pm_qos_update_request(struct dev_pm_qos_request *req, s32 new_value);
85int dev_pm_qos_remove_request(struct dev_pm_qos_request *req);
86int dev_pm_qos_add_notifier(struct device *dev,
87 struct notifier_block *notifier);
88int dev_pm_qos_remove_notifier(struct device *dev,
89 struct notifier_block *notifier);
Jean Pihetb66213c2011-08-25 15:35:47 +020090int dev_pm_qos_add_global_notifier(struct notifier_block *notifier);
91int dev_pm_qos_remove_global_notifier(struct notifier_block *notifier);
Jean Pihet91ff4cb2011-08-25 15:35:41 +020092void dev_pm_qos_constraints_init(struct device *dev);
93void dev_pm_qos_constraints_destroy(struct device *dev);
Rafael J. Wysocki40a5f8b2011-12-23 01:23:52 +010094int dev_pm_qos_add_ancestor_request(struct device *dev,
95 struct dev_pm_qos_request *req, s32 value);
Jean Pihete8db0be2011-08-25 15:35:03 +020096#else
Jean Pihetabe98ec2011-08-25 15:35:34 +020097static inline int pm_qos_update_target(struct pm_qos_constraints *c,
98 struct plist_node *node,
99 enum pm_qos_req_action action,
100 int value)
101 { return 0; }
Jean Pihetcc749982011-08-25 15:35:12 +0200102static inline void pm_qos_add_request(struct pm_qos_request *req,
Jean Pihete8db0be2011-08-25 15:35:03 +0200103 int pm_qos_class, s32 value)
104 { return; }
Jean Pihetcc749982011-08-25 15:35:12 +0200105static inline void pm_qos_update_request(struct pm_qos_request *req,
Jean Pihete8db0be2011-08-25 15:35:03 +0200106 s32 new_value)
107 { return; }
Jean Pihetcc749982011-08-25 15:35:12 +0200108static inline void pm_qos_remove_request(struct pm_qos_request *req)
Jean Pihete8db0be2011-08-25 15:35:03 +0200109 { return; }
110
111static inline int pm_qos_request(int pm_qos_class)
112 { return 0; }
113static inline int pm_qos_add_notifier(int pm_qos_class,
114 struct notifier_block *notifier)
115 { return 0; }
116static inline int pm_qos_remove_notifier(int pm_qos_class,
117 struct notifier_block *notifier)
118 { return 0; }
Jean Pihetcc749982011-08-25 15:35:12 +0200119static inline int pm_qos_request_active(struct pm_qos_request *req)
Jean Pihete8db0be2011-08-25 15:35:03 +0200120 { return 0; }
Jean Pihetb66213c2011-08-25 15:35:47 +0200121static inline s32 pm_qos_read_value(struct pm_qos_constraints *c)
122 { return 0; }
Jean Pihet91ff4cb2011-08-25 15:35:41 +0200123
Rafael J. Wysocki1a9a9152011-09-29 22:29:44 +0200124static inline s32 dev_pm_qos_read_value(struct device *dev)
125 { return 0; }
Jean Pihet91ff4cb2011-08-25 15:35:41 +0200126static inline int dev_pm_qos_add_request(struct device *dev,
127 struct dev_pm_qos_request *req,
128 s32 value)
129 { return 0; }
130static inline int dev_pm_qos_update_request(struct dev_pm_qos_request *req,
131 s32 new_value)
132 { return 0; }
133static inline int dev_pm_qos_remove_request(struct dev_pm_qos_request *req)
134 { return 0; }
135static inline int dev_pm_qos_add_notifier(struct device *dev,
136 struct notifier_block *notifier)
137 { return 0; }
138static inline int dev_pm_qos_remove_notifier(struct device *dev,
139 struct notifier_block *notifier)
140 { return 0; }
Jean Pihetb66213c2011-08-25 15:35:47 +0200141static inline int dev_pm_qos_add_global_notifier(
142 struct notifier_block *notifier)
143 { return 0; }
144static inline int dev_pm_qos_remove_global_notifier(
145 struct notifier_block *notifier)
146 { return 0; }
Jean Pihet91ff4cb2011-08-25 15:35:41 +0200147static inline void dev_pm_qos_constraints_init(struct device *dev)
Rafael J. Wysocki1a9a9152011-09-29 22:29:44 +0200148{
149 dev->power.power_state = PMSG_ON;
150}
Jean Pihet91ff4cb2011-08-25 15:35:41 +0200151static inline void dev_pm_qos_constraints_destroy(struct device *dev)
Rafael J. Wysocki1a9a9152011-09-29 22:29:44 +0200152{
153 dev->power.power_state = PMSG_INVALID;
154}
Rafael J. Wysocki40a5f8b2011-12-23 01:23:52 +0100155static inline int dev_pm_qos_add_ancestor_request(struct device *dev,
156 struct dev_pm_qos_request *req, s32 value)
157 { return 0; }
Jean Pihete8db0be2011-08-25 15:35:03 +0200158#endif
159
160#endif