Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

interconnect: Add helpers for enabling/disabling a path

There is a repeated pattern in multiple drivers where they want to switch
the bandwidth between zero and some other value. This is happening often
in the suspend/resume callbacks. Let's add helper functions to enable and
disable the path, so that callers don't have to take care of remembering
the bandwidth values and handle this in the framework instead.

With this patch the users can call icc_disable() and icc_enable() to lower
their bandwidth request to zero and then restore it back to it's previous
value.

Suggested-by: Evan Green <evgreen@chromium.org>
Suggested-by: Bjorn Andersson <bjorn.andersson@linaro.org>
Signed-off-by: Georgi Djakov <georgi.djakov@linaro.org>
Reviewed-by: Matthias Kaehlcke <mka@chromium.org>
Link: https://lore.kernel.org/r/20200507120846.8354-1-georgi.djakov@linaro.org
Signed-off-by: Georgi Djakov <georgi.djakov@linaro.org>

+52 -1
+38 -1
drivers/interconnect/core.c
··· 158 158 hlist_add_head(&path->reqs[i].req_node, &node->req_list); 159 159 path->reqs[i].node = node; 160 160 path->reqs[i].dev = dev; 161 + path->reqs[i].enabled = true; 161 162 /* reference to previous node was saved during path traversal */ 162 163 node = node->reverse; 163 164 } ··· 250 249 if (p->pre_aggregate) 251 250 p->pre_aggregate(node); 252 251 253 - hlist_for_each_entry(r, &node->req_list, req_node) 252 + hlist_for_each_entry(r, &node->req_list, req_node) { 253 + if (!r->enabled) 254 + continue; 254 255 p->aggregate(node, r->tag, r->avg_bw, r->peak_bw, 255 256 &node->avg_bw, &node->peak_bw); 257 + } 256 258 257 259 return 0; 258 260 } ··· 574 570 return ret; 575 571 } 576 572 EXPORT_SYMBOL_GPL(icc_set_bw); 573 + 574 + static int __icc_enable(struct icc_path *path, bool enable) 575 + { 576 + int i; 577 + 578 + if (!path) 579 + return 0; 580 + 581 + if (WARN_ON(IS_ERR(path) || !path->num_nodes)) 582 + return -EINVAL; 583 + 584 + mutex_lock(&icc_lock); 585 + 586 + for (i = 0; i < path->num_nodes; i++) 587 + path->reqs[i].enabled = enable; 588 + 589 + mutex_unlock(&icc_lock); 590 + 591 + return icc_set_bw(path, path->reqs[0].avg_bw, 592 + path->reqs[0].peak_bw); 593 + } 594 + 595 + int icc_enable(struct icc_path *path) 596 + { 597 + return __icc_enable(path, true); 598 + } 599 + EXPORT_SYMBOL_GPL(icc_enable); 600 + 601 + int icc_disable(struct icc_path *path) 602 + { 603 + return __icc_enable(path, false); 604 + } 605 + EXPORT_SYMBOL_GPL(icc_disable); 577 606 578 607 /** 579 608 * icc_get() - return a handle for path between two endpoints
+2
drivers/interconnect/internal.h
··· 14 14 * @req_node: entry in list of requests for the particular @node 15 15 * @node: the interconnect node to which this constraint applies 16 16 * @dev: reference to the device that sets the constraints 17 + * @enabled: indicates whether the path with this request is enabled 17 18 * @tag: path tag (optional) 18 19 * @avg_bw: an integer describing the average bandwidth in kBps 19 20 * @peak_bw: an integer describing the peak bandwidth in kBps ··· 23 22 struct hlist_node req_node; 24 23 struct icc_node *node; 25 24 struct device *dev; 25 + bool enabled; 26 26 u32 tag; 27 27 u32 avg_bw; 28 28 u32 peak_bw;
+12
include/linux/interconnect.h
··· 30 30 struct icc_path *of_icc_get(struct device *dev, const char *name); 31 31 struct icc_path *devm_of_icc_get(struct device *dev, const char *name); 32 32 void icc_put(struct icc_path *path); 33 + int icc_enable(struct icc_path *path); 34 + int icc_disable(struct icc_path *path); 33 35 int icc_set_bw(struct icc_path *path, u32 avg_bw, u32 peak_bw); 34 36 void icc_set_tag(struct icc_path *path, u32 tag); 35 37 ··· 57 55 58 56 static inline void icc_put(struct icc_path *path) 59 57 { 58 + } 59 + 60 + static inline int icc_enable(struct icc_path *path) 61 + { 62 + return 0; 63 + } 64 + 65 + static inline int icc_disable(struct icc_path *path) 66 + { 67 + return 0; 60 68 } 61 69 62 70 static inline int icc_set_bw(struct icc_path *path, u32 avg_bw, u32 peak_bw)