1 // SPDX-License-Identifier: GPL-2.0
3 * System Control and Management Interface (SCMI) Performance Protocol
5 * Copyright (C) 2018-2022 ARM Ltd.
8 #define pr_fmt(fmt) "SCMI Notifications PERF - " fmt
10 #include <linux/bits.h>
13 #include <linux/io-64-nonatomic-hi-lo.h>
14 #include <linux/module.h>
15 #include <linux/platform_device.h>
16 #include <linux/pm_opp.h>
17 #include <linux/scmi_protocol.h>
18 #include <linux/sort.h>
20 #include "protocols.h"
25 enum scmi_performance_protocol_cmd {
26 PERF_DOMAIN_ATTRIBUTES = 0x3,
27 PERF_DESCRIBE_LEVELS = 0x4,
28 PERF_LIMITS_SET = 0x5,
29 PERF_LIMITS_GET = 0x6,
32 PERF_NOTIFY_LIMITS = 0x9,
33 PERF_NOTIFY_LEVEL = 0xa,
34 PERF_DESCRIBE_FASTCHANNEL = 0xb,
35 PERF_DOMAIN_NAME_GET = 0xc,
44 struct scmi_msg_resp_perf_attributes {
47 #define POWER_SCALE_IN_MILLIWATT(x) ((x) & BIT(0))
48 #define POWER_SCALE_IN_MICROWATT(x) ((x) & BIT(1))
49 __le32 stats_addr_low;
50 __le32 stats_addr_high;
54 struct scmi_msg_resp_perf_domain_attributes {
56 #define SUPPORTS_SET_LIMITS(x) ((x) & BIT(31))
57 #define SUPPORTS_SET_PERF_LVL(x) ((x) & BIT(30))
58 #define SUPPORTS_PERF_LIMIT_NOTIFY(x) ((x) & BIT(29))
59 #define SUPPORTS_PERF_LEVEL_NOTIFY(x) ((x) & BIT(28))
60 #define SUPPORTS_PERF_FASTCHANNELS(x) ((x) & BIT(27))
61 #define SUPPORTS_EXTENDED_NAMES(x) ((x) & BIT(26))
63 __le32 sustained_freq_khz;
64 __le32 sustained_perf_level;
65 u8 name[SCMI_SHORT_NAME_MAX_SIZE];
68 struct scmi_msg_perf_describe_levels {
73 struct scmi_perf_set_limits {
79 struct scmi_perf_get_limits {
84 struct scmi_perf_set_level {
89 struct scmi_perf_notify_level_or_limits {
94 struct scmi_perf_limits_notify_payld {
101 struct scmi_perf_level_notify_payld {
104 __le32 performance_level;
107 struct scmi_msg_resp_perf_describe_levels {
109 __le16 num_remaining;
113 __le16 transition_latency_us;
118 struct scmi_perf_get_fc_info {
123 struct scmi_msg_resp_perf_desc_fc {
125 #define SUPPORTS_DOORBELL(x) ((x) & BIT(0))
126 #define DOORBELL_REG_WIDTH(x) FIELD_GET(GENMASK(2, 1), (x))
128 __le32 chan_addr_low;
129 __le32 chan_addr_high;
135 __le32 db_preserve_lmask;
136 __le32 db_preserve_hmask;
139 struct scmi_fc_db_info {
146 struct scmi_fc_info {
147 void __iomem *level_set_addr;
148 void __iomem *limit_set_addr;
149 void __iomem *level_get_addr;
150 void __iomem *limit_get_addr;
151 struct scmi_fc_db_info *level_set_db;
152 struct scmi_fc_db_info *limit_set_db;
155 struct perf_dom_info {
158 bool perf_limit_notify;
159 bool perf_level_notify;
160 bool perf_fastchannels;
162 u32 sustained_freq_khz;
163 u32 sustained_perf_level;
165 char name[SCMI_MAX_STR_SIZE];
166 struct scmi_opp opp[MAX_OPPS];
167 struct scmi_fc_info *fc_info;
170 struct scmi_perf_info {
173 enum scmi_power_scale power_scale;
176 struct perf_dom_info *dom_info;
179 static enum scmi_performance_protocol_cmd evt_2_cmd[] = {
184 static int scmi_perf_attributes_get(const struct scmi_protocol_handle *ph,
185 struct scmi_perf_info *pi)
189 struct scmi_msg_resp_perf_attributes *attr;
191 ret = ph->xops->xfer_get_init(ph, PROTOCOL_ATTRIBUTES, 0,
198 ret = ph->xops->do_xfer(ph, t);
200 u16 flags = le16_to_cpu(attr->flags);
202 pi->num_domains = le16_to_cpu(attr->num_domains);
204 if (POWER_SCALE_IN_MILLIWATT(flags))
205 pi->power_scale = SCMI_POWER_MILLIWATTS;
206 if (PROTOCOL_REV_MAJOR(pi->version) >= 0x3)
207 if (POWER_SCALE_IN_MICROWATT(flags))
208 pi->power_scale = SCMI_POWER_MICROWATTS;
210 pi->stats_addr = le32_to_cpu(attr->stats_addr_low) |
211 (u64)le32_to_cpu(attr->stats_addr_high) << 32;
212 pi->stats_size = le32_to_cpu(attr->stats_size);
215 ph->xops->xfer_put(ph, t);
220 scmi_perf_domain_attributes_get(const struct scmi_protocol_handle *ph,
221 u32 domain, struct perf_dom_info *dom_info,
227 struct scmi_msg_resp_perf_domain_attributes *attr;
229 ret = ph->xops->xfer_get_init(ph, PERF_DOMAIN_ATTRIBUTES,
230 sizeof(domain), sizeof(*attr), &t);
234 put_unaligned_le32(domain, t->tx.buf);
237 ret = ph->xops->do_xfer(ph, t);
239 flags = le32_to_cpu(attr->flags);
241 dom_info->set_limits = SUPPORTS_SET_LIMITS(flags);
242 dom_info->set_perf = SUPPORTS_SET_PERF_LVL(flags);
243 dom_info->perf_limit_notify = SUPPORTS_PERF_LIMIT_NOTIFY(flags);
244 dom_info->perf_level_notify = SUPPORTS_PERF_LEVEL_NOTIFY(flags);
245 dom_info->perf_fastchannels = SUPPORTS_PERF_FASTCHANNELS(flags);
246 dom_info->sustained_freq_khz =
247 le32_to_cpu(attr->sustained_freq_khz);
248 dom_info->sustained_perf_level =
249 le32_to_cpu(attr->sustained_perf_level);
250 if (!dom_info->sustained_freq_khz ||
251 !dom_info->sustained_perf_level)
252 /* CPUFreq converts to kHz, hence default 1000 */
253 dom_info->mult_factor = 1000;
255 dom_info->mult_factor =
256 (dom_info->sustained_freq_khz * 1000) /
257 dom_info->sustained_perf_level;
258 strscpy(dom_info->name, attr->name, SCMI_SHORT_NAME_MAX_SIZE);
261 ph->xops->xfer_put(ph, t);
264 * If supported overwrite short name with the extended one;
265 * on error just carry on and use already provided short name.
267 if (!ret && PROTOCOL_REV_MAJOR(version) >= 0x3 &&
268 SUPPORTS_EXTENDED_NAMES(flags))
269 ph->hops->extended_name_get(ph, PERF_DOMAIN_NAME_GET, domain,
270 dom_info->name, SCMI_MAX_STR_SIZE);
275 static int opp_cmp_func(const void *opp1, const void *opp2)
277 const struct scmi_opp *t1 = opp1, *t2 = opp2;
279 return t1->perf - t2->perf;
282 struct scmi_perf_ipriv {
284 struct perf_dom_info *perf_dom;
287 static void iter_perf_levels_prepare_message(void *message,
288 unsigned int desc_index,
291 struct scmi_msg_perf_describe_levels *msg = message;
292 const struct scmi_perf_ipriv *p = priv;
294 msg->domain = cpu_to_le32(p->domain);
295 /* Set the number of OPPs to be skipped/already read */
296 msg->level_index = cpu_to_le32(desc_index);
299 static int iter_perf_levels_update_state(struct scmi_iterator_state *st,
300 const void *response, void *priv)
302 const struct scmi_msg_resp_perf_describe_levels *r = response;
304 st->num_returned = le16_to_cpu(r->num_returned);
305 st->num_remaining = le16_to_cpu(r->num_remaining);
311 iter_perf_levels_process_response(const struct scmi_protocol_handle *ph,
312 const void *response,
313 struct scmi_iterator_state *st, void *priv)
315 struct scmi_opp *opp;
316 const struct scmi_msg_resp_perf_describe_levels *r = response;
317 struct scmi_perf_ipriv *p = priv;
319 opp = &p->perf_dom->opp[st->desc_index + st->loop_idx];
320 opp->perf = le32_to_cpu(r->opp[st->loop_idx].perf_val);
321 opp->power = le32_to_cpu(r->opp[st->loop_idx].power);
322 opp->trans_latency_us =
323 le16_to_cpu(r->opp[st->loop_idx].transition_latency_us);
324 p->perf_dom->opp_count++;
326 dev_dbg(ph->dev, "Level %d Power %d Latency %dus\n",
327 opp->perf, opp->power, opp->trans_latency_us);
333 scmi_perf_describe_levels_get(const struct scmi_protocol_handle *ph, u32 domain,
334 struct perf_dom_info *perf_dom)
338 struct scmi_iterator_ops ops = {
339 .prepare_message = iter_perf_levels_prepare_message,
340 .update_state = iter_perf_levels_update_state,
341 .process_response = iter_perf_levels_process_response,
343 struct scmi_perf_ipriv ppriv = {
345 .perf_dom = perf_dom,
348 iter = ph->hops->iter_response_init(ph, &ops, MAX_OPPS,
349 PERF_DESCRIBE_LEVELS,
350 sizeof(struct scmi_msg_perf_describe_levels),
353 return PTR_ERR(iter);
355 ret = ph->hops->iter_response_run(iter);
359 if (perf_dom->opp_count)
360 sort(perf_dom->opp, perf_dom->opp_count,
361 sizeof(struct scmi_opp), opp_cmp_func, NULL);
366 #define SCMI_PERF_FC_RING_DB(w) \
371 val = ioread##w(db->addr) & db->mask; \
372 iowrite##w((u##w)db->set | val, db->addr); \
375 static void scmi_perf_fc_ring_db(struct scmi_fc_db_info *db)
377 if (!db || !db->addr)
381 SCMI_PERF_FC_RING_DB(8);
382 else if (db->width == 2)
383 SCMI_PERF_FC_RING_DB(16);
384 else if (db->width == 4)
385 SCMI_PERF_FC_RING_DB(32);
386 else /* db->width == 8 */
388 SCMI_PERF_FC_RING_DB(64);
394 val = ioread64_hi_lo(db->addr) & db->mask;
395 iowrite64_hi_lo(db->set | val, db->addr);
400 static int scmi_perf_mb_limits_set(const struct scmi_protocol_handle *ph,
401 u32 domain, u32 max_perf, u32 min_perf)
405 struct scmi_perf_set_limits *limits;
407 ret = ph->xops->xfer_get_init(ph, PERF_LIMITS_SET,
408 sizeof(*limits), 0, &t);
413 limits->domain = cpu_to_le32(domain);
414 limits->max_level = cpu_to_le32(max_perf);
415 limits->min_level = cpu_to_le32(min_perf);
417 ret = ph->xops->do_xfer(ph, t);
419 ph->xops->xfer_put(ph, t);
423 static int scmi_perf_limits_set(const struct scmi_protocol_handle *ph,
424 u32 domain, u32 max_perf, u32 min_perf)
426 struct scmi_perf_info *pi = ph->get_priv(ph);
427 struct perf_dom_info *dom = pi->dom_info + domain;
429 if (PROTOCOL_REV_MAJOR(pi->version) >= 0x3 && !max_perf && !min_perf)
432 if (dom->fc_info && dom->fc_info->limit_set_addr) {
433 iowrite32(max_perf, dom->fc_info->limit_set_addr);
434 iowrite32(min_perf, dom->fc_info->limit_set_addr + 4);
435 scmi_perf_fc_ring_db(dom->fc_info->limit_set_db);
439 return scmi_perf_mb_limits_set(ph, domain, max_perf, min_perf);
442 static int scmi_perf_mb_limits_get(const struct scmi_protocol_handle *ph,
443 u32 domain, u32 *max_perf, u32 *min_perf)
447 struct scmi_perf_get_limits *limits;
449 ret = ph->xops->xfer_get_init(ph, PERF_LIMITS_GET,
450 sizeof(__le32), 0, &t);
454 put_unaligned_le32(domain, t->tx.buf);
456 ret = ph->xops->do_xfer(ph, t);
460 *max_perf = le32_to_cpu(limits->max_level);
461 *min_perf = le32_to_cpu(limits->min_level);
464 ph->xops->xfer_put(ph, t);
468 static int scmi_perf_limits_get(const struct scmi_protocol_handle *ph,
469 u32 domain, u32 *max_perf, u32 *min_perf)
471 struct scmi_perf_info *pi = ph->get_priv(ph);
472 struct perf_dom_info *dom = pi->dom_info + domain;
474 if (dom->fc_info && dom->fc_info->limit_get_addr) {
475 *max_perf = ioread32(dom->fc_info->limit_get_addr);
476 *min_perf = ioread32(dom->fc_info->limit_get_addr + 4);
480 return scmi_perf_mb_limits_get(ph, domain, max_perf, min_perf);
483 static int scmi_perf_mb_level_set(const struct scmi_protocol_handle *ph,
484 u32 domain, u32 level, bool poll)
488 struct scmi_perf_set_level *lvl;
490 ret = ph->xops->xfer_get_init(ph, PERF_LEVEL_SET, sizeof(*lvl), 0, &t);
494 t->hdr.poll_completion = poll;
496 lvl->domain = cpu_to_le32(domain);
497 lvl->level = cpu_to_le32(level);
499 ret = ph->xops->do_xfer(ph, t);
501 ph->xops->xfer_put(ph, t);
505 static int scmi_perf_level_set(const struct scmi_protocol_handle *ph,
506 u32 domain, u32 level, bool poll)
508 struct scmi_perf_info *pi = ph->get_priv(ph);
509 struct perf_dom_info *dom = pi->dom_info + domain;
511 if (dom->fc_info && dom->fc_info->level_set_addr) {
512 iowrite32(level, dom->fc_info->level_set_addr);
513 scmi_perf_fc_ring_db(dom->fc_info->level_set_db);
517 return scmi_perf_mb_level_set(ph, domain, level, poll);
520 static int scmi_perf_mb_level_get(const struct scmi_protocol_handle *ph,
521 u32 domain, u32 *level, bool poll)
526 ret = ph->xops->xfer_get_init(ph, PERF_LEVEL_GET,
527 sizeof(u32), sizeof(u32), &t);
531 t->hdr.poll_completion = poll;
532 put_unaligned_le32(domain, t->tx.buf);
534 ret = ph->xops->do_xfer(ph, t);
536 *level = get_unaligned_le32(t->rx.buf);
538 ph->xops->xfer_put(ph, t);
542 static int scmi_perf_level_get(const struct scmi_protocol_handle *ph,
543 u32 domain, u32 *level, bool poll)
545 struct scmi_perf_info *pi = ph->get_priv(ph);
546 struct perf_dom_info *dom = pi->dom_info + domain;
548 if (dom->fc_info && dom->fc_info->level_get_addr) {
549 *level = ioread32(dom->fc_info->level_get_addr);
553 return scmi_perf_mb_level_get(ph, domain, level, poll);
556 static int scmi_perf_level_limits_notify(const struct scmi_protocol_handle *ph,
557 u32 domain, int message_id,
562 struct scmi_perf_notify_level_or_limits *notify;
564 ret = ph->xops->xfer_get_init(ph, message_id, sizeof(*notify), 0, &t);
569 notify->domain = cpu_to_le32(domain);
570 notify->notify_enable = enable ? cpu_to_le32(BIT(0)) : 0;
572 ret = ph->xops->do_xfer(ph, t);
574 ph->xops->xfer_put(ph, t);
578 static bool scmi_perf_fc_size_is_valid(u32 msg, u32 size)
580 if ((msg == PERF_LEVEL_GET || msg == PERF_LEVEL_SET) && size == 4)
582 if ((msg == PERF_LIMITS_GET || msg == PERF_LIMITS_SET) && size == 8)
588 scmi_perf_domain_desc_fc(const struct scmi_protocol_handle *ph, u32 domain,
589 u32 message_id, void __iomem **p_addr,
590 struct scmi_fc_db_info **p_db)
598 struct scmi_fc_db_info *db;
599 struct scmi_perf_get_fc_info *info;
600 struct scmi_msg_resp_perf_desc_fc *resp;
605 ret = ph->xops->xfer_get_init(ph, PERF_DESCRIBE_FASTCHANNEL,
606 sizeof(*info), sizeof(*resp), &t);
611 info->domain = cpu_to_le32(domain);
612 info->message_id = cpu_to_le32(message_id);
614 ret = ph->xops->do_xfer(ph, t);
619 flags = le32_to_cpu(resp->attr);
620 size = le32_to_cpu(resp->chan_size);
621 if (!scmi_perf_fc_size_is_valid(message_id, size))
624 phys_addr = le32_to_cpu(resp->chan_addr_low);
625 phys_addr |= (u64)le32_to_cpu(resp->chan_addr_high) << 32;
626 addr = devm_ioremap(ph->dev, phys_addr, size);
631 if (p_db && SUPPORTS_DOORBELL(flags)) {
632 db = devm_kzalloc(ph->dev, sizeof(*db), GFP_KERNEL);
636 size = 1 << DOORBELL_REG_WIDTH(flags);
637 phys_addr = le32_to_cpu(resp->db_addr_low);
638 phys_addr |= (u64)le32_to_cpu(resp->db_addr_high) << 32;
639 addr = devm_ioremap(ph->dev, phys_addr, size);
645 db->set = le32_to_cpu(resp->db_set_lmask);
646 db->set |= (u64)le32_to_cpu(resp->db_set_hmask) << 32;
647 db->mask = le32_to_cpu(resp->db_preserve_lmask);
648 db->mask |= (u64)le32_to_cpu(resp->db_preserve_hmask) << 32;
652 ph->xops->xfer_put(ph, t);
655 static void scmi_perf_domain_init_fc(const struct scmi_protocol_handle *ph,
656 u32 domain, struct scmi_fc_info **p_fc)
658 struct scmi_fc_info *fc;
660 fc = devm_kzalloc(ph->dev, sizeof(*fc), GFP_KERNEL);
664 scmi_perf_domain_desc_fc(ph, domain, PERF_LEVEL_SET,
665 &fc->level_set_addr, &fc->level_set_db);
666 scmi_perf_domain_desc_fc(ph, domain, PERF_LEVEL_GET,
667 &fc->level_get_addr, NULL);
668 scmi_perf_domain_desc_fc(ph, domain, PERF_LIMITS_SET,
669 &fc->limit_set_addr, &fc->limit_set_db);
670 scmi_perf_domain_desc_fc(ph, domain, PERF_LIMITS_GET,
671 &fc->limit_get_addr, NULL);
675 /* Device specific ops */
676 static int scmi_dev_domain_id(struct device *dev)
678 struct of_phandle_args clkspec;
680 if (of_parse_phandle_with_args(dev->of_node, "clocks", "#clock-cells",
684 return clkspec.args[0];
687 static int scmi_dvfs_device_opps_add(const struct scmi_protocol_handle *ph,
690 int idx, ret, domain;
692 struct scmi_opp *opp;
693 struct perf_dom_info *dom;
694 struct scmi_perf_info *pi = ph->get_priv(ph);
696 domain = scmi_dev_domain_id(dev);
700 dom = pi->dom_info + domain;
702 for (opp = dom->opp, idx = 0; idx < dom->opp_count; idx++, opp++) {
703 freq = opp->perf * dom->mult_factor;
705 ret = dev_pm_opp_add(dev, freq, 0);
707 dev_warn(dev, "failed to add opp %luHz\n", freq);
710 freq = (--opp)->perf * dom->mult_factor;
711 dev_pm_opp_remove(dev, freq);
720 scmi_dvfs_transition_latency_get(const struct scmi_protocol_handle *ph,
723 struct perf_dom_info *dom;
724 struct scmi_perf_info *pi = ph->get_priv(ph);
725 int domain = scmi_dev_domain_id(dev);
730 dom = pi->dom_info + domain;
732 return dom->opp[dom->opp_count - 1].trans_latency_us * 1000;
735 static int scmi_dvfs_freq_set(const struct scmi_protocol_handle *ph, u32 domain,
736 unsigned long freq, bool poll)
738 struct scmi_perf_info *pi = ph->get_priv(ph);
739 struct perf_dom_info *dom = pi->dom_info + domain;
741 return scmi_perf_level_set(ph, domain, freq / dom->mult_factor, poll);
744 static int scmi_dvfs_freq_get(const struct scmi_protocol_handle *ph, u32 domain,
745 unsigned long *freq, bool poll)
749 struct scmi_perf_info *pi = ph->get_priv(ph);
750 struct perf_dom_info *dom = pi->dom_info + domain;
752 ret = scmi_perf_level_get(ph, domain, &level, poll);
754 *freq = level * dom->mult_factor;
759 static int scmi_dvfs_est_power_get(const struct scmi_protocol_handle *ph,
760 u32 domain, unsigned long *freq,
761 unsigned long *power)
763 struct scmi_perf_info *pi = ph->get_priv(ph);
764 struct perf_dom_info *dom;
765 unsigned long opp_freq;
766 int idx, ret = -EINVAL;
767 struct scmi_opp *opp;
769 dom = pi->dom_info + domain;
773 for (opp = dom->opp, idx = 0; idx < dom->opp_count; idx++, opp++) {
774 opp_freq = opp->perf * dom->mult_factor;
775 if (opp_freq < *freq)
787 static bool scmi_fast_switch_possible(const struct scmi_protocol_handle *ph,
790 struct perf_dom_info *dom;
791 struct scmi_perf_info *pi = ph->get_priv(ph);
793 dom = pi->dom_info + scmi_dev_domain_id(dev);
795 return dom->fc_info && dom->fc_info->level_set_addr;
798 static enum scmi_power_scale
799 scmi_power_scale_get(const struct scmi_protocol_handle *ph)
801 struct scmi_perf_info *pi = ph->get_priv(ph);
803 return pi->power_scale;
806 static const struct scmi_perf_proto_ops perf_proto_ops = {
807 .limits_set = scmi_perf_limits_set,
808 .limits_get = scmi_perf_limits_get,
809 .level_set = scmi_perf_level_set,
810 .level_get = scmi_perf_level_get,
811 .device_domain_id = scmi_dev_domain_id,
812 .transition_latency_get = scmi_dvfs_transition_latency_get,
813 .device_opps_add = scmi_dvfs_device_opps_add,
814 .freq_set = scmi_dvfs_freq_set,
815 .freq_get = scmi_dvfs_freq_get,
816 .est_power_get = scmi_dvfs_est_power_get,
817 .fast_switch_possible = scmi_fast_switch_possible,
818 .power_scale_get = scmi_power_scale_get,
821 static int scmi_perf_set_notify_enabled(const struct scmi_protocol_handle *ph,
822 u8 evt_id, u32 src_id, bool enable)
826 if (evt_id >= ARRAY_SIZE(evt_2_cmd))
829 cmd_id = evt_2_cmd[evt_id];
830 ret = scmi_perf_level_limits_notify(ph, src_id, cmd_id, enable);
832 pr_debug("FAIL_ENABLED - evt[%X] dom[%d] - ret:%d\n",
833 evt_id, src_id, ret);
838 static void *scmi_perf_fill_custom_report(const struct scmi_protocol_handle *ph,
839 u8 evt_id, ktime_t timestamp,
840 const void *payld, size_t payld_sz,
841 void *report, u32 *src_id)
846 case SCMI_EVENT_PERFORMANCE_LIMITS_CHANGED:
848 const struct scmi_perf_limits_notify_payld *p = payld;
849 struct scmi_perf_limits_report *r = report;
851 if (sizeof(*p) != payld_sz)
854 r->timestamp = timestamp;
855 r->agent_id = le32_to_cpu(p->agent_id);
856 r->domain_id = le32_to_cpu(p->domain_id);
857 r->range_max = le32_to_cpu(p->range_max);
858 r->range_min = le32_to_cpu(p->range_min);
859 *src_id = r->domain_id;
863 case SCMI_EVENT_PERFORMANCE_LEVEL_CHANGED:
865 const struct scmi_perf_level_notify_payld *p = payld;
866 struct scmi_perf_level_report *r = report;
868 if (sizeof(*p) != payld_sz)
871 r->timestamp = timestamp;
872 r->agent_id = le32_to_cpu(p->agent_id);
873 r->domain_id = le32_to_cpu(p->domain_id);
874 r->performance_level = le32_to_cpu(p->performance_level);
875 *src_id = r->domain_id;
886 static int scmi_perf_get_num_sources(const struct scmi_protocol_handle *ph)
888 struct scmi_perf_info *pi = ph->get_priv(ph);
893 return pi->num_domains;
896 static const struct scmi_event perf_events[] = {
898 .id = SCMI_EVENT_PERFORMANCE_LIMITS_CHANGED,
899 .max_payld_sz = sizeof(struct scmi_perf_limits_notify_payld),
900 .max_report_sz = sizeof(struct scmi_perf_limits_report),
903 .id = SCMI_EVENT_PERFORMANCE_LEVEL_CHANGED,
904 .max_payld_sz = sizeof(struct scmi_perf_level_notify_payld),
905 .max_report_sz = sizeof(struct scmi_perf_level_report),
909 static const struct scmi_event_ops perf_event_ops = {
910 .get_num_sources = scmi_perf_get_num_sources,
911 .set_notify_enabled = scmi_perf_set_notify_enabled,
912 .fill_custom_report = scmi_perf_fill_custom_report,
915 static const struct scmi_protocol_events perf_protocol_events = {
916 .queue_sz = SCMI_PROTO_QUEUE_SZ,
917 .ops = &perf_event_ops,
919 .num_events = ARRAY_SIZE(perf_events),
922 static int scmi_perf_protocol_init(const struct scmi_protocol_handle *ph)
926 struct scmi_perf_info *pinfo;
928 ret = ph->xops->version_get(ph, &version);
932 dev_dbg(ph->dev, "Performance Version %d.%d\n",
933 PROTOCOL_REV_MAJOR(version), PROTOCOL_REV_MINOR(version));
935 pinfo = devm_kzalloc(ph->dev, sizeof(*pinfo), GFP_KERNEL);
939 ret = scmi_perf_attributes_get(ph, pinfo);
943 pinfo->dom_info = devm_kcalloc(ph->dev, pinfo->num_domains,
944 sizeof(*pinfo->dom_info), GFP_KERNEL);
945 if (!pinfo->dom_info)
948 for (domain = 0; domain < pinfo->num_domains; domain++) {
949 struct perf_dom_info *dom = pinfo->dom_info + domain;
951 scmi_perf_domain_attributes_get(ph, domain, dom, version);
952 scmi_perf_describe_levels_get(ph, domain, dom);
954 if (dom->perf_fastchannels)
955 scmi_perf_domain_init_fc(ph, domain, &dom->fc_info);
958 pinfo->version = version;
960 return ph->set_priv(ph, pinfo);
963 static const struct scmi_protocol scmi_perf = {
964 .id = SCMI_PROTOCOL_PERF,
965 .owner = THIS_MODULE,
966 .instance_init = &scmi_perf_protocol_init,
967 .ops = &perf_proto_ops,
968 .events = &perf_protocol_events,
971 DEFINE_SCMI_PROTOCOL_REGISTER_UNREGISTER(perf, scmi_perf)