Georgi Djakov | 11f1cec | 2019-01-16 18:10:56 +0200 | [diff] [blame] | 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; |
Georgi Djakov | 87e3031 | 2019-01-16 18:10:58 +0200 | [diff] [blame] | 15 | struct of_phandle_args; |
| 16 | |
| 17 | /** |
Georgi Djakov | 1521e22 | 2020-09-03 16:31:28 +0300 | [diff] [blame] | 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 | |
| 28 | /** |
Georgi Djakov | 87e3031 | 2019-01-16 18:10:58 +0200 | [diff] [blame] | 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; |
| 36 | struct icc_node *nodes[]; |
| 37 | }; |
| 38 | |
| 39 | struct icc_node *of_icc_xlate_onecell(struct of_phandle_args *spec, |
| 40 | void *data); |
Georgi Djakov | 11f1cec | 2019-01-16 18:10:56 +0200 | [diff] [blame] | 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 |
Georgi Djakov | cbd5a9c | 2019-08-09 15:13:24 +0300 | [diff] [blame] | 50 | * @pre_aggregate: pointer to device specific function that is called |
| 51 | * before the aggregation begins (optional) |
Georgi Djakov | cc80d10 | 2020-08-25 20:01:50 +0300 | [diff] [blame] | 52 | * @get_bw: pointer to device specific function to get current bandwidth |
Georgi Djakov | 87e3031 | 2019-01-16 18:10:58 +0200 | [diff] [blame] | 53 | * @xlate: provider-specific callback for mapping nodes from phandle arguments |
Georgi Djakov | 1521e22 | 2020-09-03 16:31:28 +0300 | [diff] [blame] | 54 | * @xlate_extended: vendor-specific callback for mapping node data from phandle arguments |
Georgi Djakov | 11f1cec | 2019-01-16 18:10:56 +0200 | [diff] [blame] | 55 | * @dev: the device this interconnect provider belongs to |
| 56 | * @users: count of active users |
Artur Świgoń | 65461e26 | 2020-05-21 14:28:41 +0200 | [diff] [blame] | 57 | * @inter_set: whether inter-provider pairs will be configured with @set |
Georgi Djakov | 11f1cec | 2019-01-16 18:10:56 +0200 | [diff] [blame] | 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); |
Georgi Djakov | 127ab2c | 2019-08-09 15:13:23 +0300 | [diff] [blame] | 64 | int (*aggregate)(struct icc_node *node, u32 tag, u32 avg_bw, |
| 65 | u32 peak_bw, u32 *agg_avg, u32 *agg_peak); |
Georgi Djakov | cbd5a9c | 2019-08-09 15:13:24 +0300 | [diff] [blame] | 66 | void (*pre_aggregate)(struct icc_node *node); |
Georgi Djakov | cc80d10 | 2020-08-25 20:01:50 +0300 | [diff] [blame] | 67 | int (*get_bw)(struct icc_node *node, u32 *avg, u32 *peak); |
Georgi Djakov | 87e3031 | 2019-01-16 18:10:58 +0200 | [diff] [blame] | 68 | struct icc_node* (*xlate)(struct of_phandle_args *spec, void *data); |
Georgi Djakov | 1521e22 | 2020-09-03 16:31:28 +0300 | [diff] [blame] | 69 | struct icc_node_data* (*xlate_extended)(struct of_phandle_args *spec, void *data); |
Georgi Djakov | 11f1cec | 2019-01-16 18:10:56 +0200 | [diff] [blame] | 70 | struct device *dev; |
| 71 | int users; |
Artur Świgoń | 65461e26 | 2020-05-21 14:28:41 +0200 | [diff] [blame] | 72 | bool inter_set; |
Georgi Djakov | 11f1cec | 2019-01-16 18:10:56 +0200 | [diff] [blame] | 73 | void *data; |
| 74 | }; |
| 75 | |
| 76 | /** |
| 77 | * struct icc_node - entity that is part of the interconnect topology |
| 78 | * |
| 79 | * @id: platform specific node id |
| 80 | * @name: node name used in debugfs |
| 81 | * @links: a list of targets pointing to where we can go next when traversing |
| 82 | * @num_links: number of links to other interconnect nodes |
| 83 | * @provider: points to the interconnect provider of this node |
| 84 | * @node_list: the list entry in the parent provider's "nodes" list |
| 85 | * @search_list: list used when walking the nodes graph |
| 86 | * @reverse: pointer to previous node when walking the nodes graph |
| 87 | * @is_traversed: flag that is used when walking the nodes graph |
| 88 | * @req_list: a list of QoS constraint requests associated with this node |
| 89 | * @avg_bw: aggregated value of average bandwidth requests from all consumers |
| 90 | * @peak_bw: aggregated value of peak bandwidth requests from all consumers |
Georgi Djakov | b1d681d | 2020-08-25 20:01:51 +0300 | [diff] [blame] | 91 | * @init_avg: average bandwidth value that is read from the hardware during init |
| 92 | * @init_peak: peak bandwidth value that is read from the hardware during init |
Georgi Djakov | 11f1cec | 2019-01-16 18:10:56 +0200 | [diff] [blame] | 93 | * @data: pointer to private data |
| 94 | */ |
| 95 | struct icc_node { |
| 96 | int id; |
| 97 | const char *name; |
| 98 | struct icc_node **links; |
| 99 | size_t num_links; |
| 100 | |
| 101 | struct icc_provider *provider; |
| 102 | struct list_head node_list; |
| 103 | struct list_head search_list; |
| 104 | struct icc_node *reverse; |
| 105 | u8 is_traversed:1; |
| 106 | struct hlist_head req_list; |
| 107 | u32 avg_bw; |
| 108 | u32 peak_bw; |
Georgi Djakov | b1d681d | 2020-08-25 20:01:51 +0300 | [diff] [blame] | 109 | u32 init_avg; |
| 110 | u32 init_peak; |
Georgi Djakov | 11f1cec | 2019-01-16 18:10:56 +0200 | [diff] [blame] | 111 | void *data; |
| 112 | }; |
| 113 | |
| 114 | #if IS_ENABLED(CONFIG_INTERCONNECT) |
| 115 | |
Georgi Djakov | 3172e4d | 2019-11-28 15:48:38 +0200 | [diff] [blame] | 116 | int icc_std_aggregate(struct icc_node *node, u32 tag, u32 avg_bw, |
| 117 | u32 peak_bw, u32 *agg_avg, u32 *agg_peak); |
Georgi Djakov | 11f1cec | 2019-01-16 18:10:56 +0200 | [diff] [blame] | 118 | struct icc_node *icc_node_create(int id); |
| 119 | void icc_node_destroy(int id); |
| 120 | int icc_link_create(struct icc_node *node, const int dst_id); |
| 121 | int icc_link_destroy(struct icc_node *src, struct icc_node *dst); |
| 122 | void icc_node_add(struct icc_node *node, struct icc_provider *provider); |
| 123 | void icc_node_del(struct icc_node *node); |
Georgi Djakov | 3cce2c6 | 2019-12-02 18:21:32 +0200 | [diff] [blame] | 124 | int icc_nodes_remove(struct icc_provider *provider); |
Georgi Djakov | 11f1cec | 2019-01-16 18:10:56 +0200 | [diff] [blame] | 125 | int icc_provider_add(struct icc_provider *provider); |
| 126 | int icc_provider_del(struct icc_provider *provider); |
Georgi Djakov | 1521e22 | 2020-09-03 16:31:28 +0300 | [diff] [blame] | 127 | struct icc_node_data *of_icc_get_from_provider(struct of_phandle_args *spec); |
Georgi Djakov | b1d681d | 2020-08-25 20:01:51 +0300 | [diff] [blame] | 128 | void icc_sync_state(struct device *dev); |
Georgi Djakov | 11f1cec | 2019-01-16 18:10:56 +0200 | [diff] [blame] | 129 | |
| 130 | #else |
| 131 | |
Georgi Djakov | 3172e4d | 2019-11-28 15:48:38 +0200 | [diff] [blame] | 132 | static inline int icc_std_aggregate(struct icc_node *node, u32 tag, u32 avg_bw, |
| 133 | u32 peak_bw, u32 *agg_avg, u32 *agg_peak) |
| 134 | { |
| 135 | return -ENOTSUPP; |
| 136 | } |
| 137 | |
Georgi Djakov | 11f1cec | 2019-01-16 18:10:56 +0200 | [diff] [blame] | 138 | static inline struct icc_node *icc_node_create(int id) |
| 139 | { |
| 140 | return ERR_PTR(-ENOTSUPP); |
| 141 | } |
| 142 | |
Georgi Djakov | 12a400b | 2020-06-16 16:43:23 +0300 | [diff] [blame] | 143 | static inline void icc_node_destroy(int id) |
Georgi Djakov | 11f1cec | 2019-01-16 18:10:56 +0200 | [diff] [blame] | 144 | { |
| 145 | } |
| 146 | |
| 147 | static inline int icc_link_create(struct icc_node *node, const int dst_id) |
| 148 | { |
| 149 | return -ENOTSUPP; |
| 150 | } |
| 151 | |
Georgi Djakov | 12a400b | 2020-06-16 16:43:23 +0300 | [diff] [blame] | 152 | static inline int icc_link_destroy(struct icc_node *src, struct icc_node *dst) |
Georgi Djakov | 11f1cec | 2019-01-16 18:10:56 +0200 | [diff] [blame] | 153 | { |
| 154 | return -ENOTSUPP; |
| 155 | } |
| 156 | |
Georgi Djakov | 12a400b | 2020-06-16 16:43:23 +0300 | [diff] [blame] | 157 | static inline void icc_node_add(struct icc_node *node, struct icc_provider *provider) |
Georgi Djakov | 11f1cec | 2019-01-16 18:10:56 +0200 | [diff] [blame] | 158 | { |
| 159 | } |
| 160 | |
Georgi Djakov | 12a400b | 2020-06-16 16:43:23 +0300 | [diff] [blame] | 161 | static inline void icc_node_del(struct icc_node *node) |
Georgi Djakov | 11f1cec | 2019-01-16 18:10:56 +0200 | [diff] [blame] | 162 | { |
| 163 | } |
| 164 | |
Georgi Djakov | 3cce2c6 | 2019-12-02 18:21:32 +0200 | [diff] [blame] | 165 | static inline int icc_nodes_remove(struct icc_provider *provider) |
| 166 | { |
| 167 | return -ENOTSUPP; |
| 168 | } |
| 169 | |
Georgi Djakov | 11f1cec | 2019-01-16 18:10:56 +0200 | [diff] [blame] | 170 | static inline int icc_provider_add(struct icc_provider *provider) |
| 171 | { |
| 172 | return -ENOTSUPP; |
| 173 | } |
| 174 | |
| 175 | static inline int icc_provider_del(struct icc_provider *provider) |
| 176 | { |
| 177 | return -ENOTSUPP; |
| 178 | } |
| 179 | |
Georgi Djakov | 1521e22 | 2020-09-03 16:31:28 +0300 | [diff] [blame] | 180 | static inline struct icc_node_data *of_icc_get_from_provider(struct of_phandle_args *spec) |
Artur Świgoń | 8a307d3 | 2020-05-21 14:28:39 +0200 | [diff] [blame] | 181 | { |
| 182 | return ERR_PTR(-ENOTSUPP); |
| 183 | } |
| 184 | |
Georgi Djakov | 11f1cec | 2019-01-16 18:10:56 +0200 | [diff] [blame] | 185 | #endif /* CONFIG_INTERCONNECT */ |
| 186 | |
| 187 | #endif /* __LINUX_INTERCONNECT_PROVIDER_H */ |