1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 3 * Copyright (c) 2018, Linaro Ltd. 4 * Author: Georgi Djakov <[email protected]> 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; 15 struct of_phandle_args; 16 17 /** 18 * struct icc_onecell_data - driver data for onecell interconnect providers 19 * 20 * @num_nodes: number of nodes in this device 21 * @nodes: array of pointers to the nodes in this device 22 */ 23 struct icc_onecell_data { 24 unsigned int num_nodes; 25 struct icc_node *nodes[]; 26 }; 27 28 struct icc_node *of_icc_xlate_onecell(struct of_phandle_args *spec, 29 void *data); 30 31 /** 32 * struct icc_provider - interconnect provider (controller) entity that might 33 * provide multiple interconnect controls 34 * 35 * @provider_list: list of the registered interconnect providers 36 * @nodes: internal list of the interconnect provider nodes 37 * @set: pointer to device specific set operation function 38 * @aggregate: pointer to device specific aggregate operation function 39 * @pre_aggregate: pointer to device specific function that is called 40 * before the aggregation begins (optional) 41 * @xlate: provider-specific callback for mapping nodes from phandle arguments 42 * @dev: the device this interconnect provider belongs to 43 * @users: count of active users 44 * @data: pointer to private data 45 */ 46 struct icc_provider { 47 struct list_head provider_list; 48 struct list_head nodes; 49 int (*set)(struct icc_node *src, struct icc_node *dst); 50 int (*aggregate)(struct icc_node *node, u32 tag, u32 avg_bw, 51 u32 peak_bw, u32 *agg_avg, u32 *agg_peak); 52 void (*pre_aggregate)(struct icc_node *node); 53 struct icc_node* (*xlate)(struct of_phandle_args *spec, void *data); 54 struct device *dev; 55 int users; 56 void *data; 57 }; 58 59 /** 60 * struct icc_node - entity that is part of the interconnect topology 61 * 62 * @id: platform specific node id 63 * @name: node name used in debugfs 64 * @links: a list of targets pointing to where we can go next when traversing 65 * @num_links: number of links to other interconnect nodes 66 * @provider: points to the interconnect provider of this node 67 * @node_list: the list entry in the parent provider's "nodes" list 68 * @search_list: list used when walking the nodes graph 69 * @reverse: pointer to previous node when walking the nodes graph 70 * @is_traversed: flag that is used when walking the nodes graph 71 * @req_list: a list of QoS constraint requests associated with this node 72 * @avg_bw: aggregated value of average bandwidth requests from all consumers 73 * @peak_bw: aggregated value of peak bandwidth requests from all consumers 74 * @data: pointer to private data 75 */ 76 struct icc_node { 77 int id; 78 const char *name; 79 struct icc_node **links; 80 size_t num_links; 81 82 struct icc_provider *provider; 83 struct list_head node_list; 84 struct list_head search_list; 85 struct icc_node *reverse; 86 u8 is_traversed:1; 87 struct hlist_head req_list; 88 u32 avg_bw; 89 u32 peak_bw; 90 void *data; 91 }; 92 93 #if IS_ENABLED(CONFIG_INTERCONNECT) 94 95 int icc_std_aggregate(struct icc_node *node, u32 tag, u32 avg_bw, 96 u32 peak_bw, u32 *agg_avg, u32 *agg_peak); 97 struct icc_node *icc_node_create(int id); 98 void icc_node_destroy(int id); 99 int icc_link_create(struct icc_node *node, const int dst_id); 100 int icc_link_destroy(struct icc_node *src, struct icc_node *dst); 101 void icc_node_add(struct icc_node *node, struct icc_provider *provider); 102 void icc_node_del(struct icc_node *node); 103 int icc_nodes_remove(struct icc_provider *provider); 104 int icc_provider_add(struct icc_provider *provider); 105 int icc_provider_del(struct icc_provider *provider); 106 107 #else 108 109 static inline int icc_std_aggregate(struct icc_node *node, u32 tag, u32 avg_bw, 110 u32 peak_bw, u32 *agg_avg, u32 *agg_peak) 111 { 112 return -ENOTSUPP; 113 } 114 115 static inline struct icc_node *icc_node_create(int id) 116 { 117 return ERR_PTR(-ENOTSUPP); 118 } 119 120 void icc_node_destroy(int id) 121 { 122 } 123 124 static inline int icc_link_create(struct icc_node *node, const int dst_id) 125 { 126 return -ENOTSUPP; 127 } 128 129 int icc_link_destroy(struct icc_node *src, struct icc_node *dst) 130 { 131 return -ENOTSUPP; 132 } 133 134 void icc_node_add(struct icc_node *node, struct icc_provider *provider) 135 { 136 } 137 138 void icc_node_del(struct icc_node *node) 139 { 140 } 141 142 static inline int icc_nodes_remove(struct icc_provider *provider) 143 { 144 return -ENOTSUPP; 145 } 146 147 static inline int icc_provider_add(struct icc_provider *provider) 148 { 149 return -ENOTSUPP; 150 } 151 152 static inline int icc_provider_del(struct icc_provider *provider) 153 { 154 return -ENOTSUPP; 155 } 156 157 #endif /* CONFIG_INTERCONNECT */ 158 159 #endif /* __LINUX_INTERCONNECT_PROVIDER_H */ 160