icc-rpmh.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright (c) 2020-2021, The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2023, Qualcomm Innovation Center, Inc. All rights reserved.
  5. */
  6. #ifndef __DRIVERS_INTERCONNECT_QCOM_ICC_RPMH_H__
  7. #define __DRIVERS_INTERCONNECT_QCOM_ICC_RPMH_H__
  8. #include <dt-bindings/interconnect/qcom,icc.h>
  9. #include <linux/regmap.h>
  10. #include <linux/platform_device.h>
  11. #include <soc/qcom/crm.h>
  12. #define to_qcom_provider(_provider) \
  13. container_of(_provider, struct qcom_icc_provider, provider)
  14. /**
  15. * struct qcom_icc_provider - Qualcomm specific interconnect provider
  16. * @provider: generic interconnect provider
  17. * @dev: reference to the NoC device
  18. * @bcms: list of bcms that maps to the provider
  19. * @num_bcms: number of @bcms
  20. * @voter: bcm voter targeted by this provider
  21. */
  22. struct qcom_icc_provider {
  23. struct icc_provider provider;
  24. struct device *dev;
  25. struct qcom_icc_bcm * const *bcms;
  26. size_t num_bcms;
  27. struct qcom_icc_node * const *nodes;
  28. size_t num_nodes;
  29. struct list_head probe_list;
  30. struct regmap *regmap;
  31. struct clk_bulk_data *clks;
  32. int num_clks;
  33. struct bcm_voter **voters;
  34. size_t num_voters;
  35. bool stub;
  36. bool skip_qos;
  37. };
  38. /**
  39. * struct bcm_db - Auxiliary data pertaining to each Bus Clock Manager (BCM)
  40. * @unit: divisor used to convert bytes/sec bw value to an RPMh msg
  41. * @width: multiplier used to convert bytes/sec bw value to an RPMh msg
  42. * @vcd: virtual clock domain that this bcm belongs to
  43. * @reserved: reserved field
  44. */
  45. struct bcm_db {
  46. __le32 unit;
  47. __le16 width;
  48. u8 vcd;
  49. u8 reserved;
  50. };
  51. #define MAX_LINKS 128
  52. #define MAX_BCMS 64
  53. #define MAX_BCM_PER_NODE 3
  54. #define MAX_VCD 10
  55. struct qcom_icc_crm_voter {
  56. const char *name;
  57. const struct device *dev;
  58. enum crm_drv_type client_type;
  59. u32 client_idx;
  60. u32 pwr_states;
  61. };
  62. /**
  63. * struct qcom_icc_node - Qualcomm specific interconnect nodes
  64. * @name: the node name used in debugfs
  65. * @links: an array of nodes where we can go next while traversing
  66. * @id: a unique node identifier
  67. * @num_links: the total number of @links
  68. * @channels: num of channels at this node
  69. * @buswidth: width of the interconnect between a node and the bus
  70. * @sum_avg: current sum aggregate value of all avg bw requests
  71. * @max_peak: current max aggregate value of all peak bw requests
  72. * @perf_mode: current OR aggregate value of all QCOM_ICC_TAG_PERF_MODE votes
  73. * @bcms: list of bcms associated with this logical node
  74. * @num_bcms: num of @bcms
  75. * @clk: the local clock at this node
  76. * @clk_name: the local clock name at this node
  77. * @toggle_clk: flag used to indicate whether local clock can be enabled/disabled
  78. * @clk_enabled: flag used to indicate whether local clock have been enabled
  79. * @bw_scale_numerator: the numerator of the bandwidth scale factor
  80. * @bw_scale_denominator: the denominator of the bandwidth scale factor
  81. * @disabled : flag used to indicate state of icc node
  82. */
  83. struct qcom_icc_node {
  84. const char *name;
  85. u16 links[MAX_LINKS];
  86. u16 id;
  87. u16 num_links;
  88. u16 channels;
  89. u16 buswidth;
  90. u64 sum_avg[QCOM_ICC_NUM_BUCKETS];
  91. u64 max_peak[QCOM_ICC_NUM_BUCKETS];
  92. bool perf_mode[QCOM_ICC_NUM_BUCKETS];
  93. struct qcom_icc_bcm *bcms[MAX_BCM_PER_NODE];
  94. size_t num_bcms;
  95. struct regmap *regmap;
  96. struct qcom_icc_qosbox *qosbox;
  97. const struct qcom_icc_noc_ops *noc_ops;
  98. struct clk *clk;
  99. const char *clk_name;
  100. bool toggle_clk;
  101. bool clk_enabled;
  102. u16 bw_scale_numerator;
  103. u16 bw_scale_denominator;
  104. bool disabled;
  105. };
  106. /**
  107. * struct qcom_icc_bcm - Qualcomm specific hardware accelerator nodes
  108. * known as Bus Clock Manager (BCM)
  109. * @name: the bcm node name used to fetch BCM data from command db
  110. * @type: latency or bandwidth bcm
  111. * @addr: address offsets used when voting to RPMH
  112. * @vote_x: aggregated threshold values, represents sum_bw when @type is bw bcm
  113. * @vote_y: aggregated threshold values, represents peak_bw when @type is bw bcm
  114. * @vote_scale: scaling factor for vote_x and vote_y
  115. * @enable_mask: optional mask to send as vote instead of vote_x/vote_y
  116. * @perf_mode_mask: mask to OR with enable_mask when QCOM_ICC_TAG_PERF_MODE is set
  117. * @dirty: flag used to indicate whether the bcm needs to be committed
  118. * @keepalive: flag used to indicate whether a keepalive is required
  119. * @keepalive_early: keepalive only prior to sync-state
  120. * @qos_proxy: flag used to indicate whether a proxy vote needed as part of
  121. * qos configuration
  122. * @disabled: flag used to indicate state of bcm node
  123. * @aux_data: auxiliary data used when calculating threshold values and
  124. * communicating with RPMh
  125. * @list: used to link to other bcms when compiling lists for commit
  126. * @ws_list: used to keep track of bcms that may transition between wake/sleep
  127. * @num_nodes: total number of @num_nodes
  128. * @nodes: list of qcom_icc_nodes that this BCM encapsulates
  129. */
  130. struct qcom_icc_bcm {
  131. const char *name;
  132. u32 type;
  133. u32 addr;
  134. u64 vote_x[QCOM_ICC_NUM_BUCKETS];
  135. u64 vote_y[QCOM_ICC_NUM_BUCKETS];
  136. u64 vote_scale;
  137. u32 enable_mask;
  138. u32 perf_mode_mask;
  139. bool dirty;
  140. bool keepalive;
  141. bool keepalive_early;
  142. bool qos_proxy;
  143. bool disabled;
  144. struct bcm_db aux_data;
  145. struct list_head list;
  146. struct list_head ws_list;
  147. int voter_idx;
  148. u8 crm_node;
  149. size_t num_nodes;
  150. struct qcom_icc_node *nodes[];
  151. };
  152. struct qcom_icc_fabric {
  153. struct qcom_icc_node **nodes;
  154. size_t num_nodes;
  155. };
  156. struct qcom_icc_desc {
  157. const struct regmap_config *config;
  158. struct qcom_icc_node * const *nodes;
  159. size_t num_nodes;
  160. struct qcom_icc_bcm * const *bcms;
  161. size_t num_bcms;
  162. char **voters;
  163. size_t num_voters;
  164. };
  165. #define DEFINE_QNODE(_name, _id, _channels, _buswidth, ...) \
  166. static struct qcom_icc_node _name = { \
  167. .id = _id, \
  168. .name = #_name, \
  169. .channels = _channels, \
  170. .buswidth = _buswidth, \
  171. .num_links = ARRAY_SIZE(((int[]){ __VA_ARGS__ })), \
  172. .links = { __VA_ARGS__ }, \
  173. }
  174. int qcom_icc_aggregate(struct icc_node *node, u32 tag, u32 avg_bw,
  175. u32 peak_bw, u32 *agg_avg, u32 *agg_peak);
  176. int qcom_icc_aggregate_stub(struct icc_node *node, u32 tag, u32 avg_bw,
  177. u32 peak_bw, u32 *agg_avg, u32 *agg_peak);
  178. int qcom_icc_set(struct icc_node *src, struct icc_node *dst);
  179. int qcom_icc_set_stub(struct icc_node *src, struct icc_node *dst);
  180. int qcom_icc_bcm_init(struct qcom_icc_provider *qp, struct qcom_icc_bcm *bcm, struct device *dev);
  181. void qcom_icc_pre_aggregate(struct icc_node *node);
  182. int qcom_icc_rpmh_probe(struct platform_device *pdev);
  183. int qcom_icc_rpmh_remove(struct platform_device *pdev);
  184. void qcom_icc_rpmh_sync_state(struct device *dev);
  185. int qcom_icc_get_bw_stub(struct icc_node *node, u32 *avg, u32 *peak);
  186. int qcom_icc_rpmh_configure_qos(struct qcom_icc_provider *qp);
  187. #endif