1
2
3
4
5
6
7
8#ifndef _LINUX_SCMI_PROTOCOL_H
9#define _LINUX_SCMI_PROTOCOL_H
10
11#include <linux/bitfield.h>
12#include <linux/device.h>
13#include <linux/notifier.h>
14#include <linux/types.h>
15
16#define SCMI_MAX_STR_SIZE 64
17#define SCMI_SHORT_NAME_MAX_SIZE 16
18#define SCMI_MAX_NUM_RATES 16
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34struct scmi_revision_info {
35 u16 major_ver;
36 u16 minor_ver;
37 u8 num_protocols;
38 u8 num_agents;
39 u32 impl_ver;
40 char vendor_id[SCMI_SHORT_NAME_MAX_SIZE];
41 char sub_vendor_id[SCMI_SHORT_NAME_MAX_SIZE];
42};
43
44struct scmi_clock_info {
45 char name[SCMI_MAX_STR_SIZE];
46 unsigned int enable_latency;
47 bool rate_discrete;
48 bool rate_changed_notifications;
49 bool rate_change_requested_notifications;
50 union {
51 struct {
52 int num_rates;
53 u64 rates[SCMI_MAX_NUM_RATES];
54 } list;
55 struct {
56 u64 min_rate;
57 u64 max_rate;
58 u64 step_size;
59 } range;
60 };
61};
62
63struct scmi_handle;
64struct scmi_device;
65struct scmi_protocol_handle;
66
67
68
69
70
71
72
73
74
75
76
77
78struct scmi_clk_proto_ops {
79 int (*count_get)(const struct scmi_protocol_handle *ph);
80
81 const struct scmi_clock_info *(*info_get)
82 (const struct scmi_protocol_handle *ph, u32 clk_id);
83 int (*rate_get)(const struct scmi_protocol_handle *ph, u32 clk_id,
84 u64 *rate);
85 int (*rate_set)(const struct scmi_protocol_handle *ph, u32 clk_id,
86 u64 rate);
87 int (*enable)(const struct scmi_protocol_handle *ph, u32 clk_id);
88 int (*disable)(const struct scmi_protocol_handle *ph, u32 clk_id);
89 int (*enable_atomic)(const struct scmi_protocol_handle *ph, u32 clk_id);
90 int (*disable_atomic)(const struct scmi_protocol_handle *ph,
91 u32 clk_id);
92};
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116struct scmi_perf_proto_ops {
117 int (*limits_set)(const struct scmi_protocol_handle *ph, u32 domain,
118 u32 max_perf, u32 min_perf);
119 int (*limits_get)(const struct scmi_protocol_handle *ph, u32 domain,
120 u32 *max_perf, u32 *min_perf);
121 int (*level_set)(const struct scmi_protocol_handle *ph, u32 domain,
122 u32 level, bool poll);
123 int (*level_get)(const struct scmi_protocol_handle *ph, u32 domain,
124 u32 *level, bool poll);
125 int (*device_domain_id)(struct device *dev);
126 int (*transition_latency_get)(const struct scmi_protocol_handle *ph,
127 struct device *dev);
128 int (*device_opps_add)(const struct scmi_protocol_handle *ph,
129 struct device *dev);
130 int (*freq_set)(const struct scmi_protocol_handle *ph, u32 domain,
131 unsigned long rate, bool poll);
132 int (*freq_get)(const struct scmi_protocol_handle *ph, u32 domain,
133 unsigned long *rate, bool poll);
134 int (*est_power_get)(const struct scmi_protocol_handle *ph, u32 domain,
135 unsigned long *rate, unsigned long *power);
136 bool (*fast_switch_possible)(const struct scmi_protocol_handle *ph,
137 struct device *dev);
138 bool (*power_scale_mw_get)(const struct scmi_protocol_handle *ph);
139};
140
141
142
143
144
145
146
147
148
149
150struct scmi_power_proto_ops {
151 int (*num_domains_get)(const struct scmi_protocol_handle *ph);
152 const char *(*name_get)(const struct scmi_protocol_handle *ph,
153 u32 domain);
154#define SCMI_POWER_STATE_TYPE_SHIFT 30
155#define SCMI_POWER_STATE_ID_MASK (BIT(28) - 1)
156#define SCMI_POWER_STATE_PARAM(type, id) \
157 ((((type) & BIT(0)) << SCMI_POWER_STATE_TYPE_SHIFT) | \
158 ((id) & SCMI_POWER_STATE_ID_MASK))
159#define SCMI_POWER_STATE_GENERIC_ON SCMI_POWER_STATE_PARAM(0, 0)
160#define SCMI_POWER_STATE_GENERIC_OFF SCMI_POWER_STATE_PARAM(1, 0)
161 int (*state_set)(const struct scmi_protocol_handle *ph, u32 domain,
162 u32 state);
163 int (*state_get)(const struct scmi_protocol_handle *ph, u32 domain,
164 u32 *state);
165};
166
167
168
169
170
171
172
173
174
175
176struct scmi_sensor_reading {
177 long long value;
178 unsigned long long timestamp;
179};
180
181
182
183
184
185
186struct scmi_range_attrs {
187 long long min_range;
188 long long max_range;
189};
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208struct scmi_sensor_axis_info {
209 unsigned int id;
210 unsigned int type;
211 int scale;
212 char name[SCMI_MAX_STR_SIZE];
213 bool extended_attrs;
214 unsigned int resolution;
215 int exponent;
216 struct scmi_range_attrs attrs;
217};
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234struct scmi_sensor_intervals_info {
235 bool segmented;
236 unsigned int count;
237#define SCMI_SENS_INTVL_SEGMENT_LOW 0
238#define SCMI_SENS_INTVL_SEGMENT_HIGH 1
239#define SCMI_SENS_INTVL_SEGMENT_STEP 2
240 unsigned int *desc;
241#define SCMI_SENS_INTVL_GET_SECS(x) FIELD_GET(GENMASK(20, 5), (x))
242#define SCMI_SENS_INTVL_GET_EXP(x) \
243 ({ \
244 int __signed_exp = FIELD_GET(GENMASK(4, 0), (x)); \
245 \
246 if (__signed_exp & BIT(4)) \
247 __signed_exp |= GENMASK(31, 5); \
248 __signed_exp; \
249 })
250#define SCMI_MAX_PREALLOC_POOL 16
251 unsigned int prealloc_pool[SCMI_MAX_PREALLOC_POOL];
252};
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292struct scmi_sensor_info {
293 unsigned int id;
294 unsigned int type;
295 int scale;
296 unsigned int num_trip_points;
297 bool async;
298 bool update;
299 bool timestamped;
300 int tstamp_scale;
301 unsigned int num_axis;
302 struct scmi_sensor_axis_info *axis;
303 struct scmi_sensor_intervals_info intervals;
304 unsigned int sensor_config;
305#define SCMI_SENS_CFG_UPDATE_SECS_MASK GENMASK(31, 16)
306#define SCMI_SENS_CFG_GET_UPDATE_SECS(x) \
307 FIELD_GET(SCMI_SENS_CFG_UPDATE_SECS_MASK, (x))
308
309#define SCMI_SENS_CFG_UPDATE_EXP_MASK GENMASK(15, 11)
310#define SCMI_SENS_CFG_GET_UPDATE_EXP(x) \
311 ({ \
312 int __signed_exp = \
313 FIELD_GET(SCMI_SENS_CFG_UPDATE_EXP_MASK, (x)); \
314 \
315 if (__signed_exp & BIT(4)) \
316 __signed_exp |= GENMASK(31, 5); \
317 __signed_exp; \
318 })
319
320#define SCMI_SENS_CFG_ROUND_MASK GENMASK(10, 9)
321#define SCMI_SENS_CFG_ROUND_AUTO 2
322#define SCMI_SENS_CFG_ROUND_UP 1
323#define SCMI_SENS_CFG_ROUND_DOWN 0
324
325#define SCMI_SENS_CFG_TSTAMP_ENABLED_MASK BIT(1)
326#define SCMI_SENS_CFG_TSTAMP_ENABLE 1
327#define SCMI_SENS_CFG_TSTAMP_DISABLE 0
328#define SCMI_SENS_CFG_IS_TSTAMP_ENABLED(x) \
329 FIELD_GET(SCMI_SENS_CFG_TSTAMP_ENABLED_MASK, (x))
330
331#define SCMI_SENS_CFG_SENSOR_ENABLED_MASK BIT(0)
332#define SCMI_SENS_CFG_SENSOR_ENABLE 1
333#define SCMI_SENS_CFG_SENSOR_DISABLE 0
334 char name[SCMI_MAX_STR_SIZE];
335#define SCMI_SENS_CFG_IS_ENABLED(x) FIELD_GET(BIT(0), (x))
336 bool extended_scalar_attrs;
337 unsigned int sensor_power;
338 unsigned int resolution;
339 int exponent;
340 struct scmi_range_attrs scalar_attrs;
341};
342
343
344
345
346
347enum scmi_sensor_class {
348 NONE = 0x0,
349 UNSPEC = 0x1,
350 TEMPERATURE_C = 0x2,
351 TEMPERATURE_F = 0x3,
352 TEMPERATURE_K = 0x4,
353 VOLTAGE = 0x5,
354 CURRENT = 0x6,
355 POWER = 0x7,
356 ENERGY = 0x8,
357 CHARGE = 0x9,
358 VOLTAMPERE = 0xA,
359 NITS = 0xB,
360 LUMENS = 0xC,
361 LUX = 0xD,
362 CANDELAS = 0xE,
363 KPA = 0xF,
364 PSI = 0x10,
365 NEWTON = 0x11,
366 CFM = 0x12,
367 RPM = 0x13,
368 HERTZ = 0x14,
369 SECS = 0x15,
370 MINS = 0x16,
371 HOURS = 0x17,
372 DAYS = 0x18,
373 WEEKS = 0x19,
374 MILS = 0x1A,
375 INCHES = 0x1B,
376 FEET = 0x1C,
377 CUBIC_INCHES = 0x1D,
378 CUBIC_FEET = 0x1E,
379 METERS = 0x1F,
380 CUBIC_CM = 0x20,
381 CUBIC_METERS = 0x21,
382 LITERS = 0x22,
383 FLUID_OUNCES = 0x23,
384 RADIANS = 0x24,
385 STERADIANS = 0x25,
386 REVOLUTIONS = 0x26,
387 CYCLES = 0x27,
388 GRAVITIES = 0x28,
389 OUNCES = 0x29,
390 POUNDS = 0x2A,
391 FOOT_POUNDS = 0x2B,
392 OUNCE_INCHES = 0x2C,
393 GAUSS = 0x2D,
394 GILBERTS = 0x2E,
395 HENRIES = 0x2F,
396 FARADS = 0x30,
397 OHMS = 0x31,
398 SIEMENS = 0x32,
399 MOLES = 0x33,
400 BECQUERELS = 0x34,
401 PPM = 0x35,
402 DECIBELS = 0x36,
403 DBA = 0x37,
404 DBC = 0x38,
405 GRAYS = 0x39,
406 SIEVERTS = 0x3A,
407 COLOR_TEMP_K = 0x3B,
408 BITS = 0x3C,
409 BYTES = 0x3D,
410 WORDS = 0x3E,
411 DWORDS = 0x3F,
412 QWORDS = 0x40,
413 PERCENTAGE = 0x41,
414 PASCALS = 0x42,
415 COUNTS = 0x43,
416 GRAMS = 0x44,
417 NEWTON_METERS = 0x45,
418 HITS = 0x46,
419 MISSES = 0x47,
420 RETRIES = 0x48,
421 OVERRUNS = 0x49,
422 UNDERRUNS = 0x4A,
423 COLLISIONS = 0x4B,
424 PACKETS = 0x4C,
425 MESSAGES = 0x4D,
426 CHARS = 0x4E,
427 ERRORS = 0x4F,
428 CORRECTED_ERRS = 0x50,
429 UNCORRECTABLE_ERRS = 0x51,
430 SQ_MILS = 0x52,
431 SQ_INCHES = 0x53,
432 SQ_FEET = 0x54,
433 SQ_CM = 0x55,
434 SQ_METERS = 0x56,
435 RADIANS_SEC = 0x57,
436 BPM = 0x58,
437 METERS_SEC_SQUARED = 0x59,
438 METERS_SEC = 0x5A,
439 CUBIC_METERS_SEC = 0x5B,
440 MM_MERCURY = 0x5C,
441 RADIANS_SEC_SQUARED = 0x5D,
442 OEM_UNIT = 0xFF
443};
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461struct scmi_sensor_proto_ops {
462 int (*count_get)(const struct scmi_protocol_handle *ph);
463 const struct scmi_sensor_info *(*info_get)
464 (const struct scmi_protocol_handle *ph, u32 sensor_id);
465 int (*trip_point_config)(const struct scmi_protocol_handle *ph,
466 u32 sensor_id, u8 trip_id, u64 trip_value);
467 int (*reading_get)(const struct scmi_protocol_handle *ph, u32 sensor_id,
468 u64 *value);
469 int (*reading_get_timestamped)(const struct scmi_protocol_handle *ph,
470 u32 sensor_id, u8 count,
471 struct scmi_sensor_reading *readings);
472 int (*config_get)(const struct scmi_protocol_handle *ph,
473 u32 sensor_id, u32 *sensor_config);
474 int (*config_set)(const struct scmi_protocol_handle *ph,
475 u32 sensor_id, u32 sensor_config);
476};
477
478
479
480
481
482
483
484
485
486
487
488
489struct scmi_reset_proto_ops {
490 int (*num_domains_get)(const struct scmi_protocol_handle *ph);
491 const char *(*name_get)(const struct scmi_protocol_handle *ph,
492 u32 domain);
493 int (*latency_get)(const struct scmi_protocol_handle *ph, u32 domain);
494 int (*reset)(const struct scmi_protocol_handle *ph, u32 domain);
495 int (*assert)(const struct scmi_protocol_handle *ph, u32 domain);
496 int (*deassert)(const struct scmi_protocol_handle *ph, u32 domain);
497};
498
499enum scmi_voltage_level_mode {
500 SCMI_VOLTAGE_LEVEL_SET_AUTO,
501 SCMI_VOLTAGE_LEVEL_SET_SYNC,
502};
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523struct scmi_voltage_info {
524 unsigned int id;
525 bool segmented;
526 bool negative_volts_allowed;
527 bool async_level_set;
528 char name[SCMI_MAX_STR_SIZE];
529 unsigned int num_levels;
530#define SCMI_VOLTAGE_SEGMENT_LOW 0
531#define SCMI_VOLTAGE_SEGMENT_HIGH 1
532#define SCMI_VOLTAGE_SEGMENT_STEP 2
533 int *levels_uv;
534};
535
536
537
538
539
540
541
542
543
544
545
546
547struct scmi_voltage_proto_ops {
548 int (*num_domains_get)(const struct scmi_protocol_handle *ph);
549 const struct scmi_voltage_info __must_check *(*info_get)
550 (const struct scmi_protocol_handle *ph, u32 domain_id);
551 int (*config_set)(const struct scmi_protocol_handle *ph, u32 domain_id,
552 u32 config);
553#define SCMI_VOLTAGE_ARCH_STATE_OFF 0x0
554#define SCMI_VOLTAGE_ARCH_STATE_ON 0x7
555 int (*config_get)(const struct scmi_protocol_handle *ph, u32 domain_id,
556 u32 *config);
557 int (*level_set)(const struct scmi_protocol_handle *ph, u32 domain_id,
558 enum scmi_voltage_level_mode mode, s32 volt_uV);
559 int (*level_get)(const struct scmi_protocol_handle *ph, u32 domain_id,
560 s32 *volt_uV);
561};
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603struct scmi_notify_ops {
604 int (*devm_event_notifier_register)(struct scmi_device *sdev,
605 u8 proto_id, u8 evt_id,
606 const u32 *src_id,
607 struct notifier_block *nb);
608 int (*devm_event_notifier_unregister)(struct scmi_device *sdev,
609 u8 proto_id, u8 evt_id,
610 const u32 *src_id,
611 struct notifier_block *nb);
612 int (*event_notifier_register)(const struct scmi_handle *handle,
613 u8 proto_id, u8 evt_id,
614 const u32 *src_id,
615 struct notifier_block *nb);
616 int (*event_notifier_unregister)(const struct scmi_handle *handle,
617 u8 proto_id, u8 evt_id,
618 const u32 *src_id,
619 struct notifier_block *nb);
620};
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641struct scmi_handle {
642 struct device *dev;
643 struct scmi_revision_info *version;
644
645 const void __must_check *
646 (*devm_protocol_get)(struct scmi_device *sdev, u8 proto,
647 struct scmi_protocol_handle **ph);
648 void (*devm_protocol_put)(struct scmi_device *sdev, u8 proto);
649 bool (*is_transport_atomic)(const struct scmi_handle *handle,
650 unsigned int *atomic_threshold);
651
652 const struct scmi_notify_ops *notify_ops;
653};
654
655enum scmi_std_protocol {
656 SCMI_PROTOCOL_BASE = 0x10,
657 SCMI_PROTOCOL_POWER = 0x11,
658 SCMI_PROTOCOL_SYSTEM = 0x12,
659 SCMI_PROTOCOL_PERF = 0x13,
660 SCMI_PROTOCOL_CLOCK = 0x14,
661 SCMI_PROTOCOL_SENSOR = 0x15,
662 SCMI_PROTOCOL_RESET = 0x16,
663 SCMI_PROTOCOL_VOLTAGE = 0x17,
664};
665
666enum scmi_system_events {
667 SCMI_SYSTEM_SHUTDOWN,
668 SCMI_SYSTEM_COLDRESET,
669 SCMI_SYSTEM_WARMRESET,
670 SCMI_SYSTEM_POWERUP,
671 SCMI_SYSTEM_SUSPEND,
672 SCMI_SYSTEM_MAX
673};
674
675struct scmi_device {
676 u32 id;
677 u8 protocol_id;
678 const char *name;
679 struct device dev;
680 struct scmi_handle *handle;
681};
682
683#define to_scmi_dev(d) container_of(d, struct scmi_device, dev)
684
685struct scmi_device *
686scmi_device_create(struct device_node *np, struct device *parent, int protocol,
687 const char *name);
688void scmi_device_destroy(struct scmi_device *scmi_dev);
689
690struct scmi_device_id {
691 u8 protocol_id;
692 const char *name;
693};
694
695struct scmi_driver {
696 const char *name;
697 int (*probe)(struct scmi_device *sdev);
698 void (*remove)(struct scmi_device *sdev);
699 const struct scmi_device_id *id_table;
700
701 struct device_driver driver;
702};
703
704#define to_scmi_driver(d) container_of(d, struct scmi_driver, driver)
705
706#if IS_REACHABLE(CONFIG_ARM_SCMI_PROTOCOL)
707int scmi_driver_register(struct scmi_driver *driver,
708 struct module *owner, const char *mod_name);
709void scmi_driver_unregister(struct scmi_driver *driver);
710#else
711static inline int
712scmi_driver_register(struct scmi_driver *driver, struct module *owner,
713 const char *mod_name)
714{
715 return -EINVAL;
716}
717
718static inline void scmi_driver_unregister(struct scmi_driver *driver) {}
719#endif
720
721#define scmi_register(driver) \
722 scmi_driver_register(driver, THIS_MODULE, KBUILD_MODNAME)
723#define scmi_unregister(driver) \
724 scmi_driver_unregister(driver)
725
726
727
728
729
730
731
732
733
734#define module_scmi_driver(__scmi_driver) \
735 module_driver(__scmi_driver, scmi_register, scmi_unregister)
736
737
738
739
740
741
742
743
744
745#define module_scmi_protocol(__scmi_protocol) \
746 module_driver(__scmi_protocol, \
747 scmi_protocol_register, scmi_protocol_unregister)
748
749struct scmi_protocol;
750int scmi_protocol_register(const struct scmi_protocol *proto);
751void scmi_protocol_unregister(const struct scmi_protocol *proto);
752
753
754enum scmi_notification_events {
755 SCMI_EVENT_POWER_STATE_CHANGED = 0x0,
756 SCMI_EVENT_CLOCK_RATE_CHANGED = 0x0,
757 SCMI_EVENT_CLOCK_RATE_CHANGE_REQUESTED = 0x1,
758 SCMI_EVENT_PERFORMANCE_LIMITS_CHANGED = 0x0,
759 SCMI_EVENT_PERFORMANCE_LEVEL_CHANGED = 0x1,
760 SCMI_EVENT_SENSOR_TRIP_POINT_EVENT = 0x0,
761 SCMI_EVENT_SENSOR_UPDATE = 0x1,
762 SCMI_EVENT_RESET_ISSUED = 0x0,
763 SCMI_EVENT_BASE_ERROR_EVENT = 0x0,
764 SCMI_EVENT_SYSTEM_POWER_STATE_NOTIFIER = 0x0,
765};
766
767struct scmi_power_state_changed_report {
768 ktime_t timestamp;
769 unsigned int agent_id;
770 unsigned int domain_id;
771 unsigned int power_state;
772};
773
774struct scmi_clock_rate_notif_report {
775 ktime_t timestamp;
776 unsigned int agent_id;
777 unsigned int clock_id;
778 unsigned long long rate;
779};
780
781struct scmi_system_power_state_notifier_report {
782 ktime_t timestamp;
783 unsigned int agent_id;
784 unsigned int flags;
785 unsigned int system_state;
786};
787
788struct scmi_perf_limits_report {
789 ktime_t timestamp;
790 unsigned int agent_id;
791 unsigned int domain_id;
792 unsigned int range_max;
793 unsigned int range_min;
794};
795
796struct scmi_perf_level_report {
797 ktime_t timestamp;
798 unsigned int agent_id;
799 unsigned int domain_id;
800 unsigned int performance_level;
801};
802
803struct scmi_sensor_trip_point_report {
804 ktime_t timestamp;
805 unsigned int agent_id;
806 unsigned int sensor_id;
807 unsigned int trip_point_desc;
808};
809
810struct scmi_sensor_update_report {
811 ktime_t timestamp;
812 unsigned int agent_id;
813 unsigned int sensor_id;
814 unsigned int readings_count;
815 struct scmi_sensor_reading readings[];
816};
817
818struct scmi_reset_issued_report {
819 ktime_t timestamp;
820 unsigned int agent_id;
821 unsigned int domain_id;
822 unsigned int reset_state;
823};
824
825struct scmi_base_error_report {
826 ktime_t timestamp;
827 unsigned int agent_id;
828 bool fatal;
829 unsigned int cmd_count;
830 unsigned long long reports[];
831};
832
833#endif
834