xref: /linux/include/linux/interconnect.h (revision e45f1c1d70cae0d7a28ad60f9c6391e210354f0b)
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);
471597d453SGeorgi Djakov struct icc_path *of_icc_get_by_index(struct device *dev, int idx);
4811f1cecaSGeorgi Djakov void icc_put(struct icc_path *path);
497d374b20SGeorgi Djakov int icc_enable(struct icc_path *path);
507d374b20SGeorgi Djakov int icc_disable(struct icc_path *path);
5111f1cecaSGeorgi Djakov int icc_set_bw(struct icc_path *path, u32 avg_bw, u32 peak_bw);
52127ab2ccSGeorgi Djakov void icc_set_tag(struct icc_path *path, u32 tag);
530430b1d5SViresh Kumar const char *icc_get_name(struct icc_path *path);
54*e45f1c1dSGeorgi Djakov int __must_check of_icc_bulk_get(struct device *dev, int num_paths,
55*e45f1c1dSGeorgi Djakov 				 struct icc_bulk_data *paths);
56*e45f1c1dSGeorgi Djakov void icc_bulk_put(int num_paths, struct icc_bulk_data *paths);
57*e45f1c1dSGeorgi Djakov int icc_bulk_set_bw(int num_paths, const struct icc_bulk_data *paths);
58*e45f1c1dSGeorgi Djakov int icc_bulk_enable(int num_paths, const struct icc_bulk_data *paths);
59*e45f1c1dSGeorgi Djakov void icc_bulk_disable(int num_paths, const struct icc_bulk_data *paths);
6011f1cecaSGeorgi Djakov 
6111f1cecaSGeorgi Djakov #else
6211f1cecaSGeorgi Djakov 
6311f1cecaSGeorgi Djakov static inline struct icc_path *icc_get(struct device *dev, const int src_id,
6411f1cecaSGeorgi Djakov 				       const int dst_id)
6511f1cecaSGeorgi Djakov {
6611f1cecaSGeorgi Djakov 	return NULL;
6711f1cecaSGeorgi Djakov }
6811f1cecaSGeorgi Djakov 
6987e3031bSGeorgi Djakov static inline struct icc_path *of_icc_get(struct device *dev,
7087e3031bSGeorgi Djakov 					  const char *name)
7187e3031bSGeorgi Djakov {
7287e3031bSGeorgi Djakov 	return NULL;
7387e3031bSGeorgi Djakov }
7487e3031bSGeorgi Djakov 
75e145d9a1SAkash Asthana static inline struct icc_path *devm_of_icc_get(struct device *dev,
76e145d9a1SAkash Asthana 						const char *name)
77e145d9a1SAkash Asthana {
78e145d9a1SAkash Asthana 	return NULL;
79e145d9a1SAkash Asthana }
80e145d9a1SAkash Asthana 
811597d453SGeorgi Djakov static inline struct icc_path *of_icc_get_by_index(struct device *dev, int idx)
821597d453SGeorgi Djakov {
831597d453SGeorgi Djakov 	return NULL;
841597d453SGeorgi Djakov }
851597d453SGeorgi Djakov 
8611f1cecaSGeorgi Djakov static inline void icc_put(struct icc_path *path)
8711f1cecaSGeorgi Djakov {
8811f1cecaSGeorgi Djakov }
8911f1cecaSGeorgi Djakov 
907d374b20SGeorgi Djakov static inline int icc_enable(struct icc_path *path)
917d374b20SGeorgi Djakov {
927d374b20SGeorgi Djakov 	return 0;
937d374b20SGeorgi Djakov }
947d374b20SGeorgi Djakov 
957d374b20SGeorgi Djakov static inline int icc_disable(struct icc_path *path)
967d374b20SGeorgi Djakov {
977d374b20SGeorgi Djakov 	return 0;
987d374b20SGeorgi Djakov }
997d374b20SGeorgi Djakov 
10011f1cecaSGeorgi Djakov static inline int icc_set_bw(struct icc_path *path, u32 avg_bw, u32 peak_bw)
10111f1cecaSGeorgi Djakov {
10211f1cecaSGeorgi Djakov 	return 0;
10311f1cecaSGeorgi Djakov }
10411f1cecaSGeorgi Djakov 
105127ab2ccSGeorgi Djakov static inline void icc_set_tag(struct icc_path *path, u32 tag)
106127ab2ccSGeorgi Djakov {
107127ab2ccSGeorgi Djakov }
108127ab2ccSGeorgi Djakov 
1090430b1d5SViresh Kumar static inline const char *icc_get_name(struct icc_path *path)
1100430b1d5SViresh Kumar {
1110430b1d5SViresh Kumar 	return NULL;
1120430b1d5SViresh Kumar }
1130430b1d5SViresh Kumar 
114*e45f1c1dSGeorgi Djakov static inline int of_icc_bulk_get(struct device *dev, int num_paths, struct icc_bulk_data *paths)
115*e45f1c1dSGeorgi Djakov {
116*e45f1c1dSGeorgi Djakov 	return 0;
117*e45f1c1dSGeorgi Djakov }
118*e45f1c1dSGeorgi Djakov 
119*e45f1c1dSGeorgi Djakov static inline void icc_bulk_put(int num_paths, struct icc_bulk_data *paths)
120*e45f1c1dSGeorgi Djakov {
121*e45f1c1dSGeorgi Djakov }
122*e45f1c1dSGeorgi Djakov 
123*e45f1c1dSGeorgi Djakov static inline int icc_bulk_set_bw(int num_paths, const struct icc_bulk_data *paths)
124*e45f1c1dSGeorgi Djakov {
125*e45f1c1dSGeorgi Djakov 	return 0;
126*e45f1c1dSGeorgi Djakov }
127*e45f1c1dSGeorgi Djakov 
128*e45f1c1dSGeorgi Djakov static inline int icc_bulk_enable(int num_paths, const struct icc_bulk_data *paths)
129*e45f1c1dSGeorgi Djakov {
130*e45f1c1dSGeorgi Djakov 	return 0;
131*e45f1c1dSGeorgi Djakov }
132*e45f1c1dSGeorgi Djakov 
133*e45f1c1dSGeorgi Djakov static inline void icc_bulk_disable(int num_paths, const struct icc_bulk_data *paths)
134*e45f1c1dSGeorgi Djakov {
135*e45f1c1dSGeorgi Djakov }
136*e45f1c1dSGeorgi Djakov 
13711f1cecaSGeorgi Djakov #endif /* CONFIG_INTERCONNECT */
13811f1cecaSGeorgi Djakov 
13911f1cecaSGeorgi Djakov #endif /* __LINUX_INTERCONNECT_H */
140