Lines Matching +full:node +full:- +full:id
1 // SPDX-License-Identifier: GPL-2.0
5 * Copyright (c) 2017-2019, Linaro Ltd.
14 #include <linux/interconnect-provider.h>
41 seq_printf(s, "%-42s %12u %12u\n", in icc_summary_show_one()
42 n->name, n->avg_bw, n->peak_bw); in icc_summary_show_one()
49 seq_puts(s, " node tag avg peak\n"); in icc_summary_show()
50 seq_puts(s, "--------------------------------------------------------------------\n"); in icc_summary_show()
57 list_for_each_entry(n, &provider->nodes, node_list) { in icc_summary_show()
61 hlist_for_each_entry(r, &n->req_list, req_node) { in icc_summary_show()
64 if (!r->dev) in icc_summary_show()
67 if (r->enabled) { in icc_summary_show()
68 avg_bw = r->avg_bw; in icc_summary_show()
69 peak_bw = r->peak_bw; in icc_summary_show()
72 seq_printf(s, " %-27s %12u %12u %12u\n", in icc_summary_show()
73 dev_name(r->dev), r->tag, avg_bw, peak_bw); in icc_summary_show()
87 seq_printf(s, "%s\"%d:%s\" -> \"%d:%s\"\n", in icc_graph_show_link()
89 n->id, n->name, m->id, m->name); in icc_graph_show_link()
95 n->id, n->name, n->id, n->name); in icc_graph_show_node()
96 seq_printf(s, "\n\t\t\t|avg_bw=%ukBps", n->avg_bw); in icc_graph_show_node()
97 seq_printf(s, "\n\t\t\t|peak_bw=%ukBps", n->peak_bw); in icc_graph_show_node()
115 if (provider->dev) in icc_graph_show()
117 dev_name(provider->dev)); in icc_graph_show()
120 list_for_each_entry(n, &provider->nodes, node_list) in icc_graph_show()
124 list_for_each_entry(n, &provider->nodes, node_list) in icc_graph_show()
125 for (i = 0; i < n->num_links; ++i) in icc_graph_show()
126 if (n->provider == n->links[i]->provider) in icc_graph_show()
128 n->links[i]); in icc_graph_show()
135 list_for_each_entry(n, &provider->nodes, node_list) in icc_graph_show()
136 for (i = 0; i < n->num_links; ++i) in icc_graph_show()
137 if (n->provider != n->links[i]->provider) in icc_graph_show()
139 n->links[i]); in icc_graph_show()
148 static struct icc_node *node_find(const int id) in node_find() argument
150 return idr_find(&icc_idr, id); in node_find()
159 list_for_each_entry(n, &provider->nodes, node_list) { in node_find_by_name()
160 if (!strcmp(n->name, name)) in node_find_by_name()
171 struct icc_node *node = dst; in path_init() local
177 return ERR_PTR(-ENOMEM); in path_init()
179 path->num_nodes = num_nodes; in path_init()
183 for (i = num_nodes - 1; i >= 0; i--) { in path_init()
184 node->provider->users++; in path_init()
185 hlist_add_head(&path->reqs[i].req_node, &node->req_list); in path_init()
186 path->reqs[i].node = node; in path_init()
187 path->reqs[i].dev = dev; in path_init()
188 path->reqs[i].enabled = true; in path_init()
189 /* reference to previous node was saved during path traversal */ in path_init()
190 node = node->reverse; in path_init()
201 struct icc_path *path = ERR_PTR(-EPROBE_DEFER); in path_find()
202 struct icc_node *n, *node = NULL; in path_find() local
213 list_add(&src->search_list, &traverse_list); in path_find()
214 src->reverse = NULL; in path_find()
217 list_for_each_entry_safe(node, n, &traverse_list, search_list) { in path_find()
218 if (node == dst) { in path_find()
224 for (i = 0; i < node->num_links; i++) { in path_find()
225 struct icc_node *tmp = node->links[i]; in path_find()
228 path = ERR_PTR(-ENOENT); in path_find()
232 if (tmp->is_traversed) in path_find()
235 tmp->is_traversed = true; in path_find()
236 tmp->reverse = node; in path_find()
237 list_add_tail(&tmp->search_list, &edge_list); in path_find()
256 n->is_traversed = false; in path_find()
266 * bandwidth requirements from each consumer are aggregated at each node.
271 static int aggregate_requests(struct icc_node *node) in aggregate_requests() argument
273 struct icc_provider *p = node->provider; in aggregate_requests()
277 node->avg_bw = 0; in aggregate_requests()
278 node->peak_bw = 0; in aggregate_requests()
280 if (p->pre_aggregate) in aggregate_requests()
281 p->pre_aggregate(node); in aggregate_requests()
283 hlist_for_each_entry(r, &node->req_list, req_node) { in aggregate_requests()
284 if (r->enabled) { in aggregate_requests()
285 avg_bw = r->avg_bw; in aggregate_requests()
286 peak_bw = r->peak_bw; in aggregate_requests()
291 p->aggregate(node, r->tag, avg_bw, peak_bw, in aggregate_requests()
292 &node->avg_bw, &node->peak_bw); in aggregate_requests()
296 node->avg_bw = max(node->avg_bw, node->init_avg); in aggregate_requests()
297 node->peak_bw = max(node->peak_bw, node->init_peak); in aggregate_requests()
308 int ret = -EINVAL; in apply_constraints()
311 for (i = 0; i < path->num_nodes; i++) { in apply_constraints()
312 next = path->reqs[i].node; in apply_constraints()
313 p = next->provider; in apply_constraints()
315 /* both endpoints should be valid master-slave pairs */ in apply_constraints()
316 if (!prev || (p != prev->provider && !p->inter_set)) { in apply_constraints()
322 ret = p->set(prev, next); in apply_constraints()
332 int icc_std_aggregate(struct icc_node *node, u32 tag, u32 avg_bw, in icc_std_aggregate() argument
342 /* of_icc_xlate_onecell() - Translate function using a single index.
343 * @spec: OF phandle args to map into an interconnect node.
347 * interconnect providers that have one device tree node and provide
356 unsigned int idx = spec->args[0]; in of_icc_xlate_onecell()
358 if (idx >= icc_data->num_nodes) { in of_icc_xlate_onecell()
360 return ERR_PTR(-EINVAL); in of_icc_xlate_onecell()
363 return icc_data->nodes[idx]; in of_icc_xlate_onecell()
368 * of_icc_get_from_provider() - Look-up interconnect node
369 * @spec: OF phandle args to use for look-up
371 * Looks for interconnect provider under the node specified by @spec and if
372 * found, uses xlate function of the provider to map phandle args to node.
379 struct icc_node *node = ERR_PTR(-EPROBE_DEFER); in of_icc_get_from_provider() local
384 return ERR_PTR(-EINVAL); in of_icc_get_from_provider()
388 if (device_match_of_node(provider->dev, spec->np)) { in of_icc_get_from_provider()
389 if (provider->xlate_extended) { in of_icc_get_from_provider()
390 data = provider->xlate_extended(spec, provider->data); in of_icc_get_from_provider()
392 node = data->node; in of_icc_get_from_provider()
396 node = provider->xlate(spec, provider->data); in of_icc_get_from_provider()
397 if (!IS_ERR(node)) in of_icc_get_from_provider()
404 if (!node) in of_icc_get_from_provider()
405 return ERR_PTR(-EINVAL); in of_icc_get_from_provider()
407 if (IS_ERR(node)) in of_icc_get_from_provider()
408 return ERR_CAST(node); in of_icc_get_from_provider()
413 return ERR_PTR(-ENOMEM); in of_icc_get_from_provider()
414 data->node = node; in of_icc_get_from_provider()
432 return ERR_PTR(-ENOMEM); in devm_of_icc_get()
452 return ERR_PTR(-ENOMEM); in devm_of_icc_get_by_index()
467 * of_icc_get_by_index() - get a path handle from a DT node based on index
489 if (!dev || !dev->of_node) in of_icc_get_by_index()
490 return ERR_PTR(-ENODEV); in of_icc_get_by_index()
492 np = dev->of_node; in of_icc_get_by_index()
495 * When the consumer DT node do not have "interconnects" property in of_icc_get_by_index()
507 "#interconnect-cells", idx * 2, in of_icc_get_by_index()
515 "#interconnect-cells", idx * 2 + 1, in of_icc_get_by_index()
525 dev_err_probe(dev, PTR_ERR(src_data), "error finding src node\n"); in of_icc_get_by_index()
532 dev_err_probe(dev, PTR_ERR(dst_data), "error finding dst node\n"); in of_icc_get_by_index()
538 path = path_find(dev, src_data->node, dst_data->node); in of_icc_get_by_index()
545 if (src_data->tag && src_data->tag == dst_data->tag) in of_icc_get_by_index()
546 icc_set_tag(path, src_data->tag); in of_icc_get_by_index()
548 path->name = kasprintf(GFP_KERNEL, "%s-%s", in of_icc_get_by_index()
549 src_data->node->name, dst_data->node->name); in of_icc_get_by_index()
550 if (!path->name) { in of_icc_get_by_index()
552 path = ERR_PTR(-ENOMEM); in of_icc_get_by_index()
563 * of_icc_get() - get a path handle from a DT node based on name
582 if (!dev || !dev->of_node) in of_icc_get()
583 return ERR_PTR(-ENODEV); in of_icc_get()
585 np = dev->of_node; in of_icc_get()
588 * When the consumer DT node do not have "interconnects" property in of_icc_get()
600 idx = of_property_match_string(np, "interconnect-names", name); in of_icc_get()
610 * icc_get() - get a path handle between two endpoints
612 * @src: source node name
613 * @dst: destination node name
625 struct icc_path *path = ERR_PTR(-EPROBE_DEFER); in icc_get()
647 path->name = kasprintf(GFP_KERNEL, "%s-%s", src_node->name, dst_node->name); in icc_get()
648 if (!path->name) { in icc_get()
650 path = ERR_PTR(-ENOMEM); in icc_get()
658 * icc_set_tag() - set an optional tag on a path
674 for (i = 0; i < path->num_nodes; i++) in icc_set_tag()
675 path->reqs[i].tag = tag; in icc_set_tag()
682 * icc_get_name() - Get name of the icc path
695 return path->name; in icc_get_name()
700 * icc_set_bw() - set bandwidth constraints on an interconnect path
707 * The requests are aggregated and each node is updated accordingly. The entire
716 struct icc_node *node; in icc_set_bw() local
724 if (WARN_ON(IS_ERR(path) || !path->num_nodes)) in icc_set_bw()
725 return -EINVAL; in icc_set_bw()
729 old_avg = path->reqs[0].avg_bw; in icc_set_bw()
730 old_peak = path->reqs[0].peak_bw; in icc_set_bw()
732 for (i = 0; i < path->num_nodes; i++) { in icc_set_bw()
733 node = path->reqs[i].node; in icc_set_bw()
736 path->reqs[i].avg_bw = avg_bw; in icc_set_bw()
737 path->reqs[i].peak_bw = peak_bw; in icc_set_bw()
739 /* aggregate requests for this node */ in icc_set_bw()
740 aggregate_requests(node); in icc_set_bw()
742 trace_icc_set_bw(path, node, i, avg_bw, peak_bw); in icc_set_bw()
750 for (i = 0; i < path->num_nodes; i++) { in icc_set_bw()
751 node = path->reqs[i].node; in icc_set_bw()
752 path->reqs[i].avg_bw = old_avg; in icc_set_bw()
753 path->reqs[i].peak_bw = old_peak; in icc_set_bw()
754 aggregate_requests(node); in icc_set_bw()
774 if (WARN_ON(IS_ERR(path) || !path->num_nodes)) in __icc_enable()
775 return -EINVAL; in __icc_enable()
779 for (i = 0; i < path->num_nodes; i++) in __icc_enable()
780 path->reqs[i].enabled = enable; in __icc_enable()
784 return icc_set_bw(path, path->reqs[0].avg_bw, in __icc_enable()
785 path->reqs[0].peak_bw); in __icc_enable()
801 * icc_put() - release the reference to the icc_path
805 * no longer needed. The constraints will be re-aggregated.
809 struct icc_node *node; in icc_put() local
823 for (i = 0; i < path->num_nodes; i++) { in icc_put()
824 node = path->reqs[i].node; in icc_put()
825 hlist_del(&path->reqs[i].req_node); in icc_put()
826 if (!WARN_ON(!node->provider->users)) in icc_put()
827 node->provider->users--; in icc_put()
833 kfree(path->name); in icc_put()
838 static struct icc_node *icc_node_create_nolock(int id) in icc_node_create_nolock() argument
840 struct icc_node *node; in icc_node_create_nolock() local
842 if (id >= ICC_DYN_ID_START) in icc_node_create_nolock()
843 return ERR_PTR(-EINVAL); in icc_node_create_nolock()
845 /* check if node already exists */ in icc_node_create_nolock()
846 node = node_find(id); in icc_node_create_nolock()
847 if (node) in icc_node_create_nolock()
848 return node; in icc_node_create_nolock()
850 node = kzalloc_obj(*node); in icc_node_create_nolock()
851 if (!node) in icc_node_create_nolock()
852 return ERR_PTR(-ENOMEM); in icc_node_create_nolock()
854 /* dynamic id allocation */ in icc_node_create_nolock()
855 if (id == ICC_ALLOC_DYN_ID) in icc_node_create_nolock()
856 id = idr_alloc(&icc_idr, node, ICC_DYN_ID_START, 0, GFP_KERNEL); in icc_node_create_nolock()
858 id = idr_alloc(&icc_idr, node, id, id + 1, GFP_KERNEL); in icc_node_create_nolock()
860 if (id < 0) { in icc_node_create_nolock()
862 kfree(node); in icc_node_create_nolock()
863 return ERR_PTR(id); in icc_node_create_nolock()
866 node->id = id; in icc_node_create_nolock()
868 return node; in icc_node_create_nolock()
872 * icc_node_create_dyn() - create a node with dynamic id
878 struct icc_node *node; in icc_node_create_dyn() local
882 node = icc_node_create_nolock(ICC_ALLOC_DYN_ID); in icc_node_create_dyn()
886 return node; in icc_node_create_dyn()
891 * icc_node_create() - create a node
892 * @id: node id
896 struct icc_node *icc_node_create(int id) in icc_node_create() argument
898 struct icc_node *node; in icc_node_create() local
902 node = icc_node_create_nolock(id); in icc_node_create()
906 return node; in icc_node_create()
911 * icc_node_destroy() - destroy a node
912 * @id: node id
914 void icc_node_destroy(int id) in icc_node_destroy() argument
916 struct icc_node *node; in icc_node_destroy() local
920 node = node_find(id); in icc_node_destroy()
921 if (node) { in icc_node_destroy()
922 idr_remove(&icc_idr, node->id); in icc_node_destroy()
923 WARN_ON(!hlist_empty(&node->req_list)); in icc_node_destroy()
928 if (!node) in icc_node_destroy()
931 kfree(node->links); in icc_node_destroy()
932 if (node->id >= ICC_DYN_ID_START) in icc_node_destroy()
933 kfree(node->name); in icc_node_destroy()
934 kfree(node); in icc_node_destroy()
939 * icc_node_set_name() - set node name
940 * @node: node
941 * @provider: node provider
942 * @name: node name
944 * Return: 0 on success, or -ENOMEM on allocation failure
946 int icc_node_set_name(struct icc_node *node, const struct icc_provider *provider, const char *name) in icc_node_set_name() argument
948 if (node->id >= ICC_DYN_ID_START) { in icc_node_set_name()
949 node->name = kasprintf(GFP_KERNEL, "%s@%s", name, in icc_node_set_name()
950 dev_name(provider->dev)); in icc_node_set_name()
951 if (!node->name) in icc_node_set_name()
952 return -ENOMEM; in icc_node_set_name()
954 node->name = name; in icc_node_set_name()
962 * icc_link_nodes() - create link between two nodes
963 * @src_node: source node
964 * @dst_node: destination node
969 * and when the actual provider driver is probed, the rest of the node
979 if (!src_node->provider) in icc_link_nodes()
980 return -EINVAL; in icc_link_nodes()
993 new = krealloc(src_node->links, in icc_link_nodes()
994 (src_node->num_links + 1) * sizeof(*src_node->links), in icc_link_nodes()
997 ret = -ENOMEM; in icc_link_nodes()
1001 src_node->links = new; in icc_link_nodes()
1002 src_node->links[src_node->num_links++] = *dst_node; in icc_link_nodes()
1012 * icc_link_create() - create a link between two nodes
1013 * @node: source node id
1014 * @dst_id: destination node id
1017 * interconnect providers and the @dst_id node might not exist (if the
1018 * provider driver has not probed yet). So just create the @dst_id node
1019 * and when the actual provider driver is probed, the rest of the node
1024 int icc_link_create(struct icc_node *node, const int dst_id) in icc_link_create() argument
1030 if (!node->provider) in icc_link_create()
1031 return -EINVAL; in icc_link_create()
1045 new = krealloc(node->links, in icc_link_create()
1046 (node->num_links + 1) * sizeof(*node->links), in icc_link_create()
1049 ret = -ENOMEM; in icc_link_create()
1053 node->links = new; in icc_link_create()
1054 node->links[node->num_links++] = dst; in icc_link_create()
1064 * icc_node_add() - add interconnect node to interconnect provider
1065 * @node: pointer to the interconnect node
1068 void icc_node_add(struct icc_node *node, struct icc_provider *provider) in icc_node_add() argument
1070 if (WARN_ON(node->provider)) in icc_node_add()
1076 node->provider = provider; in icc_node_add()
1077 list_add_tail(&node->node_list, &provider->nodes); in icc_node_add()
1080 if (provider->get_bw) { in icc_node_add()
1081 provider->get_bw(node, &node->init_avg, &node->init_peak); in icc_node_add()
1083 node->init_avg = INT_MAX; in icc_node_add()
1084 node->init_peak = INT_MAX; in icc_node_add()
1086 node->avg_bw = node->init_avg; in icc_node_add()
1087 node->peak_bw = node->init_peak; in icc_node_add()
1089 if (node->avg_bw || node->peak_bw) { in icc_node_add()
1090 if (provider->pre_aggregate) in icc_node_add()
1091 provider->pre_aggregate(node); in icc_node_add()
1093 if (provider->aggregate) in icc_node_add()
1094 provider->aggregate(node, 0, node->init_avg, node->init_peak, in icc_node_add()
1095 &node->avg_bw, &node->peak_bw); in icc_node_add()
1096 if (provider->set) in icc_node_add()
1097 provider->set(node, node); in icc_node_add()
1100 node->avg_bw = 0; in icc_node_add()
1101 node->peak_bw = 0; in icc_node_add()
1109 * icc_node_del() - delete interconnect node from interconnect provider
1110 * @node: pointer to the interconnect node
1112 void icc_node_del(struct icc_node *node) in icc_node_del() argument
1116 list_del(&node->node_list); in icc_node_del()
1123 * icc_nodes_remove() - remove all previously added nodes from provider
1133 return -EINVAL; in icc_nodes_remove()
1135 list_for_each_entry_safe_reverse(n, tmp, &provider->nodes, node_list) { in icc_nodes_remove()
1137 icc_node_destroy(n->id); in icc_nodes_remove()
1145 * icc_provider_init() - initialize a new interconnect provider
1152 WARN_ON(!provider->set); in icc_provider_init()
1154 INIT_LIST_HEAD(&provider->nodes); in icc_provider_init()
1159 * icc_provider_register() - register a new interconnect provider
1166 if (WARN_ON(!provider->xlate && !provider->xlate_extended)) in icc_provider_register()
1167 return -EINVAL; in icc_provider_register()
1170 list_add_tail(&provider->provider_list, &icc_providers); in icc_provider_register()
1173 dev_dbg(provider->dev, "interconnect provider registered\n"); in icc_provider_register()
1180 * icc_provider_deregister() - deregister an interconnect provider
1186 WARN_ON(provider->users); in icc_provider_deregister()
1188 list_del(&provider->provider_list); in icc_provider_deregister()
1194 { .compatible = "qcom,sc7180-ipa-virt" },
1195 { .compatible = "qcom,sc8180x-ipa-virt" },
1196 { .compatible = "qcom,sdx55-ipa-virt" },
1197 { .compatible = "qcom,sm8150-ipa-virt" },
1198 { .compatible = "qcom,sm8250-ipa-virt" },
1208 if (of_property_present(child, "#interconnect-cells") && in of_count_icc_providers()
1232 dev_dbg(p->dev, "interconnect provider is in synced state\n"); in icc_sync_state()
1233 list_for_each_entry(n, &p->nodes, node_list) { in icc_sync_state()
1234 if (n->init_avg || n->init_peak) { in icc_sync_state()
1235 n->init_avg = 0; in icc_sync_state()
1236 n->init_peak = 0; in icc_sync_state()
1238 p->set(n, n); in icc_sync_state()