interconnect-provider.h 5.5 KB

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