blob: f75f74dd9b90978fdedc6ce74393ebb94ddff203 [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>
10
11#define PM_QOS_RESERVED 0
12#define PM_QOS_CPU_DMA_LATENCY 1
13#define PM_QOS_NETWORK_LATENCY 2
14#define PM_QOS_NETWORK_THROUGHPUT 3
15
16#define PM_QOS_NUM_CLASSES 4
17#define PM_QOS_DEFAULT_VALUE -1
18
19#define PM_QOS_CPU_DMA_LAT_DEFAULT_VALUE (2000 * USEC_PER_SEC)
20#define PM_QOS_NETWORK_LAT_DEFAULT_VALUE (2000 * USEC_PER_SEC)
21#define PM_QOS_NETWORK_THROUGHPUT_DEFAULT_VALUE 0
Jean Pihet91ff4cb2011-08-25 15:35:41 +020022#define PM_QOS_DEV_LAT_DEFAULT_VALUE 0
Jean Pihete8db0be2011-08-25 15:35:03 +020023
Jean Pihetcc749982011-08-25 15:35:12 +020024struct pm_qos_request {
25 struct plist_node node;
Jean Pihete8db0be2011-08-25 15:35:03 +020026 int pm_qos_class;
27};
28
Jean Pihet91ff4cb2011-08-25 15:35:41 +020029struct dev_pm_qos_request {
30 struct plist_node node;
31 struct device *dev;
32};
33
Jean Pihet4e1779b2011-08-25 15:35:27 +020034enum pm_qos_type {
35 PM_QOS_UNITIALIZED,
36 PM_QOS_MAX, /* return the largest value */
37 PM_QOS_MIN /* return the smallest value */
38};
39
40/*
41 * Note: The lockless read path depends on the CPU accessing
42 * target_value atomically. Atomic access is only guaranteed on all CPU
43 * types linux supports for 32 bit quantites
44 */
45struct pm_qos_constraints {
46 struct plist_head list;
47 s32 target_value; /* Do not change to 64 bit */
48 s32 default_value;
49 enum pm_qos_type type;
50 struct blocking_notifier_head *notifiers;
51};
52
Jean Pihetabe98ec2011-08-25 15:35:34 +020053/* Action requested to pm_qos_update_target */
54enum pm_qos_req_action {
55 PM_QOS_ADD_REQ, /* Add a new request */
56 PM_QOS_UPDATE_REQ, /* Update an existing request */
57 PM_QOS_REMOVE_REQ /* Remove an existing request */
58};
59
Jean Pihet91ff4cb2011-08-25 15:35:41 +020060static inline int dev_pm_qos_request_active(struct dev_pm_qos_request *req)
61{
62 return req->dev != 0;
63}
64
Jean Pihete8db0be2011-08-25 15:35:03 +020065#ifdef CONFIG_PM
Jean Pihetabe98ec2011-08-25 15:35:34 +020066int pm_qos_update_target(struct pm_qos_constraints *c, struct plist_node *node,
67 enum pm_qos_req_action action, int value);
Jean Pihetcc749982011-08-25 15:35:12 +020068void pm_qos_add_request(struct pm_qos_request *req, int pm_qos_class,
69 s32 value);
70void pm_qos_update_request(struct pm_qos_request *req,
Jean Pihete8db0be2011-08-25 15:35:03 +020071 s32 new_value);
Jean Pihetcc749982011-08-25 15:35:12 +020072void pm_qos_remove_request(struct pm_qos_request *req);
Jean Pihete8db0be2011-08-25 15:35:03 +020073
74int pm_qos_request(int pm_qos_class);
75int pm_qos_add_notifier(int pm_qos_class, struct notifier_block *notifier);
76int pm_qos_remove_notifier(int pm_qos_class, struct notifier_block *notifier);
Jean Pihetcc749982011-08-25 15:35:12 +020077int pm_qos_request_active(struct pm_qos_request *req);
Jean Pihet91ff4cb2011-08-25 15:35:41 +020078
79int dev_pm_qos_add_request(struct device *dev, struct dev_pm_qos_request *req,
80 s32 value);
81int dev_pm_qos_update_request(struct dev_pm_qos_request *req, s32 new_value);
82int dev_pm_qos_remove_request(struct dev_pm_qos_request *req);
83int dev_pm_qos_add_notifier(struct device *dev,
84 struct notifier_block *notifier);
85int dev_pm_qos_remove_notifier(struct device *dev,
86 struct notifier_block *notifier);
87void dev_pm_qos_constraints_init(struct device *dev);
88void dev_pm_qos_constraints_destroy(struct device *dev);
Jean Pihete8db0be2011-08-25 15:35:03 +020089#else
Jean Pihetabe98ec2011-08-25 15:35:34 +020090static inline int pm_qos_update_target(struct pm_qos_constraints *c,
91 struct plist_node *node,
92 enum pm_qos_req_action action,
93 int value)
94 { return 0; }
Jean Pihetcc749982011-08-25 15:35:12 +020095static inline void pm_qos_add_request(struct pm_qos_request *req,
Jean Pihete8db0be2011-08-25 15:35:03 +020096 int pm_qos_class, s32 value)
97 { return; }
Jean Pihetcc749982011-08-25 15:35:12 +020098static inline void pm_qos_update_request(struct pm_qos_request *req,
Jean Pihete8db0be2011-08-25 15:35:03 +020099 s32 new_value)
100 { return; }
Jean Pihetcc749982011-08-25 15:35:12 +0200101static inline void pm_qos_remove_request(struct pm_qos_request *req)
Jean Pihete8db0be2011-08-25 15:35:03 +0200102 { return; }
103
104static inline int pm_qos_request(int pm_qos_class)
105 { return 0; }
106static inline int pm_qos_add_notifier(int pm_qos_class,
107 struct notifier_block *notifier)
108 { return 0; }
109static inline int pm_qos_remove_notifier(int pm_qos_class,
110 struct notifier_block *notifier)
111 { return 0; }
Jean Pihetcc749982011-08-25 15:35:12 +0200112static inline int pm_qos_request_active(struct pm_qos_request *req)
Jean Pihete8db0be2011-08-25 15:35:03 +0200113 { return 0; }
Jean Pihet91ff4cb2011-08-25 15:35:41 +0200114
115static inline int dev_pm_qos_add_request(struct device *dev,
116 struct dev_pm_qos_request *req,
117 s32 value)
118 { return 0; }
119static inline int dev_pm_qos_update_request(struct dev_pm_qos_request *req,
120 s32 new_value)
121 { return 0; }
122static inline int dev_pm_qos_remove_request(struct dev_pm_qos_request *req)
123 { return 0; }
124static inline int dev_pm_qos_add_notifier(struct device *dev,
125 struct notifier_block *notifier)
126 { return 0; }
127static inline int dev_pm_qos_remove_notifier(struct device *dev,
128 struct notifier_block *notifier)
129 { return 0; }
130static inline void dev_pm_qos_constraints_init(struct device *dev)
131 { return; }
132static inline void dev_pm_qos_constraints_destroy(struct device *dev)
133 { return; }
Jean Pihete8db0be2011-08-25 15:35:03 +0200134#endif
135
136#endif