Lines Matching defs:dtpm

20 #include <linux/dtpm.h>
38 static struct dtpm *root;
52 struct dtpm *dtpm = to_dtpm(pcz);
54 *max_power_uw = dtpm->power_max - dtpm->power_min;
59 static int __get_power_uw(struct dtpm *dtpm, u64 *power_uw)
61 struct dtpm *child;
65 if (dtpm->ops) {
66 *power_uw = dtpm->ops->get_power_uw(dtpm);
72 list_for_each_entry(child, &dtpm->children, sibling) {
87 static void __dtpm_rebalance_weight(struct dtpm *dtpm)
89 struct dtpm *child;
91 list_for_each_entry(child, &dtpm->children, sibling) {
97 child->power_max * 1024, dtpm->power_max);
103 static void __dtpm_sub_power(struct dtpm *dtpm)
105 struct dtpm *parent = dtpm->parent;
108 parent->power_min -= dtpm->power_min;
109 parent->power_max -= dtpm->power_max;
110 parent->power_limit -= dtpm->power_limit;
115 static void __dtpm_add_power(struct dtpm *dtpm)
117 struct dtpm *parent = dtpm->parent;
120 parent->power_min += dtpm->power_min;
121 parent->power_max += dtpm->power_max;
122 parent->power_limit += dtpm->power_limit;
128 * dtpm_update_power - Update the power on the dtpm
129 * @dtpm: a pointer to a dtpm structure to update
131 * Function to update the power values of the dtpm node specified in
136 int dtpm_update_power(struct dtpm *dtpm)
140 __dtpm_sub_power(dtpm);
142 ret = dtpm->ops->update_power_uw(dtpm);
145 dtpm->zone.name, ret);
147 if (!test_bit(DTPM_POWER_LIMIT_FLAG, &dtpm->flags))
148 dtpm->power_limit = dtpm->power_max;
150 __dtpm_add_power(dtpm);
171 struct dtpm *dtpm = to_dtpm(pcz);
172 struct dtpm *parent = dtpm->parent;
174 if (!list_empty(&dtpm->children))
178 list_del(&dtpm->sibling);
180 __dtpm_sub_power(dtpm);
182 if (dtpm->ops)
183 dtpm->ops->release(dtpm);
185 kfree(dtpm);
202 * The dtpm node lock must be held when calling this function.
204 static int __set_power_limit_uw(struct dtpm *dtpm, int cid, u64 power_limit)
206 struct dtpm *child;
212 * otherwise we set a constraint and flag the dtpm node.
214 if (power_limit == dtpm->power_max) {
215 clear_bit(DTPM_POWER_LIMIT_FLAG, &dtpm->flags);
217 set_bit(DTPM_POWER_LIMIT_FLAG, &dtpm->flags);
221 dtpm->zone.name, power_limit);
224 * Only leaves of the dtpm tree has ops to get/set the power
226 if (dtpm->ops) {
227 dtpm->power_limit = dtpm->ops->set_power_uw(dtpm, power_limit);
229 dtpm->power_limit = 0;
231 list_for_each_entry(child, &dtpm->children, sibling) {
241 if (power_limit == dtpm->power_max) {
243 } else if (power_limit == dtpm->power_min) {
260 dtpm->power_limit += power;
270 struct dtpm *dtpm = to_dtpm(pcz);
277 power_limit = clamp_val(power_limit, dtpm->power_min, dtpm->power_max);
279 ret = __set_power_limit_uw(dtpm, cid, power_limit);
282 dtpm->zone.name, dtpm->power_limit, dtpm->power_max);
315 * dtpm_init - Allocate and initialize a dtpm struct
316 * @dtpm: The dtpm struct pointer to be initialized
317 * @ops: The dtpm device specific ops, NULL for a virtual node
319 void dtpm_init(struct dtpm *dtpm, struct dtpm_ops *ops)
321 if (dtpm) {
322 INIT_LIST_HEAD(&dtpm->children);
323 INIT_LIST_HEAD(&dtpm->sibling);
324 dtpm->weight = 1024;
325 dtpm->ops = ops;
330 * dtpm_unregister - Unregister a dtpm node from the hierarchy tree
331 * @dtpm: a pointer to a dtpm structure corresponding to the node to be removed
336 void dtpm_unregister(struct dtpm *dtpm)
338 powercap_unregister_zone(pct, &dtpm->zone);
340 pr_debug("Unregistered dtpm node '%s'\n", dtpm->zone.name);
344 * dtpm_register - Register a dtpm node in the hierarchy tree
346 * @dtpm: a pointer to a dtpm structure corresponding to the new node
347 * @parent: a pointer to a dtpm structure corresponding to the parent node
349 * Create a dtpm node in the tree. If no parent is specified, the node
354 * The dtpm structure must be initialized with the power numbers
365 int dtpm_register(const char *name, struct dtpm *dtpm, struct dtpm *parent)
381 if (!dtpm)
384 if (dtpm->ops && !(dtpm->ops->set_power_uw &&
385 dtpm->ops->get_power_uw &&
386 dtpm->ops->update_power_uw &&
387 dtpm->ops->release))
390 pcz = powercap_register_zone(&dtpm->zone, pct, name,
398 list_add_tail(&dtpm->sibling, &parent->children);
399 dtpm->parent = parent;
401 root = dtpm;
404 if (dtpm->ops && !dtpm->ops->update_power_uw(dtpm)) {
405 __dtpm_add_power(dtpm);
406 dtpm->power_limit = dtpm->power_max;
409 pr_debug("Registered dtpm node '%s' / %llu-%llu uW, \n",
410 dtpm->zone.name, dtpm->power_min, dtpm->power_max);
415 static struct dtpm *dtpm_setup_virtual(const struct dtpm_node *hierarchy,
416 struct dtpm *parent)
418 struct dtpm *dtpm;
421 dtpm = kzalloc(sizeof(*dtpm), GFP_KERNEL);
422 if (!dtpm)
424 dtpm_init(dtpm, NULL);
426 ret = dtpm_register(hierarchy->name, dtpm, parent);
428 pr_err("Failed to register dtpm node '%s': %d\n",
430 kfree(dtpm);
434 return dtpm;
437 static struct dtpm *dtpm_setup_dt(const struct dtpm_node *hierarchy,
438 struct dtpm *parent)
471 typedef struct dtpm * (*dtpm_node_callback_t)(const struct dtpm_node *, struct dtpm *);
479 const struct dtpm_node *it, struct dtpm *parent)
481 struct dtpm *dtpm;
489 dtpm = dtpm_node_callback[hierarchy[i].type](&hierarchy[i], parent);
495 if (!dtpm)
509 if (IS_ERR(dtpm)) {
515 ret = dtpm_for_each_child(hierarchy, &hierarchy[i], dtpm);
524 * dtpm_create_hierarchy - Create the dtpm hierarchy
529 * tree in the sysfs filesystem under the powercap dtpm entry.
563 pct = powercap_register_control_type(NULL, "dtpm", NULL);
618 static void __dtpm_destroy_hierarchy(struct dtpm *dtpm)
620 struct dtpm *child, *aux;
622 list_for_each_entry_safe(child, aux, &dtpm->children, sibling)
629 dtpm_unregister(dtpm);