Commit | Line | Data |
---|---|---|
11f1ceca GD |
1 | /* SPDX-License-Identifier: GPL-2.0 */ |
2 | /* | |
3 | * Copyright (c) 2018, Linaro Ltd. | |
4 | * Author: Georgi Djakov <georgi.djakov@linaro.org> | |
5 | */ | |
6 | ||
7 | #ifndef __LINUX_INTERCONNECT_PROVIDER_H | |
8 | #define __LINUX_INTERCONNECT_PROVIDER_H | |
9 | ||
10 | #include <linux/interconnect.h> | |
11 | ||
12 | #define icc_units_to_bps(bw) ((bw) * 1000ULL) | |
13 | ||
14 | struct icc_node; | |
87e3031b GD |
15 | struct of_phandle_args; |
16 | ||
1521e22b GD |
17 | /** |
18 | * struct icc_node_data - icc node data | |
19 | * | |
20 | * @node: icc node | |
21 | * @tag: tag | |
22 | */ | |
23 | struct icc_node_data { | |
24 | struct icc_node *node; | |
25 | u32 tag; | |
26 | }; | |
27 | ||
87e3031b GD |
28 | /** |
29 | * struct icc_onecell_data - driver data for onecell interconnect providers | |
30 | * | |
31 | * @num_nodes: number of nodes in this device | |
32 | * @nodes: array of pointers to the nodes in this device | |
33 | */ | |
34 | struct icc_onecell_data { | |
35 | unsigned int num_nodes; | |
dd4904f3 | 36 | struct icc_node *nodes[] __counted_by(num_nodes); |
87e3031b GD |
37 | }; |
38 | ||
0dc5b8ab | 39 | struct icc_node *of_icc_xlate_onecell(const struct of_phandle_args *spec, |
87e3031b | 40 | void *data); |
11f1ceca GD |
41 | |
42 | /** | |
43 | * struct icc_provider - interconnect provider (controller) entity that might | |
44 | * provide multiple interconnect controls | |
45 | * | |
46 | * @provider_list: list of the registered interconnect providers | |
47 | * @nodes: internal list of the interconnect provider nodes | |
48 | * @set: pointer to device specific set operation function | |
49 | * @aggregate: pointer to device specific aggregate operation function | |
cbd5a9c2 GD |
50 | * @pre_aggregate: pointer to device specific function that is called |
51 | * before the aggregation begins (optional) | |
cc80d10d | 52 | * @get_bw: pointer to device specific function to get current bandwidth |
87e3031b | 53 | * @xlate: provider-specific callback for mapping nodes from phandle arguments |
1521e22b | 54 | * @xlate_extended: vendor-specific callback for mapping node data from phandle arguments |
11f1ceca GD |
55 | * @dev: the device this interconnect provider belongs to |
56 | * @users: count of active users | |
65461e26 | 57 | * @inter_set: whether inter-provider pairs will be configured with @set |
11f1ceca GD |
58 | * @data: pointer to private data |
59 | */ | |
60 | struct icc_provider { | |
61 | struct list_head provider_list; | |
62 | struct list_head nodes; | |
63 | int (*set)(struct icc_node *src, struct icc_node *dst); | |
127ab2cc GD |
64 | int (*aggregate)(struct icc_node *node, u32 tag, u32 avg_bw, |
65 | u32 peak_bw, u32 *agg_avg, u32 *agg_peak); | |
cbd5a9c2 | 66 | void (*pre_aggregate)(struct icc_node *node); |
cc80d10d | 67 | int (*get_bw)(struct icc_node *node, u32 *avg, u32 *peak); |
0dc5b8ab KK |
68 | struct icc_node* (*xlate)(const struct of_phandle_args *spec, void *data); |
69 | struct icc_node_data* (*xlate_extended)(const struct of_phandle_args *spec, | |
70 | void *data); | |
11f1ceca GD |
71 | struct device *dev; |
72 | int users; | |
65461e26 | 73 | bool inter_set; |
11f1ceca GD |
74 | void *data; |
75 | }; | |
76 | ||
77 | /** | |
78 | * struct icc_node - entity that is part of the interconnect topology | |
79 | * | |
80 | * @id: platform specific node id | |
81 | * @name: node name used in debugfs | |
82 | * @links: a list of targets pointing to where we can go next when traversing | |
83 | * @num_links: number of links to other interconnect nodes | |
84 | * @provider: points to the interconnect provider of this node | |
85 | * @node_list: the list entry in the parent provider's "nodes" list | |
86 | * @search_list: list used when walking the nodes graph | |
87 | * @reverse: pointer to previous node when walking the nodes graph | |
88 | * @is_traversed: flag that is used when walking the nodes graph | |
89 | * @req_list: a list of QoS constraint requests associated with this node | |
90 | * @avg_bw: aggregated value of average bandwidth requests from all consumers | |
91 | * @peak_bw: aggregated value of peak bandwidth requests from all consumers | |
b1d681d8 GD |
92 | * @init_avg: average bandwidth value that is read from the hardware during init |
93 | * @init_peak: peak bandwidth value that is read from the hardware during init | |
11f1ceca GD |
94 | * @data: pointer to private data |
95 | */ | |
96 | struct icc_node { | |
97 | int id; | |
98 | const char *name; | |
99 | struct icc_node **links; | |
100 | size_t num_links; | |
101 | ||
102 | struct icc_provider *provider; | |
103 | struct list_head node_list; | |
104 | struct list_head search_list; | |
105 | struct icc_node *reverse; | |
106 | u8 is_traversed:1; | |
107 | struct hlist_head req_list; | |
108 | u32 avg_bw; | |
109 | u32 peak_bw; | |
b1d681d8 GD |
110 | u32 init_avg; |
111 | u32 init_peak; | |
11f1ceca GD |
112 | void *data; |
113 | }; | |
114 | ||
115 | #if IS_ENABLED(CONFIG_INTERCONNECT) | |
116 | ||
3172e4d2 GD |
117 | int icc_std_aggregate(struct icc_node *node, u32 tag, u32 avg_bw, |
118 | u32 peak_bw, u32 *agg_avg, u32 *agg_peak); | |
11f1ceca GD |
119 | struct icc_node *icc_node_create(int id); |
120 | void icc_node_destroy(int id); | |
121 | int icc_link_create(struct icc_node *node, const int dst_id); | |
11f1ceca GD |
122 | void icc_node_add(struct icc_node *node, struct icc_provider *provider); |
123 | void icc_node_del(struct icc_node *node); | |
3cce2c6f | 124 | int icc_nodes_remove(struct icc_provider *provider); |
eb59eca0 JH |
125 | void icc_provider_init(struct icc_provider *provider); |
126 | int icc_provider_register(struct icc_provider *provider); | |
127 | void icc_provider_deregister(struct icc_provider *provider); | |
0dc5b8ab | 128 | struct icc_node_data *of_icc_get_from_provider(const struct of_phandle_args *spec); |
b1d681d8 | 129 | void icc_sync_state(struct device *dev); |
11f1ceca GD |
130 | |
131 | #else | |
132 | ||
3172e4d2 GD |
133 | static inline int icc_std_aggregate(struct icc_node *node, u32 tag, u32 avg_bw, |
134 | u32 peak_bw, u32 *agg_avg, u32 *agg_peak) | |
135 | { | |
136 | return -ENOTSUPP; | |
137 | } | |
138 | ||
11f1ceca GD |
139 | static inline struct icc_node *icc_node_create(int id) |
140 | { | |
141 | return ERR_PTR(-ENOTSUPP); | |
142 | } | |
143 | ||
12a400b0 | 144 | static inline void icc_node_destroy(int id) |
11f1ceca GD |
145 | { |
146 | } | |
147 | ||
148 | static inline int icc_link_create(struct icc_node *node, const int dst_id) | |
149 | { | |
150 | return -ENOTSUPP; | |
151 | } | |
152 | ||
12a400b0 | 153 | static inline void icc_node_add(struct icc_node *node, struct icc_provider *provider) |
11f1ceca GD |
154 | { |
155 | } | |
156 | ||
12a400b0 | 157 | static inline void icc_node_del(struct icc_node *node) |
11f1ceca GD |
158 | { |
159 | } | |
160 | ||
3cce2c6f GD |
161 | static inline int icc_nodes_remove(struct icc_provider *provider) |
162 | { | |
163 | return -ENOTSUPP; | |
164 | } | |
165 | ||
eb59eca0 JH |
166 | static inline void icc_provider_init(struct icc_provider *provider) { } |
167 | ||
168 | static inline int icc_provider_register(struct icc_provider *provider) | |
169 | { | |
170 | return -ENOTSUPP; | |
171 | } | |
172 | ||
173 | static inline void icc_provider_deregister(struct icc_provider *provider) { } | |
174 | ||
0dc5b8ab | 175 | static inline struct icc_node_data *of_icc_get_from_provider(const struct of_phandle_args *spec) |
8a307d36 AŚ |
176 | { |
177 | return ERR_PTR(-ENOTSUPP); | |
178 | } | |
179 | ||
11f1ceca GD |
180 | #endif /* CONFIG_INTERCONNECT */ |
181 | ||
182 | #endif /* __LINUX_INTERCONNECT_PROVIDER_H */ |