xref: /linux/include/linux/interconnect.h (revision 2fcfa72fc13f0203bb676bd1ec30ec85e17855be)
111f1cecaSGeorgi Djakov /* SPDX-License-Identifier: GPL-2.0 */
211f1cecaSGeorgi Djakov /*
311f1cecaSGeorgi Djakov  * Copyright (c) 2018-2019, Linaro Ltd.
411f1cecaSGeorgi Djakov  * Author: Georgi Djakov <georgi.djakov@linaro.org>
511f1cecaSGeorgi Djakov  */
611f1cecaSGeorgi Djakov 
711f1cecaSGeorgi Djakov #ifndef __LINUX_INTERCONNECT_H
811f1cecaSGeorgi Djakov #define __LINUX_INTERCONNECT_H
911f1cecaSGeorgi Djakov 
1011f1cecaSGeorgi Djakov #include <linux/mutex.h>
1111f1cecaSGeorgi Djakov #include <linux/types.h>
1211f1cecaSGeorgi Djakov 
1311f1cecaSGeorgi Djakov /* macros for converting to icc units */
1411f1cecaSGeorgi Djakov #define Bps_to_icc(x)	((x) / 1000)
1511f1cecaSGeorgi Djakov #define kBps_to_icc(x)	(x)
1611f1cecaSGeorgi Djakov #define MBps_to_icc(x)	((x) * 1000)
1711f1cecaSGeorgi Djakov #define GBps_to_icc(x)	((x) * 1000 * 1000)
1811f1cecaSGeorgi Djakov #define bps_to_icc(x)	(1)
1911f1cecaSGeorgi Djakov #define kbps_to_icc(x)	((x) / 8 + ((x) % 8 ? 1 : 0))
2011f1cecaSGeorgi Djakov #define Mbps_to_icc(x)	((x) * 1000 / 8)
2111f1cecaSGeorgi Djakov #define Gbps_to_icc(x)	((x) * 1000 * 1000 / 8)
2211f1cecaSGeorgi Djakov 
2311f1cecaSGeorgi Djakov struct icc_path;
2411f1cecaSGeorgi Djakov struct device;
2511f1cecaSGeorgi Djakov 
26b41b0ce5SGeorgi Djakov /**
27b41b0ce5SGeorgi Djakov  * struct icc_bulk_data - Data used for bulk icc operations.
28b41b0ce5SGeorgi Djakov  *
29b41b0ce5SGeorgi Djakov  * @path: reference to the interconnect path (internal use)
30b41b0ce5SGeorgi Djakov  * @name: the name from the "interconnect-names" DT property
31b41b0ce5SGeorgi Djakov  * @avg_bw: average bandwidth in icc units
32b41b0ce5SGeorgi Djakov  * @peak_bw: peak bandwidth in icc units
33b41b0ce5SGeorgi Djakov  */
34b41b0ce5SGeorgi Djakov struct icc_bulk_data {
35b41b0ce5SGeorgi Djakov 	struct icc_path	*path;
36b41b0ce5SGeorgi Djakov 	const char *name;
37b41b0ce5SGeorgi Djakov 	u32 avg_bw;
38b41b0ce5SGeorgi Djakov 	u32 peak_bw;
39b41b0ce5SGeorgi Djakov };
40b41b0ce5SGeorgi Djakov 
4111f1cecaSGeorgi Djakov #if IS_ENABLED(CONFIG_INTERCONNECT)
4211f1cecaSGeorgi Djakov 
4311f1cecaSGeorgi Djakov struct icc_path *icc_get(struct device *dev, const int src_id,
4411f1cecaSGeorgi Djakov 			 const int dst_id);
4587e3031bSGeorgi Djakov struct icc_path *of_icc_get(struct device *dev, const char *name);
46e145d9a1SAkash Asthana struct icc_path *devm_of_icc_get(struct device *dev, const char *name);
47*2fcfa72fSPeng Fan int devm_of_icc_bulk_get(struct device *dev, int num_paths, struct icc_bulk_data *paths);
481597d453SGeorgi Djakov struct icc_path *of_icc_get_by_index(struct device *dev, int idx);
4911f1cecaSGeorgi Djakov void icc_put(struct icc_path *path);
507d374b20SGeorgi Djakov int icc_enable(struct icc_path *path);
517d374b20SGeorgi Djakov int icc_disable(struct icc_path *path);
5211f1cecaSGeorgi Djakov int icc_set_bw(struct icc_path *path, u32 avg_bw, u32 peak_bw);
53127ab2ccSGeorgi Djakov void icc_set_tag(struct icc_path *path, u32 tag);
540430b1d5SViresh Kumar const char *icc_get_name(struct icc_path *path);
55e45f1c1dSGeorgi Djakov int __must_check of_icc_bulk_get(struct device *dev, int num_paths,
56e45f1c1dSGeorgi Djakov 				 struct icc_bulk_data *paths);
57e45f1c1dSGeorgi Djakov void icc_bulk_put(int num_paths, struct icc_bulk_data *paths);
58e45f1c1dSGeorgi Djakov int icc_bulk_set_bw(int num_paths, const struct icc_bulk_data *paths);
59e45f1c1dSGeorgi Djakov int icc_bulk_enable(int num_paths, const struct icc_bulk_data *paths);
60e45f1c1dSGeorgi Djakov void icc_bulk_disable(int num_paths, const struct icc_bulk_data *paths);
6111f1cecaSGeorgi Djakov 
6211f1cecaSGeorgi Djakov #else
6311f1cecaSGeorgi Djakov 
6411f1cecaSGeorgi Djakov static inline struct icc_path *icc_get(struct device *dev, const int src_id,
6511f1cecaSGeorgi Djakov 				       const int dst_id)
6611f1cecaSGeorgi Djakov {
6711f1cecaSGeorgi Djakov 	return NULL;
6811f1cecaSGeorgi Djakov }
6911f1cecaSGeorgi Djakov 
7087e3031bSGeorgi Djakov static inline struct icc_path *of_icc_get(struct device *dev,
7187e3031bSGeorgi Djakov 					  const char *name)
7287e3031bSGeorgi Djakov {
7387e3031bSGeorgi Djakov 	return NULL;
7487e3031bSGeorgi Djakov }
7587e3031bSGeorgi Djakov 
76e145d9a1SAkash Asthana static inline struct icc_path *devm_of_icc_get(struct device *dev,
77e145d9a1SAkash Asthana 						const char *name)
78e145d9a1SAkash Asthana {
79e145d9a1SAkash Asthana 	return NULL;
80e145d9a1SAkash Asthana }
81e145d9a1SAkash Asthana 
821597d453SGeorgi Djakov static inline struct icc_path *of_icc_get_by_index(struct device *dev, int idx)
831597d453SGeorgi Djakov {
841597d453SGeorgi Djakov 	return NULL;
851597d453SGeorgi Djakov }
861597d453SGeorgi Djakov 
8711f1cecaSGeorgi Djakov static inline void icc_put(struct icc_path *path)
8811f1cecaSGeorgi Djakov {
8911f1cecaSGeorgi Djakov }
9011f1cecaSGeorgi Djakov 
917d374b20SGeorgi Djakov static inline int icc_enable(struct icc_path *path)
927d374b20SGeorgi Djakov {
937d374b20SGeorgi Djakov 	return 0;
947d374b20SGeorgi Djakov }
957d374b20SGeorgi Djakov 
967d374b20SGeorgi Djakov static inline int icc_disable(struct icc_path *path)
977d374b20SGeorgi Djakov {
987d374b20SGeorgi Djakov 	return 0;
997d374b20SGeorgi Djakov }
1007d374b20SGeorgi Djakov 
10111f1cecaSGeorgi Djakov static inline int icc_set_bw(struct icc_path *path, u32 avg_bw, u32 peak_bw)
10211f1cecaSGeorgi Djakov {
10311f1cecaSGeorgi Djakov 	return 0;
10411f1cecaSGeorgi Djakov }
10511f1cecaSGeorgi Djakov 
106127ab2ccSGeorgi Djakov static inline void icc_set_tag(struct icc_path *path, u32 tag)
107127ab2ccSGeorgi Djakov {
108127ab2ccSGeorgi Djakov }
109127ab2ccSGeorgi Djakov 
1100430b1d5SViresh Kumar static inline const char *icc_get_name(struct icc_path *path)
1110430b1d5SViresh Kumar {
1120430b1d5SViresh Kumar 	return NULL;
1130430b1d5SViresh Kumar }
1140430b1d5SViresh Kumar 
115e45f1c1dSGeorgi Djakov static inline int of_icc_bulk_get(struct device *dev, int num_paths, struct icc_bulk_data *paths)
116e45f1c1dSGeorgi Djakov {
117e45f1c1dSGeorgi Djakov 	return 0;
118e45f1c1dSGeorgi Djakov }
119e45f1c1dSGeorgi Djakov 
120*2fcfa72fSPeng Fan static inline int devm_of_icc_bulk_get(struct device *dev, int num_paths,
121*2fcfa72fSPeng Fan 				       struct icc_bulk_data *paths)
122*2fcfa72fSPeng Fan {
123*2fcfa72fSPeng Fan 	return 0;
124*2fcfa72fSPeng Fan }
125*2fcfa72fSPeng Fan 
126e45f1c1dSGeorgi Djakov static inline void icc_bulk_put(int num_paths, struct icc_bulk_data *paths)
127e45f1c1dSGeorgi Djakov {
128e45f1c1dSGeorgi Djakov }
129e45f1c1dSGeorgi Djakov 
130e45f1c1dSGeorgi Djakov static inline int icc_bulk_set_bw(int num_paths, const struct icc_bulk_data *paths)
131e45f1c1dSGeorgi Djakov {
132e45f1c1dSGeorgi Djakov 	return 0;
133e45f1c1dSGeorgi Djakov }
134e45f1c1dSGeorgi Djakov 
135e45f1c1dSGeorgi Djakov static inline int icc_bulk_enable(int num_paths, const struct icc_bulk_data *paths)
136e45f1c1dSGeorgi Djakov {
137e45f1c1dSGeorgi Djakov 	return 0;
138e45f1c1dSGeorgi Djakov }
139e45f1c1dSGeorgi Djakov 
140e45f1c1dSGeorgi Djakov static inline void icc_bulk_disable(int num_paths, const struct icc_bulk_data *paths)
141e45f1c1dSGeorgi Djakov {
142e45f1c1dSGeorgi Djakov }
143e45f1c1dSGeorgi Djakov 
14411f1cecaSGeorgi Djakov #endif /* CONFIG_INTERCONNECT */
14511f1cecaSGeorgi Djakov 
14611f1cecaSGeorgi Djakov #endif /* __LINUX_INTERCONNECT_H */
147