Skip to content

Commit b41b0ce

Browse files
author
Georgi Djakov
committed
interconnect: Add bulk API helpers
There are drivers which just need to get multiple interconnect paths, request some predefined amounts of bandwidth and then just toggle the paths between enabled/disabled state. The aim of this patch is simplify the above and to allow drivers to put all the path names and bandwidth data into a single static icc_bulk_data table and call the icc_bulk_* functions on that table in order to scale all the interconnect paths in parallel. Suggested-by: Evan Green <evgreen@chromium.org> Suggested-by: Bjorn Andersson <bjorn.andersson@linaro.org> Reviewed-by: Bjorn Andersson <bjorn.andersson@linaro.org> Link: https://lore.kernel.org/r/20200729123439.9961-1-georgi.djakov@linaro.org Signed-off-by: Georgi Djakov <georgi.djakov@linaro.org>
1 parent 91e045b commit b41b0ce

3 files changed

Lines changed: 140 additions & 1 deletion

File tree

drivers/interconnect/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# SPDX-License-Identifier: GPL-2.0
22

33
CFLAGS_core.o := -I$(src)
4-
icc-core-objs := core.o
4+
icc-core-objs := core.o bulk.o
55

66
obj-$(CONFIG_INTERCONNECT) += icc-core.o
77
obj-$(CONFIG_INTERCONNECT_IMX) += imx/

drivers/interconnect/bulk.c

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
3+
#include <linux/interconnect-provider.h>
4+
#include <linux/device.h>
5+
#include <linux/export.h>
6+
7+
/**
8+
* of_icc_bulk_get() - get interconnect paths
9+
* @dev: the device requesting the path
10+
* @num_paths: the number of icc_bulk_data
11+
* @paths: the table with the paths we want to get
12+
*
13+
* Returns 0 on success or negative errno otherwise.
14+
*/
15+
int __must_check of_icc_bulk_get(struct device *dev, int num_paths,
16+
struct icc_bulk_data *paths)
17+
{
18+
int ret, i;
19+
20+
for (i = 0; i < num_paths; i++) {
21+
paths[i].path = of_icc_get(dev, paths[i].name);
22+
if (IS_ERR(paths[i].path)) {
23+
ret = PTR_ERR(paths[i].path);
24+
if (ret != -EPROBE_DEFER)
25+
dev_err(dev, "of_icc_get() failed on path %s (%d)\n",
26+
paths[i].name, ret);
27+
paths[i].path = NULL;
28+
goto err;
29+
}
30+
}
31+
32+
return 0;
33+
34+
err:
35+
icc_bulk_put(i, paths);
36+
37+
return ret;
38+
}
39+
EXPORT_SYMBOL_GPL(of_icc_bulk_get);
40+
41+
/**
42+
* icc_bulk_put() - put a list of interconnect paths
43+
* @num_paths: the number of icc_bulk_data
44+
* @paths: the icc_bulk_data table with the paths being put
45+
*/
46+
void icc_bulk_put(int num_paths, struct icc_bulk_data *paths)
47+
{
48+
while (--num_paths >= 0) {
49+
icc_put(paths[num_paths].path);
50+
paths[num_paths].path = NULL;
51+
}
52+
}
53+
EXPORT_SYMBOL_GPL(icc_bulk_put);
54+
55+
/**
56+
* icc_bulk_set() - set bandwidth to a set of paths
57+
* @num_paths: the number of icc_bulk_data
58+
* @paths: the icc_bulk_data table containing the paths and bandwidth
59+
*
60+
* Returns 0 on success or negative errno otherwise.
61+
*/
62+
int icc_bulk_set_bw(int num_paths, const struct icc_bulk_data *paths)
63+
{
64+
int ret = 0;
65+
int i;
66+
67+
for (i = 0; i < num_paths; i++) {
68+
ret = icc_set_bw(paths[i].path, paths[i].avg_bw, paths[i].peak_bw);
69+
if (ret) {
70+
pr_err("icc_set_bw() failed on path %s (%d)\n", paths[i].name, ret);
71+
return ret;
72+
}
73+
}
74+
75+
return ret;
76+
}
77+
EXPORT_SYMBOL_GPL(icc_bulk_set_bw);
78+
79+
/**
80+
* icc_bulk_enable() - enable a previously disabled set of paths
81+
* @num_paths: the number of icc_bulk_data
82+
* @paths: the icc_bulk_data table containing the paths and bandwidth
83+
*
84+
* Returns 0 on success or negative errno otherwise.
85+
*/
86+
int icc_bulk_enable(int num_paths, const struct icc_bulk_data *paths)
87+
{
88+
int ret, i;
89+
90+
for (i = 0; i < num_paths; i++) {
91+
ret = icc_enable(paths[i].path);
92+
if (ret) {
93+
pr_err("icc_enable() failed on path %s (%d)\n", paths[i].name, ret);
94+
goto err;
95+
}
96+
}
97+
98+
return 0;
99+
100+
err:
101+
icc_bulk_disable(i, paths);
102+
103+
return ret;
104+
}
105+
EXPORT_SYMBOL_GPL(icc_bulk_enable);
106+
107+
/**
108+
* icc_bulk_disable() - disable a set of interconnect paths
109+
* @num_paths: the number of icc_bulk_data
110+
* @paths: the icc_bulk_data table containing the paths and bandwidth
111+
*/
112+
void icc_bulk_disable(int num_paths, const struct icc_bulk_data *paths)
113+
{
114+
while (--num_paths >= 0)
115+
icc_disable(paths[num_paths].path);
116+
}
117+
EXPORT_SYMBOL_GPL(icc_bulk_disable);

include/linux/interconnect.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,28 @@
2323
struct icc_path;
2424
struct device;
2525

26+
/**
27+
* struct icc_bulk_data - Data used for bulk icc operations.
28+
*
29+
* @path: reference to the interconnect path (internal use)
30+
* @name: the name from the "interconnect-names" DT property
31+
* @avg_bw: average bandwidth in icc units
32+
* @peak_bw: peak bandwidth in icc units
33+
*/
34+
struct icc_bulk_data {
35+
struct icc_path *path;
36+
const char *name;
37+
u32 avg_bw;
38+
u32 peak_bw;
39+
};
40+
41+
int __must_check of_icc_bulk_get(struct device *dev, int num_paths,
42+
struct icc_bulk_data *paths);
43+
void icc_bulk_put(int num_paths, struct icc_bulk_data *paths);
44+
int icc_bulk_set_bw(int num_paths, const struct icc_bulk_data *paths);
45+
int icc_bulk_enable(int num_paths, const struct icc_bulk_data *paths);
46+
void icc_bulk_disable(int num_paths, const struct icc_bulk_data *paths);
47+
2648
#if IS_ENABLED(CONFIG_INTERCONNECT)
2749

2850
struct icc_path *icc_get(struct device *dev, const int src_id,

0 commit comments

Comments
 (0)