blob: 38701925ab91ea54ee88a478a1865b1adb2795e7 [file] [log] [blame]
Georgi Djakov11f1cec2019-01-16 18:10:56 +02001/* 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
14struct icc_node;
Georgi Djakov87e30312019-01-16 18:10:58 +020015struct 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 */
23struct icc_onecell_data {
24 unsigned int num_nodes;
25 struct icc_node *nodes[];
26};
27
28struct icc_node *of_icc_xlate_onecell(struct of_phandle_args *spec,
29 void *data);
Georgi Djakov11f1cec2019-01-16 18:10:56 +020030
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
Georgi Djakovcbd5a9c2019-08-09 15:13:24 +030039 * @pre_aggregate: pointer to device specific function that is called
40 * before the aggregation begins (optional)
Georgi Djakov87e30312019-01-16 18:10:58 +020041 * @xlate: provider-specific callback for mapping nodes from phandle arguments
Georgi Djakov11f1cec2019-01-16 18:10:56 +020042 * @dev: the device this interconnect provider belongs to
43 * @users: count of active users
Artur Świgoń65461e262020-05-21 14:28:41 +020044 * @inter_set: whether inter-provider pairs will be configured with @set
Georgi Djakov11f1cec2019-01-16 18:10:56 +020045 * @data: pointer to private data
46 */
47struct icc_provider {
48 struct list_head provider_list;
49 struct list_head nodes;
50 int (*set)(struct icc_node *src, struct icc_node *dst);
Georgi Djakov127ab2c2019-08-09 15:13:23 +030051 int (*aggregate)(struct icc_node *node, u32 tag, u32 avg_bw,
52 u32 peak_bw, u32 *agg_avg, u32 *agg_peak);
Georgi Djakovcbd5a9c2019-08-09 15:13:24 +030053 void (*pre_aggregate)(struct icc_node *node);
Georgi Djakov87e30312019-01-16 18:10:58 +020054 struct icc_node* (*xlate)(struct of_phandle_args *spec, void *data);
Georgi Djakov11f1cec2019-01-16 18:10:56 +020055 struct device *dev;
56 int users;
Artur Świgoń65461e262020-05-21 14:28:41 +020057 bool inter_set;
Georgi Djakov11f1cec2019-01-16 18:10:56 +020058 void *data;
59};
60
61/**
62 * struct icc_node - entity that is part of the interconnect topology
63 *
64 * @id: platform specific node id
65 * @name: node name used in debugfs
66 * @links: a list of targets pointing to where we can go next when traversing
67 * @num_links: number of links to other interconnect nodes
68 * @provider: points to the interconnect provider of this node
69 * @node_list: the list entry in the parent provider's "nodes" list
70 * @search_list: list used when walking the nodes graph
71 * @reverse: pointer to previous node when walking the nodes graph
72 * @is_traversed: flag that is used when walking the nodes graph
73 * @req_list: a list of QoS constraint requests associated with this node
74 * @avg_bw: aggregated value of average bandwidth requests from all consumers
75 * @peak_bw: aggregated value of peak bandwidth requests from all consumers
76 * @data: pointer to private data
77 */
78struct icc_node {
79 int id;
80 const char *name;
81 struct icc_node **links;
82 size_t num_links;
83
84 struct icc_provider *provider;
85 struct list_head node_list;
86 struct list_head search_list;
87 struct icc_node *reverse;
88 u8 is_traversed:1;
89 struct hlist_head req_list;
90 u32 avg_bw;
91 u32 peak_bw;
92 void *data;
93};
94
95#if IS_ENABLED(CONFIG_INTERCONNECT)
96
Georgi Djakov3172e4d2019-11-28 15:48:38 +020097int icc_std_aggregate(struct icc_node *node, u32 tag, u32 avg_bw,
98 u32 peak_bw, u32 *agg_avg, u32 *agg_peak);
Georgi Djakov11f1cec2019-01-16 18:10:56 +020099struct icc_node *icc_node_create(int id);
100void icc_node_destroy(int id);
101int icc_link_create(struct icc_node *node, const int dst_id);
102int icc_link_destroy(struct icc_node *src, struct icc_node *dst);
103void icc_node_add(struct icc_node *node, struct icc_provider *provider);
104void icc_node_del(struct icc_node *node);
Georgi Djakov3cce2c62019-12-02 18:21:32 +0200105int icc_nodes_remove(struct icc_provider *provider);
Georgi Djakov11f1cec2019-01-16 18:10:56 +0200106int icc_provider_add(struct icc_provider *provider);
107int icc_provider_del(struct icc_provider *provider);
Artur Świgoń8a307d32020-05-21 14:28:39 +0200108struct icc_node *of_icc_get_from_provider(struct of_phandle_args *spec);
Georgi Djakov11f1cec2019-01-16 18:10:56 +0200109
110#else
111
Georgi Djakov3172e4d2019-11-28 15:48:38 +0200112static inline int icc_std_aggregate(struct icc_node *node, u32 tag, u32 avg_bw,
113 u32 peak_bw, u32 *agg_avg, u32 *agg_peak)
114{
115 return -ENOTSUPP;
116}
117
Georgi Djakov11f1cec2019-01-16 18:10:56 +0200118static inline struct icc_node *icc_node_create(int id)
119{
120 return ERR_PTR(-ENOTSUPP);
121}
122
123void icc_node_destroy(int id)
124{
125}
126
127static inline int icc_link_create(struct icc_node *node, const int dst_id)
128{
129 return -ENOTSUPP;
130}
131
132int icc_link_destroy(struct icc_node *src, struct icc_node *dst)
133{
134 return -ENOTSUPP;
135}
136
137void icc_node_add(struct icc_node *node, struct icc_provider *provider)
138{
139}
140
141void icc_node_del(struct icc_node *node)
142{
143}
144
Georgi Djakov3cce2c62019-12-02 18:21:32 +0200145static inline int icc_nodes_remove(struct icc_provider *provider)
146{
147 return -ENOTSUPP;
148}
149
Georgi Djakov11f1cec2019-01-16 18:10:56 +0200150static inline int icc_provider_add(struct icc_provider *provider)
151{
152 return -ENOTSUPP;
153}
154
155static inline int icc_provider_del(struct icc_provider *provider)
156{
157 return -ENOTSUPP;
158}
159
Artur Świgoń8a307d32020-05-21 14:28:39 +0200160static inline struct icc_node *of_icc_get_from_provider(struct of_phandle_args *spec)
161{
162 return ERR_PTR(-ENOTSUPP);
163}
164
Georgi Djakov11f1cec2019-01-16 18:10:56 +0200165#endif /* CONFIG_INTERCONNECT */
166
167#endif /* __LINUX_INTERCONNECT_PROVIDER_H */