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