Skip to content

Commit 4e1a53b

Browse files
cris-masudeep-holla
authored andcommitted
firmware: arm_scmi: Refactor the internal powercap get/set helpers
Refactor the SCMI powercap internal get/set helpers in preparation to adding the powercap protocol enable/disable support. Signed-off-by: Cristian Marussi <cristian.marussi@arm.com> Link: https://lore.kernel.org/r/20230531152039.2363181-2-cristian.marussi@arm.com Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
1 parent 5f2ea10 commit 4e1a53b

1 file changed

Lines changed: 45 additions & 20 deletions

File tree

drivers/firmware/arm_scmi/powercap.c

Lines changed: 45 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -313,24 +313,33 @@ static int scmi_powercap_xfer_cap_get(const struct scmi_protocol_handle *ph,
313313
return ret;
314314
}
315315

316-
static int scmi_powercap_cap_get(const struct scmi_protocol_handle *ph,
317-
u32 domain_id, u32 *power_cap)
316+
static int __scmi_powercap_cap_get(const struct scmi_protocol_handle *ph,
317+
const struct scmi_powercap_info *dom,
318+
u32 *power_cap)
318319
{
319-
struct scmi_powercap_info *dom;
320-
struct powercap_info *pi = ph->get_priv(ph);
321-
322-
if (!power_cap || domain_id >= pi->num_domains)
323-
return -EINVAL;
324-
325-
dom = pi->powercaps + domain_id;
326320
if (dom->fc_info && dom->fc_info[POWERCAP_FC_CAP].get_addr) {
327321
*power_cap = ioread32(dom->fc_info[POWERCAP_FC_CAP].get_addr);
328322
trace_scmi_fc_call(SCMI_PROTOCOL_POWERCAP, POWERCAP_CAP_GET,
329-
domain_id, *power_cap, 0);
323+
dom->id, *power_cap, 0);
330324
return 0;
331325
}
332326

333-
return scmi_powercap_xfer_cap_get(ph, domain_id, power_cap);
327+
return scmi_powercap_xfer_cap_get(ph, dom->id, power_cap);
328+
}
329+
330+
static int scmi_powercap_cap_get(const struct scmi_protocol_handle *ph,
331+
u32 domain_id, u32 *power_cap)
332+
{
333+
const struct scmi_powercap_info *dom;
334+
335+
if (!power_cap)
336+
return -EINVAL;
337+
338+
dom = scmi_powercap_dom_info_get(ph, domain_id);
339+
if (!dom)
340+
return -EINVAL;
341+
342+
return __scmi_powercap_cap_get(ph, dom, power_cap);
334343
}
335344

336345
static int scmi_powercap_xfer_cap_set(const struct scmi_protocol_handle *ph,
@@ -375,17 +384,20 @@ static int scmi_powercap_xfer_cap_set(const struct scmi_protocol_handle *ph,
375384
return ret;
376385
}
377386

378-
static int scmi_powercap_cap_set(const struct scmi_protocol_handle *ph,
379-
u32 domain_id, u32 power_cap,
380-
bool ignore_dresp)
387+
static int __scmi_powercap_cap_set(const struct scmi_protocol_handle *ph,
388+
struct powercap_info *pi, u32 domain_id,
389+
u32 power_cap, bool ignore_dresp)
381390
{
391+
int ret = -EINVAL;
382392
const struct scmi_powercap_info *pc;
383393

384394
pc = scmi_powercap_dom_info_get(ph, domain_id);
385-
if (!pc || !pc->powercap_cap_config || !power_cap ||
386-
power_cap < pc->min_power_cap ||
387-
power_cap > pc->max_power_cap)
388-
return -EINVAL;
395+
if (!pc || !pc->powercap_cap_config)
396+
return ret;
397+
398+
if (power_cap &&
399+
(power_cap < pc->min_power_cap || power_cap > pc->max_power_cap))
400+
return ret;
389401

390402
if (pc->fc_info && pc->fc_info[POWERCAP_FC_CAP].set_addr) {
391403
struct scmi_fc_info *fci = &pc->fc_info[POWERCAP_FC_CAP];
@@ -394,10 +406,23 @@ static int scmi_powercap_cap_set(const struct scmi_protocol_handle *ph,
394406
ph->hops->fastchannel_db_ring(fci->set_db);
395407
trace_scmi_fc_call(SCMI_PROTOCOL_POWERCAP, POWERCAP_CAP_SET,
396408
domain_id, power_cap, 0);
397-
return 0;
409+
ret = 0;
410+
} else {
411+
ret = scmi_powercap_xfer_cap_set(ph, pc, power_cap,
412+
ignore_dresp);
398413
}
399414

400-
return scmi_powercap_xfer_cap_set(ph, pc, power_cap, ignore_dresp);
415+
return ret;
416+
}
417+
418+
static int scmi_powercap_cap_set(const struct scmi_protocol_handle *ph,
419+
u32 domain_id, u32 power_cap,
420+
bool ignore_dresp)
421+
{
422+
struct powercap_info *pi = ph->get_priv(ph);
423+
424+
return __scmi_powercap_cap_set(ph, pi, domain_id,
425+
power_cap, ignore_dresp);
401426
}
402427

403428
static int scmi_powercap_xfer_pai_get(const struct scmi_protocol_handle *ph,

0 commit comments

Comments
 (0)