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>
This commit is contained in:
Georgi Djakov 2020-07-29 15:34:39 +03:00
Родитель 91e045b93d
Коммит b41b0ce598
3 изменённых файлов: 140 добавлений и 1 удалений

Просмотреть файл

@ -1,7 +1,7 @@
# SPDX-License-Identifier: GPL-2.0
CFLAGS_core.o := -I$(src)
icc-core-objs := core.o
icc-core-objs := core.o bulk.o
obj-$(CONFIG_INTERCONNECT) += icc-core.o
obj-$(CONFIG_INTERCONNECT_IMX) += imx/

117
drivers/interconnect/bulk.c Normal file
Просмотреть файл

@ -0,0 +1,117 @@
// SPDX-License-Identifier: GPL-2.0
#include <linux/interconnect-provider.h>
#include <linux/device.h>
#include <linux/export.h>
/**
* of_icc_bulk_get() - get interconnect paths
* @dev: the device requesting the path
* @num_paths: the number of icc_bulk_data
* @paths: the table with the paths we want to get
*
* Returns 0 on success or negative errno otherwise.
*/
int __must_check of_icc_bulk_get(struct device *dev, int num_paths,
struct icc_bulk_data *paths)
{
int ret, i;
for (i = 0; i < num_paths; i++) {
paths[i].path = of_icc_get(dev, paths[i].name);
if (IS_ERR(paths[i].path)) {
ret = PTR_ERR(paths[i].path);
if (ret != -EPROBE_DEFER)
dev_err(dev, "of_icc_get() failed on path %s (%d)\n",
paths[i].name, ret);
paths[i].path = NULL;
goto err;
}
}
return 0;
err:
icc_bulk_put(i, paths);
return ret;
}
EXPORT_SYMBOL_GPL(of_icc_bulk_get);
/**
* icc_bulk_put() - put a list of interconnect paths
* @num_paths: the number of icc_bulk_data
* @paths: the icc_bulk_data table with the paths being put
*/
void icc_bulk_put(int num_paths, struct icc_bulk_data *paths)
{
while (--num_paths >= 0) {
icc_put(paths[num_paths].path);
paths[num_paths].path = NULL;
}
}
EXPORT_SYMBOL_GPL(icc_bulk_put);
/**
* icc_bulk_set() - set bandwidth to a set of paths
* @num_paths: the number of icc_bulk_data
* @paths: the icc_bulk_data table containing the paths and bandwidth
*
* Returns 0 on success or negative errno otherwise.
*/
int icc_bulk_set_bw(int num_paths, const struct icc_bulk_data *paths)
{
int ret = 0;
int i;
for (i = 0; i < num_paths; i++) {
ret = icc_set_bw(paths[i].path, paths[i].avg_bw, paths[i].peak_bw);
if (ret) {
pr_err("icc_set_bw() failed on path %s (%d)\n", paths[i].name, ret);
return ret;
}
}
return ret;
}
EXPORT_SYMBOL_GPL(icc_bulk_set_bw);
/**
* icc_bulk_enable() - enable a previously disabled set of paths
* @num_paths: the number of icc_bulk_data
* @paths: the icc_bulk_data table containing the paths and bandwidth
*
* Returns 0 on success or negative errno otherwise.
*/
int icc_bulk_enable(int num_paths, const struct icc_bulk_data *paths)
{
int ret, i;
for (i = 0; i < num_paths; i++) {
ret = icc_enable(paths[i].path);
if (ret) {
pr_err("icc_enable() failed on path %s (%d)\n", paths[i].name, ret);
goto err;
}
}
return 0;
err:
icc_bulk_disable(i, paths);
return ret;
}
EXPORT_SYMBOL_GPL(icc_bulk_enable);
/**
* icc_bulk_disable() - disable a set of interconnect paths
* @num_paths: the number of icc_bulk_data
* @paths: the icc_bulk_data table containing the paths and bandwidth
*/
void icc_bulk_disable(int num_paths, const struct icc_bulk_data *paths)
{
while (--num_paths >= 0)
icc_disable(paths[num_paths].path);
}
EXPORT_SYMBOL_GPL(icc_bulk_disable);

Просмотреть файл

@ -23,6 +23,28 @@
struct icc_path;
struct device;
/**
* struct icc_bulk_data - Data used for bulk icc operations.
*
* @path: reference to the interconnect path (internal use)
* @name: the name from the "interconnect-names" DT property
* @avg_bw: average bandwidth in icc units
* @peak_bw: peak bandwidth in icc units
*/
struct icc_bulk_data {
struct icc_path *path;
const char *name;
u32 avg_bw;
u32 peak_bw;
};
int __must_check of_icc_bulk_get(struct device *dev, int num_paths,
struct icc_bulk_data *paths);
void icc_bulk_put(int num_paths, struct icc_bulk_data *paths);
int icc_bulk_set_bw(int num_paths, const struct icc_bulk_data *paths);
int icc_bulk_enable(int num_paths, const struct icc_bulk_data *paths);
void icc_bulk_disable(int num_paths, const struct icc_bulk_data *paths);
#if IS_ENABLED(CONFIG_INTERCONNECT)
struct icc_path *icc_get(struct device *dev, const int src_id,