1 // SPDX-License-Identifier: GPL-2.0
3 * Interconnect framework core driver
5 * Copyright (c) 2017-2019, Linaro Ltd.
6 * Author: Georgi Djakov <georgi.djakov@linaro.org>
9 #include <linux/debugfs.h>
10 #include <linux/device.h>
11 #include <linux/idr.h>
12 #include <linux/init.h>
13 #include <linux/interconnect.h>
14 #include <linux/interconnect-provider.h>
15 #include <linux/list.h>
16 #include <linux/mutex.h>
17 #include <linux/slab.h>
19 #include <linux/overflow.h>
23 #define CREATE_TRACE_POINTS
26 static DEFINE_IDR(icc_idr);
27 static LIST_HEAD(icc_providers);
28 static int providers_count;
29 static bool synced_state;
30 static DEFINE_MUTEX(icc_lock);
31 static struct dentry *icc_debugfs_dir;
33 static void icc_summary_show_one(struct seq_file *s, struct icc_node *n)
38 seq_printf(s, "%-42s %12u %12u\n",
39 n->name, n->avg_bw, n->peak_bw);
42 static int icc_summary_show(struct seq_file *s, void *data)
44 struct icc_provider *provider;
46 seq_puts(s, " node tag avg peak\n");
47 seq_puts(s, "--------------------------------------------------------------------\n");
49 mutex_lock(&icc_lock);
51 list_for_each_entry(provider, &icc_providers, provider_list) {
54 list_for_each_entry(n, &provider->nodes, node_list) {
57 icc_summary_show_one(s, n);
58 hlist_for_each_entry(r, &n->req_list, req_node) {
59 u32 avg_bw = 0, peak_bw = 0;
69 seq_printf(s, " %-27s %12u %12u %12u\n",
70 dev_name(r->dev), r->tag, avg_bw, peak_bw);
75 mutex_unlock(&icc_lock);
79 DEFINE_SHOW_ATTRIBUTE(icc_summary);
81 static void icc_graph_show_link(struct seq_file *s, int level,
82 struct icc_node *n, struct icc_node *m)
84 seq_printf(s, "%s\"%d:%s\" -> \"%d:%s\"\n",
85 level == 2 ? "\t\t" : "\t",
86 n->id, n->name, m->id, m->name);
89 static void icc_graph_show_node(struct seq_file *s, struct icc_node *n)
91 seq_printf(s, "\t\t\"%d:%s\" [label=\"%d:%s",
92 n->id, n->name, n->id, n->name);
93 seq_printf(s, "\n\t\t\t|avg_bw=%ukBps", n->avg_bw);
94 seq_printf(s, "\n\t\t\t|peak_bw=%ukBps", n->peak_bw);
98 static int icc_graph_show(struct seq_file *s, void *data)
100 struct icc_provider *provider;
102 int cluster_index = 0;
105 seq_puts(s, "digraph {\n\trankdir = LR\n\tnode [shape = record]\n");
106 mutex_lock(&icc_lock);
108 /* draw providers as cluster subgraphs */
110 list_for_each_entry(provider, &icc_providers, provider_list) {
111 seq_printf(s, "\tsubgraph cluster_%d {\n", ++cluster_index);
113 seq_printf(s, "\t\tlabel = \"%s\"\n",
114 dev_name(provider->dev));
117 list_for_each_entry(n, &provider->nodes, node_list)
118 icc_graph_show_node(s, n);
120 /* draw internal links */
121 list_for_each_entry(n, &provider->nodes, node_list)
122 for (i = 0; i < n->num_links; ++i)
123 if (n->provider == n->links[i]->provider)
124 icc_graph_show_link(s, 2, n,
127 seq_puts(s, "\t}\n");
130 /* draw external links */
131 list_for_each_entry(provider, &icc_providers, provider_list)
132 list_for_each_entry(n, &provider->nodes, node_list)
133 for (i = 0; i < n->num_links; ++i)
134 if (n->provider != n->links[i]->provider)
135 icc_graph_show_link(s, 1, n,
138 mutex_unlock(&icc_lock);
143 DEFINE_SHOW_ATTRIBUTE(icc_graph);
145 static struct icc_node *node_find(const int id)
147 return idr_find(&icc_idr, id);
150 static struct icc_node *node_find_by_name(const char *name)
152 struct icc_provider *provider;
155 list_for_each_entry(provider, &icc_providers, provider_list) {
156 list_for_each_entry(n, &provider->nodes, node_list) {
157 if (!strcmp(n->name, name))
165 static struct icc_path *path_init(struct device *dev, struct icc_node *dst,
168 struct icc_node *node = dst;
169 struct icc_path *path;
172 path = kzalloc(struct_size(path, reqs, num_nodes), GFP_KERNEL);
174 return ERR_PTR(-ENOMEM);
176 path->num_nodes = num_nodes;
178 for (i = num_nodes - 1; i >= 0; i--) {
179 node->provider->users++;
180 hlist_add_head(&path->reqs[i].req_node, &node->req_list);
181 path->reqs[i].node = node;
182 path->reqs[i].dev = dev;
183 path->reqs[i].enabled = true;
184 /* reference to previous node was saved during path traversal */
185 node = node->reverse;
191 static struct icc_path *path_find(struct device *dev, struct icc_node *src,
192 struct icc_node *dst)
194 struct icc_path *path = ERR_PTR(-EPROBE_DEFER);
195 struct icc_node *n, *node = NULL;
196 struct list_head traverse_list;
197 struct list_head edge_list;
198 struct list_head visited_list;
202 INIT_LIST_HEAD(&traverse_list);
203 INIT_LIST_HEAD(&edge_list);
204 INIT_LIST_HEAD(&visited_list);
206 list_add(&src->search_list, &traverse_list);
210 list_for_each_entry_safe(node, n, &traverse_list, search_list) {
213 list_splice_init(&edge_list, &visited_list);
214 list_splice_init(&traverse_list, &visited_list);
217 for (i = 0; i < node->num_links; i++) {
218 struct icc_node *tmp = node->links[i];
221 path = ERR_PTR(-ENOENT);
225 if (tmp->is_traversed)
228 tmp->is_traversed = true;
230 list_add_tail(&tmp->search_list, &edge_list);
237 list_splice_init(&traverse_list, &visited_list);
238 list_splice_init(&edge_list, &traverse_list);
240 /* count the hops including the source */
243 } while (!list_empty(&traverse_list));
247 /* reset the traversed state */
248 list_for_each_entry_reverse(n, &visited_list, search_list)
249 n->is_traversed = false;
252 path = path_init(dev, dst, depth);
258 * We want the path to honor all bandwidth requests, so the average and peak
259 * bandwidth requirements from each consumer are aggregated at each node.
260 * The aggregation is platform specific, so each platform can customize it by
261 * implementing its own aggregate() function.
264 static int aggregate_requests(struct icc_node *node)
266 struct icc_provider *p = node->provider;
273 if (p->pre_aggregate)
274 p->pre_aggregate(node);
276 hlist_for_each_entry(r, &node->req_list, req_node) {
279 peak_bw = r->peak_bw;
284 p->aggregate(node, r->tag, avg_bw, peak_bw,
285 &node->avg_bw, &node->peak_bw);
287 /* during boot use the initial bandwidth as a floor value */
289 node->avg_bw = max(node->avg_bw, node->init_avg);
290 node->peak_bw = max(node->peak_bw, node->init_peak);
297 static int apply_constraints(struct icc_path *path)
299 struct icc_node *next, *prev = NULL;
300 struct icc_provider *p;
304 for (i = 0; i < path->num_nodes; i++) {
305 next = path->reqs[i].node;
308 /* both endpoints should be valid master-slave pairs */
309 if (!prev || (p != prev->provider && !p->inter_set)) {
314 /* set the constraints */
315 ret = p->set(prev, next);
325 int icc_std_aggregate(struct icc_node *node, u32 tag, u32 avg_bw,
326 u32 peak_bw, u32 *agg_avg, u32 *agg_peak)
329 *agg_peak = max(*agg_peak, peak_bw);
333 EXPORT_SYMBOL_GPL(icc_std_aggregate);
335 /* of_icc_xlate_onecell() - Translate function using a single index.
336 * @spec: OF phandle args to map into an interconnect node.
337 * @data: private data (pointer to struct icc_onecell_data)
339 * This is a generic translate function that can be used to model simple
340 * interconnect providers that have one device tree node and provide
341 * multiple interconnect nodes. A single cell is used as an index into
342 * an array of icc nodes specified in the icc_onecell_data struct when
343 * registering the provider.
345 struct icc_node *of_icc_xlate_onecell(struct of_phandle_args *spec,
348 struct icc_onecell_data *icc_data = data;
349 unsigned int idx = spec->args[0];
351 if (idx >= icc_data->num_nodes) {
352 pr_err("%s: invalid index %u\n", __func__, idx);
353 return ERR_PTR(-EINVAL);
356 return icc_data->nodes[idx];
358 EXPORT_SYMBOL_GPL(of_icc_xlate_onecell);
361 * of_icc_get_from_provider() - Look-up interconnect node
362 * @spec: OF phandle args to use for look-up
364 * Looks for interconnect provider under the node specified by @spec and if
365 * found, uses xlate function of the provider to map phandle args to node.
367 * Returns a valid pointer to struct icc_node_data on success or ERR_PTR()
370 struct icc_node_data *of_icc_get_from_provider(struct of_phandle_args *spec)
372 struct icc_node *node = ERR_PTR(-EPROBE_DEFER);
373 struct icc_node_data *data = NULL;
374 struct icc_provider *provider;
377 return ERR_PTR(-EINVAL);
379 mutex_lock(&icc_lock);
380 list_for_each_entry(provider, &icc_providers, provider_list) {
381 if (provider->dev->of_node == spec->np) {
382 if (provider->xlate_extended) {
383 data = provider->xlate_extended(spec, provider->data);
389 node = provider->xlate(spec, provider->data);
395 mutex_unlock(&icc_lock);
398 return ERR_CAST(node);
401 data = kzalloc(sizeof(*data), GFP_KERNEL);
403 return ERR_PTR(-ENOMEM);
409 EXPORT_SYMBOL_GPL(of_icc_get_from_provider);
411 static void devm_icc_release(struct device *dev, void *res)
413 icc_put(*(struct icc_path **)res);
416 struct icc_path *devm_of_icc_get(struct device *dev, const char *name)
418 struct icc_path **ptr, *path;
420 ptr = devres_alloc(devm_icc_release, sizeof(*ptr), GFP_KERNEL);
422 return ERR_PTR(-ENOMEM);
424 path = of_icc_get(dev, name);
427 devres_add(dev, ptr);
434 EXPORT_SYMBOL_GPL(devm_of_icc_get);
437 * of_icc_get_by_index() - get a path handle from a DT node based on index
438 * @dev: device pointer for the consumer device
439 * @idx: interconnect path index
441 * This function will search for a path between two endpoints and return an
442 * icc_path handle on success. Use icc_put() to release constraints when they
443 * are not needed anymore.
444 * If the interconnect API is disabled, NULL is returned and the consumer
445 * drivers will still build. Drivers are free to handle this specifically,
446 * but they don't have to.
448 * Return: icc_path pointer on success or ERR_PTR() on error. NULL is returned
449 * when the API is disabled or the "interconnects" DT property is missing.
451 struct icc_path *of_icc_get_by_index(struct device *dev, int idx)
453 struct icc_path *path;
454 struct icc_node_data *src_data, *dst_data;
455 struct device_node *np;
456 struct of_phandle_args src_args, dst_args;
459 if (!dev || !dev->of_node)
460 return ERR_PTR(-ENODEV);
465 * When the consumer DT node do not have "interconnects" property
466 * return a NULL path to skip setting constraints.
468 if (!of_property_present(np, "interconnects"))
472 * We use a combination of phandle and specifier for endpoint. For now
473 * lets support only global ids and extend this in the future if needed
474 * without breaking DT compatibility.
476 ret = of_parse_phandle_with_args(np, "interconnects",
477 "#interconnect-cells", idx * 2,
482 of_node_put(src_args.np);
484 ret = of_parse_phandle_with_args(np, "interconnects",
485 "#interconnect-cells", idx * 2 + 1,
490 of_node_put(dst_args.np);
492 src_data = of_icc_get_from_provider(&src_args);
494 if (IS_ERR(src_data)) {
495 dev_err_probe(dev, PTR_ERR(src_data), "error finding src node\n");
496 return ERR_CAST(src_data);
499 dst_data = of_icc_get_from_provider(&dst_args);
501 if (IS_ERR(dst_data)) {
502 dev_err_probe(dev, PTR_ERR(dst_data), "error finding dst node\n");
504 return ERR_CAST(dst_data);
507 mutex_lock(&icc_lock);
508 path = path_find(dev, src_data->node, dst_data->node);
509 mutex_unlock(&icc_lock);
511 dev_err(dev, "%s: invalid path=%ld\n", __func__, PTR_ERR(path));
515 if (src_data->tag && src_data->tag == dst_data->tag)
516 icc_set_tag(path, src_data->tag);
518 path->name = kasprintf(GFP_KERNEL, "%s-%s",
519 src_data->node->name, dst_data->node->name);
522 path = ERR_PTR(-ENOMEM);
530 EXPORT_SYMBOL_GPL(of_icc_get_by_index);
533 * of_icc_get() - get a path handle from a DT node based on name
534 * @dev: device pointer for the consumer device
535 * @name: interconnect path name
537 * This function will search for a path between two endpoints and return an
538 * icc_path handle on success. Use icc_put() to release constraints when they
539 * are not needed anymore.
540 * If the interconnect API is disabled, NULL is returned and the consumer
541 * drivers will still build. Drivers are free to handle this specifically,
542 * but they don't have to.
544 * Return: icc_path pointer on success or ERR_PTR() on error. NULL is returned
545 * when the API is disabled or the "interconnects" DT property is missing.
547 struct icc_path *of_icc_get(struct device *dev, const char *name)
549 struct device_node *np;
552 if (!dev || !dev->of_node)
553 return ERR_PTR(-ENODEV);
558 * When the consumer DT node do not have "interconnects" property
559 * return a NULL path to skip setting constraints.
561 if (!of_property_present(np, "interconnects"))
565 * We use a combination of phandle and specifier for endpoint. For now
566 * lets support only global ids and extend this in the future if needed
567 * without breaking DT compatibility.
570 idx = of_property_match_string(np, "interconnect-names", name);
575 return of_icc_get_by_index(dev, idx);
577 EXPORT_SYMBOL_GPL(of_icc_get);
580 * icc_get() - get a path handle between two endpoints
581 * @dev: device pointer for the consumer device
582 * @src: source node name
583 * @dst: destination node name
585 * This function will search for a path between two endpoints and return an
586 * icc_path handle on success. Use icc_put() to release constraints when they
587 * are not needed anymore.
589 * Return: icc_path pointer on success or ERR_PTR() on error. NULL is returned
590 * when the API is disabled.
592 struct icc_path *icc_get(struct device *dev, const char *src, const char *dst)
594 struct icc_node *src_node, *dst_node;
595 struct icc_path *path = ERR_PTR(-EPROBE_DEFER);
597 mutex_lock(&icc_lock);
599 src_node = node_find_by_name(src);
601 dev_err(dev, "%s: invalid src=%s\n", __func__, src);
605 dst_node = node_find_by_name(dst);
607 dev_err(dev, "%s: invalid dst=%s\n", __func__, dst);
611 path = path_find(dev, src_node, dst_node);
613 dev_err(dev, "%s: invalid path=%ld\n", __func__, PTR_ERR(path));
617 path->name = kasprintf(GFP_KERNEL, "%s-%s", src_node->name, dst_node->name);
620 path = ERR_PTR(-ENOMEM);
623 mutex_unlock(&icc_lock);
628 * icc_set_tag() - set an optional tag on a path
629 * @path: the path we want to tag
630 * @tag: the tag value
632 * This function allows consumers to append a tag to the requests associated
633 * with a path, so that a different aggregation could be done based on this tag.
635 void icc_set_tag(struct icc_path *path, u32 tag)
642 mutex_lock(&icc_lock);
644 for (i = 0; i < path->num_nodes; i++)
645 path->reqs[i].tag = tag;
647 mutex_unlock(&icc_lock);
649 EXPORT_SYMBOL_GPL(icc_set_tag);
652 * icc_get_name() - Get name of the icc path
653 * @path: interconnect path
655 * This function is used by an interconnect consumer to get the name of the icc
658 * Returns a valid pointer on success, or NULL otherwise.
660 const char *icc_get_name(struct icc_path *path)
667 EXPORT_SYMBOL_GPL(icc_get_name);
670 * icc_set_bw() - set bandwidth constraints on an interconnect path
671 * @path: interconnect path
672 * @avg_bw: average bandwidth in kilobytes per second
673 * @peak_bw: peak bandwidth in kilobytes per second
675 * This function is used by an interconnect consumer to express its own needs
676 * in terms of bandwidth for a previously requested path between two endpoints.
677 * The requests are aggregated and each node is updated accordingly. The entire
678 * path is locked by a mutex to ensure that the set() is completed.
679 * The @path can be NULL when the "interconnects" DT properties is missing,
680 * which will mean that no constraints will be set.
682 * Returns 0 on success, or an appropriate error code otherwise.
684 int icc_set_bw(struct icc_path *path, u32 avg_bw, u32 peak_bw)
686 struct icc_node *node;
687 u32 old_avg, old_peak;
694 if (WARN_ON(IS_ERR(path) || !path->num_nodes))
697 mutex_lock(&icc_lock);
699 old_avg = path->reqs[0].avg_bw;
700 old_peak = path->reqs[0].peak_bw;
702 for (i = 0; i < path->num_nodes; i++) {
703 node = path->reqs[i].node;
705 /* update the consumer request for this path */
706 path->reqs[i].avg_bw = avg_bw;
707 path->reqs[i].peak_bw = peak_bw;
709 /* aggregate requests for this node */
710 aggregate_requests(node);
712 trace_icc_set_bw(path, node, i, avg_bw, peak_bw);
715 ret = apply_constraints(path);
717 pr_debug("interconnect: error applying constraints (%d)\n",
720 for (i = 0; i < path->num_nodes; i++) {
721 node = path->reqs[i].node;
722 path->reqs[i].avg_bw = old_avg;
723 path->reqs[i].peak_bw = old_peak;
724 aggregate_requests(node);
726 apply_constraints(path);
729 mutex_unlock(&icc_lock);
731 trace_icc_set_bw_end(path, ret);
735 EXPORT_SYMBOL_GPL(icc_set_bw);
737 static int __icc_enable(struct icc_path *path, bool enable)
744 if (WARN_ON(IS_ERR(path) || !path->num_nodes))
747 mutex_lock(&icc_lock);
749 for (i = 0; i < path->num_nodes; i++)
750 path->reqs[i].enabled = enable;
752 mutex_unlock(&icc_lock);
754 return icc_set_bw(path, path->reqs[0].avg_bw,
755 path->reqs[0].peak_bw);
758 int icc_enable(struct icc_path *path)
760 return __icc_enable(path, true);
762 EXPORT_SYMBOL_GPL(icc_enable);
764 int icc_disable(struct icc_path *path)
766 return __icc_enable(path, false);
768 EXPORT_SYMBOL_GPL(icc_disable);
771 * icc_put() - release the reference to the icc_path
772 * @path: interconnect path
774 * Use this function to release the constraints on a path when the path is
775 * no longer needed. The constraints will be re-aggregated.
777 void icc_put(struct icc_path *path)
779 struct icc_node *node;
783 if (!path || WARN_ON(IS_ERR(path)))
786 ret = icc_set_bw(path, 0, 0);
788 pr_err("%s: error (%d)\n", __func__, ret);
790 mutex_lock(&icc_lock);
791 for (i = 0; i < path->num_nodes; i++) {
792 node = path->reqs[i].node;
793 hlist_del(&path->reqs[i].req_node);
794 if (!WARN_ON(!node->provider->users))
795 node->provider->users--;
797 mutex_unlock(&icc_lock);
799 kfree_const(path->name);
802 EXPORT_SYMBOL_GPL(icc_put);
804 static struct icc_node *icc_node_create_nolock(int id)
806 struct icc_node *node;
808 /* check if node already exists */
809 node = node_find(id);
813 node = kzalloc(sizeof(*node), GFP_KERNEL);
815 return ERR_PTR(-ENOMEM);
817 id = idr_alloc(&icc_idr, node, id, id + 1, GFP_KERNEL);
819 WARN(1, "%s: couldn't get idr\n", __func__);
830 * icc_node_create() - create a node
833 * Return: icc_node pointer on success, or ERR_PTR() on error
835 struct icc_node *icc_node_create(int id)
837 struct icc_node *node;
839 mutex_lock(&icc_lock);
841 node = icc_node_create_nolock(id);
843 mutex_unlock(&icc_lock);
847 EXPORT_SYMBOL_GPL(icc_node_create);
850 * icc_node_destroy() - destroy a node
853 void icc_node_destroy(int id)
855 struct icc_node *node;
857 mutex_lock(&icc_lock);
859 node = node_find(id);
861 idr_remove(&icc_idr, node->id);
862 WARN_ON(!hlist_empty(&node->req_list));
865 mutex_unlock(&icc_lock);
873 EXPORT_SYMBOL_GPL(icc_node_destroy);
876 * icc_link_create() - create a link between two nodes
877 * @node: source node id
878 * @dst_id: destination node id
880 * Create a link between two nodes. The nodes might belong to different
881 * interconnect providers and the @dst_id node might not exist (if the
882 * provider driver has not probed yet). So just create the @dst_id node
883 * and when the actual provider driver is probed, the rest of the node
886 * Return: 0 on success, or an error code otherwise
888 int icc_link_create(struct icc_node *node, const int dst_id)
890 struct icc_node *dst;
891 struct icc_node **new;
897 mutex_lock(&icc_lock);
899 dst = node_find(dst_id);
901 dst = icc_node_create_nolock(dst_id);
909 new = krealloc(node->links,
910 (node->num_links + 1) * sizeof(*node->links),
918 node->links[node->num_links++] = dst;
921 mutex_unlock(&icc_lock);
925 EXPORT_SYMBOL_GPL(icc_link_create);
928 * icc_node_add() - add interconnect node to interconnect provider
929 * @node: pointer to the interconnect node
930 * @provider: pointer to the interconnect provider
932 void icc_node_add(struct icc_node *node, struct icc_provider *provider)
934 if (WARN_ON(node->provider))
937 mutex_lock(&icc_lock);
939 node->provider = provider;
940 list_add_tail(&node->node_list, &provider->nodes);
942 /* get the initial bandwidth values and sync them with hardware */
943 if (provider->get_bw) {
944 provider->get_bw(node, &node->init_avg, &node->init_peak);
946 node->init_avg = INT_MAX;
947 node->init_peak = INT_MAX;
949 node->avg_bw = node->init_avg;
950 node->peak_bw = node->init_peak;
952 if (node->avg_bw || node->peak_bw) {
953 if (provider->pre_aggregate)
954 provider->pre_aggregate(node);
956 if (provider->aggregate)
957 provider->aggregate(node, 0, node->init_avg, node->init_peak,
958 &node->avg_bw, &node->peak_bw);
960 provider->set(node, node);
966 mutex_unlock(&icc_lock);
968 EXPORT_SYMBOL_GPL(icc_node_add);
971 * icc_node_del() - delete interconnect node from interconnect provider
972 * @node: pointer to the interconnect node
974 void icc_node_del(struct icc_node *node)
976 mutex_lock(&icc_lock);
978 list_del(&node->node_list);
980 mutex_unlock(&icc_lock);
982 EXPORT_SYMBOL_GPL(icc_node_del);
985 * icc_nodes_remove() - remove all previously added nodes from provider
986 * @provider: the interconnect provider we are removing nodes from
988 * Return: 0 on success, or an error code otherwise
990 int icc_nodes_remove(struct icc_provider *provider)
992 struct icc_node *n, *tmp;
994 if (WARN_ON(IS_ERR_OR_NULL(provider)))
997 list_for_each_entry_safe_reverse(n, tmp, &provider->nodes, node_list) {
999 icc_node_destroy(n->id);
1004 EXPORT_SYMBOL_GPL(icc_nodes_remove);
1007 * icc_provider_init() - initialize a new interconnect provider
1008 * @provider: the interconnect provider to initialize
1010 * Must be called before adding nodes to the provider.
1012 void icc_provider_init(struct icc_provider *provider)
1014 WARN_ON(!provider->set);
1016 INIT_LIST_HEAD(&provider->nodes);
1018 EXPORT_SYMBOL_GPL(icc_provider_init);
1021 * icc_provider_register() - register a new interconnect provider
1022 * @provider: the interconnect provider to register
1024 * Return: 0 on success, or an error code otherwise
1026 int icc_provider_register(struct icc_provider *provider)
1028 if (WARN_ON(!provider->xlate && !provider->xlate_extended))
1031 mutex_lock(&icc_lock);
1032 list_add_tail(&provider->provider_list, &icc_providers);
1033 mutex_unlock(&icc_lock);
1035 dev_dbg(provider->dev, "interconnect provider registered\n");
1039 EXPORT_SYMBOL_GPL(icc_provider_register);
1042 * icc_provider_deregister() - deregister an interconnect provider
1043 * @provider: the interconnect provider to deregister
1045 void icc_provider_deregister(struct icc_provider *provider)
1047 mutex_lock(&icc_lock);
1048 WARN_ON(provider->users);
1050 list_del(&provider->provider_list);
1051 mutex_unlock(&icc_lock);
1053 EXPORT_SYMBOL_GPL(icc_provider_deregister);
1055 static const struct of_device_id __maybe_unused ignore_list[] = {
1056 { .compatible = "qcom,sc7180-ipa-virt" },
1057 { .compatible = "qcom,sc8180x-ipa-virt" },
1058 { .compatible = "qcom,sdx55-ipa-virt" },
1059 { .compatible = "qcom,sm8150-ipa-virt" },
1060 { .compatible = "qcom,sm8250-ipa-virt" },
1064 static int of_count_icc_providers(struct device_node *np)
1066 struct device_node *child;
1069 for_each_available_child_of_node(np, child) {
1070 if (of_property_read_bool(child, "#interconnect-cells") &&
1071 likely(!of_match_node(ignore_list, child)))
1073 count += of_count_icc_providers(child);
1079 void icc_sync_state(struct device *dev)
1081 struct icc_provider *p;
1087 if (count < providers_count)
1090 mutex_lock(&icc_lock);
1091 synced_state = true;
1092 list_for_each_entry(p, &icc_providers, provider_list) {
1093 dev_dbg(p->dev, "interconnect provider is in synced state\n");
1094 list_for_each_entry(n, &p->nodes, node_list) {
1095 if (n->init_avg || n->init_peak) {
1098 aggregate_requests(n);
1103 mutex_unlock(&icc_lock);
1105 EXPORT_SYMBOL_GPL(icc_sync_state);
1107 static int __init icc_init(void)
1109 struct device_node *root = of_find_node_by_path("/");
1111 providers_count = of_count_icc_providers(root);
1114 icc_debugfs_dir = debugfs_create_dir("interconnect", NULL);
1115 debugfs_create_file("interconnect_summary", 0444,
1116 icc_debugfs_dir, NULL, &icc_summary_fops);
1117 debugfs_create_file("interconnect_graph", 0444,
1118 icc_debugfs_dir, NULL, &icc_graph_fops);
1122 device_initcall(icc_init);