Skip to content

Commit 24a0ffe

Browse files
cris-masudeep-holla
authored andcommitted
firmware: arm_scmi: Remove legacy protocol versioning logic
Protocol version negotiation logic is centralized in the SCMI core stack so that most of the legacy per-protocol versioning logic is redundant and can be removed. Remove protocol-specific versioning code and refactor all the protocols to use the new simplified centralized logic. Signed-off-by: Cristian Marussi <cristian.marussi@arm.com> Message-Id: <20251227164132.1311988-3-cristian.marussi@arm.com> Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
1 parent 0fac05f commit 24a0ffe

16 files changed

Lines changed: 72 additions & 186 deletions

File tree

drivers/firmware/arm_scmi/base.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -375,18 +375,13 @@ static int scmi_base_protocol_init(const struct scmi_protocol_handle *ph)
375375
{
376376
int id, ret;
377377
u8 *prot_imp;
378-
u32 version;
379378
char name[SCMI_SHORT_NAME_MAX_SIZE];
380379
struct device *dev = ph->dev;
381380
struct scmi_revision_info *rev = scmi_revision_area_get(ph);
382381

383-
ret = ph->xops->version_get(ph, &version);
384-
if (ret)
385-
return ret;
386-
387-
rev->major_ver = PROTOCOL_REV_MAJOR(version);
388-
rev->minor_ver = PROTOCOL_REV_MINOR(version);
389-
ph->set_priv(ph, rev, version);
382+
rev->major_ver = PROTOCOL_REV_MAJOR(ph->version);
383+
rev->minor_ver = PROTOCOL_REV_MINOR(ph->version);
384+
ph->set_priv(ph, rev);
390385

391386
ret = scmi_base_attributes_get(ph);
392387
if (ret)

drivers/firmware/arm_scmi/clock.c

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,6 @@ struct scmi_clock_rate_notify_payld {
157157
};
158158

159159
struct clock_info {
160-
u32 version;
161160
int num_clocks;
162161
int max_async_req;
163162
bool notify_rate_changed_cmd;
@@ -346,8 +345,7 @@ scmi_clock_get_permissions(const struct scmi_protocol_handle *ph, u32 clk_id,
346345
}
347346

348347
static int scmi_clock_attributes_get(const struct scmi_protocol_handle *ph,
349-
u32 clk_id, struct clock_info *cinfo,
350-
u32 version)
348+
u32 clk_id, struct clock_info *cinfo)
351349
{
352350
int ret;
353351
u32 attributes;
@@ -370,7 +368,7 @@ static int scmi_clock_attributes_get(const struct scmi_protocol_handle *ph,
370368
attributes = le32_to_cpu(attr->attributes);
371369
strscpy(clk->name, attr->name, SCMI_SHORT_NAME_MAX_SIZE);
372370
/* clock_enable_latency field is present only since SCMI v3.1 */
373-
if (PROTOCOL_REV_MAJOR(version) >= 0x2)
371+
if (PROTOCOL_REV_MAJOR(ph->version) >= 0x2)
374372
latency = le32_to_cpu(attr->clock_enable_latency);
375373
clk->enable_latency = latency ? : U32_MAX;
376374
}
@@ -381,7 +379,7 @@ static int scmi_clock_attributes_get(const struct scmi_protocol_handle *ph,
381379
* If supported overwrite short name with the extended one;
382380
* on error just carry on and use already provided short name.
383381
*/
384-
if (!ret && PROTOCOL_REV_MAJOR(version) >= 0x2) {
382+
if (!ret && PROTOCOL_REV_MAJOR(ph->version) >= 0x2) {
385383
if (SUPPORTS_EXTENDED_NAMES(attributes))
386384
ph->hops->extended_name_get(ph, CLOCK_NAME_GET, clk_id,
387385
NULL, clk->name,
@@ -393,7 +391,7 @@ static int scmi_clock_attributes_get(const struct scmi_protocol_handle *ph,
393391
if (cinfo->notify_rate_change_requested_cmd &&
394392
SUPPORTS_RATE_CHANGE_REQUESTED_NOTIF(attributes))
395393
clk->rate_change_requested_notifications = true;
396-
if (PROTOCOL_REV_MAJOR(version) >= 0x3) {
394+
if (PROTOCOL_REV_MAJOR(ph->version) >= 0x3) {
397395
if (SUPPORTS_PARENT_CLOCK(attributes))
398396
scmi_clock_possible_parents(ph, clk_id, clk);
399397
if (SUPPORTS_GET_PERMISSIONS(attributes))
@@ -1068,16 +1066,11 @@ static const struct scmi_protocol_events clk_protocol_events = {
10681066

10691067
static int scmi_clock_protocol_init(const struct scmi_protocol_handle *ph)
10701068
{
1071-
u32 version;
10721069
int clkid, ret;
10731070
struct clock_info *cinfo;
10741071

1075-
ret = ph->xops->version_get(ph, &version);
1076-
if (ret)
1077-
return ret;
1078-
10791072
dev_dbg(ph->dev, "Clock Version %d.%d\n",
1080-
PROTOCOL_REV_MAJOR(version), PROTOCOL_REV_MINOR(version));
1073+
PROTOCOL_REV_MAJOR(ph->version), PROTOCOL_REV_MINOR(ph->version));
10811074

10821075
cinfo = devm_kzalloc(ph->dev, sizeof(*cinfo), GFP_KERNEL);
10831076
if (!cinfo)
@@ -1095,21 +1088,20 @@ static int scmi_clock_protocol_init(const struct scmi_protocol_handle *ph)
10951088
for (clkid = 0; clkid < cinfo->num_clocks; clkid++) {
10961089
struct scmi_clock_info *clk = cinfo->clk + clkid;
10971090

1098-
ret = scmi_clock_attributes_get(ph, clkid, cinfo, version);
1091+
ret = scmi_clock_attributes_get(ph, clkid, cinfo);
10991092
if (!ret)
11001093
scmi_clock_describe_rates_get(ph, clkid, clk);
11011094
}
11021095

1103-
if (PROTOCOL_REV_MAJOR(version) >= 0x3) {
1096+
if (PROTOCOL_REV_MAJOR(ph->version) >= 0x3) {
11041097
cinfo->clock_config_set = scmi_clock_config_set_v2;
11051098
cinfo->clock_config_get = scmi_clock_config_get_v2;
11061099
} else {
11071100
cinfo->clock_config_set = scmi_clock_config_set;
11081101
cinfo->clock_config_get = scmi_clock_config_get;
11091102
}
11101103

1111-
cinfo->version = version;
1112-
return ph->set_priv(ph, cinfo, version);
1104+
return ph->set_priv(ph, cinfo);
11131105
}
11141106

11151107
static const struct scmi_protocol scmi_clock = {

drivers/firmware/arm_scmi/driver.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1627,17 +1627,15 @@ static int version_get(const struct scmi_protocol_handle *ph, u32 *version)
16271627
*
16281628
* @ph: A reference to the protocol handle.
16291629
* @priv: The private data to set.
1630-
* @version: The detected protocol version for the core to register.
16311630
*
16321631
* Return: 0 on Success
16331632
*/
16341633
static int scmi_set_protocol_priv(const struct scmi_protocol_handle *ph,
1635-
void *priv, u32 version)
1634+
void *priv)
16361635
{
16371636
struct scmi_protocol_instance *pi = ph_to_pi(ph);
16381637

16391638
pi->priv = priv;
1640-
pi->version = version;
16411639

16421640
return 0;
16431641
}
@@ -1657,7 +1655,6 @@ static void *scmi_get_protocol_priv(const struct scmi_protocol_handle *ph)
16571655
}
16581656

16591657
static const struct scmi_xfer_ops xfer_ops = {
1660-
.version_get = version_get,
16611658
.xfer_get_init = xfer_get_init,
16621659
.reset_rx_to_maxsz = reset_rx_to_maxsz,
16631660
.do_xfer = do_xfer,

drivers/firmware/arm_scmi/perf.c

Lines changed: 19 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,6 @@ struct perf_dom_info {
178178
})
179179

180180
struct scmi_perf_info {
181-
u32 version;
182181
u16 num_domains;
183182
enum scmi_power_scale power_scale;
184183
u64 stats_addr;
@@ -215,7 +214,7 @@ static int scmi_perf_attributes_get(const struct scmi_protocol_handle *ph,
215214

216215
if (POWER_SCALE_IN_MILLIWATT(flags))
217216
pi->power_scale = SCMI_POWER_MILLIWATTS;
218-
if (PROTOCOL_REV_MAJOR(pi->version) >= 0x3)
217+
if (PROTOCOL_REV_MAJOR(ph->version) >= 0x3)
219218
if (POWER_SCALE_IN_MICROWATT(flags))
220219
pi->power_scale = SCMI_POWER_MICROWATTS;
221220

@@ -251,8 +250,7 @@ static void scmi_perf_xa_destroy(void *data)
251250
static int
252251
scmi_perf_domain_attributes_get(const struct scmi_protocol_handle *ph,
253252
struct perf_dom_info *dom_info,
254-
bool notify_lim_cmd, bool notify_lvl_cmd,
255-
u32 version)
253+
bool notify_lim_cmd, bool notify_lvl_cmd)
256254
{
257255
int ret;
258256
u32 flags;
@@ -280,7 +278,7 @@ scmi_perf_domain_attributes_get(const struct scmi_protocol_handle *ph,
280278
dom_info->perf_level_notify =
281279
SUPPORTS_PERF_LEVEL_NOTIFY(flags);
282280
dom_info->perf_fastchannels = SUPPORTS_PERF_FASTCHANNELS(flags);
283-
if (PROTOCOL_REV_MAJOR(version) >= 0x4)
281+
if (PROTOCOL_REV_MAJOR(ph->version) >= 0x4)
284282
dom_info->level_indexing_mode =
285283
SUPPORTS_LEVEL_INDEXING(flags);
286284
dom_info->rate_limit_us = le32_to_cpu(attr->rate_limit_us) &
@@ -323,7 +321,7 @@ scmi_perf_domain_attributes_get(const struct scmi_protocol_handle *ph,
323321
* If supported overwrite short name with the extended one;
324322
* on error just carry on and use already provided short name.
325323
*/
326-
if (!ret && PROTOCOL_REV_MAJOR(version) >= 0x3 &&
324+
if (!ret && PROTOCOL_REV_MAJOR(ph->version) >= 0x3 &&
327325
SUPPORTS_EXTENDED_NAMES(flags))
328326
ph->hops->extended_name_get(ph, PERF_DOMAIN_NAME_GET,
329327
dom_info->id, NULL, dom_info->info.name,
@@ -345,19 +343,14 @@ static int opp_cmp_func(const void *opp1, const void *opp2)
345343
return t1->perf - t2->perf;
346344
}
347345

348-
struct scmi_perf_ipriv {
349-
u32 version;
350-
struct perf_dom_info *perf_dom;
351-
};
352-
353346
static void iter_perf_levels_prepare_message(void *message,
354347
unsigned int desc_index,
355348
const void *priv)
356349
{
357350
struct scmi_msg_perf_describe_levels *msg = message;
358-
const struct scmi_perf_ipriv *p = priv;
351+
const struct perf_dom_info *perf_dom = priv;
359352

360-
msg->domain = cpu_to_le32(p->perf_dom->id);
353+
msg->domain = cpu_to_le32(perf_dom->id);
361354
/* Set the number of OPPs to be skipped/already read */
362355
msg->level_index = cpu_to_le32(desc_index);
363356
}
@@ -445,21 +438,21 @@ iter_perf_levels_process_response(const struct scmi_protocol_handle *ph,
445438
{
446439
int ret;
447440
struct scmi_opp *opp;
448-
struct scmi_perf_ipriv *p = priv;
441+
struct perf_dom_info *perf_dom = priv;
449442

450-
opp = &p->perf_dom->opp[p->perf_dom->opp_count];
451-
if (PROTOCOL_REV_MAJOR(p->version) <= 0x3)
452-
ret = process_response_opp(ph->dev, p->perf_dom, opp,
443+
opp = &perf_dom->opp[perf_dom->opp_count];
444+
if (PROTOCOL_REV_MAJOR(ph->version) <= 0x3)
445+
ret = process_response_opp(ph->dev, perf_dom, opp,
453446
st->loop_idx, response);
454447
else
455-
ret = process_response_opp_v4(ph->dev, p->perf_dom, opp,
448+
ret = process_response_opp_v4(ph->dev, perf_dom, opp,
456449
st->loop_idx, response);
457450

458451
/* Skip BAD duplicates received from firmware */
459452
if (ret)
460453
return ret == -EBUSY ? 0 : ret;
461454

462-
p->perf_dom->opp_count++;
455+
perf_dom->opp_count++;
463456

464457
dev_dbg(ph->dev, "Level %d Power %d Latency %dus Ifreq %d Index %d\n",
465458
opp->perf, opp->power, opp->trans_latency_us,
@@ -470,7 +463,7 @@ iter_perf_levels_process_response(const struct scmi_protocol_handle *ph,
470463

471464
static int
472465
scmi_perf_describe_levels_get(const struct scmi_protocol_handle *ph,
473-
struct perf_dom_info *perf_dom, u32 version)
466+
struct perf_dom_info *perf_dom)
474467
{
475468
int ret;
476469
void *iter;
@@ -479,15 +472,11 @@ scmi_perf_describe_levels_get(const struct scmi_protocol_handle *ph,
479472
.update_state = iter_perf_levels_update_state,
480473
.process_response = iter_perf_levels_process_response,
481474
};
482-
struct scmi_perf_ipriv ppriv = {
483-
.version = version,
484-
.perf_dom = perf_dom,
485-
};
486475

487476
iter = ph->hops->iter_response_init(ph, &ops, MAX_OPPS,
488477
PERF_DESCRIBE_LEVELS,
489478
sizeof(struct scmi_msg_perf_describe_levels),
490-
&ppriv);
479+
perf_dom);
491480
if (IS_ERR(iter))
492481
return PTR_ERR(iter);
493482

@@ -576,7 +565,6 @@ static int __scmi_perf_limits_set(const struct scmi_protocol_handle *ph,
576565
static int scmi_perf_limits_set(const struct scmi_protocol_handle *ph,
577566
u32 domain, u32 max_perf, u32 min_perf)
578567
{
579-
struct scmi_perf_info *pi = ph->get_priv(ph);
580568
struct perf_dom_info *dom;
581569

582570
dom = scmi_perf_domain_lookup(ph, domain);
@@ -586,7 +574,7 @@ static int scmi_perf_limits_set(const struct scmi_protocol_handle *ph,
586574
if (!dom->set_limits)
587575
return -EOPNOTSUPP;
588576

589-
if (PROTOCOL_REV_MAJOR(pi->version) >= 0x3 && !max_perf && !min_perf)
577+
if (PROTOCOL_REV_MAJOR(ph->version) >= 0x3 && !max_perf && !min_perf)
590578
return -EINVAL;
591579

592580
if (dom->level_indexing_mode) {
@@ -1281,22 +1269,15 @@ static const struct scmi_protocol_events perf_protocol_events = {
12811269
static int scmi_perf_protocol_init(const struct scmi_protocol_handle *ph)
12821270
{
12831271
int domain, ret;
1284-
u32 version;
12851272
struct scmi_perf_info *pinfo;
12861273

1287-
ret = ph->xops->version_get(ph, &version);
1288-
if (ret)
1289-
return ret;
1290-
12911274
dev_dbg(ph->dev, "Performance Version %d.%d\n",
1292-
PROTOCOL_REV_MAJOR(version), PROTOCOL_REV_MINOR(version));
1275+
PROTOCOL_REV_MAJOR(ph->version), PROTOCOL_REV_MINOR(ph->version));
12931276

12941277
pinfo = devm_kzalloc(ph->dev, sizeof(*pinfo), GFP_KERNEL);
12951278
if (!pinfo)
12961279
return -ENOMEM;
12971280

1298-
pinfo->version = version;
1299-
13001281
ret = scmi_perf_attributes_get(ph, pinfo);
13011282
if (ret)
13021283
return ret;
@@ -1311,8 +1292,8 @@ static int scmi_perf_protocol_init(const struct scmi_protocol_handle *ph)
13111292

13121293
dom->id = domain;
13131294
scmi_perf_domain_attributes_get(ph, dom, pinfo->notify_lim_cmd,
1314-
pinfo->notify_lvl_cmd, version);
1315-
scmi_perf_describe_levels_get(ph, dom, version);
1295+
pinfo->notify_lvl_cmd);
1296+
scmi_perf_describe_levels_get(ph, dom);
13161297

13171298
if (dom->perf_fastchannels)
13181299
scmi_perf_domain_init_fc(ph, dom);
@@ -1322,7 +1303,7 @@ static int scmi_perf_protocol_init(const struct scmi_protocol_handle *ph)
13221303
if (ret)
13231304
return ret;
13241305

1325-
return ph->set_priv(ph, pinfo, version);
1306+
return ph->set_priv(ph, pinfo);
13261307
}
13271308

13281309
static const struct scmi_protocol scmi_perf = {

drivers/firmware/arm_scmi/pinctrl.c

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ struct scmi_pin_info {
117117
};
118118

119119
struct scmi_pinctrl_info {
120-
u32 version;
121120
int nr_groups;
122121
int nr_functions;
123122
int nr_pins;
@@ -831,15 +830,10 @@ static const struct scmi_pinctrl_proto_ops pinctrl_proto_ops = {
831830
static int scmi_pinctrl_protocol_init(const struct scmi_protocol_handle *ph)
832831
{
833832
int ret;
834-
u32 version;
835833
struct scmi_pinctrl_info *pinfo;
836834

837-
ret = ph->xops->version_get(ph, &version);
838-
if (ret)
839-
return ret;
840-
841835
dev_dbg(ph->dev, "Pinctrl Version %d.%d\n",
842-
PROTOCOL_REV_MAJOR(version), PROTOCOL_REV_MINOR(version));
836+
PROTOCOL_REV_MAJOR(ph->version), PROTOCOL_REV_MINOR(ph->version));
843837

844838
pinfo = devm_kzalloc(ph->dev, sizeof(*pinfo), GFP_KERNEL);
845839
if (!pinfo)
@@ -864,9 +858,7 @@ static int scmi_pinctrl_protocol_init(const struct scmi_protocol_handle *ph)
864858
if (!pinfo->functions)
865859
return -ENOMEM;
866860

867-
pinfo->version = version;
868-
869-
return ph->set_priv(ph, pinfo, version);
861+
return ph->set_priv(ph, pinfo);
870862
}
871863

872864
static int scmi_pinctrl_protocol_deinit(const struct scmi_protocol_handle *ph)

0 commit comments

Comments
 (0)