xref: /linux/drivers/interconnect/qcom/icc-rpmh.h (revision 3df692169e8486fc3dd91fcd5ea81c27a0bac033)
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 #include <dt-bindings/interconnect/qcom,icc.h>
10 
11 #define to_qcom_provider(_provider) \
12 	container_of(_provider, struct qcom_icc_provider, provider)
13 
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 bcm_voter *voter;
28 };
29 
30 /**
31  * struct bcm_db - Auxiliary data pertaining to each Bus Clock Manager (BCM)
32  * @unit: divisor used to convert bytes/sec bw value to an RPMh msg
33  * @width: multiplier used to convert bytes/sec bw value to an RPMh msg
34  * @vcd: virtual clock domain that this bcm belongs to
35  * @reserved: reserved field
36  */
37 struct bcm_db {
38 	__le32 unit;
39 	__le16 width;
40 	u8 vcd;
41 	u8 reserved;
42 };
43 
44 #define MAX_LINKS		128
45 #define MAX_BCMS		64
46 #define MAX_BCM_PER_NODE	3
47 #define MAX_VCD			10
48 
49 /**
50  * struct qcom_icc_node - Qualcomm specific interconnect nodes
51  * @name: the node name used in debugfs
52  * @links: an array of nodes where we can go next while traversing
53  * @id: a unique node identifier
54  * @num_links: the total number of @links
55  * @channels: num of channels at this node
56  * @buswidth: width of the interconnect between a node and the bus
57  * @sum_avg: current sum aggregate value of all avg bw requests
58  * @max_peak: current max aggregate value of all peak bw requests
59  * @bcms: list of bcms associated with this logical node
60  * @num_bcms: num of @bcms
61  */
62 struct qcom_icc_node {
63 	const char *name;
64 	u16 links[MAX_LINKS];
65 	u16 id;
66 	u16 num_links;
67 	u16 channels;
68 	u16 buswidth;
69 	u64 sum_avg[QCOM_ICC_NUM_BUCKETS];
70 	u64 max_peak[QCOM_ICC_NUM_BUCKETS];
71 	struct qcom_icc_bcm *bcms[MAX_BCM_PER_NODE];
72 	size_t num_bcms;
73 };
74 
75 /**
76  * struct qcom_icc_bcm - Qualcomm specific hardware accelerator nodes
77  * known as Bus Clock Manager (BCM)
78  * @name: the bcm node name used to fetch BCM data from command db
79  * @type: latency or bandwidth bcm
80  * @addr: address offsets used when voting to RPMH
81  * @vote_x: aggregated threshold values, represents sum_bw when @type is bw bcm
82  * @vote_y: aggregated threshold values, represents peak_bw when @type is bw bcm
83  * @vote_scale: scaling factor for vote_x and vote_y
84  * @enable_mask: optional mask to send as vote instead of vote_x/vote_y
85  * @dirty: flag used to indicate whether the bcm needs to be committed
86  * @keepalive: flag used to indicate whether a keepalive is required
87  * @aux_data: auxiliary data used when calculating threshold values and
88  * communicating with RPMh
89  * @list: used to link to other bcms when compiling lists for commit
90  * @ws_list: used to keep track of bcms that may transition between wake/sleep
91  * @num_nodes: total number of @num_nodes
92  * @nodes: list of qcom_icc_nodes that this BCM encapsulates
93  */
94 struct qcom_icc_bcm {
95 	const char *name;
96 	u32 type;
97 	u32 addr;
98 	u64 vote_x[QCOM_ICC_NUM_BUCKETS];
99 	u64 vote_y[QCOM_ICC_NUM_BUCKETS];
100 	u64 vote_scale;
101 	u32 enable_mask;
102 	bool dirty;
103 	bool keepalive;
104 	struct bcm_db aux_data;
105 	struct list_head list;
106 	struct list_head ws_list;
107 	size_t num_nodes;
108 	struct qcom_icc_node *nodes[];
109 };
110 
111 struct qcom_icc_fabric {
112 	struct qcom_icc_node **nodes;
113 	size_t num_nodes;
114 };
115 
116 struct qcom_icc_desc {
117 	struct qcom_icc_node * const *nodes;
118 	size_t num_nodes;
119 	struct qcom_icc_bcm * const *bcms;
120 	size_t num_bcms;
121 };
122 
123 int qcom_icc_aggregate(struct icc_node *node, u32 tag, u32 avg_bw,
124 		       u32 peak_bw, u32 *agg_avg, u32 *agg_peak);
125 int qcom_icc_set(struct icc_node *src, struct icc_node *dst);
126 int qcom_icc_bcm_init(struct qcom_icc_bcm *bcm, struct device *dev);
127 void qcom_icc_pre_aggregate(struct icc_node *node);
128 int qcom_icc_rpmh_probe(struct platform_device *pdev);
129 void qcom_icc_rpmh_remove(struct platform_device *pdev);
130 
131 #endif
132