| 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 | */ | 
| Mark Gross | ed77134 | 2010-05-06 01:59:26 +0200 | [diff] [blame] | 51 | struct pm_qos_request_list { | 
| Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 52 | struct list_head list; | 
|  | 53 | union { | 
|  | 54 | s32 value; | 
|  | 55 | s32 usec; | 
|  | 56 | s32 kbps; | 
|  | 57 | }; | 
| Mark Gross | ed77134 | 2010-05-06 01:59:26 +0200 | [diff] [blame] | 58 | int pm_qos_class; | 
| Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 59 | }; | 
|  | 60 |  | 
|  | 61 | static s32 max_compare(s32 v1, s32 v2); | 
|  | 62 | static s32 min_compare(s32 v1, s32 v2); | 
|  | 63 |  | 
|  | 64 | struct pm_qos_object { | 
| Mark Gross | ed77134 | 2010-05-06 01:59:26 +0200 | [diff] [blame] | 65 | struct pm_qos_request_list requests; | 
| Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 66 | struct blocking_notifier_head *notifiers; | 
|  | 67 | struct miscdevice pm_qos_power_miscdev; | 
|  | 68 | char *name; | 
|  | 69 | s32 default_value; | 
| John Kacur | 9d35935 | 2008-09-02 14:36:13 -0700 | [diff] [blame] | 70 | atomic_t target_value; | 
| Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 71 | s32 (*comparitor)(s32, s32); | 
|  | 72 | }; | 
|  | 73 |  | 
|  | 74 | static struct pm_qos_object null_pm_qos; | 
|  | 75 | static BLOCKING_NOTIFIER_HEAD(cpu_dma_lat_notifier); | 
|  | 76 | static struct pm_qos_object cpu_dma_pm_qos = { | 
| Mark Gross | ed77134 | 2010-05-06 01:59:26 +0200 | [diff] [blame] | 77 | .requests = {LIST_HEAD_INIT(cpu_dma_pm_qos.requests.list)}, | 
| Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 78 | .notifiers = &cpu_dma_lat_notifier, | 
|  | 79 | .name = "cpu_dma_latency", | 
|  | 80 | .default_value = 2000 * USEC_PER_SEC, | 
| John Kacur | 9d35935 | 2008-09-02 14:36:13 -0700 | [diff] [blame] | 81 | .target_value = ATOMIC_INIT(2000 * USEC_PER_SEC), | 
| Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 82 | .comparitor = min_compare | 
|  | 83 | }; | 
|  | 84 |  | 
|  | 85 | static BLOCKING_NOTIFIER_HEAD(network_lat_notifier); | 
|  | 86 | static struct pm_qos_object network_lat_pm_qos = { | 
| Mark Gross | ed77134 | 2010-05-06 01:59:26 +0200 | [diff] [blame] | 87 | .requests = {LIST_HEAD_INIT(network_lat_pm_qos.requests.list)}, | 
| Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 88 | .notifiers = &network_lat_notifier, | 
|  | 89 | .name = "network_latency", | 
|  | 90 | .default_value = 2000 * USEC_PER_SEC, | 
| John Kacur | 9d35935 | 2008-09-02 14:36:13 -0700 | [diff] [blame] | 91 | .target_value = ATOMIC_INIT(2000 * USEC_PER_SEC), | 
| Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 92 | .comparitor = min_compare | 
|  | 93 | }; | 
|  | 94 |  | 
|  | 95 |  | 
|  | 96 | static BLOCKING_NOTIFIER_HEAD(network_throughput_notifier); | 
|  | 97 | static struct pm_qos_object network_throughput_pm_qos = { | 
| Mark Gross | ed77134 | 2010-05-06 01:59:26 +0200 | [diff] [blame] | 98 | .requests = {LIST_HEAD_INIT(network_throughput_pm_qos.requests.list)}, | 
| Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 99 | .notifiers = &network_throughput_notifier, | 
|  | 100 | .name = "network_throughput", | 
|  | 101 | .default_value = 0, | 
| John Kacur | 9d35935 | 2008-09-02 14:36:13 -0700 | [diff] [blame] | 102 | .target_value = ATOMIC_INIT(0), | 
| Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 103 | .comparitor = max_compare | 
|  | 104 | }; | 
|  | 105 |  | 
|  | 106 |  | 
|  | 107 | static struct pm_qos_object *pm_qos_array[] = { | 
|  | 108 | &null_pm_qos, | 
|  | 109 | &cpu_dma_pm_qos, | 
|  | 110 | &network_lat_pm_qos, | 
|  | 111 | &network_throughput_pm_qos | 
|  | 112 | }; | 
|  | 113 |  | 
|  | 114 | static DEFINE_SPINLOCK(pm_qos_lock); | 
|  | 115 |  | 
|  | 116 | static ssize_t pm_qos_power_write(struct file *filp, const char __user *buf, | 
|  | 117 | size_t count, loff_t *f_pos); | 
|  | 118 | static int pm_qos_power_open(struct inode *inode, struct file *filp); | 
|  | 119 | static int pm_qos_power_release(struct inode *inode, struct file *filp); | 
|  | 120 |  | 
|  | 121 | static const struct file_operations pm_qos_power_fops = { | 
|  | 122 | .write = pm_qos_power_write, | 
|  | 123 | .open = pm_qos_power_open, | 
|  | 124 | .release = pm_qos_power_release, | 
|  | 125 | }; | 
|  | 126 |  | 
|  | 127 | /* static helper functions */ | 
|  | 128 | static s32 max_compare(s32 v1, s32 v2) | 
|  | 129 | { | 
|  | 130 | return max(v1, v2); | 
|  | 131 | } | 
|  | 132 |  | 
|  | 133 | static s32 min_compare(s32 v1, s32 v2) | 
|  | 134 | { | 
|  | 135 | return min(v1, v2); | 
|  | 136 | } | 
|  | 137 |  | 
|  | 138 |  | 
| Mark Gross | ed77134 | 2010-05-06 01:59:26 +0200 | [diff] [blame] | 139 | static void update_target(int pm_qos_class) | 
| Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 140 | { | 
|  | 141 | s32 extreme_value; | 
| Mark Gross | ed77134 | 2010-05-06 01:59:26 +0200 | [diff] [blame] | 142 | struct pm_qos_request_list *node; | 
| Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 143 | unsigned long flags; | 
|  | 144 | int call_notifier = 0; | 
|  | 145 |  | 
|  | 146 | spin_lock_irqsave(&pm_qos_lock, flags); | 
| Mark Gross | ed77134 | 2010-05-06 01:59:26 +0200 | [diff] [blame] | 147 | extreme_value = pm_qos_array[pm_qos_class]->default_value; | 
| Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 148 | list_for_each_entry(node, | 
| Mark Gross | ed77134 | 2010-05-06 01:59:26 +0200 | [diff] [blame] | 149 | &pm_qos_array[pm_qos_class]->requests.list, list) { | 
|  | 150 | extreme_value = pm_qos_array[pm_qos_class]->comparitor( | 
| Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 151 | extreme_value, node->value); | 
|  | 152 | } | 
| Mark Gross | ed77134 | 2010-05-06 01:59:26 +0200 | [diff] [blame] | 153 | if (atomic_read(&pm_qos_array[pm_qos_class]->target_value) != | 
|  | 154 | extreme_value) { | 
| Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 155 | call_notifier = 1; | 
| Mark Gross | ed77134 | 2010-05-06 01:59:26 +0200 | [diff] [blame] | 156 | atomic_set(&pm_qos_array[pm_qos_class]->target_value, | 
|  | 157 | extreme_value); | 
|  | 158 | pr_debug(KERN_ERR "new target for qos %d is %d\n", pm_qos_class, | 
|  | 159 | atomic_read(&pm_qos_array[pm_qos_class]->target_value)); | 
| Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 160 | } | 
|  | 161 | spin_unlock_irqrestore(&pm_qos_lock, flags); | 
|  | 162 |  | 
|  | 163 | if (call_notifier) | 
| Mark Gross | ed77134 | 2010-05-06 01:59:26 +0200 | [diff] [blame] | 164 | blocking_notifier_call_chain( | 
|  | 165 | pm_qos_array[pm_qos_class]->notifiers, | 
|  | 166 | (unsigned long) extreme_value, NULL); | 
| Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 167 | } | 
|  | 168 |  | 
|  | 169 | static int register_pm_qos_misc(struct pm_qos_object *qos) | 
|  | 170 | { | 
|  | 171 | qos->pm_qos_power_miscdev.minor = MISC_DYNAMIC_MINOR; | 
|  | 172 | qos->pm_qos_power_miscdev.name = qos->name; | 
|  | 173 | qos->pm_qos_power_miscdev.fops = &pm_qos_power_fops; | 
|  | 174 |  | 
|  | 175 | return misc_register(&qos->pm_qos_power_miscdev); | 
|  | 176 | } | 
|  | 177 |  | 
|  | 178 | static int find_pm_qos_object_by_minor(int minor) | 
|  | 179 | { | 
|  | 180 | int pm_qos_class; | 
|  | 181 |  | 
|  | 182 | for (pm_qos_class = 0; | 
|  | 183 | pm_qos_class < PM_QOS_NUM_CLASSES; pm_qos_class++) { | 
|  | 184 | if (minor == | 
|  | 185 | pm_qos_array[pm_qos_class]->pm_qos_power_miscdev.minor) | 
|  | 186 | return pm_qos_class; | 
|  | 187 | } | 
|  | 188 | return -1; | 
|  | 189 | } | 
|  | 190 |  | 
|  | 191 | /** | 
| Mark Gross | ed77134 | 2010-05-06 01:59:26 +0200 | [diff] [blame] | 192 | * pm_qos_request - returns current system wide qos expectation | 
| Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 193 | * @pm_qos_class: identification of which qos value is requested | 
|  | 194 | * | 
|  | 195 | * This function returns the current target value in an atomic manner. | 
|  | 196 | */ | 
| Mark Gross | ed77134 | 2010-05-06 01:59:26 +0200 | [diff] [blame] | 197 | int pm_qos_request(int pm_qos_class) | 
| Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 198 | { | 
| John Kacur | 9d35935 | 2008-09-02 14:36:13 -0700 | [diff] [blame] | 199 | return atomic_read(&pm_qos_array[pm_qos_class]->target_value); | 
| Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 200 | } | 
| Mark Gross | ed77134 | 2010-05-06 01:59:26 +0200 | [diff] [blame] | 201 | EXPORT_SYMBOL_GPL(pm_qos_request); | 
| Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 202 |  | 
|  | 203 | /** | 
| Mark Gross | ed77134 | 2010-05-06 01:59:26 +0200 | [diff] [blame] | 204 | * pm_qos_add_request - inserts new qos request into the list | 
| Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 205 | * @pm_qos_class: identifies which list of qos request to us | 
| Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 206 | * @value: defines the qos request | 
|  | 207 | * | 
|  | 208 | * 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] | 209 | * performance characteristics.  It recomputes the aggregate QoS expectations | 
| Mark Gross | ed77134 | 2010-05-06 01:59:26 +0200 | [diff] [blame] | 210 | * for the pm_qos_class of parameters, and returns the pm_qos_request list | 
|  | 211 | * element as a handle for use in updating and removal.  Call needs to save | 
|  | 212 | * this handle for later use. | 
| Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 213 | */ | 
| Mark Gross | ed77134 | 2010-05-06 01:59:26 +0200 | [diff] [blame] | 214 | struct pm_qos_request_list *pm_qos_add_request(int pm_qos_class, s32 value) | 
| Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 215 | { | 
| Mark Gross | ed77134 | 2010-05-06 01:59:26 +0200 | [diff] [blame] | 216 | struct pm_qos_request_list *dep; | 
| Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 217 | unsigned long flags; | 
|  | 218 |  | 
| Mark Gross | ed77134 | 2010-05-06 01:59:26 +0200 | [diff] [blame] | 219 | dep = kzalloc(sizeof(struct pm_qos_request_list), GFP_KERNEL); | 
| Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 220 | if (dep) { | 
|  | 221 | if (value == PM_QOS_DEFAULT_VALUE) | 
|  | 222 | dep->value = pm_qos_array[pm_qos_class]->default_value; | 
|  | 223 | else | 
|  | 224 | dep->value = value; | 
| Mark Gross | ed77134 | 2010-05-06 01:59:26 +0200 | [diff] [blame] | 225 | dep->pm_qos_class = pm_qos_class; | 
| Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 226 |  | 
|  | 227 | spin_lock_irqsave(&pm_qos_lock, flags); | 
|  | 228 | list_add(&dep->list, | 
| Mark Gross | ed77134 | 2010-05-06 01:59:26 +0200 | [diff] [blame] | 229 | &pm_qos_array[pm_qos_class]->requests.list); | 
| Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 230 | spin_unlock_irqrestore(&pm_qos_lock, flags); | 
|  | 231 | update_target(pm_qos_class); | 
| Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 232 | } | 
|  | 233 |  | 
| Mark Gross | ed77134 | 2010-05-06 01:59:26 +0200 | [diff] [blame] | 234 | return dep; | 
| Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 235 | } | 
| Mark Gross | ed77134 | 2010-05-06 01:59:26 +0200 | [diff] [blame] | 236 | EXPORT_SYMBOL_GPL(pm_qos_add_request); | 
| Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 237 |  | 
|  | 238 | /** | 
| Mark Gross | ed77134 | 2010-05-06 01:59:26 +0200 | [diff] [blame] | 239 | * pm_qos_update_request - modifies an existing qos request | 
|  | 240 | * @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] | 241 | * @value: defines the qos request | 
|  | 242 | * | 
| Mark Gross | ed77134 | 2010-05-06 01:59:26 +0200 | [diff] [blame] | 243 | * 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] | 244 | * with updating the target pm_qos_class value. | 
|  | 245 | * | 
| Mark Gross | ed77134 | 2010-05-06 01:59:26 +0200 | [diff] [blame] | 246 | * Attempts are made to make this code callable on hot code paths. | 
| Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 247 | */ | 
| Mark Gross | ed77134 | 2010-05-06 01:59:26 +0200 | [diff] [blame] | 248 | void pm_qos_update_request(struct pm_qos_request_list *pm_qos_req, | 
|  | 249 | s32 new_value) | 
| Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 250 | { | 
|  | 251 | unsigned long flags; | 
| Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 252 | int pending_update = 0; | 
| Mark Gross | ed77134 | 2010-05-06 01:59:26 +0200 | [diff] [blame] | 253 | s32 temp; | 
| Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 254 |  | 
| Mark Gross | 25f3a5a | 2010-05-17 00:21:03 +0200 | [diff] [blame] | 255 | if (pm_qos_req) { /*guard against callers passing in null */ | 
|  | 256 | spin_lock_irqsave(&pm_qos_lock, flags); | 
|  | 257 | if (new_value == PM_QOS_DEFAULT_VALUE) | 
|  | 258 | temp = pm_qos_array[pm_qos_req->pm_qos_class]->default_value; | 
|  | 259 | else | 
|  | 260 | temp = new_value; | 
| Mark Gross | ed77134 | 2010-05-06 01:59:26 +0200 | [diff] [blame] | 261 |  | 
| Mark Gross | 25f3a5a | 2010-05-17 00:21:03 +0200 | [diff] [blame] | 262 | if (temp != pm_qos_req->value) { | 
|  | 263 | pending_update = 1; | 
|  | 264 | pm_qos_req->value = temp; | 
|  | 265 | } | 
|  | 266 | spin_unlock_irqrestore(&pm_qos_lock, flags); | 
|  | 267 | if (pending_update) | 
|  | 268 | update_target(pm_qos_req->pm_qos_class); | 
| Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 269 | } | 
| Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 270 | } | 
| Mark Gross | ed77134 | 2010-05-06 01:59:26 +0200 | [diff] [blame] | 271 | EXPORT_SYMBOL_GPL(pm_qos_update_request); | 
| Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 272 |  | 
|  | 273 | /** | 
| Mark Gross | ed77134 | 2010-05-06 01:59:26 +0200 | [diff] [blame] | 274 | * pm_qos_remove_request - modifies an existing qos request | 
|  | 275 | * @pm_qos_req: handle to request list element | 
| Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 276 | * | 
| Mark Gross | ed77134 | 2010-05-06 01:59:26 +0200 | [diff] [blame] | 277 | * Will remove pm qos request from the list of requests and | 
|  | 278 | * recompute the current target value for the pm_qos_class.  Call this | 
|  | 279 | * on slow code paths. | 
| Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 280 | */ | 
| Mark Gross | ed77134 | 2010-05-06 01:59:26 +0200 | [diff] [blame] | 281 | 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] | 282 | { | 
|  | 283 | unsigned long flags; | 
| Mark Gross | ed77134 | 2010-05-06 01:59:26 +0200 | [diff] [blame] | 284 | int qos_class; | 
| Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 285 |  | 
| Mark Gross | ed77134 | 2010-05-06 01:59:26 +0200 | [diff] [blame] | 286 | if (pm_qos_req == NULL) | 
|  | 287 | return; | 
|  | 288 | /* silent return to keep pcm code cleaner */ | 
|  | 289 |  | 
|  | 290 | qos_class = pm_qos_req->pm_qos_class; | 
| Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 291 | spin_lock_irqsave(&pm_qos_lock, flags); | 
| Mark Gross | ed77134 | 2010-05-06 01:59:26 +0200 | [diff] [blame] | 292 | list_del(&pm_qos_req->list); | 
|  | 293 | kfree(pm_qos_req); | 
| Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 294 | spin_unlock_irqrestore(&pm_qos_lock, flags); | 
| Mark Gross | ed77134 | 2010-05-06 01:59:26 +0200 | [diff] [blame] | 295 | update_target(qos_class); | 
| Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 296 | } | 
| Mark Gross | ed77134 | 2010-05-06 01:59:26 +0200 | [diff] [blame] | 297 | EXPORT_SYMBOL_GPL(pm_qos_remove_request); | 
| Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 298 |  | 
|  | 299 | /** | 
|  | 300 | * pm_qos_add_notifier - sets notification entry for changes to target value | 
|  | 301 | * @pm_qos_class: identifies which qos target changes should be notified. | 
|  | 302 | * @notifier: notifier block managed by caller. | 
|  | 303 | * | 
|  | 304 | * will register the notifier into a notification chain that gets called | 
| Richard Hughes | bf1db69 | 2008-08-05 13:01:35 -0700 | [diff] [blame] | 305 | * upon changes to the pm_qos_class target value. | 
| Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 306 | */ | 
| Mark Gross | ed77134 | 2010-05-06 01:59:26 +0200 | [diff] [blame] | 307 | 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] | 308 | { | 
|  | 309 | int retval; | 
|  | 310 |  | 
|  | 311 | retval = blocking_notifier_chain_register( | 
|  | 312 | pm_qos_array[pm_qos_class]->notifiers, notifier); | 
|  | 313 |  | 
|  | 314 | return retval; | 
|  | 315 | } | 
|  | 316 | EXPORT_SYMBOL_GPL(pm_qos_add_notifier); | 
|  | 317 |  | 
|  | 318 | /** | 
|  | 319 | * pm_qos_remove_notifier - deletes notification entry from chain. | 
|  | 320 | * @pm_qos_class: identifies which qos target changes are notified. | 
|  | 321 | * @notifier: notifier block to be removed. | 
|  | 322 | * | 
|  | 323 | * will remove the notifier from the notification chain that gets called | 
| Richard Hughes | bf1db69 | 2008-08-05 13:01:35 -0700 | [diff] [blame] | 324 | * upon changes to the pm_qos_class target value. | 
| Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 325 | */ | 
|  | 326 | int pm_qos_remove_notifier(int pm_qos_class, struct notifier_block *notifier) | 
|  | 327 | { | 
|  | 328 | int retval; | 
|  | 329 |  | 
|  | 330 | retval = blocking_notifier_chain_unregister( | 
|  | 331 | pm_qos_array[pm_qos_class]->notifiers, notifier); | 
|  | 332 |  | 
|  | 333 | return retval; | 
|  | 334 | } | 
|  | 335 | EXPORT_SYMBOL_GPL(pm_qos_remove_notifier); | 
|  | 336 |  | 
| Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 337 | static int pm_qos_power_open(struct inode *inode, struct file *filp) | 
|  | 338 | { | 
| Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 339 | long pm_qos_class; | 
|  | 340 |  | 
|  | 341 | pm_qos_class = find_pm_qos_object_by_minor(iminor(inode)); | 
|  | 342 | if (pm_qos_class >= 0) { | 
| Mark Gross | ed77134 | 2010-05-06 01:59:26 +0200 | [diff] [blame] | 343 | filp->private_data = (void *) pm_qos_add_request(pm_qos_class, | 
|  | 344 | PM_QOS_DEFAULT_VALUE); | 
|  | 345 |  | 
|  | 346 | if (filp->private_data) | 
| Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 347 | return 0; | 
|  | 348 | } | 
| Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 349 | return -EPERM; | 
|  | 350 | } | 
|  | 351 |  | 
|  | 352 | static int pm_qos_power_release(struct inode *inode, struct file *filp) | 
|  | 353 | { | 
| Mark Gross | ed77134 | 2010-05-06 01:59:26 +0200 | [diff] [blame] | 354 | struct pm_qos_request_list *req; | 
| Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 355 |  | 
| Mark Gross | ed77134 | 2010-05-06 01:59:26 +0200 | [diff] [blame] | 356 | req = (struct pm_qos_request_list *)filp->private_data; | 
|  | 357 | pm_qos_remove_request(req); | 
| Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 358 |  | 
|  | 359 | return 0; | 
|  | 360 | } | 
|  | 361 |  | 
| Mark Gross | ed77134 | 2010-05-06 01:59:26 +0200 | [diff] [blame] | 362 |  | 
| Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 363 | static ssize_t pm_qos_power_write(struct file *filp, const char __user *buf, | 
|  | 364 | size_t count, loff_t *f_pos) | 
|  | 365 | { | 
|  | 366 | s32 value; | 
| Mark Gross | ed77134 | 2010-05-06 01:59:26 +0200 | [diff] [blame] | 367 | int x; | 
|  | 368 | char ascii_value[11]; | 
|  | 369 | struct pm_qos_request_list *pm_qos_req; | 
| Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 370 |  | 
| Mark Gross | ed77134 | 2010-05-06 01:59:26 +0200 | [diff] [blame] | 371 | if (count == sizeof(s32)) { | 
|  | 372 | if (copy_from_user(&value, buf, sizeof(s32))) | 
|  | 373 | return -EFAULT; | 
|  | 374 | } else if (count == 11) { /* len('0x12345678/0') */ | 
|  | 375 | if (copy_from_user(ascii_value, buf, 11)) | 
|  | 376 | return -EFAULT; | 
|  | 377 | x = sscanf(ascii_value, "%x", &value); | 
|  | 378 | if (x != 1) | 
|  | 379 | return -EINVAL; | 
|  | 380 | pr_debug(KERN_ERR "%s, %d, 0x%x\n", ascii_value, x, value); | 
|  | 381 | } else | 
| Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 382 | return -EINVAL; | 
| Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 383 |  | 
| Mark Gross | ed77134 | 2010-05-06 01:59:26 +0200 | [diff] [blame] | 384 | pm_qos_req = (struct pm_qos_request_list *)filp->private_data; | 
|  | 385 | pm_qos_update_request(pm_qos_req, value); | 
|  | 386 |  | 
|  | 387 | return count; | 
| Mark Gross | d82b351 | 2008-02-04 22:30:08 -0800 | [diff] [blame] | 388 | } | 
|  | 389 |  | 
|  | 390 |  | 
|  | 391 | static int __init pm_qos_power_init(void) | 
|  | 392 | { | 
|  | 393 | int ret = 0; | 
|  | 394 |  | 
|  | 395 | ret = register_pm_qos_misc(&cpu_dma_pm_qos); | 
|  | 396 | if (ret < 0) { | 
|  | 397 | printk(KERN_ERR "pm_qos_param: cpu_dma_latency setup failed\n"); | 
|  | 398 | return ret; | 
|  | 399 | } | 
|  | 400 | ret = register_pm_qos_misc(&network_lat_pm_qos); | 
|  | 401 | if (ret < 0) { | 
|  | 402 | printk(KERN_ERR "pm_qos_param: network_latency setup failed\n"); | 
|  | 403 | return ret; | 
|  | 404 | } | 
|  | 405 | ret = register_pm_qos_misc(&network_throughput_pm_qos); | 
|  | 406 | if (ret < 0) | 
|  | 407 | printk(KERN_ERR | 
|  | 408 | "pm_qos_param: network_throughput setup failed\n"); | 
|  | 409 |  | 
|  | 410 | return ret; | 
|  | 411 | } | 
|  | 412 |  | 
|  | 413 | late_initcall(pm_qos_power_init); |