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 {
177 struct perf_dom_info *dom_info;
180 static enum scmi_performance_protocol_cmd evt_2_cmd[] = {
185 static int scmi_perf_attributes_get(const struct scmi_protocol_handle *ph,
186 struct scmi_perf_info *pi)
190 struct scmi_msg_resp_perf_attributes *attr;
192 ret = ph->xops->xfer_get_init(ph, PROTOCOL_ATTRIBUTES, 0,
199 ret = ph->xops->do_xfer(ph, t);
201 u16 flags = le16_to_cpu(attr->flags);
203 pi->num_domains = le16_to_cpu(attr->num_domains);
204 pi->power_scale_mw = POWER_SCALE_IN_MILLIWATT(flags);
205 if (PROTOCOL_REV_MAJOR(pi->version) >= 0x3)
206 pi->power_scale_uw = POWER_SCALE_IN_MICROWATT(flags);
207 pi->stats_addr = le32_to_cpu(attr->stats_addr_low) |
208 (u64)le32_to_cpu(attr->stats_addr_high) << 32;
209 pi->stats_size = le32_to_cpu(attr->stats_size);
212 ph->xops->xfer_put(ph, t);
217 scmi_perf_domain_attributes_get(const struct scmi_protocol_handle *ph,
218 u32 domain, struct perf_dom_info *dom_info,
224 struct scmi_msg_resp_perf_domain_attributes *attr;
226 ret = ph->xops->xfer_get_init(ph, PERF_DOMAIN_ATTRIBUTES,
227 sizeof(domain), sizeof(*attr), &t);
231 put_unaligned_le32(domain, t->tx.buf);
234 ret = ph->xops->do_xfer(ph, t);
236 flags = le32_to_cpu(attr->flags);
238 dom_info->set_limits = SUPPORTS_SET_LIMITS(flags);
239 dom_info->set_perf = SUPPORTS_SET_PERF_LVL(flags);
240 dom_info->perf_limit_notify = SUPPORTS_PERF_LIMIT_NOTIFY(flags);
241 dom_info->perf_level_notify = SUPPORTS_PERF_LEVEL_NOTIFY(flags);
242 dom_info->perf_fastchannels = SUPPORTS_PERF_FASTCHANNELS(flags);
243 dom_info->sustained_freq_khz =
244 le32_to_cpu(attr->sustained_freq_khz);
245 dom_info->sustained_perf_level =
246 le32_to_cpu(attr->sustained_perf_level);
247 if (!dom_info->sustained_freq_khz ||
248 !dom_info->sustained_perf_level)
249 /* CPUFreq converts to kHz, hence default 1000 */
250 dom_info->mult_factor = 1000;
252 dom_info->mult_factor =
253 (dom_info->sustained_freq_khz * 1000) /
254 dom_info->sustained_perf_level;
255 strscpy(dom_info->name, attr->name, SCMI_SHORT_NAME_MAX_SIZE);
258 ph->xops->xfer_put(ph, t);
261 * If supported overwrite short name with the extended one;
262 * on error just carry on and use already provided short name.
264 if (!ret && PROTOCOL_REV_MAJOR(version) >= 0x3 &&
265 SUPPORTS_EXTENDED_NAMES(flags))
266 ph->hops->extended_name_get(ph, PERF_DOMAIN_NAME_GET, domain,
267 dom_info->name, SCMI_MAX_STR_SIZE);
272 static int opp_cmp_func(const void *opp1, const void *opp2)
274 const struct scmi_opp *t1 = opp1, *t2 = opp2;
276 return t1->perf - t2->perf;
279 struct scmi_perf_ipriv {
281 struct perf_dom_info *perf_dom;
284 static void iter_perf_levels_prepare_message(void *message,
285 unsigned int desc_index,
288 struct scmi_msg_perf_describe_levels *msg = message;
289 const struct scmi_perf_ipriv *p = priv;
291 msg->domain = cpu_to_le32(p->domain);
292 /* Set the number of OPPs to be skipped/already read */
293 msg->level_index = cpu_to_le32(desc_index);
296 static int iter_perf_levels_update_state(struct scmi_iterator_state *st,
297 const void *response, void *priv)
299 const struct scmi_msg_resp_perf_describe_levels *r = response;
301 st->num_returned = le16_to_cpu(r->num_returned);
302 st->num_remaining = le16_to_cpu(r->num_remaining);
308 iter_perf_levels_process_response(const struct scmi_protocol_handle *ph,
309 const void *response,
310 struct scmi_iterator_state *st, void *priv)
312 struct scmi_opp *opp;
313 const struct scmi_msg_resp_perf_describe_levels *r = response;
314 struct scmi_perf_ipriv *p = priv;
316 opp = &p->perf_dom->opp[st->desc_index + st->loop_idx];
317 opp->perf = le32_to_cpu(r->opp[st->loop_idx].perf_val);
318 opp->power = le32_to_cpu(r->opp[st->loop_idx].power);
319 opp->trans_latency_us =
320 le16_to_cpu(r->opp[st->loop_idx].transition_latency_us);
321 p->perf_dom->opp_count++;
323 dev_dbg(ph->dev, "Level %d Power %d Latency %dus\n",
324 opp->perf, opp->power, opp->trans_latency_us);
330 scmi_perf_describe_levels_get(const struct scmi_protocol_handle *ph, u32 domain,
331 struct perf_dom_info *perf_dom)
335 struct scmi_iterator_ops ops = {
336 .prepare_message = iter_perf_levels_prepare_message,
337 .update_state = iter_perf_levels_update_state,
338 .process_response = iter_perf_levels_process_response,
340 struct scmi_perf_ipriv ppriv = {
342 .perf_dom = perf_dom,
345 iter = ph->hops->iter_response_init(ph, &ops, MAX_OPPS,
346 PERF_DESCRIBE_LEVELS,
347 sizeof(struct scmi_msg_perf_describe_levels),
350 return PTR_ERR(iter);
352 ret = ph->hops->iter_response_run(iter);
356 if (perf_dom->opp_count)
357 sort(perf_dom->opp, perf_dom->opp_count,
358 sizeof(struct scmi_opp), opp_cmp_func, NULL);
363 #define SCMI_PERF_FC_RING_DB(w) \
368 val = ioread##w(db->addr) & db->mask; \
369 iowrite##w((u##w)db->set | val, db->addr); \
372 static void scmi_perf_fc_ring_db(struct scmi_fc_db_info *db)
374 if (!db || !db->addr)
378 SCMI_PERF_FC_RING_DB(8);
379 else if (db->width == 2)
380 SCMI_PERF_FC_RING_DB(16);
381 else if (db->width == 4)
382 SCMI_PERF_FC_RING_DB(32);
383 else /* db->width == 8 */
385 SCMI_PERF_FC_RING_DB(64);
391 val = ioread64_hi_lo(db->addr) & db->mask;
392 iowrite64_hi_lo(db->set | val, db->addr);
397 static int scmi_perf_mb_limits_set(const struct scmi_protocol_handle *ph,
398 u32 domain, u32 max_perf, u32 min_perf)
402 struct scmi_perf_set_limits *limits;
404 ret = ph->xops->xfer_get_init(ph, PERF_LIMITS_SET,
405 sizeof(*limits), 0, &t);
410 limits->domain = cpu_to_le32(domain);
411 limits->max_level = cpu_to_le32(max_perf);
412 limits->min_level = cpu_to_le32(min_perf);
414 ret = ph->xops->do_xfer(ph, t);
416 ph->xops->xfer_put(ph, t);
420 static int scmi_perf_limits_set(const struct scmi_protocol_handle *ph,
421 u32 domain, u32 max_perf, u32 min_perf)
423 struct scmi_perf_info *pi = ph->get_priv(ph);
424 struct perf_dom_info *dom = pi->dom_info + domain;
426 if (PROTOCOL_REV_MAJOR(pi->version) >= 0x3 && !max_perf && !min_perf)
429 if (dom->fc_info && dom->fc_info->limit_set_addr) {
430 iowrite32(max_perf, dom->fc_info->limit_set_addr);
431 iowrite32(min_perf, dom->fc_info->limit_set_addr + 4);
432 scmi_perf_fc_ring_db(dom->fc_info->limit_set_db);
436 return scmi_perf_mb_limits_set(ph, domain, max_perf, min_perf);
439 static int scmi_perf_mb_limits_get(const struct scmi_protocol_handle *ph,
440 u32 domain, u32 *max_perf, u32 *min_perf)
444 struct scmi_perf_get_limits *limits;
446 ret = ph->xops->xfer_get_init(ph, PERF_LIMITS_GET,
447 sizeof(__le32), 0, &t);
451 put_unaligned_le32(domain, t->tx.buf);
453 ret = ph->xops->do_xfer(ph, t);
457 *max_perf = le32_to_cpu(limits->max_level);
458 *min_perf = le32_to_cpu(limits->min_level);
461 ph->xops->xfer_put(ph, t);
465 static int scmi_perf_limits_get(const struct scmi_protocol_handle *ph,
466 u32 domain, u32 *max_perf, u32 *min_perf)
468 struct scmi_perf_info *pi = ph->get_priv(ph);
469 struct perf_dom_info *dom = pi->dom_info + domain;
471 if (dom->fc_info && dom->fc_info->limit_get_addr) {
472 *max_perf = ioread32(dom->fc_info->limit_get_addr);
473 *min_perf = ioread32(dom->fc_info->limit_get_addr + 4);
477 return scmi_perf_mb_limits_get(ph, domain, max_perf, min_perf);
480 static int scmi_perf_mb_level_set(const struct scmi_protocol_handle *ph,
481 u32 domain, u32 level, bool poll)
485 struct scmi_perf_set_level *lvl;
487 ret = ph->xops->xfer_get_init(ph, PERF_LEVEL_SET, sizeof(*lvl), 0, &t);
491 t->hdr.poll_completion = poll;
493 lvl->domain = cpu_to_le32(domain);
494 lvl->level = cpu_to_le32(level);
496 ret = ph->xops->do_xfer(ph, t);
498 ph->xops->xfer_put(ph, t);
502 static int scmi_perf_level_set(const struct scmi_protocol_handle *ph,
503 u32 domain, u32 level, bool poll)
505 struct scmi_perf_info *pi = ph->get_priv(ph);
506 struct perf_dom_info *dom = pi->dom_info + domain;
508 if (dom->fc_info && dom->fc_info->level_set_addr) {
509 iowrite32(level, dom->fc_info->level_set_addr);
510 scmi_perf_fc_ring_db(dom->fc_info->level_set_db);
514 return scmi_perf_mb_level_set(ph, domain, level, poll);
517 static int scmi_perf_mb_level_get(const struct scmi_protocol_handle *ph,
518 u32 domain, u32 *level, bool poll)
523 ret = ph->xops->xfer_get_init(ph, PERF_LEVEL_GET,
524 sizeof(u32), sizeof(u32), &t);
528 t->hdr.poll_completion = poll;
529 put_unaligned_le32(domain, t->tx.buf);
531 ret = ph->xops->do_xfer(ph, t);
533 *level = get_unaligned_le32(t->rx.buf);
535 ph->xops->xfer_put(ph, t);
539 static int scmi_perf_level_get(const struct scmi_protocol_handle *ph,
540 u32 domain, u32 *level, bool poll)
542 struct scmi_perf_info *pi = ph->get_priv(ph);
543 struct perf_dom_info *dom = pi->dom_info + domain;
545 if (dom->fc_info && dom->fc_info->level_get_addr) {
546 *level = ioread32(dom->fc_info->level_get_addr);
550 return scmi_perf_mb_level_get(ph, domain, level, poll);
553 static int scmi_perf_level_limits_notify(const struct scmi_protocol_handle *ph,
554 u32 domain, int message_id,
559 struct scmi_perf_notify_level_or_limits *notify;
561 ret = ph->xops->xfer_get_init(ph, message_id, sizeof(*notify), 0, &t);
566 notify->domain = cpu_to_le32(domain);
567 notify->notify_enable = enable ? cpu_to_le32(BIT(0)) : 0;
569 ret = ph->xops->do_xfer(ph, t);
571 ph->xops->xfer_put(ph, t);
575 static bool scmi_perf_fc_size_is_valid(u32 msg, u32 size)
577 if ((msg == PERF_LEVEL_GET || msg == PERF_LEVEL_SET) && size == 4)
579 if ((msg == PERF_LIMITS_GET || msg == PERF_LIMITS_SET) && size == 8)
585 scmi_perf_domain_desc_fc(const struct scmi_protocol_handle *ph, u32 domain,
586 u32 message_id, void __iomem **p_addr,
587 struct scmi_fc_db_info **p_db)
595 struct scmi_fc_db_info *db;
596 struct scmi_perf_get_fc_info *info;
597 struct scmi_msg_resp_perf_desc_fc *resp;
602 ret = ph->xops->xfer_get_init(ph, PERF_DESCRIBE_FASTCHANNEL,
603 sizeof(*info), sizeof(*resp), &t);
608 info->domain = cpu_to_le32(domain);
609 info->message_id = cpu_to_le32(message_id);
611 ret = ph->xops->do_xfer(ph, t);
616 flags = le32_to_cpu(resp->attr);
617 size = le32_to_cpu(resp->chan_size);
618 if (!scmi_perf_fc_size_is_valid(message_id, size))
621 phys_addr = le32_to_cpu(resp->chan_addr_low);
622 phys_addr |= (u64)le32_to_cpu(resp->chan_addr_high) << 32;
623 addr = devm_ioremap(ph->dev, phys_addr, size);
628 if (p_db && SUPPORTS_DOORBELL(flags)) {
629 db = devm_kzalloc(ph->dev, sizeof(*db), GFP_KERNEL);
633 size = 1 << DOORBELL_REG_WIDTH(flags);
634 phys_addr = le32_to_cpu(resp->db_addr_low);
635 phys_addr |= (u64)le32_to_cpu(resp->db_addr_high) << 32;
636 addr = devm_ioremap(ph->dev, phys_addr, size);
642 db->set = le32_to_cpu(resp->db_set_lmask);
643 db->set |= (u64)le32_to_cpu(resp->db_set_hmask) << 32;
644 db->mask = le32_to_cpu(resp->db_preserve_lmask);
645 db->mask |= (u64)le32_to_cpu(resp->db_preserve_hmask) << 32;
649 ph->xops->xfer_put(ph, t);
652 static void scmi_perf_domain_init_fc(const struct scmi_protocol_handle *ph,
653 u32 domain, struct scmi_fc_info **p_fc)
655 struct scmi_fc_info *fc;
657 fc = devm_kzalloc(ph->dev, sizeof(*fc), GFP_KERNEL);
661 scmi_perf_domain_desc_fc(ph, domain, PERF_LEVEL_SET,
662 &fc->level_set_addr, &fc->level_set_db);
663 scmi_perf_domain_desc_fc(ph, domain, PERF_LEVEL_GET,
664 &fc->level_get_addr, NULL);
665 scmi_perf_domain_desc_fc(ph, domain, PERF_LIMITS_SET,
666 &fc->limit_set_addr, &fc->limit_set_db);
667 scmi_perf_domain_desc_fc(ph, domain, PERF_LIMITS_GET,
668 &fc->limit_get_addr, NULL);
672 /* Device specific ops */
673 static int scmi_dev_domain_id(struct device *dev)
675 struct of_phandle_args clkspec;
677 if (of_parse_phandle_with_args(dev->of_node, "clocks", "#clock-cells",
681 return clkspec.args[0];
684 static int scmi_dvfs_device_opps_add(const struct scmi_protocol_handle *ph,
687 int idx, ret, domain;
689 struct scmi_opp *opp;
690 struct perf_dom_info *dom;
691 struct scmi_perf_info *pi = ph->get_priv(ph);
693 domain = scmi_dev_domain_id(dev);
697 dom = pi->dom_info + domain;
699 for (opp = dom->opp, idx = 0; idx < dom->opp_count; idx++, opp++) {
700 freq = opp->perf * dom->mult_factor;
702 ret = dev_pm_opp_add(dev, freq, 0);
704 dev_warn(dev, "failed to add opp %luHz\n", freq);
707 freq = (--opp)->perf * dom->mult_factor;
708 dev_pm_opp_remove(dev, freq);
717 scmi_dvfs_transition_latency_get(const struct scmi_protocol_handle *ph,
720 struct perf_dom_info *dom;
721 struct scmi_perf_info *pi = ph->get_priv(ph);
722 int domain = scmi_dev_domain_id(dev);
727 dom = pi->dom_info + domain;
729 return dom->opp[dom->opp_count - 1].trans_latency_us * 1000;
732 static int scmi_dvfs_freq_set(const struct scmi_protocol_handle *ph, u32 domain,
733 unsigned long freq, bool poll)
735 struct scmi_perf_info *pi = ph->get_priv(ph);
736 struct perf_dom_info *dom = pi->dom_info + domain;
738 return scmi_perf_level_set(ph, domain, freq / dom->mult_factor, poll);
741 static int scmi_dvfs_freq_get(const struct scmi_protocol_handle *ph, u32 domain,
742 unsigned long *freq, bool poll)
746 struct scmi_perf_info *pi = ph->get_priv(ph);
747 struct perf_dom_info *dom = pi->dom_info + domain;
749 ret = scmi_perf_level_get(ph, domain, &level, poll);
751 *freq = level * dom->mult_factor;
756 static int scmi_dvfs_est_power_get(const struct scmi_protocol_handle *ph,
757 u32 domain, unsigned long *freq,
758 unsigned long *power)
760 struct scmi_perf_info *pi = ph->get_priv(ph);
761 struct perf_dom_info *dom;
762 unsigned long opp_freq;
763 int idx, ret = -EINVAL;
764 struct scmi_opp *opp;
766 dom = pi->dom_info + domain;
770 for (opp = dom->opp, idx = 0; idx < dom->opp_count; idx++, opp++) {
771 opp_freq = opp->perf * dom->mult_factor;
772 if (opp_freq < *freq)
784 static bool scmi_fast_switch_possible(const struct scmi_protocol_handle *ph,
787 struct perf_dom_info *dom;
788 struct scmi_perf_info *pi = ph->get_priv(ph);
790 dom = pi->dom_info + scmi_dev_domain_id(dev);
792 return dom->fc_info && dom->fc_info->level_set_addr;
795 static bool scmi_power_scale_mw_get(const struct scmi_protocol_handle *ph)
797 struct scmi_perf_info *pi = ph->get_priv(ph);
799 return pi->power_scale_mw;
802 static const struct scmi_perf_proto_ops perf_proto_ops = {
803 .limits_set = scmi_perf_limits_set,
804 .limits_get = scmi_perf_limits_get,
805 .level_set = scmi_perf_level_set,
806 .level_get = scmi_perf_level_get,
807 .device_domain_id = scmi_dev_domain_id,
808 .transition_latency_get = scmi_dvfs_transition_latency_get,
809 .device_opps_add = scmi_dvfs_device_opps_add,
810 .freq_set = scmi_dvfs_freq_set,
811 .freq_get = scmi_dvfs_freq_get,
812 .est_power_get = scmi_dvfs_est_power_get,
813 .fast_switch_possible = scmi_fast_switch_possible,
814 .power_scale_mw_get = scmi_power_scale_mw_get,
817 static int scmi_perf_set_notify_enabled(const struct scmi_protocol_handle *ph,
818 u8 evt_id, u32 src_id, bool enable)
822 if (evt_id >= ARRAY_SIZE(evt_2_cmd))
825 cmd_id = evt_2_cmd[evt_id];
826 ret = scmi_perf_level_limits_notify(ph, src_id, cmd_id, enable);
828 pr_debug("FAIL_ENABLED - evt[%X] dom[%d] - ret:%d\n",
829 evt_id, src_id, ret);
834 static void *scmi_perf_fill_custom_report(const struct scmi_protocol_handle *ph,
835 u8 evt_id, ktime_t timestamp,
836 const void *payld, size_t payld_sz,
837 void *report, u32 *src_id)
842 case SCMI_EVENT_PERFORMANCE_LIMITS_CHANGED:
844 const struct scmi_perf_limits_notify_payld *p = payld;
845 struct scmi_perf_limits_report *r = report;
847 if (sizeof(*p) != payld_sz)
850 r->timestamp = timestamp;
851 r->agent_id = le32_to_cpu(p->agent_id);
852 r->domain_id = le32_to_cpu(p->domain_id);
853 r->range_max = le32_to_cpu(p->range_max);
854 r->range_min = le32_to_cpu(p->range_min);
855 *src_id = r->domain_id;
859 case SCMI_EVENT_PERFORMANCE_LEVEL_CHANGED:
861 const struct scmi_perf_level_notify_payld *p = payld;
862 struct scmi_perf_level_report *r = report;
864 if (sizeof(*p) != payld_sz)
867 r->timestamp = timestamp;
868 r->agent_id = le32_to_cpu(p->agent_id);
869 r->domain_id = le32_to_cpu(p->domain_id);
870 r->performance_level = le32_to_cpu(p->performance_level);
871 *src_id = r->domain_id;
882 static int scmi_perf_get_num_sources(const struct scmi_protocol_handle *ph)
884 struct scmi_perf_info *pi = ph->get_priv(ph);
889 return pi->num_domains;
892 static const struct scmi_event perf_events[] = {
894 .id = SCMI_EVENT_PERFORMANCE_LIMITS_CHANGED,
895 .max_payld_sz = sizeof(struct scmi_perf_limits_notify_payld),
896 .max_report_sz = sizeof(struct scmi_perf_limits_report),
899 .id = SCMI_EVENT_PERFORMANCE_LEVEL_CHANGED,
900 .max_payld_sz = sizeof(struct scmi_perf_level_notify_payld),
901 .max_report_sz = sizeof(struct scmi_perf_level_report),
905 static const struct scmi_event_ops perf_event_ops = {
906 .get_num_sources = scmi_perf_get_num_sources,
907 .set_notify_enabled = scmi_perf_set_notify_enabled,
908 .fill_custom_report = scmi_perf_fill_custom_report,
911 static const struct scmi_protocol_events perf_protocol_events = {
912 .queue_sz = SCMI_PROTO_QUEUE_SZ,
913 .ops = &perf_event_ops,
915 .num_events = ARRAY_SIZE(perf_events),
918 static int scmi_perf_protocol_init(const struct scmi_protocol_handle *ph)
922 struct scmi_perf_info *pinfo;
924 ret = ph->xops->version_get(ph, &version);
928 dev_dbg(ph->dev, "Performance Version %d.%d\n",
929 PROTOCOL_REV_MAJOR(version), PROTOCOL_REV_MINOR(version));
931 pinfo = devm_kzalloc(ph->dev, sizeof(*pinfo), GFP_KERNEL);
935 ret = scmi_perf_attributes_get(ph, pinfo);
939 pinfo->dom_info = devm_kcalloc(ph->dev, pinfo->num_domains,
940 sizeof(*pinfo->dom_info), GFP_KERNEL);
941 if (!pinfo->dom_info)
944 for (domain = 0; domain < pinfo->num_domains; domain++) {
945 struct perf_dom_info *dom = pinfo->dom_info + domain;
947 scmi_perf_domain_attributes_get(ph, domain, dom, version);
948 scmi_perf_describe_levels_get(ph, domain, dom);
950 if (dom->perf_fastchannels)
951 scmi_perf_domain_init_fc(ph, domain, &dom->fc_info);
954 pinfo->version = version;
956 return ph->set_priv(ph, pinfo);
959 static const struct scmi_protocol scmi_perf = {
960 .id = SCMI_PROTOCOL_PERF,
961 .owner = THIS_MODULE,
962 .instance_init = &scmi_perf_protocol_init,
963 .ops = &perf_proto_ops,
964 .events = &perf_protocol_events,
967 DEFINE_SCMI_PROTOCOL_REGISTER_UNREGISTER(perf, scmi_perf)