hc
2024-05-10 cde9070d9970eef1f7ec2360586c802a16230ad8
kernel/drivers/firmware/arm_scmi/perf.c
....@@ -2,15 +2,23 @@
22 /*
33 * System Control and Management Interface (SCMI) Performance Protocol
44 *
5
- * Copyright (C) 2018 ARM Ltd.
5
+ * Copyright (C) 2018-2020 ARM Ltd.
66 */
77
8
+#define pr_fmt(fmt) "SCMI Notifications PERF - " fmt
9
+
10
+#include <linux/bits.h>
811 #include <linux/of.h>
12
+#include <linux/io.h>
13
+#include <linux/io-64-nonatomic-hi-lo.h>
14
+#include <linux/module.h>
915 #include <linux/platform_device.h>
1016 #include <linux/pm_opp.h>
17
+#include <linux/scmi_protocol.h>
1118 #include <linux/sort.h>
1219
1320 #include "common.h"
21
+#include "notify.h"
1422
1523 enum scmi_performance_protocol_cmd {
1624 PERF_DOMAIN_ATTRIBUTES = 0x3,
....@@ -21,6 +29,7 @@
2129 PERF_LEVEL_GET = 0x8,
2230 PERF_NOTIFY_LIMITS = 0x9,
2331 PERF_NOTIFY_LEVEL = 0xa,
32
+ PERF_DESCRIBE_FASTCHANNEL = 0xb,
2433 };
2534
2635 struct scmi_opp {
....@@ -44,6 +53,7 @@
4453 #define SUPPORTS_SET_PERF_LVL(x) ((x) & BIT(30))
4554 #define SUPPORTS_PERF_LIMIT_NOTIFY(x) ((x) & BIT(29))
4655 #define SUPPORTS_PERF_LEVEL_NOTIFY(x) ((x) & BIT(28))
56
+#define SUPPORTS_PERF_FASTCHANNELS(x) ((x) & BIT(27))
4757 __le32 rate_limit_us;
4858 __le32 sustained_freq_khz;
4959 __le32 sustained_perf_level;
....@@ -76,6 +86,19 @@
7686 __le32 notify_enable;
7787 };
7888
89
+struct scmi_perf_limits_notify_payld {
90
+ __le32 agent_id;
91
+ __le32 domain_id;
92
+ __le32 range_max;
93
+ __le32 range_min;
94
+};
95
+
96
+struct scmi_perf_level_notify_payld {
97
+ __le32 agent_id;
98
+ __le32 domain_id;
99
+ __le32 performance_level;
100
+};
101
+
79102 struct scmi_msg_resp_perf_describe_levels {
80103 __le16 num_returned;
81104 __le16 num_remaining;
....@@ -84,7 +107,44 @@
84107 __le32 power;
85108 __le16 transition_latency_us;
86109 __le16 reserved;
87
- } opp[0];
110
+ } opp[];
111
+};
112
+
113
+struct scmi_perf_get_fc_info {
114
+ __le32 domain;
115
+ __le32 message_id;
116
+};
117
+
118
+struct scmi_msg_resp_perf_desc_fc {
119
+ __le32 attr;
120
+#define SUPPORTS_DOORBELL(x) ((x) & BIT(0))
121
+#define DOORBELL_REG_WIDTH(x) FIELD_GET(GENMASK(2, 1), (x))
122
+ __le32 rate_limit;
123
+ __le32 chan_addr_low;
124
+ __le32 chan_addr_high;
125
+ __le32 chan_size;
126
+ __le32 db_addr_low;
127
+ __le32 db_addr_high;
128
+ __le32 db_set_lmask;
129
+ __le32 db_set_hmask;
130
+ __le32 db_preserve_lmask;
131
+ __le32 db_preserve_hmask;
132
+};
133
+
134
+struct scmi_fc_db_info {
135
+ int width;
136
+ u64 set;
137
+ u64 mask;
138
+ void __iomem *addr;
139
+};
140
+
141
+struct scmi_fc_info {
142
+ void __iomem *level_set_addr;
143
+ void __iomem *limit_set_addr;
144
+ void __iomem *level_get_addr;
145
+ void __iomem *limit_get_addr;
146
+ struct scmi_fc_db_info *level_set_db;
147
+ struct scmi_fc_db_info *limit_set_db;
88148 };
89149
90150 struct perf_dom_info {
....@@ -92,12 +152,14 @@
92152 bool set_perf;
93153 bool perf_limit_notify;
94154 bool perf_level_notify;
155
+ bool perf_fastchannels;
95156 u32 opp_count;
96157 u32 sustained_freq_khz;
97158 u32 sustained_perf_level;
98159 u32 mult_factor;
99160 char name[SCMI_MAX_STR_SIZE];
100161 struct scmi_opp opp[MAX_OPPS];
162
+ struct scmi_fc_info *fc_info;
101163 };
102164
103165 struct scmi_perf_info {
....@@ -109,21 +171,26 @@
109171 struct perf_dom_info *dom_info;
110172 };
111173
112
-static int scmi_perf_attributes_get(const struct scmi_handle *handle,
174
+static enum scmi_performance_protocol_cmd evt_2_cmd[] = {
175
+ PERF_NOTIFY_LIMITS,
176
+ PERF_NOTIFY_LEVEL,
177
+};
178
+
179
+static int scmi_perf_attributes_get(const struct scmi_protocol_handle *ph,
113180 struct scmi_perf_info *pi)
114181 {
115182 int ret;
116183 struct scmi_xfer *t;
117184 struct scmi_msg_resp_perf_attributes *attr;
118185
119
- ret = scmi_xfer_get_init(handle, PROTOCOL_ATTRIBUTES,
120
- SCMI_PROTOCOL_PERF, 0, sizeof(*attr), &t);
186
+ ret = ph->xops->xfer_get_init(ph, PROTOCOL_ATTRIBUTES, 0,
187
+ sizeof(*attr), &t);
121188 if (ret)
122189 return ret;
123190
124191 attr = t->rx.buf;
125192
126
- ret = scmi_do_xfer(handle, t);
193
+ ret = ph->xops->do_xfer(ph, t);
127194 if (!ret) {
128195 u16 flags = le16_to_cpu(attr->flags);
129196
....@@ -134,28 +201,27 @@
134201 pi->stats_size = le32_to_cpu(attr->stats_size);
135202 }
136203
137
- scmi_xfer_put(handle, t);
204
+ ph->xops->xfer_put(ph, t);
138205 return ret;
139206 }
140207
141208 static int
142
-scmi_perf_domain_attributes_get(const struct scmi_handle *handle, u32 domain,
143
- struct perf_dom_info *dom_info)
209
+scmi_perf_domain_attributes_get(const struct scmi_protocol_handle *ph,
210
+ u32 domain, struct perf_dom_info *dom_info)
144211 {
145212 int ret;
146213 struct scmi_xfer *t;
147214 struct scmi_msg_resp_perf_domain_attributes *attr;
148215
149
- ret = scmi_xfer_get_init(handle, PERF_DOMAIN_ATTRIBUTES,
150
- SCMI_PROTOCOL_PERF, sizeof(domain),
151
- sizeof(*attr), &t);
216
+ ret = ph->xops->xfer_get_init(ph, PERF_DOMAIN_ATTRIBUTES,
217
+ sizeof(domain), sizeof(*attr), &t);
152218 if (ret)
153219 return ret;
154220
155221 put_unaligned_le32(domain, t->tx.buf);
156222 attr = t->rx.buf;
157223
158
- ret = scmi_do_xfer(handle, t);
224
+ ret = ph->xops->do_xfer(ph, t);
159225 if (!ret) {
160226 u32 flags = le32_to_cpu(attr->flags);
161227
....@@ -163,6 +229,7 @@
163229 dom_info->set_perf = SUPPORTS_SET_PERF_LVL(flags);
164230 dom_info->perf_limit_notify = SUPPORTS_PERF_LIMIT_NOTIFY(flags);
165231 dom_info->perf_level_notify = SUPPORTS_PERF_LEVEL_NOTIFY(flags);
232
+ dom_info->perf_fastchannels = SUPPORTS_PERF_FASTCHANNELS(flags);
166233 dom_info->sustained_freq_khz =
167234 le32_to_cpu(attr->sustained_freq_khz);
168235 dom_info->sustained_perf_level =
....@@ -178,7 +245,7 @@
178245 strlcpy(dom_info->name, attr->name, SCMI_MAX_STR_SIZE);
179246 }
180247
181
- scmi_xfer_put(handle, t);
248
+ ph->xops->xfer_put(ph, t);
182249 return ret;
183250 }
184251
....@@ -190,7 +257,7 @@
190257 }
191258
192259 static int
193
-scmi_perf_describe_levels_get(const struct scmi_handle *handle, u32 domain,
260
+scmi_perf_describe_levels_get(const struct scmi_protocol_handle *ph, u32 domain,
194261 struct perf_dom_info *perf_dom)
195262 {
196263 int ret, cnt;
....@@ -201,8 +268,8 @@
201268 struct scmi_msg_perf_describe_levels *dom_info;
202269 struct scmi_msg_resp_perf_describe_levels *level_info;
203270
204
- ret = scmi_xfer_get_init(handle, PERF_DESCRIBE_LEVELS,
205
- SCMI_PROTOCOL_PERF, sizeof(*dom_info), 0, &t);
271
+ ret = ph->xops->xfer_get_init(ph, PERF_DESCRIBE_LEVELS,
272
+ sizeof(*dom_info), 0, &t);
206273 if (ret)
207274 return ret;
208275
....@@ -214,14 +281,14 @@
214281 /* Set the number of OPPs to be skipped/already read */
215282 dom_info->level_index = cpu_to_le32(tot_opp_cnt);
216283
217
- ret = scmi_do_xfer(handle, t);
284
+ ret = ph->xops->do_xfer(ph, t);
218285 if (ret)
219286 break;
220287
221288 num_returned = le16_to_cpu(level_info->num_returned);
222289 num_remaining = le16_to_cpu(level_info->num_remaining);
223290 if (tot_opp_cnt + num_returned > MAX_OPPS) {
224
- dev_err(handle->dev, "No. of OPPs exceeded MAX_OPPS");
291
+ dev_err(ph->dev, "No. of OPPs exceeded MAX_OPPS");
225292 break;
226293 }
227294
....@@ -232,11 +299,13 @@
232299 opp->trans_latency_us = le16_to_cpu
233300 (level_info->opp[cnt].transition_latency_us);
234301
235
- dev_dbg(handle->dev, "Level %d Power %d Latency %dus\n",
302
+ dev_dbg(ph->dev, "Level %d Power %d Latency %dus\n",
236303 opp->perf, opp->power, opp->trans_latency_us);
237304 }
238305
239306 tot_opp_cnt += num_returned;
307
+
308
+ ph->xops->reset_rx_to_maxsz(ph, t);
240309 /*
241310 * check for both returned and remaining to avoid infinite
242311 * loop due to buggy firmware
....@@ -244,21 +313,55 @@
244313 } while (num_returned && num_remaining);
245314
246315 perf_dom->opp_count = tot_opp_cnt;
247
- scmi_xfer_put(handle, t);
316
+ ph->xops->xfer_put(ph, t);
248317
249318 sort(perf_dom->opp, tot_opp_cnt, sizeof(*opp), opp_cmp_func, NULL);
250319 return ret;
251320 }
252321
253
-static int scmi_perf_limits_set(const struct scmi_handle *handle, u32 domain,
254
- u32 max_perf, u32 min_perf)
322
+#define SCMI_PERF_FC_RING_DB(w) \
323
+do { \
324
+ u##w val = 0; \
325
+ \
326
+ if (db->mask) \
327
+ val = ioread##w(db->addr) & db->mask; \
328
+ iowrite##w((u##w)db->set | val, db->addr); \
329
+} while (0)
330
+
331
+static void scmi_perf_fc_ring_db(struct scmi_fc_db_info *db)
332
+{
333
+ if (!db || !db->addr)
334
+ return;
335
+
336
+ if (db->width == 1)
337
+ SCMI_PERF_FC_RING_DB(8);
338
+ else if (db->width == 2)
339
+ SCMI_PERF_FC_RING_DB(16);
340
+ else if (db->width == 4)
341
+ SCMI_PERF_FC_RING_DB(32);
342
+ else /* db->width == 8 */
343
+#ifdef CONFIG_64BIT
344
+ SCMI_PERF_FC_RING_DB(64);
345
+#else
346
+ {
347
+ u64 val = 0;
348
+
349
+ if (db->mask)
350
+ val = ioread64_hi_lo(db->addr) & db->mask;
351
+ iowrite64_hi_lo(db->set | val, db->addr);
352
+ }
353
+#endif
354
+}
355
+
356
+static int scmi_perf_mb_limits_set(const struct scmi_protocol_handle *ph,
357
+ u32 domain, u32 max_perf, u32 min_perf)
255358 {
256359 int ret;
257360 struct scmi_xfer *t;
258361 struct scmi_perf_set_limits *limits;
259362
260
- ret = scmi_xfer_get_init(handle, PERF_LIMITS_SET, SCMI_PROTOCOL_PERF,
261
- sizeof(*limits), 0, &t);
363
+ ret = ph->xops->xfer_get_init(ph, PERF_LIMITS_SET,
364
+ sizeof(*limits), 0, &t);
262365 if (ret)
263366 return ret;
264367
....@@ -267,27 +370,43 @@
267370 limits->max_level = cpu_to_le32(max_perf);
268371 limits->min_level = cpu_to_le32(min_perf);
269372
270
- ret = scmi_do_xfer(handle, t);
373
+ ret = ph->xops->do_xfer(ph, t);
271374
272
- scmi_xfer_put(handle, t);
375
+ ph->xops->xfer_put(ph, t);
273376 return ret;
274377 }
275378
276
-static int scmi_perf_limits_get(const struct scmi_handle *handle, u32 domain,
277
- u32 *max_perf, u32 *min_perf)
379
+static int scmi_perf_limits_set(const struct scmi_protocol_handle *ph,
380
+ u32 domain, u32 max_perf, u32 min_perf)
381
+{
382
+ struct scmi_perf_info *pi = ph->get_priv(ph);
383
+ struct perf_dom_info *dom = pi->dom_info + domain;
384
+
385
+ if (dom->fc_info && dom->fc_info->limit_set_addr) {
386
+ iowrite32(max_perf, dom->fc_info->limit_set_addr);
387
+ iowrite32(min_perf, dom->fc_info->limit_set_addr + 4);
388
+ scmi_perf_fc_ring_db(dom->fc_info->limit_set_db);
389
+ return 0;
390
+ }
391
+
392
+ return scmi_perf_mb_limits_set(ph, domain, max_perf, min_perf);
393
+}
394
+
395
+static int scmi_perf_mb_limits_get(const struct scmi_protocol_handle *ph,
396
+ u32 domain, u32 *max_perf, u32 *min_perf)
278397 {
279398 int ret;
280399 struct scmi_xfer *t;
281400 struct scmi_perf_get_limits *limits;
282401
283
- ret = scmi_xfer_get_init(handle, PERF_LIMITS_GET, SCMI_PROTOCOL_PERF,
284
- sizeof(__le32), 0, &t);
402
+ ret = ph->xops->xfer_get_init(ph, PERF_LIMITS_GET,
403
+ sizeof(__le32), 0, &t);
285404 if (ret)
286405 return ret;
287406
288407 put_unaligned_le32(domain, t->tx.buf);
289408
290
- ret = scmi_do_xfer(handle, t);
409
+ ret = ph->xops->do_xfer(ph, t);
291410 if (!ret) {
292411 limits = t->rx.buf;
293412
....@@ -295,19 +414,33 @@
295414 *min_perf = le32_to_cpu(limits->min_level);
296415 }
297416
298
- scmi_xfer_put(handle, t);
417
+ ph->xops->xfer_put(ph, t);
299418 return ret;
300419 }
301420
302
-static int scmi_perf_level_set(const struct scmi_handle *handle, u32 domain,
303
- u32 level, bool poll)
421
+static int scmi_perf_limits_get(const struct scmi_protocol_handle *ph,
422
+ u32 domain, u32 *max_perf, u32 *min_perf)
423
+{
424
+ struct scmi_perf_info *pi = ph->get_priv(ph);
425
+ struct perf_dom_info *dom = pi->dom_info + domain;
426
+
427
+ if (dom->fc_info && dom->fc_info->limit_get_addr) {
428
+ *max_perf = ioread32(dom->fc_info->limit_get_addr);
429
+ *min_perf = ioread32(dom->fc_info->limit_get_addr + 4);
430
+ return 0;
431
+ }
432
+
433
+ return scmi_perf_mb_limits_get(ph, domain, max_perf, min_perf);
434
+}
435
+
436
+static int scmi_perf_mb_level_set(const struct scmi_protocol_handle *ph,
437
+ u32 domain, u32 level, bool poll)
304438 {
305439 int ret;
306440 struct scmi_xfer *t;
307441 struct scmi_perf_set_level *lvl;
308442
309
- ret = scmi_xfer_get_init(handle, PERF_LEVEL_SET, SCMI_PROTOCOL_PERF,
310
- sizeof(*lvl), 0, &t);
443
+ ret = ph->xops->xfer_get_init(ph, PERF_LEVEL_SET, sizeof(*lvl), 0, &t);
311444 if (ret)
312445 return ret;
313446
....@@ -316,32 +449,180 @@
316449 lvl->domain = cpu_to_le32(domain);
317450 lvl->level = cpu_to_le32(level);
318451
319
- ret = scmi_do_xfer(handle, t);
452
+ ret = ph->xops->do_xfer(ph, t);
320453
321
- scmi_xfer_put(handle, t);
454
+ ph->xops->xfer_put(ph, t);
322455 return ret;
323456 }
324457
325
-static int scmi_perf_level_get(const struct scmi_handle *handle, u32 domain,
326
- u32 *level, bool poll)
458
+static int scmi_perf_level_set(const struct scmi_protocol_handle *ph,
459
+ u32 domain, u32 level, bool poll)
460
+{
461
+ struct scmi_perf_info *pi = ph->get_priv(ph);
462
+ struct perf_dom_info *dom = pi->dom_info + domain;
463
+
464
+ if (dom->fc_info && dom->fc_info->level_set_addr) {
465
+ iowrite32(level, dom->fc_info->level_set_addr);
466
+ scmi_perf_fc_ring_db(dom->fc_info->level_set_db);
467
+ return 0;
468
+ }
469
+
470
+ return scmi_perf_mb_level_set(ph, domain, level, poll);
471
+}
472
+
473
+static int scmi_perf_mb_level_get(const struct scmi_protocol_handle *ph,
474
+ u32 domain, u32 *level, bool poll)
327475 {
328476 int ret;
329477 struct scmi_xfer *t;
330478
331
- ret = scmi_xfer_get_init(handle, PERF_LEVEL_GET, SCMI_PROTOCOL_PERF,
332
- sizeof(u32), sizeof(u32), &t);
479
+ ret = ph->xops->xfer_get_init(ph, PERF_LEVEL_GET,
480
+ sizeof(u32), sizeof(u32), &t);
333481 if (ret)
334482 return ret;
335483
336484 t->hdr.poll_completion = poll;
337485 put_unaligned_le32(domain, t->tx.buf);
338486
339
- ret = scmi_do_xfer(handle, t);
487
+ ret = ph->xops->do_xfer(ph, t);
340488 if (!ret)
341489 *level = get_unaligned_le32(t->rx.buf);
342490
343
- scmi_xfer_put(handle, t);
491
+ ph->xops->xfer_put(ph, t);
344492 return ret;
493
+}
494
+
495
+static int scmi_perf_level_get(const struct scmi_protocol_handle *ph,
496
+ u32 domain, u32 *level, bool poll)
497
+{
498
+ struct scmi_perf_info *pi = ph->get_priv(ph);
499
+ struct perf_dom_info *dom = pi->dom_info + domain;
500
+
501
+ if (dom->fc_info && dom->fc_info->level_get_addr) {
502
+ *level = ioread32(dom->fc_info->level_get_addr);
503
+ return 0;
504
+ }
505
+
506
+ return scmi_perf_mb_level_get(ph, domain, level, poll);
507
+}
508
+
509
+static int scmi_perf_level_limits_notify(const struct scmi_protocol_handle *ph,
510
+ u32 domain, int message_id,
511
+ bool enable)
512
+{
513
+ int ret;
514
+ struct scmi_xfer *t;
515
+ struct scmi_perf_notify_level_or_limits *notify;
516
+
517
+ ret = ph->xops->xfer_get_init(ph, message_id, sizeof(*notify), 0, &t);
518
+ if (ret)
519
+ return ret;
520
+
521
+ notify = t->tx.buf;
522
+ notify->domain = cpu_to_le32(domain);
523
+ notify->notify_enable = enable ? cpu_to_le32(BIT(0)) : 0;
524
+
525
+ ret = ph->xops->do_xfer(ph, t);
526
+
527
+ ph->xops->xfer_put(ph, t);
528
+ return ret;
529
+}
530
+
531
+static bool scmi_perf_fc_size_is_valid(u32 msg, u32 size)
532
+{
533
+ if ((msg == PERF_LEVEL_GET || msg == PERF_LEVEL_SET) && size == 4)
534
+ return true;
535
+ if ((msg == PERF_LIMITS_GET || msg == PERF_LIMITS_SET) && size == 8)
536
+ return true;
537
+ return false;
538
+}
539
+
540
+static void
541
+scmi_perf_domain_desc_fc(const struct scmi_protocol_handle *ph, u32 domain,
542
+ u32 message_id, void __iomem **p_addr,
543
+ struct scmi_fc_db_info **p_db)
544
+{
545
+ int ret;
546
+ u32 flags;
547
+ u64 phys_addr;
548
+ u8 size;
549
+ void __iomem *addr;
550
+ struct scmi_xfer *t;
551
+ struct scmi_fc_db_info *db;
552
+ struct scmi_perf_get_fc_info *info;
553
+ struct scmi_msg_resp_perf_desc_fc *resp;
554
+
555
+ if (!p_addr)
556
+ return;
557
+
558
+ ret = ph->xops->xfer_get_init(ph, PERF_DESCRIBE_FASTCHANNEL,
559
+ sizeof(*info), sizeof(*resp), &t);
560
+ if (ret)
561
+ return;
562
+
563
+ info = t->tx.buf;
564
+ info->domain = cpu_to_le32(domain);
565
+ info->message_id = cpu_to_le32(message_id);
566
+
567
+ ret = ph->xops->do_xfer(ph, t);
568
+ if (ret)
569
+ goto err_xfer;
570
+
571
+ resp = t->rx.buf;
572
+ flags = le32_to_cpu(resp->attr);
573
+ size = le32_to_cpu(resp->chan_size);
574
+ if (!scmi_perf_fc_size_is_valid(message_id, size))
575
+ goto err_xfer;
576
+
577
+ phys_addr = le32_to_cpu(resp->chan_addr_low);
578
+ phys_addr |= (u64)le32_to_cpu(resp->chan_addr_high) << 32;
579
+ addr = devm_ioremap(ph->dev, phys_addr, size);
580
+ if (!addr)
581
+ goto err_xfer;
582
+ *p_addr = addr;
583
+
584
+ if (p_db && SUPPORTS_DOORBELL(flags)) {
585
+ db = devm_kzalloc(ph->dev, sizeof(*db), GFP_KERNEL);
586
+ if (!db)
587
+ goto err_xfer;
588
+
589
+ size = 1 << DOORBELL_REG_WIDTH(flags);
590
+ phys_addr = le32_to_cpu(resp->db_addr_low);
591
+ phys_addr |= (u64)le32_to_cpu(resp->db_addr_high) << 32;
592
+ addr = devm_ioremap(ph->dev, phys_addr, size);
593
+ if (!addr)
594
+ goto err_xfer;
595
+
596
+ db->addr = addr;
597
+ db->width = size;
598
+ db->set = le32_to_cpu(resp->db_set_lmask);
599
+ db->set |= (u64)le32_to_cpu(resp->db_set_hmask) << 32;
600
+ db->mask = le32_to_cpu(resp->db_preserve_lmask);
601
+ db->mask |= (u64)le32_to_cpu(resp->db_preserve_hmask) << 32;
602
+ *p_db = db;
603
+ }
604
+err_xfer:
605
+ ph->xops->xfer_put(ph, t);
606
+}
607
+
608
+static void scmi_perf_domain_init_fc(const struct scmi_protocol_handle *ph,
609
+ u32 domain, struct scmi_fc_info **p_fc)
610
+{
611
+ struct scmi_fc_info *fc;
612
+
613
+ fc = devm_kzalloc(ph->dev, sizeof(*fc), GFP_KERNEL);
614
+ if (!fc)
615
+ return;
616
+
617
+ scmi_perf_domain_desc_fc(ph, domain, PERF_LEVEL_SET,
618
+ &fc->level_set_addr, &fc->level_set_db);
619
+ scmi_perf_domain_desc_fc(ph, domain, PERF_LEVEL_GET,
620
+ &fc->level_get_addr, NULL);
621
+ scmi_perf_domain_desc_fc(ph, domain, PERF_LIMITS_SET,
622
+ &fc->limit_set_addr, &fc->limit_set_db);
623
+ scmi_perf_domain_desc_fc(ph, domain, PERF_LIMITS_GET,
624
+ &fc->limit_get_addr, NULL);
625
+ *p_fc = fc;
345626 }
346627
347628 /* Device specific ops */
....@@ -356,14 +637,14 @@
356637 return clkspec.args[0];
357638 }
358639
359
-static int scmi_dvfs_device_opps_add(const struct scmi_handle *handle,
640
+static int scmi_dvfs_device_opps_add(const struct scmi_protocol_handle *ph,
360641 struct device *dev)
361642 {
362643 int idx, ret, domain;
363644 unsigned long freq;
364645 struct scmi_opp *opp;
365646 struct perf_dom_info *dom;
366
- struct scmi_perf_info *pi = handle->perf_priv;
647
+ struct scmi_perf_info *pi = ph->get_priv(ph);
367648
368649 domain = scmi_dev_domain_id(dev);
369650 if (domain < 0)
....@@ -388,11 +669,12 @@
388669 return 0;
389670 }
390671
391
-static int scmi_dvfs_transition_latency_get(const struct scmi_handle *handle,
392
- struct device *dev)
672
+static int
673
+scmi_dvfs_transition_latency_get(const struct scmi_protocol_handle *ph,
674
+ struct device *dev)
393675 {
394676 struct perf_dom_info *dom;
395
- struct scmi_perf_info *pi = handle->perf_priv;
677
+ struct scmi_perf_info *pi = ph->get_priv(ph);
396678 int domain = scmi_dev_domain_id(dev);
397679
398680 if (domain < 0)
....@@ -403,35 +685,35 @@
403685 return dom->opp[dom->opp_count - 1].trans_latency_us * 1000;
404686 }
405687
406
-static int scmi_dvfs_freq_set(const struct scmi_handle *handle, u32 domain,
688
+static int scmi_dvfs_freq_set(const struct scmi_protocol_handle *ph, u32 domain,
407689 unsigned long freq, bool poll)
408690 {
409
- struct scmi_perf_info *pi = handle->perf_priv;
691
+ struct scmi_perf_info *pi = ph->get_priv(ph);
410692 struct perf_dom_info *dom = pi->dom_info + domain;
411693
412
- return scmi_perf_level_set(handle, domain, freq / dom->mult_factor,
413
- poll);
694
+ return scmi_perf_level_set(ph, domain, freq / dom->mult_factor, poll);
414695 }
415696
416
-static int scmi_dvfs_freq_get(const struct scmi_handle *handle, u32 domain,
697
+static int scmi_dvfs_freq_get(const struct scmi_protocol_handle *ph, u32 domain,
417698 unsigned long *freq, bool poll)
418699 {
419700 int ret;
420701 u32 level;
421
- struct scmi_perf_info *pi = handle->perf_priv;
702
+ struct scmi_perf_info *pi = ph->get_priv(ph);
422703 struct perf_dom_info *dom = pi->dom_info + domain;
423704
424
- ret = scmi_perf_level_get(handle, domain, &level, poll);
705
+ ret = scmi_perf_level_get(ph, domain, &level, poll);
425706 if (!ret)
426707 *freq = level * dom->mult_factor;
427708
428709 return ret;
429710 }
430711
431
-static int scmi_dvfs_est_power_get(const struct scmi_handle *handle, u32 domain,
432
- unsigned long *freq, unsigned long *power)
712
+static int scmi_dvfs_est_power_get(const struct scmi_protocol_handle *ph,
713
+ u32 domain, unsigned long *freq,
714
+ unsigned long *power)
433715 {
434
- struct scmi_perf_info *pi = handle->perf_priv;
716
+ struct scmi_perf_info *pi = ph->get_priv(ph);
435717 struct perf_dom_info *dom;
436718 unsigned long opp_freq;
437719 int idx, ret = -EINVAL;
....@@ -455,7 +737,25 @@
455737 return ret;
456738 }
457739
458
-static struct scmi_perf_ops perf_ops = {
740
+static bool scmi_fast_switch_possible(const struct scmi_protocol_handle *ph,
741
+ struct device *dev)
742
+{
743
+ struct perf_dom_info *dom;
744
+ struct scmi_perf_info *pi = ph->get_priv(ph);
745
+
746
+ dom = pi->dom_info + scmi_dev_domain_id(dev);
747
+
748
+ return dom->fc_info && dom->fc_info->level_set_addr;
749
+}
750
+
751
+static bool scmi_power_scale_mw_get(const struct scmi_protocol_handle *ph)
752
+{
753
+ struct scmi_perf_info *pi = ph->get_priv(ph);
754
+
755
+ return pi->power_scale_mw;
756
+}
757
+
758
+static const struct scmi_perf_proto_ops perf_proto_ops = {
459759 .limits_set = scmi_perf_limits_set,
460760 .limits_get = scmi_perf_limits_get,
461761 .level_set = scmi_perf_level_set,
....@@ -466,26 +766,129 @@
466766 .freq_set = scmi_dvfs_freq_set,
467767 .freq_get = scmi_dvfs_freq_get,
468768 .est_power_get = scmi_dvfs_est_power_get,
769
+ .fast_switch_possible = scmi_fast_switch_possible,
770
+ .power_scale_mw_get = scmi_power_scale_mw_get,
469771 };
470772
471
-static int scmi_perf_protocol_init(struct scmi_handle *handle)
773
+static int scmi_perf_set_notify_enabled(const struct scmi_protocol_handle *ph,
774
+ u8 evt_id, u32 src_id, bool enable)
775
+{
776
+ int ret, cmd_id;
777
+
778
+ if (evt_id >= ARRAY_SIZE(evt_2_cmd))
779
+ return -EINVAL;
780
+
781
+ cmd_id = evt_2_cmd[evt_id];
782
+ ret = scmi_perf_level_limits_notify(ph, src_id, cmd_id, enable);
783
+ if (ret)
784
+ pr_debug("FAIL_ENABLED - evt[%X] dom[%d] - ret:%d\n",
785
+ evt_id, src_id, ret);
786
+
787
+ return ret;
788
+}
789
+
790
+static void *scmi_perf_fill_custom_report(const struct scmi_protocol_handle *ph,
791
+ u8 evt_id, ktime_t timestamp,
792
+ const void *payld, size_t payld_sz,
793
+ void *report, u32 *src_id)
794
+{
795
+ void *rep = NULL;
796
+
797
+ switch (evt_id) {
798
+ case SCMI_EVENT_PERFORMANCE_LIMITS_CHANGED:
799
+ {
800
+ const struct scmi_perf_limits_notify_payld *p = payld;
801
+ struct scmi_perf_limits_report *r = report;
802
+
803
+ if (sizeof(*p) != payld_sz)
804
+ break;
805
+
806
+ r->timestamp = timestamp;
807
+ r->agent_id = le32_to_cpu(p->agent_id);
808
+ r->domain_id = le32_to_cpu(p->domain_id);
809
+ r->range_max = le32_to_cpu(p->range_max);
810
+ r->range_min = le32_to_cpu(p->range_min);
811
+ *src_id = r->domain_id;
812
+ rep = r;
813
+ break;
814
+ }
815
+ case SCMI_EVENT_PERFORMANCE_LEVEL_CHANGED:
816
+ {
817
+ const struct scmi_perf_level_notify_payld *p = payld;
818
+ struct scmi_perf_level_report *r = report;
819
+
820
+ if (sizeof(*p) != payld_sz)
821
+ break;
822
+
823
+ r->timestamp = timestamp;
824
+ r->agent_id = le32_to_cpu(p->agent_id);
825
+ r->domain_id = le32_to_cpu(p->domain_id);
826
+ r->performance_level = le32_to_cpu(p->performance_level);
827
+ *src_id = r->domain_id;
828
+ rep = r;
829
+ break;
830
+ }
831
+ default:
832
+ break;
833
+ }
834
+
835
+ return rep;
836
+}
837
+
838
+static int scmi_perf_get_num_sources(const struct scmi_protocol_handle *ph)
839
+{
840
+ struct scmi_perf_info *pi = ph->get_priv(ph);
841
+
842
+ if (!pi)
843
+ return -EINVAL;
844
+
845
+ return pi->num_domains;
846
+}
847
+
848
+static const struct scmi_event perf_events[] = {
849
+ {
850
+ .id = SCMI_EVENT_PERFORMANCE_LIMITS_CHANGED,
851
+ .max_payld_sz = sizeof(struct scmi_perf_limits_notify_payld),
852
+ .max_report_sz = sizeof(struct scmi_perf_limits_report),
853
+ },
854
+ {
855
+ .id = SCMI_EVENT_PERFORMANCE_LEVEL_CHANGED,
856
+ .max_payld_sz = sizeof(struct scmi_perf_level_notify_payld),
857
+ .max_report_sz = sizeof(struct scmi_perf_level_report),
858
+ },
859
+};
860
+
861
+static const struct scmi_event_ops perf_event_ops = {
862
+ .get_num_sources = scmi_perf_get_num_sources,
863
+ .set_notify_enabled = scmi_perf_set_notify_enabled,
864
+ .fill_custom_report = scmi_perf_fill_custom_report,
865
+};
866
+
867
+static const struct scmi_protocol_events perf_protocol_events = {
868
+ .queue_sz = SCMI_PROTO_QUEUE_SZ,
869
+ .ops = &perf_event_ops,
870
+ .evts = perf_events,
871
+ .num_events = ARRAY_SIZE(perf_events),
872
+};
873
+
874
+static int scmi_perf_protocol_init(const struct scmi_protocol_handle *ph)
472875 {
473876 int domain;
474877 u32 version;
475878 struct scmi_perf_info *pinfo;
476879
477
- scmi_version_get(handle, SCMI_PROTOCOL_PERF, &version);
880
+ ph->xops->version_get(ph, &version);
478881
479
- dev_dbg(handle->dev, "Performance Version %d.%d\n",
882
+ dev_dbg(ph->dev, "Performance Version %d.%d\n",
480883 PROTOCOL_REV_MAJOR(version), PROTOCOL_REV_MINOR(version));
481884
482
- pinfo = devm_kzalloc(handle->dev, sizeof(*pinfo), GFP_KERNEL);
885
+ pinfo = devm_kzalloc(ph->dev, sizeof(*pinfo), GFP_KERNEL);
483886 if (!pinfo)
484887 return -ENOMEM;
485888
486
- scmi_perf_attributes_get(handle, pinfo);
889
+ scmi_perf_attributes_get(ph, pinfo);
487890
488
- pinfo->dom_info = devm_kcalloc(handle->dev, pinfo->num_domains,
891
+ pinfo->dom_info = devm_kcalloc(ph->dev, pinfo->num_domains,
489892 sizeof(*pinfo->dom_info), GFP_KERNEL);
490893 if (!pinfo->dom_info)
491894 return -ENOMEM;
....@@ -493,15 +896,24 @@
493896 for (domain = 0; domain < pinfo->num_domains; domain++) {
494897 struct perf_dom_info *dom = pinfo->dom_info + domain;
495898
496
- scmi_perf_domain_attributes_get(handle, domain, dom);
497
- scmi_perf_describe_levels_get(handle, domain, dom);
899
+ scmi_perf_domain_attributes_get(ph, domain, dom);
900
+ scmi_perf_describe_levels_get(ph, domain, dom);
901
+
902
+ if (dom->perf_fastchannels)
903
+ scmi_perf_domain_init_fc(ph, domain, &dom->fc_info);
498904 }
499905
500906 pinfo->version = version;
501
- handle->perf_ops = &perf_ops;
502
- handle->perf_priv = pinfo;
503907
504
- return 0;
908
+ return ph->set_priv(ph, pinfo);
505909 }
506910
507
-DEFINE_SCMI_PROTOCOL_REGISTER_UNREGISTER(SCMI_PROTOCOL_PERF, perf)
911
+static const struct scmi_protocol scmi_perf = {
912
+ .id = SCMI_PROTOCOL_PERF,
913
+ .owner = THIS_MODULE,
914
+ .init_instance = &scmi_perf_protocol_init,
915
+ .ops = &perf_proto_ops,
916
+ .events = &perf_protocol_events,
917
+};
918
+
919
+DEFINE_SCMI_PROTOCOL_REGISTER_UNREGISTER(perf, scmi_perf)