Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

interconnect: qcom: Consolidate interconnect RPMh support

Add bcm voter driver and add support for RPMh specific interconnect
providers which implements the set and aggregate functionalities that
translates bandwidth requests into RPMh messages. These modules provide
a common set of functionalities for all Qualcomm RPMh based interconnect
providers and should help reduce code duplication when adding new
providers.

Signed-off-by: David Dai <daidavid1@codeaurora.org>
Signed-off-by: Odelu Kukatla <okukatla@codeaurora.org>
Reviewed-by: Evan Green <evgreen@chromium.org>
Signed-off-by: Sibi Sankar <sibis@codeaurora.org>
Link: https://lore.kernel.org/r/20200228095951.15457-1-sibis@codeaurora.org
Signed-off-by: Georgi Djakov <georgi.djakov@linaro.org>

authored by

David Dai and committed by
Georgi Djakov
976daac4 6f690e16

+704
+8
drivers/interconnect/qcom/Kconfig
··· 5 5 help 6 6 Support for Qualcomm's Network-on-Chip interconnect hardware. 7 7 8 + config INTERCONNECT_QCOM_BCM_VOTER 9 + tristate 10 + 8 11 config INTERCONNECT_QCOM_MSM8916 9 12 tristate "Qualcomm MSM8916 interconnect driver" 10 13 depends on INTERCONNECT_QCOM ··· 35 32 This is a driver for the Qualcomm Network-on-Chip on qcs404-based 36 33 platforms. 37 34 35 + config INTERCONNECT_QCOM_RPMH 36 + tristate 37 + 38 38 config INTERCONNECT_QCOM_SDM845 39 39 tristate "Qualcomm SDM845 interconnect driver" 40 40 depends on INTERCONNECT_QCOM 41 41 depends on (QCOM_RPMH && QCOM_COMMAND_DB && OF) || COMPILE_TEST 42 + select INTERCONNECT_QCOM_RPMH 43 + select INTERCONNECT_QCOM_BCM_VOTER 42 44 help 43 45 This is a driver for the Qualcomm Network-on-Chip on sdm845-based 44 46 platforms.
+4
drivers/interconnect/qcom/Makefile
··· 1 1 # SPDX-License-Identifier: GPL-2.0 2 2 3 + icc-bcm-voter-objs := bcm-voter.o 3 4 qnoc-msm8916-objs := msm8916.o 4 5 qnoc-msm8974-objs := msm8974.o 5 6 qnoc-qcs404-objs := qcs404.o 7 + icc-rpmh-obj := icc-rpmh.o 6 8 qnoc-sdm845-objs := sdm845.o 7 9 icc-smd-rpm-objs := smd-rpm.o 8 10 11 + obj-$(CONFIG_INTERCONNECT_QCOM_BCM_VOTER) += icc-bcm-voter.o 9 12 obj-$(CONFIG_INTERCONNECT_QCOM_MSM8916) += qnoc-msm8916.o 10 13 obj-$(CONFIG_INTERCONNECT_QCOM_MSM8974) += qnoc-msm8974.o 11 14 obj-$(CONFIG_INTERCONNECT_QCOM_QCS404) += qnoc-qcs404.o 15 + obj-$(CONFIG_INTERCONNECT_QCOM_RPMH) += icc-rpmh.o 12 16 obj-$(CONFIG_INTERCONNECT_QCOM_SDM845) += qnoc-sdm845.o 13 17 obj-$(CONFIG_INTERCONNECT_QCOM_SMD_RPM) += icc-smd-rpm.o
+366
drivers/interconnect/qcom/bcm-voter.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * Copyright (c) 2020, The Linux Foundation. All rights reserved. 4 + */ 5 + 6 + #include <asm/div64.h> 7 + #include <linux/interconnect-provider.h> 8 + #include <linux/list_sort.h> 9 + #include <linux/module.h> 10 + #include <linux/of.h> 11 + #include <linux/platform_device.h> 12 + 13 + #include <soc/qcom/rpmh.h> 14 + #include <soc/qcom/tcs.h> 15 + 16 + #include "bcm-voter.h" 17 + #include "icc-rpmh.h" 18 + 19 + static LIST_HEAD(bcm_voters); 20 + static DEFINE_MUTEX(bcm_voter_lock); 21 + 22 + /** 23 + * struct bcm_voter - Bus Clock Manager voter 24 + * @dev: reference to the device that communicates with the BCM 25 + * @np: reference to the device node to match bcm voters 26 + * @lock: mutex to protect commit and wake/sleep lists in the voter 27 + * @commit_list: list containing bcms to be committed to hardware 28 + * @ws_list: list containing bcms that have different wake/sleep votes 29 + * @voter_node: list of bcm voters 30 + */ 31 + struct bcm_voter { 32 + struct device *dev; 33 + struct device_node *np; 34 + struct mutex lock; 35 + struct list_head commit_list; 36 + struct list_head ws_list; 37 + struct list_head voter_node; 38 + }; 39 + 40 + static int cmp_vcd(void *priv, struct list_head *a, struct list_head *b) 41 + { 42 + const struct qcom_icc_bcm *bcm_a = 43 + list_entry(a, struct qcom_icc_bcm, list); 44 + const struct qcom_icc_bcm *bcm_b = 45 + list_entry(b, struct qcom_icc_bcm, list); 46 + 47 + if (bcm_a->aux_data.vcd < bcm_b->aux_data.vcd) 48 + return -1; 49 + else if (bcm_a->aux_data.vcd == bcm_b->aux_data.vcd) 50 + return 0; 51 + else 52 + return 1; 53 + } 54 + 55 + static void bcm_aggregate(struct qcom_icc_bcm *bcm) 56 + { 57 + size_t i, bucket; 58 + u64 agg_avg[QCOM_ICC_NUM_BUCKETS] = {0}; 59 + u64 agg_peak[QCOM_ICC_NUM_BUCKETS] = {0}; 60 + u64 temp; 61 + 62 + for (bucket = 0; bucket < QCOM_ICC_NUM_BUCKETS; bucket++) { 63 + for (i = 0; i < bcm->num_nodes; i++) { 64 + temp = bcm->nodes[i]->sum_avg[bucket] * bcm->aux_data.width; 65 + do_div(temp, bcm->nodes[i]->buswidth * bcm->nodes[i]->channels); 66 + agg_avg[bucket] = max(agg_avg[bucket], temp); 67 + 68 + temp = bcm->nodes[i]->max_peak[bucket] * bcm->aux_data.width; 69 + do_div(temp, bcm->nodes[i]->buswidth); 70 + agg_peak[bucket] = max(agg_peak[bucket], temp); 71 + } 72 + 73 + temp = agg_avg[bucket] * 1000ULL; 74 + do_div(temp, bcm->aux_data.unit); 75 + bcm->vote_x[bucket] = temp; 76 + 77 + temp = agg_peak[bucket] * 1000ULL; 78 + do_div(temp, bcm->aux_data.unit); 79 + bcm->vote_y[bucket] = temp; 80 + } 81 + 82 + if (bcm->keepalive && bcm->vote_x[QCOM_ICC_BUCKET_AMC] == 0 && 83 + bcm->vote_y[QCOM_ICC_BUCKET_AMC] == 0) { 84 + bcm->vote_x[QCOM_ICC_BUCKET_AMC] = 1; 85 + bcm->vote_x[QCOM_ICC_BUCKET_WAKE] = 1; 86 + bcm->vote_y[QCOM_ICC_BUCKET_AMC] = 1; 87 + bcm->vote_y[QCOM_ICC_BUCKET_WAKE] = 1; 88 + } 89 + } 90 + 91 + static inline void tcs_cmd_gen(struct tcs_cmd *cmd, u64 vote_x, u64 vote_y, 92 + u32 addr, bool commit) 93 + { 94 + bool valid = true; 95 + 96 + if (!cmd) 97 + return; 98 + 99 + if (vote_x == 0 && vote_y == 0) 100 + valid = false; 101 + 102 + if (vote_x > BCM_TCS_CMD_VOTE_MASK) 103 + vote_x = BCM_TCS_CMD_VOTE_MASK; 104 + 105 + if (vote_y > BCM_TCS_CMD_VOTE_MASK) 106 + vote_y = BCM_TCS_CMD_VOTE_MASK; 107 + 108 + cmd->addr = addr; 109 + cmd->data = BCM_TCS_CMD(commit, valid, vote_x, vote_y); 110 + 111 + /* 112 + * Set the wait for completion flag on command that need to be completed 113 + * before the next command. 114 + */ 115 + if (commit) 116 + cmd->wait = true; 117 + } 118 + 119 + static void tcs_list_gen(struct list_head *bcm_list, int bucket, 120 + struct tcs_cmd tcs_list[MAX_BCMS], 121 + int n[MAX_VCD + 1]) 122 + { 123 + struct qcom_icc_bcm *bcm; 124 + bool commit; 125 + size_t idx = 0, batch = 0, cur_vcd_size = 0; 126 + 127 + memset(n, 0, sizeof(int) * (MAX_VCD + 1)); 128 + 129 + list_for_each_entry(bcm, bcm_list, list) { 130 + commit = false; 131 + cur_vcd_size++; 132 + if ((list_is_last(&bcm->list, bcm_list)) || 133 + bcm->aux_data.vcd != list_next_entry(bcm, list)->aux_data.vcd) { 134 + commit = true; 135 + cur_vcd_size = 0; 136 + } 137 + tcs_cmd_gen(&tcs_list[idx], bcm->vote_x[bucket], 138 + bcm->vote_y[bucket], bcm->addr, commit); 139 + idx++; 140 + n[batch]++; 141 + /* 142 + * Batch the BCMs in such a way that we do not split them in 143 + * multiple payloads when they are under the same VCD. This is 144 + * to ensure that every BCM is committed since we only set the 145 + * commit bit on the last BCM request of every VCD. 146 + */ 147 + if (n[batch] >= MAX_RPMH_PAYLOAD) { 148 + if (!commit) { 149 + n[batch] -= cur_vcd_size; 150 + n[batch + 1] = cur_vcd_size; 151 + } 152 + batch++; 153 + } 154 + } 155 + } 156 + 157 + /** 158 + * of_bcm_voter_get - gets a bcm voter handle from DT node 159 + * @dev: device pointer for the consumer device 160 + * @name: name for the bcm voter device 161 + * 162 + * This function will match a device_node pointer for the phandle 163 + * specified in the device DT and return a bcm_voter handle on success. 164 + * 165 + * Returns bcm_voter pointer or ERR_PTR() on error. EPROBE_DEFER is returned 166 + * when matching bcm voter is yet to be found. 167 + */ 168 + struct bcm_voter *of_bcm_voter_get(struct device *dev, const char *name) 169 + { 170 + struct bcm_voter *voter = ERR_PTR(-EPROBE_DEFER); 171 + struct bcm_voter *temp; 172 + struct device_node *np, *node; 173 + int idx = 0; 174 + 175 + if (!dev || !dev->of_node) 176 + return ERR_PTR(-ENODEV); 177 + 178 + np = dev->of_node; 179 + 180 + if (name) { 181 + idx = of_property_match_string(np, "qcom,bcm-voter-names", name); 182 + if (idx < 0) 183 + return ERR_PTR(idx); 184 + } 185 + 186 + node = of_parse_phandle(np, "qcom,bcm-voters", idx); 187 + 188 + mutex_lock(&bcm_voter_lock); 189 + list_for_each_entry(temp, &bcm_voters, voter_node) { 190 + if (temp->np == node) { 191 + voter = temp; 192 + break; 193 + } 194 + } 195 + mutex_unlock(&bcm_voter_lock); 196 + 197 + return voter; 198 + } 199 + EXPORT_SYMBOL_GPL(of_bcm_voter_get); 200 + 201 + /** 202 + * qcom_icc_bcm_voter_add - queues up the bcm nodes that require updates 203 + * @voter: voter that the bcms are being added to 204 + * @bcm: bcm to add to the commit and wake sleep list 205 + */ 206 + void qcom_icc_bcm_voter_add(struct bcm_voter *voter, struct qcom_icc_bcm *bcm) 207 + { 208 + if (!voter) 209 + return; 210 + 211 + mutex_lock(&voter->lock); 212 + if (list_empty(&bcm->list)) 213 + list_add_tail(&bcm->list, &voter->commit_list); 214 + 215 + if (list_empty(&bcm->ws_list)) 216 + list_add_tail(&bcm->ws_list, &voter->ws_list); 217 + 218 + mutex_unlock(&voter->lock); 219 + } 220 + EXPORT_SYMBOL_GPL(qcom_icc_bcm_voter_add); 221 + 222 + /** 223 + * qcom_icc_bcm_voter_commit - generates and commits tcs cmds based on bcms 224 + * @voter: voter that needs flushing 225 + * 226 + * This function generates a set of AMC commands and flushes to the BCM device 227 + * associated with the voter. It conditionally generate WAKE and SLEEP commands 228 + * based on deltas between WAKE/SLEEP requirements. The ws_list persists 229 + * through multiple commit requests and bcm nodes are removed only when the 230 + * requirements for WAKE matches SLEEP. 231 + * 232 + * Returns 0 on success, or an appropriate error code otherwise. 233 + */ 234 + int qcom_icc_bcm_voter_commit(struct bcm_voter *voter) 235 + { 236 + struct qcom_icc_bcm *bcm; 237 + struct qcom_icc_bcm *bcm_tmp; 238 + int commit_idx[MAX_VCD + 1]; 239 + struct tcs_cmd cmds[MAX_BCMS]; 240 + int ret = 0; 241 + 242 + if (!voter) 243 + return 0; 244 + 245 + mutex_lock(&voter->lock); 246 + list_for_each_entry(bcm, &voter->commit_list, list) 247 + bcm_aggregate(bcm); 248 + 249 + /* 250 + * Pre sort the BCMs based on VCD for ease of generating a command list 251 + * that groups the BCMs with the same VCD together. VCDs are numbered 252 + * with lowest being the most expensive time wise, ensuring that 253 + * those commands are being sent the earliest in the queue. This needs 254 + * to be sorted every commit since we can't guarantee the order in which 255 + * the BCMs are added to the list. 256 + */ 257 + list_sort(NULL, &voter->commit_list, cmp_vcd); 258 + 259 + /* 260 + * Construct the command list based on a pre ordered list of BCMs 261 + * based on VCD. 262 + */ 263 + tcs_list_gen(&voter->commit_list, QCOM_ICC_BUCKET_AMC, cmds, commit_idx); 264 + 265 + if (!commit_idx[0]) 266 + goto out; 267 + 268 + ret = rpmh_invalidate(voter->dev); 269 + if (ret) { 270 + pr_err("Error invalidating RPMH client (%d)\n", ret); 271 + goto out; 272 + } 273 + 274 + ret = rpmh_write_batch(voter->dev, RPMH_ACTIVE_ONLY_STATE, 275 + cmds, commit_idx); 276 + if (ret) { 277 + pr_err("Error sending AMC RPMH requests (%d)\n", ret); 278 + goto out; 279 + } 280 + 281 + list_for_each_entry_safe(bcm, bcm_tmp, &voter->commit_list, list) 282 + list_del_init(&bcm->list); 283 + 284 + list_for_each_entry_safe(bcm, bcm_tmp, &voter->ws_list, ws_list) { 285 + /* 286 + * Only generate WAKE and SLEEP commands if a resource's 287 + * requirements change as the execution environment transitions 288 + * between different power states. 289 + */ 290 + if (bcm->vote_x[QCOM_ICC_BUCKET_WAKE] != 291 + bcm->vote_x[QCOM_ICC_BUCKET_SLEEP] || 292 + bcm->vote_y[QCOM_ICC_BUCKET_WAKE] != 293 + bcm->vote_y[QCOM_ICC_BUCKET_SLEEP]) 294 + list_add_tail(&bcm->list, &voter->commit_list); 295 + else 296 + list_del_init(&bcm->ws_list); 297 + } 298 + 299 + if (list_empty(&voter->commit_list)) 300 + goto out; 301 + 302 + list_sort(NULL, &voter->commit_list, cmp_vcd); 303 + 304 + tcs_list_gen(&voter->commit_list, QCOM_ICC_BUCKET_WAKE, cmds, commit_idx); 305 + 306 + ret = rpmh_write_batch(voter->dev, RPMH_WAKE_ONLY_STATE, cmds, commit_idx); 307 + if (ret) { 308 + pr_err("Error sending WAKE RPMH requests (%d)\n", ret); 309 + goto out; 310 + } 311 + 312 + tcs_list_gen(&voter->commit_list, QCOM_ICC_BUCKET_SLEEP, cmds, commit_idx); 313 + 314 + ret = rpmh_write_batch(voter->dev, RPMH_SLEEP_STATE, cmds, commit_idx); 315 + if (ret) { 316 + pr_err("Error sending SLEEP RPMH requests (%d)\n", ret); 317 + goto out; 318 + } 319 + 320 + out: 321 + list_for_each_entry_safe(bcm, bcm_tmp, &voter->commit_list, list) 322 + list_del_init(&bcm->list); 323 + 324 + mutex_unlock(&voter->lock); 325 + return ret; 326 + } 327 + EXPORT_SYMBOL_GPL(qcom_icc_bcm_voter_commit); 328 + 329 + static int qcom_icc_bcm_voter_probe(struct platform_device *pdev) 330 + { 331 + struct bcm_voter *voter; 332 + 333 + voter = devm_kzalloc(&pdev->dev, sizeof(*voter), GFP_KERNEL); 334 + if (!voter) 335 + return -ENOMEM; 336 + 337 + voter->dev = &pdev->dev; 338 + voter->np = pdev->dev.of_node; 339 + mutex_init(&voter->lock); 340 + INIT_LIST_HEAD(&voter->commit_list); 341 + INIT_LIST_HEAD(&voter->ws_list); 342 + 343 + mutex_lock(&bcm_voter_lock); 344 + list_add_tail(&voter->voter_node, &bcm_voters); 345 + mutex_unlock(&bcm_voter_lock); 346 + 347 + return 0; 348 + } 349 + 350 + static const struct of_device_id bcm_voter_of_match[] = { 351 + { .compatible = "qcom,bcm-voter" }, 352 + { } 353 + }; 354 + 355 + static struct platform_driver qcom_icc_bcm_voter_driver = { 356 + .probe = qcom_icc_bcm_voter_probe, 357 + .driver = { 358 + .name = "bcm_voter", 359 + .of_match_table = bcm_voter_of_match, 360 + }, 361 + }; 362 + module_platform_driver(qcom_icc_bcm_voter_driver); 363 + 364 + MODULE_AUTHOR("David Dai <daidavid1@codeaurora.org>"); 365 + MODULE_DESCRIPTION("Qualcomm BCM Voter interconnect driver"); 366 + MODULE_LICENSE("GPL v2");
+27
drivers/interconnect/qcom/bcm-voter.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + /* 3 + * Copyright (c) 2020, The Linux Foundation. All rights reserved. 4 + */ 5 + 6 + #ifndef __DRIVERS_INTERCONNECT_QCOM_BCM_VOTER_H__ 7 + #define __DRIVERS_INTERCONNECT_QCOM_BCM_VOTER_H__ 8 + 9 + #include <soc/qcom/cmd-db.h> 10 + #include <soc/qcom/rpmh.h> 11 + #include <soc/qcom/tcs.h> 12 + 13 + #include "icc-rpmh.h" 14 + 15 + #define DEFINE_QBCM(_name, _bcmname, _keepalive, ...) \ 16 + static struct qcom_icc_bcm _name = { \ 17 + .name = _bcmname, \ 18 + .keepalive = _keepalive, \ 19 + .num_nodes = ARRAY_SIZE(((struct qcom_icc_node *[]){ __VA_ARGS__ })), \ 20 + .nodes = { __VA_ARGS__ }, \ 21 + } 22 + 23 + struct bcm_voter *of_bcm_voter_get(struct device *dev, const char *name); 24 + void qcom_icc_bcm_voter_add(struct bcm_voter *voter, struct qcom_icc_bcm *bcm); 25 + int qcom_icc_bcm_voter_commit(struct bcm_voter *voter); 26 + 27 + #endif
+150
drivers/interconnect/qcom/icc-rpmh.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * Copyright (c) 2020, The Linux Foundation. All rights reserved. 4 + */ 5 + 6 + #include <linux/interconnect.h> 7 + #include <linux/interconnect-provider.h> 8 + #include <linux/module.h> 9 + 10 + #include "bcm-voter.h" 11 + #include "icc-rpmh.h" 12 + 13 + /** 14 + * qcom_icc_pre_aggregate - cleans up stale values from prior icc_set 15 + * @node: icc node to operate on 16 + */ 17 + void qcom_icc_pre_aggregate(struct icc_node *node) 18 + { 19 + size_t i; 20 + struct qcom_icc_node *qn; 21 + 22 + qn = node->data; 23 + 24 + for (i = 0; i < QCOM_ICC_NUM_BUCKETS; i++) { 25 + qn->sum_avg[i] = 0; 26 + qn->max_peak[i] = 0; 27 + } 28 + } 29 + EXPORT_SYMBOL_GPL(qcom_icc_pre_aggregate); 30 + 31 + /** 32 + * qcom_icc_aggregate - aggregate bw for buckets indicated by tag 33 + * @node: node to aggregate 34 + * @tag: tag to indicate which buckets to aggregate 35 + * @avg_bw: new bw to sum aggregate 36 + * @peak_bw: new bw to max aggregate 37 + * @agg_avg: existing aggregate avg bw val 38 + * @agg_peak: existing aggregate peak bw val 39 + */ 40 + int qcom_icc_aggregate(struct icc_node *node, u32 tag, u32 avg_bw, 41 + u32 peak_bw, u32 *agg_avg, u32 *agg_peak) 42 + { 43 + size_t i; 44 + struct qcom_icc_node *qn; 45 + struct qcom_icc_provider *qp; 46 + 47 + qn = node->data; 48 + qp = to_qcom_provider(node->provider); 49 + 50 + if (!tag) 51 + tag = QCOM_ICC_TAG_ALWAYS; 52 + 53 + for (i = 0; i < QCOM_ICC_NUM_BUCKETS; i++) { 54 + if (tag & BIT(i)) { 55 + qn->sum_avg[i] += avg_bw; 56 + qn->max_peak[i] = max_t(u32, qn->max_peak[i], peak_bw); 57 + } 58 + } 59 + 60 + *agg_avg += avg_bw; 61 + *agg_peak = max_t(u32, *agg_peak, peak_bw); 62 + 63 + for (i = 0; i < qn->num_bcms; i++) 64 + qcom_icc_bcm_voter_add(qp->voter, qn->bcms[i]); 65 + 66 + return 0; 67 + } 68 + EXPORT_SYMBOL_GPL(qcom_icc_aggregate); 69 + 70 + /** 71 + * qcom_icc_set - set the constraints based on path 72 + * @src: source node for the path to set constraints on 73 + * @dst: destination node for the path to set constraints on 74 + * 75 + * Return: 0 on success, or an error code otherwise 76 + */ 77 + int qcom_icc_set(struct icc_node *src, struct icc_node *dst) 78 + { 79 + struct qcom_icc_provider *qp; 80 + struct icc_node *node; 81 + 82 + if (!src) 83 + node = dst; 84 + else 85 + node = src; 86 + 87 + qp = to_qcom_provider(node->provider); 88 + 89 + qcom_icc_bcm_voter_commit(qp->voter); 90 + 91 + return 0; 92 + } 93 + EXPORT_SYMBOL_GPL(qcom_icc_set); 94 + 95 + /** 96 + * qcom_icc_bcm_init - populates bcm aux data and connect qnodes 97 + * @bcm: bcm to be initialized 98 + * @dev: associated provider device 99 + * 100 + * Return: 0 on success, or an error code otherwise 101 + */ 102 + int qcom_icc_bcm_init(struct qcom_icc_bcm *bcm, struct device *dev) 103 + { 104 + struct qcom_icc_node *qn; 105 + const struct bcm_db *data; 106 + size_t data_count; 107 + int i; 108 + 109 + /* BCM is already initialised*/ 110 + if (bcm->addr) 111 + return 0; 112 + 113 + bcm->addr = cmd_db_read_addr(bcm->name); 114 + if (!bcm->addr) { 115 + dev_err(dev, "%s could not find RPMh address\n", 116 + bcm->name); 117 + return -EINVAL; 118 + } 119 + 120 + data = cmd_db_read_aux_data(bcm->name, &data_count); 121 + if (IS_ERR(data)) { 122 + dev_err(dev, "%s command db read error (%ld)\n", 123 + bcm->name, PTR_ERR(data)); 124 + return PTR_ERR(data); 125 + } 126 + if (!data_count) { 127 + dev_err(dev, "%s command db missing or partial aux data\n", 128 + bcm->name); 129 + return -EINVAL; 130 + } 131 + 132 + bcm->aux_data.unit = le32_to_cpu(data->unit); 133 + bcm->aux_data.width = le16_to_cpu(data->width); 134 + bcm->aux_data.vcd = data->vcd; 135 + bcm->aux_data.reserved = data->reserved; 136 + INIT_LIST_HEAD(&bcm->list); 137 + INIT_LIST_HEAD(&bcm->ws_list); 138 + 139 + /* Link Qnodes to their respective BCMs */ 140 + for (i = 0; i < bcm->num_nodes; i++) { 141 + qn = bcm->nodes[i]; 142 + qn->bcms[qn->num_bcms] = bcm; 143 + qn->num_bcms++; 144 + } 145 + 146 + return 0; 147 + } 148 + EXPORT_SYMBOL_GPL(qcom_icc_bcm_init); 149 + 150 + MODULE_LICENSE("GPL v2");
+149
drivers/interconnect/qcom/icc-rpmh.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + /* 3 + * Copyright (c) 2020, The Linux Foundation. All rights reserved. 4 + */ 5 + 6 + #ifndef __DRIVERS_INTERCONNECT_QCOM_ICC_RPMH_H__ 7 + #define __DRIVERS_INTERCONNECT_QCOM_ICC_RPMH_H__ 8 + 9 + #define to_qcom_provider(_provider) \ 10 + container_of(_provider, struct qcom_icc_provider, provider) 11 + 12 + /** 13 + * struct qcom_icc_provider - Qualcomm specific interconnect provider 14 + * @provider: generic interconnect provider 15 + * @dev: reference to the NoC device 16 + * @bcms: list of bcms that maps to the provider 17 + * @num_bcms: number of @bcms 18 + * @voter: bcm voter targeted by this provider 19 + */ 20 + struct qcom_icc_provider { 21 + struct icc_provider provider; 22 + struct device *dev; 23 + struct qcom_icc_bcm **bcms; 24 + size_t num_bcms; 25 + struct bcm_voter *voter; 26 + }; 27 + 28 + /** 29 + * struct bcm_db - Auxiliary data pertaining to each Bus Clock Manager (BCM) 30 + * @unit: divisor used to convert bytes/sec bw value to an RPMh msg 31 + * @width: multiplier used to convert bytes/sec bw value to an RPMh msg 32 + * @vcd: virtual clock domain that this bcm belongs to 33 + * @reserved: reserved field 34 + */ 35 + struct bcm_db { 36 + __le32 unit; 37 + __le16 width; 38 + u8 vcd; 39 + u8 reserved; 40 + }; 41 + 42 + #define MAX_LINKS 128 43 + #define MAX_BCMS 64 44 + #define MAX_BCM_PER_NODE 3 45 + #define MAX_VCD 10 46 + 47 + /* 48 + * The AMC bucket denotes constraints that are applied to hardware when 49 + * icc_set_bw() completes, whereas the WAKE and SLEEP constraints are applied 50 + * when the execution environment transitions between active and low power mode. 51 + */ 52 + #define QCOM_ICC_BUCKET_AMC 0 53 + #define QCOM_ICC_BUCKET_WAKE 1 54 + #define QCOM_ICC_BUCKET_SLEEP 2 55 + #define QCOM_ICC_NUM_BUCKETS 3 56 + #define QCOM_ICC_TAG_AMC BIT(QCOM_ICC_BUCKET_AMC) 57 + #define QCOM_ICC_TAG_WAKE BIT(QCOM_ICC_BUCKET_WAKE) 58 + #define QCOM_ICC_TAG_SLEEP BIT(QCOM_ICC_BUCKET_SLEEP) 59 + #define QCOM_ICC_TAG_ACTIVE_ONLY (QCOM_ICC_TAG_AMC | QCOM_ICC_TAG_WAKE) 60 + #define QCOM_ICC_TAG_ALWAYS (QCOM_ICC_TAG_AMC | QCOM_ICC_TAG_WAKE |\ 61 + QCOM_ICC_TAG_SLEEP) 62 + 63 + /** 64 + * struct qcom_icc_node - Qualcomm specific interconnect nodes 65 + * @name: the node name used in debugfs 66 + * @links: an array of nodes where we can go next while traversing 67 + * @id: a unique node identifier 68 + * @num_links: the total number of @links 69 + * @channels: num of channels at this node 70 + * @buswidth: width of the interconnect between a node and the bus 71 + * @sum_avg: current sum aggregate value of all avg bw requests 72 + * @max_peak: current max aggregate value of all peak bw requests 73 + * @bcms: list of bcms associated with this logical node 74 + * @num_bcms: num of @bcms 75 + */ 76 + struct qcom_icc_node { 77 + const char *name; 78 + u16 links[MAX_LINKS]; 79 + u16 id; 80 + u16 num_links; 81 + u16 channels; 82 + u16 buswidth; 83 + u64 sum_avg[QCOM_ICC_NUM_BUCKETS]; 84 + u64 max_peak[QCOM_ICC_NUM_BUCKETS]; 85 + struct qcom_icc_bcm *bcms[MAX_BCM_PER_NODE]; 86 + size_t num_bcms; 87 + }; 88 + 89 + /** 90 + * struct qcom_icc_bcm - Qualcomm specific hardware accelerator nodes 91 + * known as Bus Clock Manager (BCM) 92 + * @name: the bcm node name used to fetch BCM data from command db 93 + * @type: latency or bandwidth bcm 94 + * @addr: address offsets used when voting to RPMH 95 + * @vote_x: aggregated threshold values, represents sum_bw when @type is bw bcm 96 + * @vote_y: aggregated threshold values, represents peak_bw when @type is bw bcm 97 + * @dirty: flag used to indicate whether the bcm needs to be committed 98 + * @keepalive: flag used to indicate whether a keepalive is required 99 + * @aux_data: auxiliary data used when calculating threshold values and 100 + * communicating with RPMh 101 + * @list: used to link to other bcms when compiling lists for commit 102 + * @ws_list: used to keep track of bcms that may transition between wake/sleep 103 + * @num_nodes: total number of @num_nodes 104 + * @nodes: list of qcom_icc_nodes that this BCM encapsulates 105 + */ 106 + struct qcom_icc_bcm { 107 + const char *name; 108 + u32 type; 109 + u32 addr; 110 + u64 vote_x[QCOM_ICC_NUM_BUCKETS]; 111 + u64 vote_y[QCOM_ICC_NUM_BUCKETS]; 112 + bool dirty; 113 + bool keepalive; 114 + struct bcm_db aux_data; 115 + struct list_head list; 116 + struct list_head ws_list; 117 + size_t num_nodes; 118 + struct qcom_icc_node *nodes[]; 119 + }; 120 + 121 + struct qcom_icc_fabric { 122 + struct qcom_icc_node **nodes; 123 + size_t num_nodes; 124 + }; 125 + 126 + struct qcom_icc_desc { 127 + struct qcom_icc_node **nodes; 128 + size_t num_nodes; 129 + struct qcom_icc_bcm **bcms; 130 + size_t num_bcms; 131 + }; 132 + 133 + #define DEFINE_QNODE(_name, _id, _channels, _buswidth, ...) \ 134 + static struct qcom_icc_node _name = { \ 135 + .id = _id, \ 136 + .name = #_name, \ 137 + .channels = _channels, \ 138 + .buswidth = _buswidth, \ 139 + .num_links = ARRAY_SIZE(((int[]){ __VA_ARGS__ })), \ 140 + .links = { __VA_ARGS__ }, \ 141 + } 142 + 143 + int qcom_icc_aggregate(struct icc_node *node, u32 tag, u32 avg_bw, 144 + u32 peak_bw, u32 *agg_avg, u32 *agg_peak); 145 + int qcom_icc_set(struct icc_node *src, struct icc_node *dst); 146 + int qcom_icc_bcm_init(struct qcom_icc_bcm *bcm, struct device *dev); 147 + void qcom_icc_pre_aggregate(struct icc_node *node); 148 + 149 + #endif