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 * @num_links: the total number of @links 87 * @channels: num of channels at this node 88 * @buswidth: width of the interconnect between a node and the bus 89 * @sum_avg: current sum aggregate value of all avg bw requests 90 * @max_peak: current max aggregate value of all peak bw requests 91 * @bcms: list of bcms associated with this logical node 92 * @num_bcms: num of @bcms 93 * @qosbox: QoS config data associated with node 94 */ 95 struct qcom_icc_node { 96 const char *name; 97 u16 links[MAX_LINKS]; 98 u16 id; 99 u16 num_links; 100 u16 channels; 101 u16 buswidth; 102 u64 sum_avg[QCOM_ICC_NUM_BUCKETS]; 103 u64 max_peak[QCOM_ICC_NUM_BUCKETS]; 104 struct qcom_icc_bcm *bcms[MAX_BCM_PER_NODE]; 105 size_t num_bcms; 106 const struct qcom_icc_qosbox *qosbox; 107 }; 108 109 /** 110 * struct qcom_icc_bcm - Qualcomm specific hardware accelerator nodes 111 * known as Bus Clock Manager (BCM) 112 * @name: the bcm node name used to fetch BCM data from command db 113 * @type: latency or bandwidth bcm 114 * @addr: address offsets used when voting to RPMH 115 * @vote_x: aggregated threshold values, represents sum_bw when @type is bw bcm 116 * @vote_y: aggregated threshold values, represents peak_bw when @type is bw bcm 117 * @vote_scale: scaling factor for vote_x and vote_y 118 * @enable_mask: optional mask to send as vote instead of vote_x/vote_y 119 * @dirty: flag used to indicate whether the bcm needs to be committed 120 * @keepalive: flag used to indicate whether a keepalive is required 121 * @aux_data: auxiliary data used when calculating threshold values and 122 * communicating with RPMh 123 * @list: used to link to other bcms when compiling lists for commit 124 * @ws_list: used to keep track of bcms that may transition between wake/sleep 125 * @num_nodes: total number of @num_nodes 126 * @nodes: list of qcom_icc_nodes that this BCM encapsulates 127 */ 128 struct qcom_icc_bcm { 129 const char *name; 130 u32 type; 131 u32 addr; 132 u64 vote_x[QCOM_ICC_NUM_BUCKETS]; 133 u64 vote_y[QCOM_ICC_NUM_BUCKETS]; 134 u64 vote_scale; 135 u32 enable_mask; 136 bool dirty; 137 bool keepalive; 138 struct bcm_db aux_data; 139 struct list_head list; 140 struct list_head ws_list; 141 size_t num_nodes; 142 struct qcom_icc_node *nodes[]; 143 }; 144 145 struct qcom_icc_fabric { 146 struct qcom_icc_node **nodes; 147 size_t num_nodes; 148 }; 149 150 struct qcom_icc_desc { 151 const struct regmap_config *config; 152 struct qcom_icc_node * const *nodes; 153 size_t num_nodes; 154 struct qcom_icc_bcm * const *bcms; 155 size_t num_bcms; 156 bool qos_requires_clocks; 157 }; 158 159 int qcom_icc_aggregate(struct icc_node *node, u32 tag, u32 avg_bw, 160 u32 peak_bw, u32 *agg_avg, u32 *agg_peak); 161 int qcom_icc_set(struct icc_node *src, struct icc_node *dst); 162 int qcom_icc_bcm_init(struct qcom_icc_bcm *bcm, struct device *dev); 163 void qcom_icc_pre_aggregate(struct icc_node *node); 164 int qcom_icc_rpmh_probe(struct platform_device *pdev); 165 void qcom_icc_rpmh_remove(struct platform_device *pdev); 166 167 #endif 168