Lines Matching +full:dt +full:- +full:node

1 // SPDX-License-Identifier: GPL-2.0
5 * Copyright (c) 2017-2019, Linaro Ltd.
14 #include <linux/interconnect-provider.h>
39 seq_printf(s, "%-42s %12u %12u\n", in icc_summary_show_one()
40 n->name, n->avg_bw, n->peak_bw); in icc_summary_show_one()
47 seq_puts(s, " node tag avg peak\n"); in icc_summary_show()
48 seq_puts(s, "--------------------------------------------------------------------\n"); in icc_summary_show()
55 list_for_each_entry(n, &provider->nodes, node_list) { in icc_summary_show()
59 hlist_for_each_entry(r, &n->req_list, req_node) { in icc_summary_show()
62 if (!r->dev) in icc_summary_show()
65 if (r->enabled) { in icc_summary_show()
66 avg_bw = r->avg_bw; in icc_summary_show()
67 peak_bw = r->peak_bw; in icc_summary_show()
70 seq_printf(s, " %-27s %12u %12u %12u\n", in icc_summary_show()
71 dev_name(r->dev), r->tag, avg_bw, peak_bw); in icc_summary_show()
85 seq_printf(s, "%s\"%d:%s\" -> \"%d:%s\"\n", in icc_graph_show_link()
87 n->id, n->name, m->id, m->name); in icc_graph_show_link()
93 n->id, n->name, n->id, n->name); in icc_graph_show_node()
94 seq_printf(s, "\n\t\t\t|avg_bw=%ukBps", n->avg_bw); in icc_graph_show_node()
95 seq_printf(s, "\n\t\t\t|peak_bw=%ukBps", n->peak_bw); in icc_graph_show_node()
113 if (provider->dev) in icc_graph_show()
115 dev_name(provider->dev)); in icc_graph_show()
118 list_for_each_entry(n, &provider->nodes, node_list) in icc_graph_show()
122 list_for_each_entry(n, &provider->nodes, node_list) in icc_graph_show()
123 for (i = 0; i < n->num_links; ++i) in icc_graph_show()
124 if (n->provider == n->links[i]->provider) in icc_graph_show()
126 n->links[i]); in icc_graph_show()
133 list_for_each_entry(n, &provider->nodes, node_list) in icc_graph_show()
134 for (i = 0; i < n->num_links; ++i) in icc_graph_show()
135 if (n->provider != n->links[i]->provider) in icc_graph_show()
137 n->links[i]); in icc_graph_show()
157 list_for_each_entry(n, &provider->nodes, node_list) { in node_find_by_name()
158 if (!strcmp(n->name, name)) in node_find_by_name()
169 struct icc_node *node = dst; in path_init() local
175 return ERR_PTR(-ENOMEM); in path_init()
177 path->num_nodes = num_nodes; in path_init()
179 for (i = num_nodes - 1; i >= 0; i--) { in path_init()
180 node->provider->users++; in path_init()
181 hlist_add_head(&path->reqs[i].req_node, &node->req_list); in path_init()
182 path->reqs[i].node = node; in path_init()
183 path->reqs[i].dev = dev; in path_init()
184 path->reqs[i].enabled = true; in path_init()
185 /* reference to previous node was saved during path traversal */ in path_init()
186 node = node->reverse; in path_init()
195 struct icc_path *path = ERR_PTR(-EPROBE_DEFER); in path_find()
196 struct icc_node *n, *node = NULL; in path_find() local
207 list_add(&src->search_list, &traverse_list); in path_find()
208 src->reverse = NULL; in path_find()
211 list_for_each_entry_safe(node, n, &traverse_list, search_list) { in path_find()
212 if (node == dst) { in path_find()
218 for (i = 0; i < node->num_links; i++) { in path_find()
219 struct icc_node *tmp = node->links[i]; in path_find()
222 path = ERR_PTR(-ENOENT); in path_find()
226 if (tmp->is_traversed) in path_find()
229 tmp->is_traversed = true; in path_find()
230 tmp->reverse = node; in path_find()
231 list_add_tail(&tmp->search_list, &edge_list); in path_find()
250 n->is_traversed = false; in path_find()
260 * bandwidth requirements from each consumer are aggregated at each node.
265 static int aggregate_requests(struct icc_node *node) in aggregate_requests() argument
267 struct icc_provider *p = node->provider; in aggregate_requests()
271 node->avg_bw = 0; in aggregate_requests()
272 node->peak_bw = 0; in aggregate_requests()
274 if (p->pre_aggregate) in aggregate_requests()
275 p->pre_aggregate(node); in aggregate_requests()
277 hlist_for_each_entry(r, &node->req_list, req_node) { in aggregate_requests()
278 if (r->enabled) { in aggregate_requests()
279 avg_bw = r->avg_bw; in aggregate_requests()
280 peak_bw = r->peak_bw; in aggregate_requests()
285 p->aggregate(node, r->tag, avg_bw, peak_bw, in aggregate_requests()
286 &node->avg_bw, &node->peak_bw); in aggregate_requests()
290 node->avg_bw = max(node->avg_bw, node->init_avg); in aggregate_requests()
291 node->peak_bw = max(node->peak_bw, node->init_peak); in aggregate_requests()
302 int ret = -EINVAL; in apply_constraints()
305 for (i = 0; i < path->num_nodes; i++) { in apply_constraints()
306 next = path->reqs[i].node; in apply_constraints()
307 p = next->provider; in apply_constraints()
309 /* both endpoints should be valid master-slave pairs */ in apply_constraints()
310 if (!prev || (p != prev->provider && !p->inter_set)) { in apply_constraints()
316 ret = p->set(prev, next); in apply_constraints()
326 int icc_std_aggregate(struct icc_node *node, u32 tag, u32 avg_bw, in icc_std_aggregate() argument
336 /* of_icc_xlate_onecell() - Translate function using a single index.
337 * @spec: OF phandle args to map into an interconnect node.
341 * interconnect providers that have one device tree node and provide
350 unsigned int idx = spec->args[0]; in of_icc_xlate_onecell()
352 if (idx >= icc_data->num_nodes) { in of_icc_xlate_onecell()
354 return ERR_PTR(-EINVAL); in of_icc_xlate_onecell()
357 return icc_data->nodes[idx]; in of_icc_xlate_onecell()
362 * of_icc_get_from_provider() - Look-up interconnect node
363 * @spec: OF phandle args to use for look-up
365 * Looks for interconnect provider under the node specified by @spec and if
366 * found, uses xlate function of the provider to map phandle args to node.
373 struct icc_node *node = ERR_PTR(-EPROBE_DEFER); in of_icc_get_from_provider() local
378 return ERR_PTR(-EINVAL); in of_icc_get_from_provider()
382 if (provider->dev->of_node == spec->np) { in of_icc_get_from_provider()
383 if (provider->xlate_extended) { in of_icc_get_from_provider()
384 data = provider->xlate_extended(spec, provider->data); in of_icc_get_from_provider()
386 node = data->node; in of_icc_get_from_provider()
390 node = provider->xlate(spec, provider->data); in of_icc_get_from_provider()
391 if (!IS_ERR(node)) in of_icc_get_from_provider()
398 if (!node) in of_icc_get_from_provider()
399 return ERR_PTR(-EINVAL); in of_icc_get_from_provider()
401 if (IS_ERR(node)) in of_icc_get_from_provider()
402 return ERR_CAST(node); in of_icc_get_from_provider()
407 return ERR_PTR(-ENOMEM); in of_icc_get_from_provider()
408 data->node = node; in of_icc_get_from_provider()
426 return ERR_PTR(-ENOMEM); in devm_of_icc_get()
441 * of_icc_get_by_index() - get a path handle from a DT node based on index
453 * when the API is disabled or the "interconnects" DT property is missing.
463 if (!dev || !dev->of_node) in of_icc_get_by_index()
464 return ERR_PTR(-ENODEV); in of_icc_get_by_index()
466 np = dev->of_node; in of_icc_get_by_index()
469 * When the consumer DT node do not have "interconnects" property in of_icc_get_by_index()
478 * without breaking DT compatibility. in of_icc_get_by_index()
481 "#interconnect-cells", idx * 2, in of_icc_get_by_index()
489 "#interconnect-cells", idx * 2 + 1, in of_icc_get_by_index()
499 dev_err_probe(dev, PTR_ERR(src_data), "error finding src node\n"); in of_icc_get_by_index()
506 dev_err_probe(dev, PTR_ERR(dst_data), "error finding dst node\n"); in of_icc_get_by_index()
512 path = path_find(dev, src_data->node, dst_data->node); in of_icc_get_by_index()
519 if (src_data->tag && src_data->tag == dst_data->tag) in of_icc_get_by_index()
520 icc_set_tag(path, src_data->tag); in of_icc_get_by_index()
522 path->name = kasprintf(GFP_KERNEL, "%s-%s", in of_icc_get_by_index()
523 src_data->node->name, dst_data->node->name); in of_icc_get_by_index()
524 if (!path->name) { in of_icc_get_by_index()
526 path = ERR_PTR(-ENOMEM); in of_icc_get_by_index()
537 * of_icc_get() - get a path handle from a DT node based on name
549 * when the API is disabled or the "interconnects" DT property is missing.
556 if (!dev || !dev->of_node) in of_icc_get()
557 return ERR_PTR(-ENODEV); in of_icc_get()
559 np = dev->of_node; in of_icc_get()
562 * When the consumer DT node do not have "interconnects" property in of_icc_get()
571 * without breaking DT compatibility. in of_icc_get()
574 idx = of_property_match_string(np, "interconnect-names", name); in of_icc_get()
584 * icc_get() - get a path handle between two endpoints
586 * @src: source node name
587 * @dst: destination node name
599 struct icc_path *path = ERR_PTR(-EPROBE_DEFER); in icc_get()
621 path->name = kasprintf(GFP_KERNEL, "%s-%s", src_node->name, dst_node->name); in icc_get()
622 if (!path->name) { in icc_get()
624 path = ERR_PTR(-ENOMEM); in icc_get()
632 * icc_set_tag() - set an optional tag on a path
648 for (i = 0; i < path->num_nodes; i++) in icc_set_tag()
649 path->reqs[i].tag = tag; in icc_set_tag()
656 * icc_get_name() - Get name of the icc path
669 return path->name; in icc_get_name()
674 * icc_set_bw() - set bandwidth constraints on an interconnect path
681 * The requests are aggregated and each node is updated accordingly. The entire
683 * The @path can be NULL when the "interconnects" DT properties is missing,
690 struct icc_node *node; in icc_set_bw() local
698 if (WARN_ON(IS_ERR(path) || !path->num_nodes)) in icc_set_bw()
699 return -EINVAL; in icc_set_bw()
703 old_avg = path->reqs[0].avg_bw; in icc_set_bw()
704 old_peak = path->reqs[0].peak_bw; in icc_set_bw()
706 for (i = 0; i < path->num_nodes; i++) { in icc_set_bw()
707 node = path->reqs[i].node; in icc_set_bw()
710 path->reqs[i].avg_bw = avg_bw; in icc_set_bw()
711 path->reqs[i].peak_bw = peak_bw; in icc_set_bw()
713 /* aggregate requests for this node */ in icc_set_bw()
714 aggregate_requests(node); in icc_set_bw()
716 trace_icc_set_bw(path, node, i, avg_bw, peak_bw); in icc_set_bw()
724 for (i = 0; i < path->num_nodes; i++) { in icc_set_bw()
725 node = path->reqs[i].node; in icc_set_bw()
726 path->reqs[i].avg_bw = old_avg; in icc_set_bw()
727 path->reqs[i].peak_bw = old_peak; in icc_set_bw()
728 aggregate_requests(node); in icc_set_bw()
748 if (WARN_ON(IS_ERR(path) || !path->num_nodes)) in __icc_enable()
749 return -EINVAL; in __icc_enable()
753 for (i = 0; i < path->num_nodes; i++) in __icc_enable()
754 path->reqs[i].enabled = enable; in __icc_enable()
758 return icc_set_bw(path, path->reqs[0].avg_bw, in __icc_enable()
759 path->reqs[0].peak_bw); in __icc_enable()
775 * icc_put() - release the reference to the icc_path
779 * no longer needed. The constraints will be re-aggregated.
783 struct icc_node *node; in icc_put() local
795 for (i = 0; i < path->num_nodes; i++) { in icc_put()
796 node = path->reqs[i].node; in icc_put()
797 hlist_del(&path->reqs[i].req_node); in icc_put()
798 if (!WARN_ON(!node->provider->users)) in icc_put()
799 node->provider->users--; in icc_put()
803 kfree_const(path->name); in icc_put()
810 struct icc_node *node; in icc_node_create_nolock() local
812 /* check if node already exists */ in icc_node_create_nolock()
813 node = node_find(id); in icc_node_create_nolock()
814 if (node) in icc_node_create_nolock()
815 return node; in icc_node_create_nolock()
817 node = kzalloc(sizeof(*node), GFP_KERNEL); in icc_node_create_nolock()
818 if (!node) in icc_node_create_nolock()
819 return ERR_PTR(-ENOMEM); in icc_node_create_nolock()
821 id = idr_alloc(&icc_idr, node, id, id + 1, GFP_KERNEL); in icc_node_create_nolock()
824 kfree(node); in icc_node_create_nolock()
828 node->id = id; in icc_node_create_nolock()
830 return node; in icc_node_create_nolock()
834 * icc_node_create() - create a node
835 * @id: node id
841 struct icc_node *node; in icc_node_create() local
845 node = icc_node_create_nolock(id); in icc_node_create()
849 return node; in icc_node_create()
854 * icc_node_destroy() - destroy a node
855 * @id: node id
859 struct icc_node *node; in icc_node_destroy() local
863 node = node_find(id); in icc_node_destroy()
864 if (node) { in icc_node_destroy()
865 idr_remove(&icc_idr, node->id); in icc_node_destroy()
866 WARN_ON(!hlist_empty(&node->req_list)); in icc_node_destroy()
871 if (!node) in icc_node_destroy()
874 kfree(node->links); in icc_node_destroy()
875 kfree(node); in icc_node_destroy()
880 * icc_link_create() - create a link between two nodes
881 * @node: source node id
882 * @dst_id: destination node id
885 * interconnect providers and the @dst_id node might not exist (if the
886 * provider driver has not probed yet). So just create the @dst_id node
887 * and when the actual provider driver is probed, the rest of the node
892 int icc_link_create(struct icc_node *node, const int dst_id) in icc_link_create() argument
898 if (!node->provider) in icc_link_create()
899 return -EINVAL; in icc_link_create()
913 new = krealloc(node->links, in icc_link_create()
914 (node->num_links + 1) * sizeof(*node->links), in icc_link_create()
917 ret = -ENOMEM; in icc_link_create()
921 node->links = new; in icc_link_create()
922 node->links[node->num_links++] = dst; in icc_link_create()
932 * icc_node_add() - add interconnect node to interconnect provider
933 * @node: pointer to the interconnect node
936 void icc_node_add(struct icc_node *node, struct icc_provider *provider) in icc_node_add() argument
938 if (WARN_ON(node->provider)) in icc_node_add()
944 node->provider = provider; in icc_node_add()
945 list_add_tail(&node->node_list, &provider->nodes); in icc_node_add()
948 if (provider->get_bw) { in icc_node_add()
949 provider->get_bw(node, &node->init_avg, &node->init_peak); in icc_node_add()
951 node->init_avg = INT_MAX; in icc_node_add()
952 node->init_peak = INT_MAX; in icc_node_add()
954 node->avg_bw = node->init_avg; in icc_node_add()
955 node->peak_bw = node->init_peak; in icc_node_add()
957 if (node->avg_bw || node->peak_bw) { in icc_node_add()
958 if (provider->pre_aggregate) in icc_node_add()
959 provider->pre_aggregate(node); in icc_node_add()
961 if (provider->aggregate) in icc_node_add()
962 provider->aggregate(node, 0, node->init_avg, node->init_peak, in icc_node_add()
963 &node->avg_bw, &node->peak_bw); in icc_node_add()
964 if (provider->set) in icc_node_add()
965 provider->set(node, node); in icc_node_add()
968 node->avg_bw = 0; in icc_node_add()
969 node->peak_bw = 0; in icc_node_add()
977 * icc_node_del() - delete interconnect node from interconnect provider
978 * @node: pointer to the interconnect node
980 void icc_node_del(struct icc_node *node) in icc_node_del() argument
984 list_del(&node->node_list); in icc_node_del()
991 * icc_nodes_remove() - remove all previously added nodes from provider
1001 return -EINVAL; in icc_nodes_remove()
1003 list_for_each_entry_safe_reverse(n, tmp, &provider->nodes, node_list) { in icc_nodes_remove()
1005 icc_node_destroy(n->id); in icc_nodes_remove()
1013 * icc_provider_init() - initialize a new interconnect provider
1020 WARN_ON(!provider->set); in icc_provider_init()
1022 INIT_LIST_HEAD(&provider->nodes); in icc_provider_init()
1027 * icc_provider_register() - register a new interconnect provider
1034 if (WARN_ON(!provider->xlate && !provider->xlate_extended)) in icc_provider_register()
1035 return -EINVAL; in icc_provider_register()
1038 list_add_tail(&provider->provider_list, &icc_providers); in icc_provider_register()
1041 dev_dbg(provider->dev, "interconnect provider registered\n"); in icc_provider_register()
1048 * icc_provider_deregister() - deregister an interconnect provider
1054 WARN_ON(provider->users); in icc_provider_deregister()
1056 list_del(&provider->provider_list); in icc_provider_deregister()
1062 { .compatible = "qcom,sc7180-ipa-virt" },
1063 { .compatible = "qcom,sc8180x-ipa-virt" },
1064 { .compatible = "qcom,sdx55-ipa-virt" },
1065 { .compatible = "qcom,sm8150-ipa-virt" },
1066 { .compatible = "qcom,sm8250-ipa-virt" },
1076 if (of_property_read_bool(child, "#interconnect-cells") && in of_count_icc_providers()
1100 dev_dbg(p->dev, "interconnect provider is in synced state\n"); in icc_sync_state()
1101 list_for_each_entry(n, &p->nodes, node_list) { in icc_sync_state()
1102 if (n->init_avg || n->init_peak) { in icc_sync_state()
1103 n->init_avg = 0; in icc_sync_state()
1104 n->init_peak = 0; in icc_sync_state()
1106 p->set(n, n); in icc_sync_state()