Lines Matching refs:dtpm

38 static struct dtpm *root;
52 struct dtpm *dtpm = to_dtpm(pcz); in get_max_power_range_uw() local
54 *max_power_uw = dtpm->power_max - dtpm->power_min; in get_max_power_range_uw()
59 static int __get_power_uw(struct dtpm *dtpm, u64 *power_uw) in __get_power_uw() argument
61 struct dtpm *child; in __get_power_uw()
65 if (dtpm->ops) { in __get_power_uw()
66 *power_uw = dtpm->ops->get_power_uw(dtpm); in __get_power_uw()
72 list_for_each_entry(child, &dtpm->children, sibling) { in __get_power_uw()
87 static void __dtpm_rebalance_weight(struct dtpm *dtpm) in __dtpm_rebalance_weight() argument
89 struct dtpm *child; in __dtpm_rebalance_weight()
91 list_for_each_entry(child, &dtpm->children, sibling) { in __dtpm_rebalance_weight()
97 child->power_max * 1024, dtpm->power_max); in __dtpm_rebalance_weight()
103 static void __dtpm_sub_power(struct dtpm *dtpm) in __dtpm_sub_power() argument
105 struct dtpm *parent = dtpm->parent; in __dtpm_sub_power()
108 parent->power_min -= dtpm->power_min; in __dtpm_sub_power()
109 parent->power_max -= dtpm->power_max; in __dtpm_sub_power()
110 parent->power_limit -= dtpm->power_limit; in __dtpm_sub_power()
115 static void __dtpm_add_power(struct dtpm *dtpm) in __dtpm_add_power() argument
117 struct dtpm *parent = dtpm->parent; in __dtpm_add_power()
120 parent->power_min += dtpm->power_min; in __dtpm_add_power()
121 parent->power_max += dtpm->power_max; in __dtpm_add_power()
122 parent->power_limit += dtpm->power_limit; in __dtpm_add_power()
136 int dtpm_update_power(struct dtpm *dtpm) in dtpm_update_power() argument
140 __dtpm_sub_power(dtpm); in dtpm_update_power()
142 ret = dtpm->ops->update_power_uw(dtpm); in dtpm_update_power()
145 dtpm->zone.name, ret); in dtpm_update_power()
147 if (!test_bit(DTPM_POWER_LIMIT_FLAG, &dtpm->flags)) in dtpm_update_power()
148 dtpm->power_limit = dtpm->power_max; in dtpm_update_power()
150 __dtpm_add_power(dtpm); in dtpm_update_power()
171 struct dtpm *dtpm = to_dtpm(pcz); in dtpm_release_zone() local
172 struct dtpm *parent = dtpm->parent; in dtpm_release_zone()
174 if (!list_empty(&dtpm->children)) in dtpm_release_zone()
178 list_del(&dtpm->sibling); in dtpm_release_zone()
180 __dtpm_sub_power(dtpm); in dtpm_release_zone()
182 if (dtpm->ops) in dtpm_release_zone()
183 dtpm->ops->release(dtpm); in dtpm_release_zone()
185 kfree(dtpm); in dtpm_release_zone()
204 static int __set_power_limit_uw(struct dtpm *dtpm, int cid, u64 power_limit) in __set_power_limit_uw() argument
206 struct dtpm *child; in __set_power_limit_uw()
214 if (power_limit == dtpm->power_max) { in __set_power_limit_uw()
215 clear_bit(DTPM_POWER_LIMIT_FLAG, &dtpm->flags); in __set_power_limit_uw()
217 set_bit(DTPM_POWER_LIMIT_FLAG, &dtpm->flags); in __set_power_limit_uw()
221 dtpm->zone.name, power_limit); in __set_power_limit_uw()
226 if (dtpm->ops) { in __set_power_limit_uw()
227 dtpm->power_limit = dtpm->ops->set_power_uw(dtpm, power_limit); in __set_power_limit_uw()
229 dtpm->power_limit = 0; in __set_power_limit_uw()
231 list_for_each_entry(child, &dtpm->children, sibling) { in __set_power_limit_uw()
241 if (power_limit == dtpm->power_max) { in __set_power_limit_uw()
243 } else if (power_limit == dtpm->power_min) { in __set_power_limit_uw()
260 dtpm->power_limit += power; in __set_power_limit_uw()
270 struct dtpm *dtpm = to_dtpm(pcz); in set_power_limit_uw() local
277 power_limit = clamp_val(power_limit, dtpm->power_min, dtpm->power_max); in set_power_limit_uw()
279 ret = __set_power_limit_uw(dtpm, cid, power_limit); in set_power_limit_uw()
282 dtpm->zone.name, dtpm->power_limit, dtpm->power_max); in set_power_limit_uw()
319 void dtpm_init(struct dtpm *dtpm, struct dtpm_ops *ops) in dtpm_init() argument
321 if (dtpm) { in dtpm_init()
322 INIT_LIST_HEAD(&dtpm->children); in dtpm_init()
323 INIT_LIST_HEAD(&dtpm->sibling); in dtpm_init()
324 dtpm->weight = 1024; in dtpm_init()
325 dtpm->ops = ops; in dtpm_init()
336 void dtpm_unregister(struct dtpm *dtpm) in dtpm_unregister() argument
338 powercap_unregister_zone(pct, &dtpm->zone); in dtpm_unregister()
340 pr_debug("Unregistered dtpm node '%s'\n", dtpm->zone.name); in dtpm_unregister()
365 int dtpm_register(const char *name, struct dtpm *dtpm, struct dtpm *parent) in dtpm_register() argument
381 if (!dtpm) in dtpm_register()
384 if (dtpm->ops && !(dtpm->ops->set_power_uw && in dtpm_register()
385 dtpm->ops->get_power_uw && in dtpm_register()
386 dtpm->ops->update_power_uw && in dtpm_register()
387 dtpm->ops->release)) in dtpm_register()
390 pcz = powercap_register_zone(&dtpm->zone, pct, name, in dtpm_register()
398 list_add_tail(&dtpm->sibling, &parent->children); in dtpm_register()
399 dtpm->parent = parent; in dtpm_register()
401 root = dtpm; in dtpm_register()
404 if (dtpm->ops && !dtpm->ops->update_power_uw(dtpm)) { in dtpm_register()
405 __dtpm_add_power(dtpm); in dtpm_register()
406 dtpm->power_limit = dtpm->power_max; in dtpm_register()
410 dtpm->zone.name, dtpm->power_min, dtpm->power_max); in dtpm_register()
415 static struct dtpm *dtpm_setup_virtual(const struct dtpm_node *hierarchy, in dtpm_setup_virtual()
416 struct dtpm *parent) in dtpm_setup_virtual()
418 struct dtpm *dtpm; in dtpm_setup_virtual() local
421 dtpm = kzalloc(sizeof(*dtpm), GFP_KERNEL); in dtpm_setup_virtual()
422 if (!dtpm) in dtpm_setup_virtual()
424 dtpm_init(dtpm, NULL); in dtpm_setup_virtual()
426 ret = dtpm_register(hierarchy->name, dtpm, parent); in dtpm_setup_virtual()
430 kfree(dtpm); in dtpm_setup_virtual()
434 return dtpm; in dtpm_setup_virtual()
437 static struct dtpm *dtpm_setup_dt(const struct dtpm_node *hierarchy, in dtpm_setup_dt()
438 struct dtpm *parent) in dtpm_setup_dt()
471 typedef struct dtpm * (*dtpm_node_callback_t)(const struct dtpm_node *, struct dtpm *);
479 const struct dtpm_node *it, struct dtpm *parent) in dtpm_for_each_child()
481 struct dtpm *dtpm; in dtpm_for_each_child() local
489 dtpm = dtpm_node_callback[hierarchy[i].type](&hierarchy[i], parent); in dtpm_for_each_child()
495 if (!dtpm) in dtpm_for_each_child()
509 if (IS_ERR(dtpm)) { in dtpm_for_each_child()
515 ret = dtpm_for_each_child(hierarchy, &hierarchy[i], dtpm); in dtpm_for_each_child()
618 static void __dtpm_destroy_hierarchy(struct dtpm *dtpm) in __dtpm_destroy_hierarchy() argument
620 struct dtpm *child, *aux; in __dtpm_destroy_hierarchy()
622 list_for_each_entry_safe(child, aux, &dtpm->children, sibling) in __dtpm_destroy_hierarchy()
629 dtpm_unregister(dtpm); in __dtpm_destroy_hierarchy()