Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 1 | /* |
| 2 | * This module exposes the interface to kernel space for specifying |
| 3 | * QoS dependencies. It provides infrastructure for registration of: |
| 4 | * |
Mark Gross | ed77134 | 2010-05-06 01:59:26 +0200 | [diff] [blame] | 5 | * Dependents on a QoS value : register requests |
Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 6 | * Watchers of QoS value : get notified when target QoS value changes |
| 7 | * |
| 8 | * This QoS design is best effort based. Dependents register their QoS needs. |
| 9 | * Watchers register to keep track of the current QoS needs of the system. |
| 10 | * |
| 11 | * There are 3 basic classes of QoS parameter: latency, timeout, throughput |
| 12 | * each have defined units: |
| 13 | * latency: usec |
| 14 | * timeout: usec <-- currently not used. |
| 15 | * throughput: kbs (kilo byte / sec) |
| 16 | * |
Mark Gross | ed77134 | 2010-05-06 01:59:26 +0200 | [diff] [blame] | 17 | * There are lists of pm_qos_objects each one wrapping requests, notifiers |
Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 18 | * |
Mark Gross | ed77134 | 2010-05-06 01:59:26 +0200 | [diff] [blame] | 19 | * User mode requests on a QOS parameter register themselves to the |
Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 20 | * subsystem by opening the device node /dev/... and writing there request to |
| 21 | * the node. As long as the process holds a file handle open to the node the |
| 22 | * client continues to be accounted for. Upon file release the usermode |
Mark Gross | ed77134 | 2010-05-06 01:59:26 +0200 | [diff] [blame] | 23 | * request is removed and a new qos target is computed. This way when the |
| 24 | * request that the application has is cleaned up when closes the file |
Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 25 | * pointer or exits the pm_qos_object will get an opportunity to clean up. |
| 26 | * |
Richard Hughes | bf1db69 | 2008-08-05 13:01:35 -0700 | [diff] [blame] | 27 | * Mark Gross <mgross@linux.intel.com> |
Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 28 | */ |
| 29 | |
Mark Gross | ed77134 | 2010-05-06 01:59:26 +0200 | [diff] [blame] | 30 | /*#define DEBUG*/ |
| 31 | |
Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 32 | #include <linux/pm_qos_params.h> |
| 33 | #include <linux/sched.h> |
| 34 | #include <linux/spinlock.h> |
| 35 | #include <linux/slab.h> |
| 36 | #include <linux/time.h> |
| 37 | #include <linux/fs.h> |
| 38 | #include <linux/device.h> |
| 39 | #include <linux/miscdevice.h> |
| 40 | #include <linux/string.h> |
| 41 | #include <linux/platform_device.h> |
| 42 | #include <linux/init.h> |
| 43 | |
| 44 | #include <linux/uaccess.h> |
| 45 | |
| 46 | /* |
Mark Gross | ed77134 | 2010-05-06 01:59:26 +0200 | [diff] [blame] | 47 | * locking rule: all changes to requests or notifiers lists |
Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 48 | * or pm_qos_object list and pm_qos_objects need to happen with pm_qos_lock |
| 49 | * held, taken with _irqsave. One lock to rule them all |
| 50 | */ |
James Bottomley | 5f27984 | 2010-07-19 02:00:18 +0200 | [diff] [blame] | 51 | enum pm_qos_type { |
| 52 | PM_QOS_MAX, /* return the largest value */ |
| 53 | PM_QOS_MIN /* return the smallest value */ |
| 54 | }; |
Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 55 | |
Tim Chen | 333c5ae | 2011-02-11 12:49:04 -0800 | [diff] [blame^] | 56 | /* |
| 57 | * Note: The lockless read path depends on the CPU accessing |
| 58 | * target_value atomically. Atomic access is only guaranteed on all CPU |
| 59 | * types linux supports for 32 bit quantites |
| 60 | */ |
Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 61 | struct pm_qos_object { |
James Bottomley | 5f27984 | 2010-07-19 02:00:18 +0200 | [diff] [blame] | 62 | struct plist_head requests; |
Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 63 | struct blocking_notifier_head *notifiers; |
| 64 | struct miscdevice pm_qos_power_miscdev; |
| 65 | char *name; |
Tim Chen | 333c5ae | 2011-02-11 12:49:04 -0800 | [diff] [blame^] | 66 | s32 target_value; /* Do not change to 64 bit */ |
Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 67 | s32 default_value; |
James Bottomley | 5f27984 | 2010-07-19 02:00:18 +0200 | [diff] [blame] | 68 | enum pm_qos_type type; |
Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 69 | }; |
| 70 | |
James Bottomley | 5f27984 | 2010-07-19 02:00:18 +0200 | [diff] [blame] | 71 | static DEFINE_SPINLOCK(pm_qos_lock); |
| 72 | |
Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 73 | static struct pm_qos_object null_pm_qos; |
| 74 | static BLOCKING_NOTIFIER_HEAD(cpu_dma_lat_notifier); |
| 75 | static struct pm_qos_object cpu_dma_pm_qos = { |
James Bottomley | 5f27984 | 2010-07-19 02:00:18 +0200 | [diff] [blame] | 76 | .requests = PLIST_HEAD_INIT(cpu_dma_pm_qos.requests, pm_qos_lock), |
Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 77 | .notifiers = &cpu_dma_lat_notifier, |
| 78 | .name = "cpu_dma_latency", |
Tim Chen | 333c5ae | 2011-02-11 12:49:04 -0800 | [diff] [blame^] | 79 | .target_value = PM_QOS_CPU_DMA_LAT_DEFAULT_VALUE, |
| 80 | .default_value = PM_QOS_CPU_DMA_LAT_DEFAULT_VALUE, |
James Bottomley | 5f27984 | 2010-07-19 02:00:18 +0200 | [diff] [blame] | 81 | .type = PM_QOS_MIN, |
Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 82 | }; |
| 83 | |
| 84 | static BLOCKING_NOTIFIER_HEAD(network_lat_notifier); |
| 85 | static struct pm_qos_object network_lat_pm_qos = { |
James Bottomley | 5f27984 | 2010-07-19 02:00:18 +0200 | [diff] [blame] | 86 | .requests = PLIST_HEAD_INIT(network_lat_pm_qos.requests, pm_qos_lock), |
Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 87 | .notifiers = &network_lat_notifier, |
| 88 | .name = "network_latency", |
Tim Chen | 333c5ae | 2011-02-11 12:49:04 -0800 | [diff] [blame^] | 89 | .target_value = PM_QOS_NETWORK_LAT_DEFAULT_VALUE, |
| 90 | .default_value = PM_QOS_NETWORK_LAT_DEFAULT_VALUE, |
James Bottomley | 5f27984 | 2010-07-19 02:00:18 +0200 | [diff] [blame] | 91 | .type = PM_QOS_MIN |
Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 92 | }; |
| 93 | |
| 94 | |
| 95 | static BLOCKING_NOTIFIER_HEAD(network_throughput_notifier); |
| 96 | static struct pm_qos_object network_throughput_pm_qos = { |
James Bottomley | 5f27984 | 2010-07-19 02:00:18 +0200 | [diff] [blame] | 97 | .requests = PLIST_HEAD_INIT(network_throughput_pm_qos.requests, pm_qos_lock), |
Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 98 | .notifiers = &network_throughput_notifier, |
| 99 | .name = "network_throughput", |
Tim Chen | 333c5ae | 2011-02-11 12:49:04 -0800 | [diff] [blame^] | 100 | .target_value = PM_QOS_NETWORK_THROUGHPUT_DEFAULT_VALUE, |
| 101 | .default_value = PM_QOS_NETWORK_THROUGHPUT_DEFAULT_VALUE, |
James Bottomley | 5f27984 | 2010-07-19 02:00:18 +0200 | [diff] [blame] | 102 | .type = PM_QOS_MAX, |
Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 103 | }; |
| 104 | |
| 105 | |
| 106 | static struct pm_qos_object *pm_qos_array[] = { |
| 107 | &null_pm_qos, |
| 108 | &cpu_dma_pm_qos, |
| 109 | &network_lat_pm_qos, |
| 110 | &network_throughput_pm_qos |
| 111 | }; |
| 112 | |
Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 113 | static ssize_t pm_qos_power_write(struct file *filp, const char __user *buf, |
| 114 | size_t count, loff_t *f_pos); |
| 115 | static int pm_qos_power_open(struct inode *inode, struct file *filp); |
| 116 | static int pm_qos_power_release(struct inode *inode, struct file *filp); |
| 117 | |
| 118 | static const struct file_operations pm_qos_power_fops = { |
| 119 | .write = pm_qos_power_write, |
| 120 | .open = pm_qos_power_open, |
| 121 | .release = pm_qos_power_release, |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 122 | .llseek = noop_llseek, |
Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 123 | }; |
| 124 | |
James Bottomley | 5f27984 | 2010-07-19 02:00:18 +0200 | [diff] [blame] | 125 | /* unlocked internal variant */ |
| 126 | static inline int pm_qos_get_value(struct pm_qos_object *o) |
Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 127 | { |
James Bottomley | 5f27984 | 2010-07-19 02:00:18 +0200 | [diff] [blame] | 128 | if (plist_head_empty(&o->requests)) |
| 129 | return o->default_value; |
| 130 | |
| 131 | switch (o->type) { |
| 132 | case PM_QOS_MIN: |
Colin Cross | 00fafcd | 2010-11-15 22:45:22 +0100 | [diff] [blame] | 133 | return plist_first(&o->requests)->prio; |
James Bottomley | 5f27984 | 2010-07-19 02:00:18 +0200 | [diff] [blame] | 134 | |
| 135 | case PM_QOS_MAX: |
Colin Cross | 00fafcd | 2010-11-15 22:45:22 +0100 | [diff] [blame] | 136 | return plist_last(&o->requests)->prio; |
James Bottomley | 5f27984 | 2010-07-19 02:00:18 +0200 | [diff] [blame] | 137 | |
| 138 | default: |
| 139 | /* runtime check for not using enum */ |
| 140 | BUG(); |
| 141 | } |
Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 142 | } |
| 143 | |
Tim Chen | 333c5ae | 2011-02-11 12:49:04 -0800 | [diff] [blame^] | 144 | static inline s32 pm_qos_read_value(struct pm_qos_object *o) |
| 145 | { |
| 146 | return o->target_value; |
| 147 | } |
| 148 | |
| 149 | static inline void pm_qos_set_value(struct pm_qos_object *o, s32 value) |
| 150 | { |
| 151 | o->target_value = value; |
| 152 | } |
| 153 | |
James Bottomley | 5f27984 | 2010-07-19 02:00:18 +0200 | [diff] [blame] | 154 | static void update_target(struct pm_qos_object *o, struct plist_node *node, |
| 155 | int del, int value) |
Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 156 | { |
Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 157 | unsigned long flags; |
James Bottomley | 5f27984 | 2010-07-19 02:00:18 +0200 | [diff] [blame] | 158 | int prev_value, curr_value; |
Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 159 | |
| 160 | spin_lock_irqsave(&pm_qos_lock, flags); |
James Bottomley | 5f27984 | 2010-07-19 02:00:18 +0200 | [diff] [blame] | 161 | prev_value = pm_qos_get_value(o); |
| 162 | /* PM_QOS_DEFAULT_VALUE is a signal that the value is unchanged */ |
| 163 | if (value != PM_QOS_DEFAULT_VALUE) { |
| 164 | /* |
| 165 | * to change the list, we atomically remove, reinit |
| 166 | * with new value and add, then see if the extremal |
| 167 | * changed |
| 168 | */ |
| 169 | plist_del(node, &o->requests); |
| 170 | plist_node_init(node, value); |
| 171 | plist_add(node, &o->requests); |
| 172 | } else if (del) { |
| 173 | plist_del(node, &o->requests); |
| 174 | } else { |
| 175 | plist_add(node, &o->requests); |
Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 176 | } |
James Bottomley | 5f27984 | 2010-07-19 02:00:18 +0200 | [diff] [blame] | 177 | curr_value = pm_qos_get_value(o); |
Tim Chen | 333c5ae | 2011-02-11 12:49:04 -0800 | [diff] [blame^] | 178 | pm_qos_set_value(o, curr_value); |
Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 179 | spin_unlock_irqrestore(&pm_qos_lock, flags); |
| 180 | |
James Bottomley | 5f27984 | 2010-07-19 02:00:18 +0200 | [diff] [blame] | 181 | if (prev_value != curr_value) |
| 182 | blocking_notifier_call_chain(o->notifiers, |
| 183 | (unsigned long)curr_value, |
| 184 | NULL); |
Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | static int register_pm_qos_misc(struct pm_qos_object *qos) |
| 188 | { |
| 189 | qos->pm_qos_power_miscdev.minor = MISC_DYNAMIC_MINOR; |
| 190 | qos->pm_qos_power_miscdev.name = qos->name; |
| 191 | qos->pm_qos_power_miscdev.fops = &pm_qos_power_fops; |
| 192 | |
| 193 | return misc_register(&qos->pm_qos_power_miscdev); |
| 194 | } |
| 195 | |
| 196 | static int find_pm_qos_object_by_minor(int minor) |
| 197 | { |
| 198 | int pm_qos_class; |
| 199 | |
| 200 | for (pm_qos_class = 0; |
| 201 | pm_qos_class < PM_QOS_NUM_CLASSES; pm_qos_class++) { |
| 202 | if (minor == |
| 203 | pm_qos_array[pm_qos_class]->pm_qos_power_miscdev.minor) |
| 204 | return pm_qos_class; |
| 205 | } |
| 206 | return -1; |
| 207 | } |
| 208 | |
| 209 | /** |
Mark Gross | ed77134 | 2010-05-06 01:59:26 +0200 | [diff] [blame] | 210 | * pm_qos_request - returns current system wide qos expectation |
Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 211 | * @pm_qos_class: identification of which qos value is requested |
| 212 | * |
Tim Chen | 333c5ae | 2011-02-11 12:49:04 -0800 | [diff] [blame^] | 213 | * This function returns the current target value. |
Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 214 | */ |
Mark Gross | ed77134 | 2010-05-06 01:59:26 +0200 | [diff] [blame] | 215 | int pm_qos_request(int pm_qos_class) |
Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 216 | { |
Tim Chen | 333c5ae | 2011-02-11 12:49:04 -0800 | [diff] [blame^] | 217 | return pm_qos_read_value(pm_qos_array[pm_qos_class]); |
Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 218 | } |
Mark Gross | ed77134 | 2010-05-06 01:59:26 +0200 | [diff] [blame] | 219 | EXPORT_SYMBOL_GPL(pm_qos_request); |
Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 220 | |
James Bottomley | 82f6825 | 2010-07-05 22:53:06 +0200 | [diff] [blame] | 221 | int pm_qos_request_active(struct pm_qos_request_list *req) |
| 222 | { |
| 223 | return req->pm_qos_class != 0; |
| 224 | } |
| 225 | EXPORT_SYMBOL_GPL(pm_qos_request_active); |
| 226 | |
Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 227 | /** |
Mark Gross | ed77134 | 2010-05-06 01:59:26 +0200 | [diff] [blame] | 228 | * pm_qos_add_request - inserts new qos request into the list |
Saravana Kannan | 25cc69e | 2010-08-26 20:18:43 +0200 | [diff] [blame] | 229 | * @dep: pointer to a preallocated handle |
| 230 | * @pm_qos_class: identifies which list of qos request to use |
Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 231 | * @value: defines the qos request |
| 232 | * |
| 233 | * This function inserts a new entry in the pm_qos_class list of requested qos |
Richard Hughes | bf1db69 | 2008-08-05 13:01:35 -0700 | [diff] [blame] | 234 | * performance characteristics. It recomputes the aggregate QoS expectations |
Saravana Kannan | 25cc69e | 2010-08-26 20:18:43 +0200 | [diff] [blame] | 235 | * for the pm_qos_class of parameters and initializes the pm_qos_request_list |
| 236 | * handle. Caller needs to save this handle for later use in updates and |
| 237 | * removal. |
Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 238 | */ |
Saravana Kannan | 25cc69e | 2010-08-26 20:18:43 +0200 | [diff] [blame] | 239 | |
James Bottomley | 82f6825 | 2010-07-05 22:53:06 +0200 | [diff] [blame] | 240 | void pm_qos_add_request(struct pm_qos_request_list *dep, |
| 241 | int pm_qos_class, s32 value) |
Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 242 | { |
James Bottomley | 82f6825 | 2010-07-05 22:53:06 +0200 | [diff] [blame] | 243 | struct pm_qos_object *o = pm_qos_array[pm_qos_class]; |
| 244 | int new_value; |
Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 245 | |
James Bottomley | 82f6825 | 2010-07-05 22:53:06 +0200 | [diff] [blame] | 246 | if (pm_qos_request_active(dep)) { |
| 247 | WARN(1, KERN_ERR "pm_qos_add_request() called for already added request\n"); |
| 248 | return; |
Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 249 | } |
James Bottomley | 82f6825 | 2010-07-05 22:53:06 +0200 | [diff] [blame] | 250 | if (value == PM_QOS_DEFAULT_VALUE) |
| 251 | new_value = o->default_value; |
| 252 | else |
| 253 | new_value = value; |
| 254 | plist_node_init(&dep->list, new_value); |
| 255 | dep->pm_qos_class = pm_qos_class; |
| 256 | update_target(o, &dep->list, 0, PM_QOS_DEFAULT_VALUE); |
Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 257 | } |
Mark Gross | ed77134 | 2010-05-06 01:59:26 +0200 | [diff] [blame] | 258 | EXPORT_SYMBOL_GPL(pm_qos_add_request); |
Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 259 | |
| 260 | /** |
Mark Gross | ed77134 | 2010-05-06 01:59:26 +0200 | [diff] [blame] | 261 | * pm_qos_update_request - modifies an existing qos request |
| 262 | * @pm_qos_req : handle to list element holding a pm_qos request to use |
Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 263 | * @value: defines the qos request |
| 264 | * |
Mark Gross | ed77134 | 2010-05-06 01:59:26 +0200 | [diff] [blame] | 265 | * Updates an existing qos request for the pm_qos_class of parameters along |
Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 266 | * with updating the target pm_qos_class value. |
| 267 | * |
Mark Gross | ed77134 | 2010-05-06 01:59:26 +0200 | [diff] [blame] | 268 | * Attempts are made to make this code callable on hot code paths. |
Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 269 | */ |
Mark Gross | ed77134 | 2010-05-06 01:59:26 +0200 | [diff] [blame] | 270 | void pm_qos_update_request(struct pm_qos_request_list *pm_qos_req, |
James Bottomley | 5f27984 | 2010-07-19 02:00:18 +0200 | [diff] [blame] | 271 | s32 new_value) |
Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 272 | { |
Mark Gross | ed77134 | 2010-05-06 01:59:26 +0200 | [diff] [blame] | 273 | s32 temp; |
James Bottomley | 5f27984 | 2010-07-19 02:00:18 +0200 | [diff] [blame] | 274 | struct pm_qos_object *o; |
Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 275 | |
James Bottomley | 5f27984 | 2010-07-19 02:00:18 +0200 | [diff] [blame] | 276 | if (!pm_qos_req) /*guard against callers passing in null */ |
| 277 | return; |
Mark Gross | ed77134 | 2010-05-06 01:59:26 +0200 | [diff] [blame] | 278 | |
James Bottomley | 82f6825 | 2010-07-05 22:53:06 +0200 | [diff] [blame] | 279 | if (!pm_qos_request_active(pm_qos_req)) { |
| 280 | WARN(1, KERN_ERR "pm_qos_update_request() called for unknown object\n"); |
| 281 | return; |
| 282 | } |
| 283 | |
James Bottomley | 5f27984 | 2010-07-19 02:00:18 +0200 | [diff] [blame] | 284 | o = pm_qos_array[pm_qos_req->pm_qos_class]; |
| 285 | |
| 286 | if (new_value == PM_QOS_DEFAULT_VALUE) |
| 287 | temp = o->default_value; |
| 288 | else |
| 289 | temp = new_value; |
| 290 | |
| 291 | if (temp != pm_qos_req->list.prio) |
| 292 | update_target(o, &pm_qos_req->list, 0, temp); |
Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 293 | } |
Mark Gross | ed77134 | 2010-05-06 01:59:26 +0200 | [diff] [blame] | 294 | EXPORT_SYMBOL_GPL(pm_qos_update_request); |
Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 295 | |
| 296 | /** |
Mark Gross | ed77134 | 2010-05-06 01:59:26 +0200 | [diff] [blame] | 297 | * pm_qos_remove_request - modifies an existing qos request |
| 298 | * @pm_qos_req: handle to request list element |
Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 299 | * |
Mark Gross | ed77134 | 2010-05-06 01:59:26 +0200 | [diff] [blame] | 300 | * Will remove pm qos request from the list of requests and |
| 301 | * recompute the current target value for the pm_qos_class. Call this |
| 302 | * on slow code paths. |
Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 303 | */ |
Mark Gross | ed77134 | 2010-05-06 01:59:26 +0200 | [diff] [blame] | 304 | void pm_qos_remove_request(struct pm_qos_request_list *pm_qos_req) |
Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 305 | { |
James Bottomley | 5f27984 | 2010-07-19 02:00:18 +0200 | [diff] [blame] | 306 | struct pm_qos_object *o; |
Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 307 | |
Mark Gross | ed77134 | 2010-05-06 01:59:26 +0200 | [diff] [blame] | 308 | if (pm_qos_req == NULL) |
| 309 | return; |
| 310 | /* silent return to keep pcm code cleaner */ |
| 311 | |
James Bottomley | 82f6825 | 2010-07-05 22:53:06 +0200 | [diff] [blame] | 312 | if (!pm_qos_request_active(pm_qos_req)) { |
| 313 | WARN(1, KERN_ERR "pm_qos_remove_request() called for unknown object\n"); |
| 314 | return; |
| 315 | } |
| 316 | |
James Bottomley | 5f27984 | 2010-07-19 02:00:18 +0200 | [diff] [blame] | 317 | o = pm_qos_array[pm_qos_req->pm_qos_class]; |
| 318 | update_target(o, &pm_qos_req->list, 1, PM_QOS_DEFAULT_VALUE); |
James Bottomley | 82f6825 | 2010-07-05 22:53:06 +0200 | [diff] [blame] | 319 | memset(pm_qos_req, 0, sizeof(*pm_qos_req)); |
Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 320 | } |
Mark Gross | ed77134 | 2010-05-06 01:59:26 +0200 | [diff] [blame] | 321 | EXPORT_SYMBOL_GPL(pm_qos_remove_request); |
Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 322 | |
| 323 | /** |
| 324 | * pm_qos_add_notifier - sets notification entry for changes to target value |
| 325 | * @pm_qos_class: identifies which qos target changes should be notified. |
| 326 | * @notifier: notifier block managed by caller. |
| 327 | * |
| 328 | * will register the notifier into a notification chain that gets called |
Richard Hughes | bf1db69 | 2008-08-05 13:01:35 -0700 | [diff] [blame] | 329 | * upon changes to the pm_qos_class target value. |
Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 330 | */ |
Mark Gross | ed77134 | 2010-05-06 01:59:26 +0200 | [diff] [blame] | 331 | int pm_qos_add_notifier(int pm_qos_class, struct notifier_block *notifier) |
Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 332 | { |
| 333 | int retval; |
| 334 | |
| 335 | retval = blocking_notifier_chain_register( |
| 336 | pm_qos_array[pm_qos_class]->notifiers, notifier); |
| 337 | |
| 338 | return retval; |
| 339 | } |
| 340 | EXPORT_SYMBOL_GPL(pm_qos_add_notifier); |
| 341 | |
| 342 | /** |
| 343 | * pm_qos_remove_notifier - deletes notification entry from chain. |
| 344 | * @pm_qos_class: identifies which qos target changes are notified. |
| 345 | * @notifier: notifier block to be removed. |
| 346 | * |
| 347 | * will remove the notifier from the notification chain that gets called |
Richard Hughes | bf1db69 | 2008-08-05 13:01:35 -0700 | [diff] [blame] | 348 | * upon changes to the pm_qos_class target value. |
Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 349 | */ |
| 350 | int pm_qos_remove_notifier(int pm_qos_class, struct notifier_block *notifier) |
| 351 | { |
| 352 | int retval; |
| 353 | |
| 354 | retval = blocking_notifier_chain_unregister( |
| 355 | pm_qos_array[pm_qos_class]->notifiers, notifier); |
| 356 | |
| 357 | return retval; |
| 358 | } |
| 359 | EXPORT_SYMBOL_GPL(pm_qos_remove_notifier); |
| 360 | |
Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 361 | static int pm_qos_power_open(struct inode *inode, struct file *filp) |
| 362 | { |
Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 363 | long pm_qos_class; |
| 364 | |
| 365 | pm_qos_class = find_pm_qos_object_by_minor(iminor(inode)); |
| 366 | if (pm_qos_class >= 0) { |
David Alan Gilbert | bac1e74 | 2010-08-24 20:22:18 +0200 | [diff] [blame] | 367 | struct pm_qos_request_list *req = kzalloc(sizeof(*req), GFP_KERNEL); |
James Bottomley | 82f6825 | 2010-07-05 22:53:06 +0200 | [diff] [blame] | 368 | if (!req) |
| 369 | return -ENOMEM; |
| 370 | |
| 371 | pm_qos_add_request(req, pm_qos_class, PM_QOS_DEFAULT_VALUE); |
| 372 | filp->private_data = req; |
Mark Gross | ed77134 | 2010-05-06 01:59:26 +0200 | [diff] [blame] | 373 | |
| 374 | if (filp->private_data) |
Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 375 | return 0; |
| 376 | } |
Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 377 | return -EPERM; |
| 378 | } |
| 379 | |
| 380 | static int pm_qos_power_release(struct inode *inode, struct file *filp) |
| 381 | { |
Mark Gross | ed77134 | 2010-05-06 01:59:26 +0200 | [diff] [blame] | 382 | struct pm_qos_request_list *req; |
Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 383 | |
James Bottomley | 82f6825 | 2010-07-05 22:53:06 +0200 | [diff] [blame] | 384 | req = filp->private_data; |
Mark Gross | ed77134 | 2010-05-06 01:59:26 +0200 | [diff] [blame] | 385 | pm_qos_remove_request(req); |
James Bottomley | 82f6825 | 2010-07-05 22:53:06 +0200 | [diff] [blame] | 386 | kfree(req); |
Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 387 | |
| 388 | return 0; |
| 389 | } |
| 390 | |
Mark Gross | ed77134 | 2010-05-06 01:59:26 +0200 | [diff] [blame] | 391 | |
Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 392 | static ssize_t pm_qos_power_write(struct file *filp, const char __user *buf, |
| 393 | size_t count, loff_t *f_pos) |
| 394 | { |
| 395 | s32 value; |
Mark Gross | ed77134 | 2010-05-06 01:59:26 +0200 | [diff] [blame] | 396 | int x; |
| 397 | char ascii_value[11]; |
| 398 | struct pm_qos_request_list *pm_qos_req; |
Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 399 | |
Mark Gross | ed77134 | 2010-05-06 01:59:26 +0200 | [diff] [blame] | 400 | if (count == sizeof(s32)) { |
| 401 | if (copy_from_user(&value, buf, sizeof(s32))) |
| 402 | return -EFAULT; |
| 403 | } else if (count == 11) { /* len('0x12345678/0') */ |
| 404 | if (copy_from_user(ascii_value, buf, 11)) |
| 405 | return -EFAULT; |
mark gross | 0109c2c | 2010-09-09 23:20:09 +0200 | [diff] [blame] | 406 | if (strlen(ascii_value) != 10) |
| 407 | return -EINVAL; |
Mark Gross | ed77134 | 2010-05-06 01:59:26 +0200 | [diff] [blame] | 408 | x = sscanf(ascii_value, "%x", &value); |
| 409 | if (x != 1) |
| 410 | return -EINVAL; |
mark gross | 0109c2c | 2010-09-09 23:20:09 +0200 | [diff] [blame] | 411 | pr_debug("%s, %d, 0x%x\n", ascii_value, x, value); |
Mark Gross | ed77134 | 2010-05-06 01:59:26 +0200 | [diff] [blame] | 412 | } else |
Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 413 | return -EINVAL; |
Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 414 | |
Joe Perches | 99a5179 | 2010-09-04 18:52:50 -0700 | [diff] [blame] | 415 | pm_qos_req = filp->private_data; |
Mark Gross | ed77134 | 2010-05-06 01:59:26 +0200 | [diff] [blame] | 416 | pm_qos_update_request(pm_qos_req, value); |
| 417 | |
| 418 | return count; |
Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 419 | } |
| 420 | |
| 421 | |
| 422 | static int __init pm_qos_power_init(void) |
| 423 | { |
| 424 | int ret = 0; |
| 425 | |
| 426 | ret = register_pm_qos_misc(&cpu_dma_pm_qos); |
| 427 | if (ret < 0) { |
| 428 | printk(KERN_ERR "pm_qos_param: cpu_dma_latency setup failed\n"); |
| 429 | return ret; |
| 430 | } |
| 431 | ret = register_pm_qos_misc(&network_lat_pm_qos); |
| 432 | if (ret < 0) { |
| 433 | printk(KERN_ERR "pm_qos_param: network_latency setup failed\n"); |
| 434 | return ret; |
| 435 | } |
| 436 | ret = register_pm_qos_misc(&network_throughput_pm_qos); |
| 437 | if (ret < 0) |
| 438 | printk(KERN_ERR |
| 439 | "pm_qos_param: network_throughput setup failed\n"); |
| 440 | |
| 441 | return ret; |
| 442 | } |
| 443 | |
| 444 | late_initcall(pm_qos_power_init); |