aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOlof Johansson <olof@lixom.net>2018-05-15 16:48:46 -0400
committerOlof Johansson <olof@lixom.net>2018-05-15 16:48:46 -0400
commit51fe3a373ee44bbad72a27c56110f3c1d80c0a04 (patch)
treec1b1d50bced150b277d0395b5610c3f99a654eab
parentf6b3f4ac521523432761f4480dd3cad1a955593b (diff)
parent632de8f542bcd44c756637da0e7d824e7129e496 (diff)
Merge tag 'scmi-updates-4.18' of git://git.kernel.org/pub/scm/linux/kernel/git/sudeep.holla/linux into next/drivers
SCMI cleanups for v4.18 This contains all of the trivial review comments that were not addressed as the series was already queued up for v4.17 and were not critical to go as fixes. They generally just improve code readability, fix kernel-docs, remove unused/unnecessary code, follow standard function naming and simplifies certain exit paths. * tag 'scmi-updates-4.18' of git://git.kernel.org/pub/scm/linux/kernel/git/sudeep.holla/linux: firmware: arm_scmi: simplify exit path by returning on error firmware: arm_scmi: improve exit paths and code readability firmware: arm_scmi: remove unnecessary bitmap_zero firmware: arm_scmi: drop unused `con_priv` structure member firmware: arm_scmi: rename scmi_xfer_{init,get,put} firmware: arm_scmi: rename get_transition_latency and add_opps_to_device firmware: arm_scmi: fix kernel-docs documentation firmware: arm_scmi: improve code readability using bitfield accessor macros Signed-off-by: Olof Johansson <olof@lixom.net>
-rw-r--r--drivers/cpufreq/scmi-cpufreq.c4
-rw-r--r--drivers/firmware/arm_scmi/base.c43
-rw-r--r--drivers/firmware/arm_scmi/bus.c22
-rw-r--r--drivers/firmware/arm_scmi/clock.c24
-rw-r--r--drivers/firmware/arm_scmi/common.h22
-rw-r--r--drivers/firmware/arm_scmi/driver.c109
-rw-r--r--drivers/firmware/arm_scmi/perf.c38
-rw-r--r--drivers/firmware/arm_scmi/power.c16
-rw-r--r--drivers/firmware/arm_scmi/sensors.c20
-rw-r--r--include/linux/scmi_protocol.h18
10 files changed, 166 insertions, 150 deletions
diff --git a/drivers/cpufreq/scmi-cpufreq.c b/drivers/cpufreq/scmi-cpufreq.c
index b4dbc77459b6..50b1551ba894 100644
--- a/drivers/cpufreq/scmi-cpufreq.c
+++ b/drivers/cpufreq/scmi-cpufreq.c
@@ -117,7 +117,7 @@ static int scmi_cpufreq_init(struct cpufreq_policy *policy)
117 return -ENODEV; 117 return -ENODEV;
118 } 118 }
119 119
120 ret = handle->perf_ops->add_opps_to_device(handle, cpu_dev); 120 ret = handle->perf_ops->device_opps_add(handle, cpu_dev);
121 if (ret) { 121 if (ret) {
122 dev_warn(cpu_dev, "failed to add opps to the device\n"); 122 dev_warn(cpu_dev, "failed to add opps to the device\n");
123 return ret; 123 return ret;
@@ -164,7 +164,7 @@ static int scmi_cpufreq_init(struct cpufreq_policy *policy)
164 /* SCMI allows DVFS request for any domain from any CPU */ 164 /* SCMI allows DVFS request for any domain from any CPU */
165 policy->dvfs_possible_from_any_cpu = true; 165 policy->dvfs_possible_from_any_cpu = true;
166 166
167 latency = handle->perf_ops->get_transition_latency(handle, cpu_dev); 167 latency = handle->perf_ops->transition_latency_get(handle, cpu_dev);
168 if (!latency) 168 if (!latency)
169 latency = CPUFREQ_ETERNAL; 169 latency = CPUFREQ_ETERNAL;
170 170
diff --git a/drivers/firmware/arm_scmi/base.c b/drivers/firmware/arm_scmi/base.c
index 0d3806c0d432..9dff33ea6416 100644
--- a/drivers/firmware/arm_scmi/base.c
+++ b/drivers/firmware/arm_scmi/base.c
@@ -26,7 +26,7 @@ struct scmi_msg_resp_base_attributes {
26 * scmi_base_attributes_get() - gets the implementation details 26 * scmi_base_attributes_get() - gets the implementation details
27 * that are associated with the base protocol. 27 * that are associated with the base protocol.
28 * 28 *
29 * @handle - SCMI entity handle 29 * @handle: SCMI entity handle
30 * 30 *
31 * Return: 0 on success, else appropriate SCMI error. 31 * Return: 0 on success, else appropriate SCMI error.
32 */ 32 */
@@ -37,7 +37,7 @@ static int scmi_base_attributes_get(const struct scmi_handle *handle)
37 struct scmi_msg_resp_base_attributes *attr_info; 37 struct scmi_msg_resp_base_attributes *attr_info;
38 struct scmi_revision_info *rev = handle->version; 38 struct scmi_revision_info *rev = handle->version;
39 39
40 ret = scmi_one_xfer_init(handle, PROTOCOL_ATTRIBUTES, 40 ret = scmi_xfer_get_init(handle, PROTOCOL_ATTRIBUTES,
41 SCMI_PROTOCOL_BASE, 0, sizeof(*attr_info), &t); 41 SCMI_PROTOCOL_BASE, 0, sizeof(*attr_info), &t);
42 if (ret) 42 if (ret)
43 return ret; 43 return ret;
@@ -49,15 +49,16 @@ static int scmi_base_attributes_get(const struct scmi_handle *handle)
49 rev->num_agents = attr_info->num_agents; 49 rev->num_agents = attr_info->num_agents;
50 } 50 }
51 51
52 scmi_one_xfer_put(handle, t); 52 scmi_xfer_put(handle, t);
53
53 return ret; 54 return ret;
54} 55}
55 56
56/** 57/**
57 * scmi_base_vendor_id_get() - gets vendor/subvendor identifier ASCII string. 58 * scmi_base_vendor_id_get() - gets vendor/subvendor identifier ASCII string.
58 * 59 *
59 * @handle - SCMI entity handle 60 * @handle: SCMI entity handle
60 * @sub_vendor - specify true if sub-vendor ID is needed 61 * @sub_vendor: specify true if sub-vendor ID is needed
61 * 62 *
62 * Return: 0 on success, else appropriate SCMI error. 63 * Return: 0 on success, else appropriate SCMI error.
63 */ 64 */
@@ -80,7 +81,7 @@ scmi_base_vendor_id_get(const struct scmi_handle *handle, bool sub_vendor)
80 size = ARRAY_SIZE(rev->vendor_id); 81 size = ARRAY_SIZE(rev->vendor_id);
81 } 82 }
82 83
83 ret = scmi_one_xfer_init(handle, cmd, SCMI_PROTOCOL_BASE, 0, size, &t); 84 ret = scmi_xfer_get_init(handle, cmd, SCMI_PROTOCOL_BASE, 0, size, &t);
84 if (ret) 85 if (ret)
85 return ret; 86 return ret;
86 87
@@ -88,7 +89,8 @@ scmi_base_vendor_id_get(const struct scmi_handle *handle, bool sub_vendor)
88 if (!ret) 89 if (!ret)
89 memcpy(vendor_id, t->rx.buf, size); 90 memcpy(vendor_id, t->rx.buf, size);
90 91
91 scmi_one_xfer_put(handle, t); 92 scmi_xfer_put(handle, t);
93
92 return ret; 94 return ret;
93} 95}
94 96
@@ -97,7 +99,7 @@ scmi_base_vendor_id_get(const struct scmi_handle *handle, bool sub_vendor)
97 * implementation 32-bit version. The format of the version number is 99 * implementation 32-bit version. The format of the version number is
98 * vendor-specific 100 * vendor-specific
99 * 101 *
100 * @handle - SCMI entity handle 102 * @handle: SCMI entity handle
101 * 103 *
102 * Return: 0 on success, else appropriate SCMI error. 104 * Return: 0 on success, else appropriate SCMI error.
103 */ 105 */
@@ -109,7 +111,7 @@ scmi_base_implementation_version_get(const struct scmi_handle *handle)
109 struct scmi_xfer *t; 111 struct scmi_xfer *t;
110 struct scmi_revision_info *rev = handle->version; 112 struct scmi_revision_info *rev = handle->version;
111 113
112 ret = scmi_one_xfer_init(handle, BASE_DISCOVER_IMPLEMENT_VERSION, 114 ret = scmi_xfer_get_init(handle, BASE_DISCOVER_IMPLEMENT_VERSION,
113 SCMI_PROTOCOL_BASE, 0, sizeof(*impl_ver), &t); 115 SCMI_PROTOCOL_BASE, 0, sizeof(*impl_ver), &t);
114 if (ret) 116 if (ret)
115 return ret; 117 return ret;
@@ -120,7 +122,8 @@ scmi_base_implementation_version_get(const struct scmi_handle *handle)
120 rev->impl_ver = le32_to_cpu(*impl_ver); 122 rev->impl_ver = le32_to_cpu(*impl_ver);
121 } 123 }
122 124
123 scmi_one_xfer_put(handle, t); 125 scmi_xfer_put(handle, t);
126
124 return ret; 127 return ret;
125} 128}
126 129
@@ -128,8 +131,8 @@ scmi_base_implementation_version_get(const struct scmi_handle *handle)
128 * scmi_base_implementation_list_get() - gets the list of protocols it is 131 * scmi_base_implementation_list_get() - gets the list of protocols it is
129 * OSPM is allowed to access 132 * OSPM is allowed to access
130 * 133 *
131 * @handle - SCMI entity handle 134 * @handle: SCMI entity handle
132 * @protocols_imp - pointer to hold the list of protocol identifiers 135 * @protocols_imp: pointer to hold the list of protocol identifiers
133 * 136 *
134 * Return: 0 on success, else appropriate SCMI error. 137 * Return: 0 on success, else appropriate SCMI error.
135 */ 138 */
@@ -143,7 +146,7 @@ static int scmi_base_implementation_list_get(const struct scmi_handle *handle,
143 u32 tot_num_ret = 0, loop_num_ret; 146 u32 tot_num_ret = 0, loop_num_ret;
144 struct device *dev = handle->dev; 147 struct device *dev = handle->dev;
145 148
146 ret = scmi_one_xfer_init(handle, BASE_DISCOVER_LIST_PROTOCOLS, 149 ret = scmi_xfer_get_init(handle, BASE_DISCOVER_LIST_PROTOCOLS,
147 SCMI_PROTOCOL_BASE, sizeof(*num_skip), 0, &t); 150 SCMI_PROTOCOL_BASE, sizeof(*num_skip), 0, &t);
148 if (ret) 151 if (ret)
149 return ret; 152 return ret;
@@ -172,16 +175,17 @@ static int scmi_base_implementation_list_get(const struct scmi_handle *handle,
172 tot_num_ret += loop_num_ret; 175 tot_num_ret += loop_num_ret;
173 } while (loop_num_ret); 176 } while (loop_num_ret);
174 177
175 scmi_one_xfer_put(handle, t); 178 scmi_xfer_put(handle, t);
179
176 return ret; 180 return ret;
177} 181}
178 182
179/** 183/**
180 * scmi_base_discover_agent_get() - discover the name of an agent 184 * scmi_base_discover_agent_get() - discover the name of an agent
181 * 185 *
182 * @handle - SCMI entity handle 186 * @handle: SCMI entity handle
183 * @id - Agent identifier 187 * @id: Agent identifier
184 * @name - Agent identifier ASCII string 188 * @name: Agent identifier ASCII string
185 * 189 *
186 * An agent id of 0 is reserved to identify the platform itself. 190 * An agent id of 0 is reserved to identify the platform itself.
187 * Generally operating system is represented as "OSPM" 191 * Generally operating system is represented as "OSPM"
@@ -194,7 +198,7 @@ static int scmi_base_discover_agent_get(const struct scmi_handle *handle,
194 int ret; 198 int ret;
195 struct scmi_xfer *t; 199 struct scmi_xfer *t;
196 200
197 ret = scmi_one_xfer_init(handle, BASE_DISCOVER_AGENT, 201 ret = scmi_xfer_get_init(handle, BASE_DISCOVER_AGENT,
198 SCMI_PROTOCOL_BASE, sizeof(__le32), 202 SCMI_PROTOCOL_BASE, sizeof(__le32),
199 SCMI_MAX_STR_SIZE, &t); 203 SCMI_MAX_STR_SIZE, &t);
200 if (ret) 204 if (ret)
@@ -206,7 +210,8 @@ static int scmi_base_discover_agent_get(const struct scmi_handle *handle,
206 if (!ret) 210 if (!ret)
207 memcpy(name, t->rx.buf, SCMI_MAX_STR_SIZE); 211 memcpy(name, t->rx.buf, SCMI_MAX_STR_SIZE);
208 212
209 scmi_one_xfer_put(handle, t); 213 scmi_xfer_put(handle, t);
214
210 return ret; 215 return ret;
211} 216}
212 217
diff --git a/drivers/firmware/arm_scmi/bus.c b/drivers/firmware/arm_scmi/bus.c
index f2760a596c28..472c88ae1c0f 100644
--- a/drivers/firmware/arm_scmi/bus.c
+++ b/drivers/firmware/arm_scmi/bus.c
@@ -125,13 +125,13 @@ scmi_device_create(struct device_node *np, struct device *parent, int protocol)
125 int id, retval; 125 int id, retval;
126 struct scmi_device *scmi_dev; 126 struct scmi_device *scmi_dev;
127 127
128 id = ida_simple_get(&scmi_bus_id, 1, 0, GFP_KERNEL);
129 if (id < 0)
130 return NULL;
131
132 scmi_dev = kzalloc(sizeof(*scmi_dev), GFP_KERNEL); 128 scmi_dev = kzalloc(sizeof(*scmi_dev), GFP_KERNEL);
133 if (!scmi_dev) 129 if (!scmi_dev)
134 goto no_mem; 130 return NULL;
131
132 id = ida_simple_get(&scmi_bus_id, 1, 0, GFP_KERNEL);
133 if (id < 0)
134 goto free_mem;
135 135
136 scmi_dev->id = id; 136 scmi_dev->id = id;
137 scmi_dev->protocol_id = protocol; 137 scmi_dev->protocol_id = protocol;
@@ -141,13 +141,15 @@ scmi_device_create(struct device_node *np, struct device *parent, int protocol)
141 dev_set_name(&scmi_dev->dev, "scmi_dev.%d", id); 141 dev_set_name(&scmi_dev->dev, "scmi_dev.%d", id);
142 142
143 retval = device_register(&scmi_dev->dev); 143 retval = device_register(&scmi_dev->dev);
144 if (!retval) 144 if (retval)
145 return scmi_dev; 145 goto put_dev;
146 146
147 return scmi_dev;
148put_dev:
147 put_device(&scmi_dev->dev); 149 put_device(&scmi_dev->dev);
148 kfree(scmi_dev);
149no_mem:
150 ida_simple_remove(&scmi_bus_id, id); 150 ida_simple_remove(&scmi_bus_id, id);
151free_mem:
152 kfree(scmi_dev);
151 return NULL; 153 return NULL;
152} 154}
153 155
@@ -171,9 +173,9 @@ int scmi_protocol_register(int protocol_id, scmi_prot_init_fn_t fn)
171 spin_lock(&protocol_lock); 173 spin_lock(&protocol_lock);
172 ret = idr_alloc(&scmi_protocols, fn, protocol_id, protocol_id + 1, 174 ret = idr_alloc(&scmi_protocols, fn, protocol_id, protocol_id + 1,
173 GFP_ATOMIC); 175 GFP_ATOMIC);
176 spin_unlock(&protocol_lock);
174 if (ret != protocol_id) 177 if (ret != protocol_id)
175 pr_err("unable to allocate SCMI idr slot, err %d\n", ret); 178 pr_err("unable to allocate SCMI idr slot, err %d\n", ret);
176 spin_unlock(&protocol_lock);
177 179
178 return ret; 180 return ret;
179} 181}
diff --git a/drivers/firmware/arm_scmi/clock.c b/drivers/firmware/arm_scmi/clock.c
index 2b90606452a2..e4119eb34986 100644
--- a/drivers/firmware/arm_scmi/clock.c
+++ b/drivers/firmware/arm_scmi/clock.c
@@ -77,7 +77,7 @@ static int scmi_clock_protocol_attributes_get(const struct scmi_handle *handle,
77 struct scmi_xfer *t; 77 struct scmi_xfer *t;
78 struct scmi_msg_resp_clock_protocol_attributes *attr; 78 struct scmi_msg_resp_clock_protocol_attributes *attr;
79 79
80 ret = scmi_one_xfer_init(handle, PROTOCOL_ATTRIBUTES, 80 ret = scmi_xfer_get_init(handle, PROTOCOL_ATTRIBUTES,
81 SCMI_PROTOCOL_CLOCK, 0, sizeof(*attr), &t); 81 SCMI_PROTOCOL_CLOCK, 0, sizeof(*attr), &t);
82 if (ret) 82 if (ret)
83 return ret; 83 return ret;
@@ -90,7 +90,7 @@ static int scmi_clock_protocol_attributes_get(const struct scmi_handle *handle,
90 ci->max_async_req = attr->max_async_req; 90 ci->max_async_req = attr->max_async_req;
91 } 91 }
92 92
93 scmi_one_xfer_put(handle, t); 93 scmi_xfer_put(handle, t);
94 return ret; 94 return ret;
95} 95}
96 96
@@ -101,7 +101,7 @@ static int scmi_clock_attributes_get(const struct scmi_handle *handle,
101 struct scmi_xfer *t; 101 struct scmi_xfer *t;
102 struct scmi_msg_resp_clock_attributes *attr; 102 struct scmi_msg_resp_clock_attributes *attr;
103 103
104 ret = scmi_one_xfer_init(handle, CLOCK_ATTRIBUTES, SCMI_PROTOCOL_CLOCK, 104 ret = scmi_xfer_get_init(handle, CLOCK_ATTRIBUTES, SCMI_PROTOCOL_CLOCK,
105 sizeof(clk_id), sizeof(*attr), &t); 105 sizeof(clk_id), sizeof(*attr), &t);
106 if (ret) 106 if (ret)
107 return ret; 107 return ret;
@@ -115,7 +115,7 @@ static int scmi_clock_attributes_get(const struct scmi_handle *handle,
115 else 115 else
116 clk->name[0] = '\0'; 116 clk->name[0] = '\0';
117 117
118 scmi_one_xfer_put(handle, t); 118 scmi_xfer_put(handle, t);
119 return ret; 119 return ret;
120} 120}
121 121
@@ -132,7 +132,7 @@ scmi_clock_describe_rates_get(const struct scmi_handle *handle, u32 clk_id,
132 struct scmi_msg_clock_describe_rates *clk_desc; 132 struct scmi_msg_clock_describe_rates *clk_desc;
133 struct scmi_msg_resp_clock_describe_rates *rlist; 133 struct scmi_msg_resp_clock_describe_rates *rlist;
134 134
135 ret = scmi_one_xfer_init(handle, CLOCK_DESCRIBE_RATES, 135 ret = scmi_xfer_get_init(handle, CLOCK_DESCRIBE_RATES,
136 SCMI_PROTOCOL_CLOCK, sizeof(*clk_desc), 0, &t); 136 SCMI_PROTOCOL_CLOCK, sizeof(*clk_desc), 0, &t);
137 if (ret) 137 if (ret)
138 return ret; 138 return ret;
@@ -186,7 +186,7 @@ scmi_clock_describe_rates_get(const struct scmi_handle *handle, u32 clk_id,
186 clk->list.num_rates = tot_rate_cnt; 186 clk->list.num_rates = tot_rate_cnt;
187 187
188err: 188err:
189 scmi_one_xfer_put(handle, t); 189 scmi_xfer_put(handle, t);
190 return ret; 190 return ret;
191} 191}
192 192
@@ -196,7 +196,7 @@ scmi_clock_rate_get(const struct scmi_handle *handle, u32 clk_id, u64 *value)
196 int ret; 196 int ret;
197 struct scmi_xfer *t; 197 struct scmi_xfer *t;
198 198
199 ret = scmi_one_xfer_init(handle, CLOCK_RATE_GET, SCMI_PROTOCOL_CLOCK, 199 ret = scmi_xfer_get_init(handle, CLOCK_RATE_GET, SCMI_PROTOCOL_CLOCK,
200 sizeof(__le32), sizeof(u64), &t); 200 sizeof(__le32), sizeof(u64), &t);
201 if (ret) 201 if (ret)
202 return ret; 202 return ret;
@@ -211,7 +211,7 @@ scmi_clock_rate_get(const struct scmi_handle *handle, u32 clk_id, u64 *value)
211 *value |= (u64)le32_to_cpu(*(pval + 1)) << 32; 211 *value |= (u64)le32_to_cpu(*(pval + 1)) << 32;
212 } 212 }
213 213
214 scmi_one_xfer_put(handle, t); 214 scmi_xfer_put(handle, t);
215 return ret; 215 return ret;
216} 216}
217 217
@@ -222,7 +222,7 @@ static int scmi_clock_rate_set(const struct scmi_handle *handle, u32 clk_id,
222 struct scmi_xfer *t; 222 struct scmi_xfer *t;
223 struct scmi_clock_set_rate *cfg; 223 struct scmi_clock_set_rate *cfg;
224 224
225 ret = scmi_one_xfer_init(handle, CLOCK_RATE_SET, SCMI_PROTOCOL_CLOCK, 225 ret = scmi_xfer_get_init(handle, CLOCK_RATE_SET, SCMI_PROTOCOL_CLOCK,
226 sizeof(*cfg), 0, &t); 226 sizeof(*cfg), 0, &t);
227 if (ret) 227 if (ret)
228 return ret; 228 return ret;
@@ -235,7 +235,7 @@ static int scmi_clock_rate_set(const struct scmi_handle *handle, u32 clk_id,
235 235
236 ret = scmi_do_xfer(handle, t); 236 ret = scmi_do_xfer(handle, t);
237 237
238 scmi_one_xfer_put(handle, t); 238 scmi_xfer_put(handle, t);
239 return ret; 239 return ret;
240} 240}
241 241
@@ -246,7 +246,7 @@ scmi_clock_config_set(const struct scmi_handle *handle, u32 clk_id, u32 config)
246 struct scmi_xfer *t; 246 struct scmi_xfer *t;
247 struct scmi_clock_set_config *cfg; 247 struct scmi_clock_set_config *cfg;
248 248
249 ret = scmi_one_xfer_init(handle, CLOCK_CONFIG_SET, SCMI_PROTOCOL_CLOCK, 249 ret = scmi_xfer_get_init(handle, CLOCK_CONFIG_SET, SCMI_PROTOCOL_CLOCK,
250 sizeof(*cfg), 0, &t); 250 sizeof(*cfg), 0, &t);
251 if (ret) 251 if (ret)
252 return ret; 252 return ret;
@@ -257,7 +257,7 @@ scmi_clock_config_set(const struct scmi_handle *handle, u32 clk_id, u32 config)
257 257
258 ret = scmi_do_xfer(handle, t); 258 ret = scmi_do_xfer(handle, t);
259 259
260 scmi_one_xfer_put(handle, t); 260 scmi_xfer_put(handle, t);
261 return ret; 261 return ret;
262} 262}
263 263
diff --git a/drivers/firmware/arm_scmi/common.h b/drivers/firmware/arm_scmi/common.h
index 0c30234f9098..937a930ce87d 100644
--- a/drivers/firmware/arm_scmi/common.h
+++ b/drivers/firmware/arm_scmi/common.h
@@ -7,6 +7,7 @@
7 * Copyright (C) 2018 ARM Ltd. 7 * Copyright (C) 2018 ARM Ltd.
8 */ 8 */
9 9
10#include <linux/bitfield.h>
10#include <linux/completion.h> 11#include <linux/completion.h>
11#include <linux/device.h> 12#include <linux/device.h>
12#include <linux/errno.h> 13#include <linux/errno.h>
@@ -14,10 +15,10 @@
14#include <linux/scmi_protocol.h> 15#include <linux/scmi_protocol.h>
15#include <linux/types.h> 16#include <linux/types.h>
16 17
17#define PROTOCOL_REV_MINOR_BITS 16 18#define PROTOCOL_REV_MINOR_MASK GENMASK(15, 0)
18#define PROTOCOL_REV_MINOR_MASK ((1U << PROTOCOL_REV_MINOR_BITS) - 1) 19#define PROTOCOL_REV_MAJOR_MASK GENMASK(31, 16)
19#define PROTOCOL_REV_MAJOR(x) ((x) >> PROTOCOL_REV_MINOR_BITS) 20#define PROTOCOL_REV_MAJOR(x) (u16)(FIELD_GET(PROTOCOL_REV_MAJOR_MASK, (x)))
20#define PROTOCOL_REV_MINOR(x) ((x) & PROTOCOL_REV_MINOR_MASK) 21#define PROTOCOL_REV_MINOR(x) (u16)(FIELD_GET(PROTOCOL_REV_MINOR_MASK, (x)))
21#define MAX_PROTOCOLS_IMP 16 22#define MAX_PROTOCOLS_IMP 16
22#define MAX_OPPS 16 23#define MAX_OPPS 16
23 24
@@ -50,8 +51,11 @@ struct scmi_msg_resp_prot_version {
50 * @id: The identifier of the command being sent 51 * @id: The identifier of the command being sent
51 * @protocol_id: The identifier of the protocol used to send @id command 52 * @protocol_id: The identifier of the protocol used to send @id command
52 * @seq: The token to identify the message. when a message/command returns, 53 * @seq: The token to identify the message. when a message/command returns,
53 * the platform returns the whole message header unmodified including 54 * the platform returns the whole message header unmodified including
54 * the token. 55 * the token
56 * @status: Status of the transfer once it's complete
57 * @poll_completion: Indicate if the transfer needs to be polled for
58 * completion or interrupt mode is used
55 */ 59 */
56struct scmi_msg_hdr { 60struct scmi_msg_hdr {
57 u8 id; 61 u8 id;
@@ -82,18 +86,16 @@ struct scmi_msg {
82 * buffer for the rx path as we use for the tx path. 86 * buffer for the rx path as we use for the tx path.
83 * @done: completion event 87 * @done: completion event
84 */ 88 */
85
86struct scmi_xfer { 89struct scmi_xfer {
87 void *con_priv;
88 struct scmi_msg_hdr hdr; 90 struct scmi_msg_hdr hdr;
89 struct scmi_msg tx; 91 struct scmi_msg tx;
90 struct scmi_msg rx; 92 struct scmi_msg rx;
91 struct completion done; 93 struct completion done;
92}; 94};
93 95
94void scmi_one_xfer_put(const struct scmi_handle *h, struct scmi_xfer *xfer); 96void scmi_xfer_put(const struct scmi_handle *h, struct scmi_xfer *xfer);
95int scmi_do_xfer(const struct scmi_handle *h, struct scmi_xfer *xfer); 97int scmi_do_xfer(const struct scmi_handle *h, struct scmi_xfer *xfer);
96int scmi_one_xfer_init(const struct scmi_handle *h, u8 msg_id, u8 prot_id, 98int scmi_xfer_get_init(const struct scmi_handle *h, u8 msg_id, u8 prot_id,
97 size_t tx_size, size_t rx_size, struct scmi_xfer **p); 99 size_t tx_size, size_t rx_size, struct scmi_xfer **p);
98int scmi_handle_put(const struct scmi_handle *handle); 100int scmi_handle_put(const struct scmi_handle *handle);
99struct scmi_handle *scmi_handle_get(struct device *dev); 101struct scmi_handle *scmi_handle_get(struct device *dev);
diff --git a/drivers/firmware/arm_scmi/driver.c b/drivers/firmware/arm_scmi/driver.c
index 14b147135a0c..e996395af5f2 100644
--- a/drivers/firmware/arm_scmi/driver.c
+++ b/drivers/firmware/arm_scmi/driver.c
@@ -29,16 +29,12 @@
29 29
30#include "common.h" 30#include "common.h"
31 31
32#define MSG_ID_SHIFT 0 32#define MSG_ID_MASK GENMASK(7, 0)
33#define MSG_ID_MASK 0xff 33#define MSG_TYPE_MASK GENMASK(9, 8)
34#define MSG_TYPE_SHIFT 8 34#define MSG_PROTOCOL_ID_MASK GENMASK(17, 10)
35#define MSG_TYPE_MASK 0x3 35#define MSG_TOKEN_ID_MASK GENMASK(27, 18)
36#define MSG_PROTOCOL_ID_SHIFT 10 36#define MSG_XTRACT_TOKEN(hdr) FIELD_GET(MSG_TOKEN_ID_MASK, (hdr))
37#define MSG_PROTOCOL_ID_MASK 0xff 37#define MSG_TOKEN_MAX (MSG_XTRACT_TOKEN(MSG_TOKEN_ID_MASK) + 1)
38#define MSG_TOKEN_ID_SHIFT 18
39#define MSG_TOKEN_ID_MASK 0x3ff
40#define MSG_XTRACT_TOKEN(header) \
41 (((header) >> MSG_TOKEN_ID_SHIFT) & MSG_TOKEN_ID_MASK)
42 38
43enum scmi_error_codes { 39enum scmi_error_codes {
44 SCMI_SUCCESS = 0, /* Success */ 40 SCMI_SUCCESS = 0, /* Success */
@@ -55,7 +51,7 @@ enum scmi_error_codes {
55 SCMI_ERR_MAX 51 SCMI_ERR_MAX
56}; 52};
57 53
58/* List of all SCMI devices active in system */ 54/* List of all SCMI devices active in system */
59static LIST_HEAD(scmi_list); 55static LIST_HEAD(scmi_list);
60/* Protection for the entire list */ 56/* Protection for the entire list */
61static DEFINE_MUTEX(scmi_list_mutex); 57static DEFINE_MUTEX(scmi_list_mutex);
@@ -72,7 +68,6 @@ static DEFINE_MUTEX(scmi_list_mutex);
72struct scmi_xfers_info { 68struct scmi_xfers_info {
73 struct scmi_xfer *xfer_block; 69 struct scmi_xfer *xfer_block;
74 unsigned long *xfer_alloc_table; 70 unsigned long *xfer_alloc_table;
75 /* protect transfer allocation */
76 spinlock_t xfer_lock; 71 spinlock_t xfer_lock;
77}; 72};
78 73
@@ -98,6 +93,7 @@ struct scmi_desc {
98 * @payload: Transmit/Receive mailbox channel payload area 93 * @payload: Transmit/Receive mailbox channel payload area
99 * @dev: Reference to device in the SCMI hierarchy corresponding to this 94 * @dev: Reference to device in the SCMI hierarchy corresponding to this
100 * channel 95 * channel
96 * @handle: Pointer to SCMI entity handle
101 */ 97 */
102struct scmi_chan_info { 98struct scmi_chan_info {
103 struct mbox_client cl; 99 struct mbox_client cl;
@@ -108,7 +104,7 @@ struct scmi_chan_info {
108}; 104};
109 105
110/** 106/**
111 * struct scmi_info - Structure representing a SCMI instance 107 * struct scmi_info - Structure representing a SCMI instance
112 * 108 *
113 * @dev: Device pointer 109 * @dev: Device pointer
114 * @desc: SoC description for this instance 110 * @desc: SoC description for this instance
@@ -117,9 +113,9 @@ struct scmi_chan_info {
117 * implementation version and (sub-)vendor identification. 113 * implementation version and (sub-)vendor identification.
118 * @minfo: Message info 114 * @minfo: Message info
119 * @tx_idr: IDR object to map protocol id to channel info pointer 115 * @tx_idr: IDR object to map protocol id to channel info pointer
120 * @protocols_imp: list of protocols implemented, currently maximum of 116 * @protocols_imp: List of protocols implemented, currently maximum of
121 * MAX_PROTOCOLS_IMP elements allocated by the base protocol 117 * MAX_PROTOCOLS_IMP elements allocated by the base protocol
122 * @node: list head 118 * @node: List head
123 * @users: Number of users of this instance 119 * @users: Number of users of this instance
124 */ 120 */
125struct scmi_info { 121struct scmi_info {
@@ -225,9 +221,7 @@ static void scmi_rx_callback(struct mbox_client *cl, void *m)
225 221
226 xfer_id = MSG_XTRACT_TOKEN(ioread32(&mem->msg_header)); 222 xfer_id = MSG_XTRACT_TOKEN(ioread32(&mem->msg_header));
227 223
228 /* 224 /* Are we even expecting this? */
229 * Are we even expecting this?
230 */
231 if (!test_bit(xfer_id, minfo->xfer_alloc_table)) { 225 if (!test_bit(xfer_id, minfo->xfer_alloc_table)) {
232 dev_err(dev, "message for %d is not expected!\n", xfer_id); 226 dev_err(dev, "message for %d is not expected!\n", xfer_id);
233 return; 227 return;
@@ -252,12 +246,14 @@ static void scmi_rx_callback(struct mbox_client *cl, void *m)
252 * 246 *
253 * @hdr: pointer to header containing all the information on message id, 247 * @hdr: pointer to header containing all the information on message id,
254 * protocol id and sequence id. 248 * protocol id and sequence id.
249 *
250 * Return: 32-bit packed command header to be sent to the platform.
255 */ 251 */
256static inline u32 pack_scmi_header(struct scmi_msg_hdr *hdr) 252static inline u32 pack_scmi_header(struct scmi_msg_hdr *hdr)
257{ 253{
258 return ((hdr->id & MSG_ID_MASK) << MSG_ID_SHIFT) | 254 return FIELD_PREP(MSG_ID_MASK, hdr->id) |
259 ((hdr->seq & MSG_TOKEN_ID_MASK) << MSG_TOKEN_ID_SHIFT) | 255 FIELD_PREP(MSG_TOKEN_ID_MASK, hdr->seq) |
260 ((hdr->protocol_id & MSG_PROTOCOL_ID_MASK) << MSG_PROTOCOL_ID_SHIFT); 256 FIELD_PREP(MSG_PROTOCOL_ID_MASK, hdr->protocol_id);
261} 257}
262 258
263/** 259/**
@@ -286,9 +282,9 @@ static void scmi_tx_prepare(struct mbox_client *cl, void *m)
286} 282}
287 283
288/** 284/**
289 * scmi_one_xfer_get() - Allocate one message 285 * scmi_xfer_get() - Allocate one message
290 * 286 *
291 * @handle: SCMI entity handle 287 * @handle: Pointer to SCMI entity handle
292 * 288 *
293 * Helper function which is used by various command functions that are 289 * Helper function which is used by various command functions that are
294 * exposed to clients of this driver for allocating a message traffic event. 290 * exposed to clients of this driver for allocating a message traffic event.
@@ -299,7 +295,7 @@ static void scmi_tx_prepare(struct mbox_client *cl, void *m)
299 * 295 *
300 * Return: 0 if all went fine, else corresponding error. 296 * Return: 0 if all went fine, else corresponding error.
301 */ 297 */
302static struct scmi_xfer *scmi_one_xfer_get(const struct scmi_handle *handle) 298static struct scmi_xfer *scmi_xfer_get(const struct scmi_handle *handle)
303{ 299{
304 u16 xfer_id; 300 u16 xfer_id;
305 struct scmi_xfer *xfer; 301 struct scmi_xfer *xfer;
@@ -328,14 +324,14 @@ static struct scmi_xfer *scmi_one_xfer_get(const struct scmi_handle *handle)
328} 324}
329 325
330/** 326/**
331 * scmi_one_xfer_put() - Release a message 327 * scmi_xfer_put() - Release a message
332 * 328 *
333 * @minfo: transfer info pointer 329 * @handle: Pointer to SCMI entity handle
334 * @xfer: message that was reserved by scmi_one_xfer_get 330 * @xfer: message that was reserved by scmi_xfer_get
335 * 331 *
336 * This holds a spinlock to maintain integrity of internal data structures. 332 * This holds a spinlock to maintain integrity of internal data structures.
337 */ 333 */
338void scmi_one_xfer_put(const struct scmi_handle *handle, struct scmi_xfer *xfer) 334void scmi_xfer_put(const struct scmi_handle *handle, struct scmi_xfer *xfer)
339{ 335{
340 unsigned long flags; 336 unsigned long flags;
341 struct scmi_info *info = handle_to_scmi_info(handle); 337 struct scmi_info *info = handle_to_scmi_info(handle);
@@ -378,12 +374,12 @@ static bool scmi_xfer_done_no_timeout(const struct scmi_chan_info *cinfo,
378/** 374/**
379 * scmi_do_xfer() - Do one transfer 375 * scmi_do_xfer() - Do one transfer
380 * 376 *
381 * @info: Pointer to SCMI entity information 377 * @handle: Pointer to SCMI entity handle
382 * @xfer: Transfer to initiate and wait for response 378 * @xfer: Transfer to initiate and wait for response
383 * 379 *
384 * Return: -ETIMEDOUT in case of no response, if transmit error, 380 * Return: -ETIMEDOUT in case of no response, if transmit error,
385 * return corresponding error, else if all goes well, 381 * return corresponding error, else if all goes well,
386 * return 0. 382 * return 0.
387 */ 383 */
388int scmi_do_xfer(const struct scmi_handle *handle, struct scmi_xfer *xfer) 384int scmi_do_xfer(const struct scmi_handle *handle, struct scmi_xfer *xfer)
389{ 385{
@@ -440,22 +436,22 @@ int scmi_do_xfer(const struct scmi_handle *handle, struct scmi_xfer *xfer)
440} 436}
441 437
442/** 438/**
443 * scmi_one_xfer_init() - Allocate and initialise one message 439 * scmi_xfer_get_init() - Allocate and initialise one message
444 * 440 *
445 * @handle: SCMI entity handle 441 * @handle: Pointer to SCMI entity handle
446 * @msg_id: Message identifier 442 * @msg_id: Message identifier
447 * @msg_prot_id: Protocol identifier for the message 443 * @prot_id: Protocol identifier for the message
448 * @tx_size: transmit message size 444 * @tx_size: transmit message size
449 * @rx_size: receive message size 445 * @rx_size: receive message size
450 * @p: pointer to the allocated and initialised message 446 * @p: pointer to the allocated and initialised message
451 * 447 *
452 * This function allocates the message using @scmi_one_xfer_get and 448 * This function allocates the message using @scmi_xfer_get and
453 * initialise the header. 449 * initialise the header.
454 * 450 *
455 * Return: 0 if all went fine with @p pointing to message, else 451 * Return: 0 if all went fine with @p pointing to message, else
456 * corresponding error. 452 * corresponding error.
457 */ 453 */
458int scmi_one_xfer_init(const struct scmi_handle *handle, u8 msg_id, u8 prot_id, 454int scmi_xfer_get_init(const struct scmi_handle *handle, u8 msg_id, u8 prot_id,
459 size_t tx_size, size_t rx_size, struct scmi_xfer **p) 455 size_t tx_size, size_t rx_size, struct scmi_xfer **p)
460{ 456{
461 int ret; 457 int ret;
@@ -468,7 +464,7 @@ int scmi_one_xfer_init(const struct scmi_handle *handle, u8 msg_id, u8 prot_id,
468 tx_size > info->desc->max_msg_size) 464 tx_size > info->desc->max_msg_size)
469 return -ERANGE; 465 return -ERANGE;
470 466
471 xfer = scmi_one_xfer_get(handle); 467 xfer = scmi_xfer_get(handle);
472 if (IS_ERR(xfer)) { 468 if (IS_ERR(xfer)) {
473 ret = PTR_ERR(xfer); 469 ret = PTR_ERR(xfer);
474 dev_err(dev, "failed to get free message slot(%d)\n", ret); 470 dev_err(dev, "failed to get free message slot(%d)\n", ret);
@@ -482,13 +478,16 @@ int scmi_one_xfer_init(const struct scmi_handle *handle, u8 msg_id, u8 prot_id,
482 xfer->hdr.poll_completion = false; 478 xfer->hdr.poll_completion = false;
483 479
484 *p = xfer; 480 *p = xfer;
481
485 return 0; 482 return 0;
486} 483}
487 484
488/** 485/**
489 * scmi_version_get() - command to get the revision of the SCMI entity 486 * scmi_version_get() - command to get the revision of the SCMI entity
490 * 487 *
491 * @handle: Handle to SCMI entity information 488 * @handle: Pointer to SCMI entity handle
489 * @protocol: Protocol identifier for the message
490 * @version: Holds returned version of protocol.
492 * 491 *
493 * Updates the SCMI information in the internal data structure. 492 * Updates the SCMI information in the internal data structure.
494 * 493 *
@@ -501,7 +500,7 @@ int scmi_version_get(const struct scmi_handle *handle, u8 protocol,
501 __le32 *rev_info; 500 __le32 *rev_info;
502 struct scmi_xfer *t; 501 struct scmi_xfer *t;
503 502
504 ret = scmi_one_xfer_init(handle, PROTOCOL_VERSION, protocol, 0, 503 ret = scmi_xfer_get_init(handle, PROTOCOL_VERSION, protocol, 0,
505 sizeof(*version), &t); 504 sizeof(*version), &t);
506 if (ret) 505 if (ret)
507 return ret; 506 return ret;
@@ -512,7 +511,7 @@ int scmi_version_get(const struct scmi_handle *handle, u8 protocol,
512 *version = le32_to_cpu(*rev_info); 511 *version = le32_to_cpu(*rev_info);
513 } 512 }
514 513
515 scmi_one_xfer_put(handle, t); 514 scmi_xfer_put(handle, t);
516 return ret; 515 return ret;
517} 516}
518 517
@@ -540,12 +539,12 @@ scmi_is_protocol_implemented(const struct scmi_handle *handle, u8 prot_id)
540} 539}
541 540
542/** 541/**
543 * scmi_handle_get() - Get the SCMI handle for a device 542 * scmi_handle_get() - Get the SCMI handle for a device
544 * 543 *
545 * @dev: pointer to device for which we want SCMI handle 544 * @dev: pointer to device for which we want SCMI handle
546 * 545 *
547 * NOTE: The function does not track individual clients of the framework 546 * NOTE: The function does not track individual clients of the framework
548 * and is expected to be maintained by caller of SCMI protocol library. 547 * and is expected to be maintained by caller of SCMI protocol library.
549 * scmi_handle_put must be balanced with successful scmi_handle_get 548 * scmi_handle_put must be balanced with successful scmi_handle_get
550 * 549 *
551 * Return: pointer to handle if successful, NULL on error 550 * Return: pointer to handle if successful, NULL on error
@@ -576,7 +575,7 @@ struct scmi_handle *scmi_handle_get(struct device *dev)
576 * @handle: handle acquired by scmi_handle_get 575 * @handle: handle acquired by scmi_handle_get
577 * 576 *
578 * NOTE: The function does not track individual clients of the framework 577 * NOTE: The function does not track individual clients of the framework
579 * and is expected to be maintained by caller of SCMI protocol library. 578 * and is expected to be maintained by caller of SCMI protocol library.
580 * scmi_handle_put must be balanced with successful scmi_handle_get 579 * scmi_handle_put must be balanced with successful scmi_handle_get
581 * 580 *
582 * Return: 0 is successfully released 581 * Return: 0 is successfully released
@@ -599,7 +598,7 @@ int scmi_handle_put(const struct scmi_handle *handle)
599} 598}
600 599
601static const struct scmi_desc scmi_generic_desc = { 600static const struct scmi_desc scmi_generic_desc = {
602 .max_rx_timeout_ms = 30, /* we may increase this if required */ 601 .max_rx_timeout_ms = 30, /* We may increase this if required */
603 .max_msg = 20, /* Limited by MBOX_TX_QUEUE_LEN */ 602 .max_msg = 20, /* Limited by MBOX_TX_QUEUE_LEN */
604 .max_msg_size = 128, 603 .max_msg_size = 128,
605}; 604};
@@ -621,9 +620,9 @@ static int scmi_xfer_info_init(struct scmi_info *sinfo)
621 struct scmi_xfers_info *info = &sinfo->minfo; 620 struct scmi_xfers_info *info = &sinfo->minfo;
622 621
623 /* Pre-allocated messages, no more than what hdr.seq can support */ 622 /* Pre-allocated messages, no more than what hdr.seq can support */
624 if (WARN_ON(desc->max_msg >= (MSG_TOKEN_ID_MASK + 1))) { 623 if (WARN_ON(desc->max_msg >= MSG_TOKEN_MAX)) {
625 dev_err(dev, "Maximum message of %d exceeds supported %d\n", 624 dev_err(dev, "Maximum message of %d exceeds supported %ld\n",
626 desc->max_msg, MSG_TOKEN_ID_MASK + 1); 625 desc->max_msg, MSG_TOKEN_MAX);
627 return -EINVAL; 626 return -EINVAL;
628 } 627 }
629 628
@@ -637,8 +636,6 @@ static int scmi_xfer_info_init(struct scmi_info *sinfo)
637 if (!info->xfer_alloc_table) 636 if (!info->xfer_alloc_table)
638 return -ENOMEM; 637 return -ENOMEM;
639 638
640 bitmap_zero(info->xfer_alloc_table, desc->max_msg);
641
642 /* Pre-initialize the buffer pointer to pre-allocated buffers */ 639 /* Pre-initialize the buffer pointer to pre-allocated buffers */
643 for (i = 0, xfer = info->xfer_block; i < desc->max_msg; i++, xfer++) { 640 for (i = 0, xfer = info->xfer_block; i < desc->max_msg; i++, xfer++) {
644 xfer->rx.buf = devm_kcalloc(dev, sizeof(u8), desc->max_msg_size, 641 xfer->rx.buf = devm_kcalloc(dev, sizeof(u8), desc->max_msg_size,
@@ -690,11 +687,12 @@ static int scmi_remove(struct platform_device *pdev)
690 list_del(&info->node); 687 list_del(&info->node);
691 mutex_unlock(&scmi_list_mutex); 688 mutex_unlock(&scmi_list_mutex);
692 689
693 if (!ret) { 690 if (ret)
694 /* Safe to free channels since no more users */ 691 return ret;
695 ret = idr_for_each(idr, scmi_mbox_free_channel, idr); 692
696 idr_destroy(&info->tx_idr); 693 /* Safe to free channels since no more users */
697 } 694 ret = idr_for_each(idr, scmi_mbox_free_channel, idr);
695 idr_destroy(&info->tx_idr);
698 696
699 return ret; 697 return ret;
700} 698}
@@ -840,7 +838,8 @@ static int scmi_probe(struct platform_device *pdev)
840 if (of_property_read_u32(child, "reg", &prot_id)) 838 if (of_property_read_u32(child, "reg", &prot_id))
841 continue; 839 continue;
842 840
843 prot_id &= MSG_PROTOCOL_ID_MASK; 841 if (!FIELD_FIT(MSG_PROTOCOL_ID_MASK, prot_id))
842 dev_err(dev, "Out of range protocol %d\n", prot_id);
844 843
845 if (!scmi_is_protocol_implemented(handle, prot_id)) { 844 if (!scmi_is_protocol_implemented(handle, prot_id)) {
846 dev_err(dev, "SCMI protocol %d not implemented\n", 845 dev_err(dev, "SCMI protocol %d not implemented\n",
diff --git a/drivers/firmware/arm_scmi/perf.c b/drivers/firmware/arm_scmi/perf.c
index 987c64d19801..2a219b1261b1 100644
--- a/drivers/firmware/arm_scmi/perf.c
+++ b/drivers/firmware/arm_scmi/perf.c
@@ -115,7 +115,7 @@ static int scmi_perf_attributes_get(const struct scmi_handle *handle,
115 struct scmi_xfer *t; 115 struct scmi_xfer *t;
116 struct scmi_msg_resp_perf_attributes *attr; 116 struct scmi_msg_resp_perf_attributes *attr;
117 117
118 ret = scmi_one_xfer_init(handle, PROTOCOL_ATTRIBUTES, 118 ret = scmi_xfer_get_init(handle, PROTOCOL_ATTRIBUTES,
119 SCMI_PROTOCOL_PERF, 0, sizeof(*attr), &t); 119 SCMI_PROTOCOL_PERF, 0, sizeof(*attr), &t);
120 if (ret) 120 if (ret)
121 return ret; 121 return ret;
@@ -133,7 +133,7 @@ static int scmi_perf_attributes_get(const struct scmi_handle *handle,
133 pi->stats_size = le32_to_cpu(attr->stats_size); 133 pi->stats_size = le32_to_cpu(attr->stats_size);
134 } 134 }
135 135
136 scmi_one_xfer_put(handle, t); 136 scmi_xfer_put(handle, t);
137 return ret; 137 return ret;
138} 138}
139 139
@@ -145,7 +145,7 @@ scmi_perf_domain_attributes_get(const struct scmi_handle *handle, u32 domain,
145 struct scmi_xfer *t; 145 struct scmi_xfer *t;
146 struct scmi_msg_resp_perf_domain_attributes *attr; 146 struct scmi_msg_resp_perf_domain_attributes *attr;
147 147
148 ret = scmi_one_xfer_init(handle, PERF_DOMAIN_ATTRIBUTES, 148 ret = scmi_xfer_get_init(handle, PERF_DOMAIN_ATTRIBUTES,
149 SCMI_PROTOCOL_PERF, sizeof(domain), 149 SCMI_PROTOCOL_PERF, sizeof(domain),
150 sizeof(*attr), &t); 150 sizeof(*attr), &t);
151 if (ret) 151 if (ret)
@@ -171,7 +171,7 @@ scmi_perf_domain_attributes_get(const struct scmi_handle *handle, u32 domain,
171 memcpy(dom_info->name, attr->name, SCMI_MAX_STR_SIZE); 171 memcpy(dom_info->name, attr->name, SCMI_MAX_STR_SIZE);
172 } 172 }
173 173
174 scmi_one_xfer_put(handle, t); 174 scmi_xfer_put(handle, t);
175 return ret; 175 return ret;
176} 176}
177 177
@@ -194,7 +194,7 @@ scmi_perf_describe_levels_get(const struct scmi_handle *handle, u32 domain,
194 struct scmi_msg_perf_describe_levels *dom_info; 194 struct scmi_msg_perf_describe_levels *dom_info;
195 struct scmi_msg_resp_perf_describe_levels *level_info; 195 struct scmi_msg_resp_perf_describe_levels *level_info;
196 196
197 ret = scmi_one_xfer_init(handle, PERF_DESCRIBE_LEVELS, 197 ret = scmi_xfer_get_init(handle, PERF_DESCRIBE_LEVELS,
198 SCMI_PROTOCOL_PERF, sizeof(*dom_info), 0, &t); 198 SCMI_PROTOCOL_PERF, sizeof(*dom_info), 0, &t);
199 if (ret) 199 if (ret)
200 return ret; 200 return ret;
@@ -237,7 +237,7 @@ scmi_perf_describe_levels_get(const struct scmi_handle *handle, u32 domain,
237 } while (num_returned && num_remaining); 237 } while (num_returned && num_remaining);
238 238
239 perf_dom->opp_count = tot_opp_cnt; 239 perf_dom->opp_count = tot_opp_cnt;
240 scmi_one_xfer_put(handle, t); 240 scmi_xfer_put(handle, t);
241 241
242 sort(perf_dom->opp, tot_opp_cnt, sizeof(*opp), opp_cmp_func, NULL); 242 sort(perf_dom->opp, tot_opp_cnt, sizeof(*opp), opp_cmp_func, NULL);
243 return ret; 243 return ret;
@@ -250,7 +250,7 @@ static int scmi_perf_limits_set(const struct scmi_handle *handle, u32 domain,
250 struct scmi_xfer *t; 250 struct scmi_xfer *t;
251 struct scmi_perf_set_limits *limits; 251 struct scmi_perf_set_limits *limits;
252 252
253 ret = scmi_one_xfer_init(handle, PERF_LIMITS_SET, SCMI_PROTOCOL_PERF, 253 ret = scmi_xfer_get_init(handle, PERF_LIMITS_SET, SCMI_PROTOCOL_PERF,
254 sizeof(*limits), 0, &t); 254 sizeof(*limits), 0, &t);
255 if (ret) 255 if (ret)
256 return ret; 256 return ret;
@@ -262,7 +262,7 @@ static int scmi_perf_limits_set(const struct scmi_handle *handle, u32 domain,
262 262
263 ret = scmi_do_xfer(handle, t); 263 ret = scmi_do_xfer(handle, t);
264 264
265 scmi_one_xfer_put(handle, t); 265 scmi_xfer_put(handle, t);
266 return ret; 266 return ret;
267} 267}
268 268
@@ -273,7 +273,7 @@ static int scmi_perf_limits_get(const struct scmi_handle *handle, u32 domain,
273 struct scmi_xfer *t; 273 struct scmi_xfer *t;
274 struct scmi_perf_get_limits *limits; 274 struct scmi_perf_get_limits *limits;
275 275
276 ret = scmi_one_xfer_init(handle, PERF_LIMITS_GET, SCMI_PROTOCOL_PERF, 276 ret = scmi_xfer_get_init(handle, PERF_LIMITS_GET, SCMI_PROTOCOL_PERF,
277 sizeof(__le32), 0, &t); 277 sizeof(__le32), 0, &t);
278 if (ret) 278 if (ret)
279 return ret; 279 return ret;
@@ -288,7 +288,7 @@ static int scmi_perf_limits_get(const struct scmi_handle *handle, u32 domain,
288 *min_perf = le32_to_cpu(limits->min_level); 288 *min_perf = le32_to_cpu(limits->min_level);
289 } 289 }
290 290
291 scmi_one_xfer_put(handle, t); 291 scmi_xfer_put(handle, t);
292 return ret; 292 return ret;
293} 293}
294 294
@@ -299,7 +299,7 @@ static int scmi_perf_level_set(const struct scmi_handle *handle, u32 domain,
299 struct scmi_xfer *t; 299 struct scmi_xfer *t;
300 struct scmi_perf_set_level *lvl; 300 struct scmi_perf_set_level *lvl;
301 301
302 ret = scmi_one_xfer_init(handle, PERF_LEVEL_SET, SCMI_PROTOCOL_PERF, 302 ret = scmi_xfer_get_init(handle, PERF_LEVEL_SET, SCMI_PROTOCOL_PERF,
303 sizeof(*lvl), 0, &t); 303 sizeof(*lvl), 0, &t);
304 if (ret) 304 if (ret)
305 return ret; 305 return ret;
@@ -311,7 +311,7 @@ static int scmi_perf_level_set(const struct scmi_handle *handle, u32 domain,
311 311
312 ret = scmi_do_xfer(handle, t); 312 ret = scmi_do_xfer(handle, t);
313 313
314 scmi_one_xfer_put(handle, t); 314 scmi_xfer_put(handle, t);
315 return ret; 315 return ret;
316} 316}
317 317
@@ -321,7 +321,7 @@ static int scmi_perf_level_get(const struct scmi_handle *handle, u32 domain,
321 int ret; 321 int ret;
322 struct scmi_xfer *t; 322 struct scmi_xfer *t;
323 323
324 ret = scmi_one_xfer_init(handle, PERF_LEVEL_GET, SCMI_PROTOCOL_PERF, 324 ret = scmi_xfer_get_init(handle, PERF_LEVEL_GET, SCMI_PROTOCOL_PERF,
325 sizeof(u32), sizeof(u32), &t); 325 sizeof(u32), sizeof(u32), &t);
326 if (ret) 326 if (ret)
327 return ret; 327 return ret;
@@ -333,7 +333,7 @@ static int scmi_perf_level_get(const struct scmi_handle *handle, u32 domain,
333 if (!ret) 333 if (!ret)
334 *level = le32_to_cpu(*(__le32 *)t->rx.buf); 334 *level = le32_to_cpu(*(__le32 *)t->rx.buf);
335 335
336 scmi_one_xfer_put(handle, t); 336 scmi_xfer_put(handle, t);
337 return ret; 337 return ret;
338} 338}
339 339
@@ -349,8 +349,8 @@ static int scmi_dev_domain_id(struct device *dev)
349 return clkspec.args[0]; 349 return clkspec.args[0];
350} 350}
351 351
352static int scmi_dvfs_add_opps_to_device(const struct scmi_handle *handle, 352static int scmi_dvfs_device_opps_add(const struct scmi_handle *handle,
353 struct device *dev) 353 struct device *dev)
354{ 354{
355 int idx, ret, domain; 355 int idx, ret, domain;
356 unsigned long freq; 356 unsigned long freq;
@@ -383,7 +383,7 @@ static int scmi_dvfs_add_opps_to_device(const struct scmi_handle *handle,
383 return 0; 383 return 0;
384} 384}
385 385
386static int scmi_dvfs_get_transition_latency(const struct scmi_handle *handle, 386static int scmi_dvfs_transition_latency_get(const struct scmi_handle *handle,
387 struct device *dev) 387 struct device *dev)
388{ 388{
389 struct perf_dom_info *dom; 389 struct perf_dom_info *dom;
@@ -432,8 +432,8 @@ static struct scmi_perf_ops perf_ops = {
432 .level_set = scmi_perf_level_set, 432 .level_set = scmi_perf_level_set,
433 .level_get = scmi_perf_level_get, 433 .level_get = scmi_perf_level_get,
434 .device_domain_id = scmi_dev_domain_id, 434 .device_domain_id = scmi_dev_domain_id,
435 .get_transition_latency = scmi_dvfs_get_transition_latency, 435 .transition_latency_get = scmi_dvfs_transition_latency_get,
436 .add_opps_to_device = scmi_dvfs_add_opps_to_device, 436 .device_opps_add = scmi_dvfs_device_opps_add,
437 .freq_set = scmi_dvfs_freq_set, 437 .freq_set = scmi_dvfs_freq_set,
438 .freq_get = scmi_dvfs_freq_get, 438 .freq_get = scmi_dvfs_freq_get,
439}; 439};
diff --git a/drivers/firmware/arm_scmi/power.c b/drivers/firmware/arm_scmi/power.c
index 087c2876cdf2..cfa033b05aed 100644
--- a/drivers/firmware/arm_scmi/power.c
+++ b/drivers/firmware/arm_scmi/power.c
@@ -63,7 +63,7 @@ static int scmi_power_attributes_get(const struct scmi_handle *handle,
63 struct scmi_xfer *t; 63 struct scmi_xfer *t;
64 struct scmi_msg_resp_power_attributes *attr; 64 struct scmi_msg_resp_power_attributes *attr;
65 65
66 ret = scmi_one_xfer_init(handle, PROTOCOL_ATTRIBUTES, 66 ret = scmi_xfer_get_init(handle, PROTOCOL_ATTRIBUTES,
67 SCMI_PROTOCOL_POWER, 0, sizeof(*attr), &t); 67 SCMI_PROTOCOL_POWER, 0, sizeof(*attr), &t);
68 if (ret) 68 if (ret)
69 return ret; 69 return ret;
@@ -78,7 +78,7 @@ static int scmi_power_attributes_get(const struct scmi_handle *handle,
78 pi->stats_size = le32_to_cpu(attr->stats_size); 78 pi->stats_size = le32_to_cpu(attr->stats_size);
79 } 79 }
80 80
81 scmi_one_xfer_put(handle, t); 81 scmi_xfer_put(handle, t);
82 return ret; 82 return ret;
83} 83}
84 84
@@ -90,7 +90,7 @@ scmi_power_domain_attributes_get(const struct scmi_handle *handle, u32 domain,
90 struct scmi_xfer *t; 90 struct scmi_xfer *t;
91 struct scmi_msg_resp_power_domain_attributes *attr; 91 struct scmi_msg_resp_power_domain_attributes *attr;
92 92
93 ret = scmi_one_xfer_init(handle, POWER_DOMAIN_ATTRIBUTES, 93 ret = scmi_xfer_get_init(handle, POWER_DOMAIN_ATTRIBUTES,
94 SCMI_PROTOCOL_POWER, sizeof(domain), 94 SCMI_PROTOCOL_POWER, sizeof(domain),
95 sizeof(*attr), &t); 95 sizeof(*attr), &t);
96 if (ret) 96 if (ret)
@@ -109,7 +109,7 @@ scmi_power_domain_attributes_get(const struct scmi_handle *handle, u32 domain,
109 memcpy(dom_info->name, attr->name, SCMI_MAX_STR_SIZE); 109 memcpy(dom_info->name, attr->name, SCMI_MAX_STR_SIZE);
110 } 110 }
111 111
112 scmi_one_xfer_put(handle, t); 112 scmi_xfer_put(handle, t);
113 return ret; 113 return ret;
114} 114}
115 115
@@ -120,7 +120,7 @@ scmi_power_state_set(const struct scmi_handle *handle, u32 domain, u32 state)
120 struct scmi_xfer *t; 120 struct scmi_xfer *t;
121 struct scmi_power_set_state *st; 121 struct scmi_power_set_state *st;
122 122
123 ret = scmi_one_xfer_init(handle, POWER_STATE_SET, SCMI_PROTOCOL_POWER, 123 ret = scmi_xfer_get_init(handle, POWER_STATE_SET, SCMI_PROTOCOL_POWER,
124 sizeof(*st), 0, &t); 124 sizeof(*st), 0, &t);
125 if (ret) 125 if (ret)
126 return ret; 126 return ret;
@@ -132,7 +132,7 @@ scmi_power_state_set(const struct scmi_handle *handle, u32 domain, u32 state)
132 132
133 ret = scmi_do_xfer(handle, t); 133 ret = scmi_do_xfer(handle, t);
134 134
135 scmi_one_xfer_put(handle, t); 135 scmi_xfer_put(handle, t);
136 return ret; 136 return ret;
137} 137}
138 138
@@ -142,7 +142,7 @@ scmi_power_state_get(const struct scmi_handle *handle, u32 domain, u32 *state)
142 int ret; 142 int ret;
143 struct scmi_xfer *t; 143 struct scmi_xfer *t;
144 144
145 ret = scmi_one_xfer_init(handle, POWER_STATE_GET, SCMI_PROTOCOL_POWER, 145 ret = scmi_xfer_get_init(handle, POWER_STATE_GET, SCMI_PROTOCOL_POWER,
146 sizeof(u32), sizeof(u32), &t); 146 sizeof(u32), sizeof(u32), &t);
147 if (ret) 147 if (ret)
148 return ret; 148 return ret;
@@ -153,7 +153,7 @@ scmi_power_state_get(const struct scmi_handle *handle, u32 domain, u32 *state)
153 if (!ret) 153 if (!ret)
154 *state = le32_to_cpu(*(__le32 *)t->rx.buf); 154 *state = le32_to_cpu(*(__le32 *)t->rx.buf);
155 155
156 scmi_one_xfer_put(handle, t); 156 scmi_xfer_put(handle, t);
157 return ret; 157 return ret;
158} 158}
159 159
diff --git a/drivers/firmware/arm_scmi/sensors.c b/drivers/firmware/arm_scmi/sensors.c
index bbb469fea0ed..27f2092b9882 100644
--- a/drivers/firmware/arm_scmi/sensors.c
+++ b/drivers/firmware/arm_scmi/sensors.c
@@ -79,7 +79,7 @@ static int scmi_sensor_attributes_get(const struct scmi_handle *handle,
79 struct scmi_xfer *t; 79 struct scmi_xfer *t;
80 struct scmi_msg_resp_sensor_attributes *attr; 80 struct scmi_msg_resp_sensor_attributes *attr;
81 81
82 ret = scmi_one_xfer_init(handle, PROTOCOL_ATTRIBUTES, 82 ret = scmi_xfer_get_init(handle, PROTOCOL_ATTRIBUTES,
83 SCMI_PROTOCOL_SENSOR, 0, sizeof(*attr), &t); 83 SCMI_PROTOCOL_SENSOR, 0, sizeof(*attr), &t);
84 if (ret) 84 if (ret)
85 return ret; 85 return ret;
@@ -95,7 +95,7 @@ static int scmi_sensor_attributes_get(const struct scmi_handle *handle,
95 si->reg_size = le32_to_cpu(attr->reg_size); 95 si->reg_size = le32_to_cpu(attr->reg_size);
96 } 96 }
97 97
98 scmi_one_xfer_put(handle, t); 98 scmi_xfer_put(handle, t);
99 return ret; 99 return ret;
100} 100}
101 101
@@ -108,7 +108,7 @@ static int scmi_sensor_description_get(const struct scmi_handle *handle,
108 struct scmi_xfer *t; 108 struct scmi_xfer *t;
109 struct scmi_msg_resp_sensor_description *buf; 109 struct scmi_msg_resp_sensor_description *buf;
110 110
111 ret = scmi_one_xfer_init(handle, SENSOR_DESCRIPTION_GET, 111 ret = scmi_xfer_get_init(handle, SENSOR_DESCRIPTION_GET,
112 SCMI_PROTOCOL_SENSOR, sizeof(__le32), 0, &t); 112 SCMI_PROTOCOL_SENSOR, sizeof(__le32), 0, &t);
113 if (ret) 113 if (ret)
114 return ret; 114 return ret;
@@ -150,7 +150,7 @@ static int scmi_sensor_description_get(const struct scmi_handle *handle,
150 */ 150 */
151 } while (num_returned && num_remaining); 151 } while (num_returned && num_remaining);
152 152
153 scmi_one_xfer_put(handle, t); 153 scmi_xfer_put(handle, t);
154 return ret; 154 return ret;
155} 155}
156 156
@@ -162,7 +162,7 @@ scmi_sensor_configuration_set(const struct scmi_handle *handle, u32 sensor_id)
162 struct scmi_xfer *t; 162 struct scmi_xfer *t;
163 struct scmi_msg_set_sensor_config *cfg; 163 struct scmi_msg_set_sensor_config *cfg;
164 164
165 ret = scmi_one_xfer_init(handle, SENSOR_CONFIG_SET, 165 ret = scmi_xfer_get_init(handle, SENSOR_CONFIG_SET,
166 SCMI_PROTOCOL_SENSOR, sizeof(*cfg), 0, &t); 166 SCMI_PROTOCOL_SENSOR, sizeof(*cfg), 0, &t);
167 if (ret) 167 if (ret)
168 return ret; 168 return ret;
@@ -173,7 +173,7 @@ scmi_sensor_configuration_set(const struct scmi_handle *handle, u32 sensor_id)
173 173
174 ret = scmi_do_xfer(handle, t); 174 ret = scmi_do_xfer(handle, t);
175 175
176 scmi_one_xfer_put(handle, t); 176 scmi_xfer_put(handle, t);
177 return ret; 177 return ret;
178} 178}
179 179
@@ -185,7 +185,7 @@ static int scmi_sensor_trip_point_set(const struct scmi_handle *handle,
185 struct scmi_xfer *t; 185 struct scmi_xfer *t;
186 struct scmi_msg_set_sensor_trip_point *trip; 186 struct scmi_msg_set_sensor_trip_point *trip;
187 187
188 ret = scmi_one_xfer_init(handle, SENSOR_TRIP_POINT_SET, 188 ret = scmi_xfer_get_init(handle, SENSOR_TRIP_POINT_SET,
189 SCMI_PROTOCOL_SENSOR, sizeof(*trip), 0, &t); 189 SCMI_PROTOCOL_SENSOR, sizeof(*trip), 0, &t);
190 if (ret) 190 if (ret)
191 return ret; 191 return ret;
@@ -198,7 +198,7 @@ static int scmi_sensor_trip_point_set(const struct scmi_handle *handle,
198 198
199 ret = scmi_do_xfer(handle, t); 199 ret = scmi_do_xfer(handle, t);
200 200
201 scmi_one_xfer_put(handle, t); 201 scmi_xfer_put(handle, t);
202 return ret; 202 return ret;
203} 203}
204 204
@@ -209,7 +209,7 @@ static int scmi_sensor_reading_get(const struct scmi_handle *handle,
209 struct scmi_xfer *t; 209 struct scmi_xfer *t;
210 struct scmi_msg_sensor_reading_get *sensor; 210 struct scmi_msg_sensor_reading_get *sensor;
211 211
212 ret = scmi_one_xfer_init(handle, SENSOR_READING_GET, 212 ret = scmi_xfer_get_init(handle, SENSOR_READING_GET,
213 SCMI_PROTOCOL_SENSOR, sizeof(*sensor), 213 SCMI_PROTOCOL_SENSOR, sizeof(*sensor),
214 sizeof(u64), &t); 214 sizeof(u64), &t);
215 if (ret) 215 if (ret)
@@ -227,7 +227,7 @@ static int scmi_sensor_reading_get(const struct scmi_handle *handle,
227 *value |= (u64)le32_to_cpu(*(pval + 1)) << 32; 227 *value |= (u64)le32_to_cpu(*(pval + 1)) << 32;
228 } 228 }
229 229
230 scmi_one_xfer_put(handle, t); 230 scmi_xfer_put(handle, t);
231 return ret; 231 return ret;
232} 232}
233 233
diff --git a/include/linux/scmi_protocol.h b/include/linux/scmi_protocol.h
index b458c87b866c..f4c9fc0fc755 100644
--- a/include/linux/scmi_protocol.h
+++ b/include/linux/scmi_protocol.h
@@ -85,8 +85,8 @@ struct scmi_clk_ops {
85 * @level_set: sets the performance level of a domain 85 * @level_set: sets the performance level of a domain
86 * @level_get: gets the performance level of a domain 86 * @level_get: gets the performance level of a domain
87 * @device_domain_id: gets the scmi domain id for a given device 87 * @device_domain_id: gets the scmi domain id for a given device
88 * @get_transition_latency: gets the DVFS transition latency for a given device 88 * @transition_latency_get: gets the DVFS transition latency for a given device
89 * @add_opps_to_device: adds all the OPPs for a given device 89 * @device_opps_add: adds all the OPPs for a given device
90 * @freq_set: sets the frequency for a given device using sustained frequency 90 * @freq_set: sets the frequency for a given device using sustained frequency
91 * to sustained performance level mapping 91 * to sustained performance level mapping
92 * @freq_get: gets the frequency for a given device using sustained frequency 92 * @freq_get: gets the frequency for a given device using sustained frequency
@@ -102,10 +102,10 @@ struct scmi_perf_ops {
102 int (*level_get)(const struct scmi_handle *handle, u32 domain, 102 int (*level_get)(const struct scmi_handle *handle, u32 domain,
103 u32 *level, bool poll); 103 u32 *level, bool poll);
104 int (*device_domain_id)(struct device *dev); 104 int (*device_domain_id)(struct device *dev);
105 int (*get_transition_latency)(const struct scmi_handle *handle, 105 int (*transition_latency_get)(const struct scmi_handle *handle,
106 struct device *dev); 106 struct device *dev);
107 int (*add_opps_to_device)(const struct scmi_handle *handle, 107 int (*device_opps_add)(const struct scmi_handle *handle,
108 struct device *dev); 108 struct device *dev);
109 int (*freq_set)(const struct scmi_handle *handle, u32 domain, 109 int (*freq_set)(const struct scmi_handle *handle, u32 domain,
110 unsigned long rate, bool poll); 110 unsigned long rate, bool poll);
111 int (*freq_get)(const struct scmi_handle *handle, u32 domain, 111 int (*freq_get)(const struct scmi_handle *handle, u32 domain,
@@ -189,6 +189,14 @@ struct scmi_sensor_ops {
189 * @perf_ops: pointer to set of performance protocol operations 189 * @perf_ops: pointer to set of performance protocol operations
190 * @clk_ops: pointer to set of clock protocol operations 190 * @clk_ops: pointer to set of clock protocol operations
191 * @sensor_ops: pointer to set of sensor protocol operations 191 * @sensor_ops: pointer to set of sensor protocol operations
192 * @perf_priv: pointer to private data structure specific to performance
193 * protocol(for internal use only)
194 * @clk_priv: pointer to private data structure specific to clock
195 * protocol(for internal use only)
196 * @power_priv: pointer to private data structure specific to power
197 * protocol(for internal use only)
198 * @sensor_priv: pointer to private data structure specific to sensors
199 * protocol(for internal use only)
192 */ 200 */
193struct scmi_handle { 201struct scmi_handle {
194 struct device *dev; 202 struct device *dev;