firmware: arm_scmi: Port perf protocol to new protocols interface
[linux-2.6-microblaze.git] / include / linux / scmi_protocol.h
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * SCMI Message Protocol driver header
4  *
5  * Copyright (C) 2018-2021 ARM Ltd.
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       16
17 #define SCMI_MAX_NUM_RATES      16
18
19 /**
20  * struct scmi_revision_info - version information structure
21  *
22  * @major_ver: Major ABI version. Change here implies risk of backward
23  *      compatibility break.
24  * @minor_ver: Minor ABI version. Change here implies new feature addition,
25  *      or compatible change in ABI.
26  * @num_protocols: Number of protocols that are implemented, excluding the
27  *      base protocol.
28  * @num_agents: Number of agents in the system.
29  * @impl_ver: A vendor-specific implementation version.
30  * @vendor_id: A vendor identifier(Null terminated ASCII string)
31  * @sub_vendor_id: A sub-vendor identifier(Null terminated ASCII string)
32  */
33 struct scmi_revision_info {
34         u16 major_ver;
35         u16 minor_ver;
36         u8 num_protocols;
37         u8 num_agents;
38         u32 impl_ver;
39         char vendor_id[SCMI_MAX_STR_SIZE];
40         char sub_vendor_id[SCMI_MAX_STR_SIZE];
41 };
42
43 struct scmi_clock_info {
44         char name[SCMI_MAX_STR_SIZE];
45         bool rate_discrete;
46         union {
47                 struct {
48                         int num_rates;
49                         u64 rates[SCMI_MAX_NUM_RATES];
50                 } list;
51                 struct {
52                         u64 min_rate;
53                         u64 max_rate;
54                         u64 step_size;
55                 } range;
56         };
57 };
58
59 struct scmi_handle;
60 struct scmi_device;
61 struct scmi_protocol_handle;
62
63 /**
64  * struct scmi_clk_ops - represents the various operations provided
65  *      by SCMI Clock Protocol
66  *
67  * @count_get: get the count of clocks provided by SCMI
68  * @info_get: get the information of the specified clock
69  * @rate_get: request the current clock rate of a clock
70  * @rate_set: set the clock rate of a clock
71  * @enable: enables the specified clock
72  * @disable: disables the specified clock
73  */
74 struct scmi_clk_ops {
75         int (*count_get)(const struct scmi_handle *handle);
76
77         const struct scmi_clock_info *(*info_get)
78                 (const struct scmi_handle *handle, u32 clk_id);
79         int (*rate_get)(const struct scmi_handle *handle, u32 clk_id,
80                         u64 *rate);
81         int (*rate_set)(const struct scmi_handle *handle, u32 clk_id,
82                         u64 rate);
83         int (*enable)(const struct scmi_handle *handle, u32 clk_id);
84         int (*disable)(const struct scmi_handle *handle, u32 clk_id);
85 };
86
87 /**
88  * struct scmi_perf_proto_ops - represents the various operations provided
89  *      by SCMI Performance Protocol
90  *
91  * @limits_set: sets limits on the performance level of a domain
92  * @limits_get: gets limits on the performance level of a domain
93  * @level_set: sets the performance level of a domain
94  * @level_get: gets the performance level of a domain
95  * @device_domain_id: gets the scmi domain id for a given device
96  * @transition_latency_get: gets the DVFS transition latency for a given device
97  * @device_opps_add: adds all the OPPs for a given device
98  * @freq_set: sets the frequency for a given device using sustained frequency
99  *      to sustained performance level mapping
100  * @freq_get: gets the frequency for a given device using sustained frequency
101  *      to sustained performance level mapping
102  * @est_power_get: gets the estimated power cost for a given performance domain
103  *      at a given frequency
104  */
105 struct scmi_perf_proto_ops {
106         int (*limits_set)(const struct scmi_protocol_handle *ph, u32 domain,
107                           u32 max_perf, u32 min_perf);
108         int (*limits_get)(const struct scmi_protocol_handle *ph, u32 domain,
109                           u32 *max_perf, u32 *min_perf);
110         int (*level_set)(const struct scmi_protocol_handle *ph, u32 domain,
111                          u32 level, bool poll);
112         int (*level_get)(const struct scmi_protocol_handle *ph, u32 domain,
113                          u32 *level, bool poll);
114         int (*device_domain_id)(struct device *dev);
115         int (*transition_latency_get)(const struct scmi_protocol_handle *ph,
116                                       struct device *dev);
117         int (*device_opps_add)(const struct scmi_protocol_handle *ph,
118                                struct device *dev);
119         int (*freq_set)(const struct scmi_protocol_handle *ph, u32 domain,
120                         unsigned long rate, bool poll);
121         int (*freq_get)(const struct scmi_protocol_handle *ph, u32 domain,
122                         unsigned long *rate, bool poll);
123         int (*est_power_get)(const struct scmi_protocol_handle *ph, u32 domain,
124                              unsigned long *rate, unsigned long *power);
125         bool (*fast_switch_possible)(const struct scmi_protocol_handle *ph,
126                                      struct device *dev);
127         bool (*power_scale_mw_get)(const struct scmi_protocol_handle *ph);
128 };
129
130 struct scmi_perf_ops {
131         int (*limits_set)(const struct scmi_handle *handle, u32 domain,
132                           u32 max_perf, u32 min_perf);
133         int (*limits_get)(const struct scmi_handle *handle, u32 domain,
134                           u32 *max_perf, u32 *min_perf);
135         int (*level_set)(const struct scmi_handle *handle, u32 domain,
136                          u32 level, bool poll);
137         int (*level_get)(const struct scmi_handle *handle, u32 domain,
138                          u32 *level, bool poll);
139         int (*device_domain_id)(struct device *dev);
140         int (*transition_latency_get)(const struct scmi_handle *handle,
141                                       struct device *dev);
142         int (*device_opps_add)(const struct scmi_handle *handle,
143                                struct device *dev);
144         int (*freq_set)(const struct scmi_handle *handle, u32 domain,
145                         unsigned long rate, bool poll);
146         int (*freq_get)(const struct scmi_handle *handle, u32 domain,
147                         unsigned long *rate, bool poll);
148         int (*est_power_get)(const struct scmi_handle *handle, u32 domain,
149                              unsigned long *rate, unsigned long *power);
150         bool (*fast_switch_possible)(const struct scmi_handle *handle,
151                                      struct device *dev);
152         bool (*power_scale_mw_get)(const struct scmi_handle *handle);
153 };
154
155 /**
156  * struct scmi_power_ops - represents the various operations provided
157  *      by SCMI Power Protocol
158  *
159  * @num_domains_get: get the count of power domains provided by SCMI
160  * @name_get: gets the name of a power domain
161  * @state_set: sets the power state of a power domain
162  * @state_get: gets the power state of a power domain
163  */
164 struct scmi_power_ops {
165         int (*num_domains_get)(const struct scmi_handle *handle);
166         char *(*name_get)(const struct scmi_handle *handle, u32 domain);
167 #define SCMI_POWER_STATE_TYPE_SHIFT     30
168 #define SCMI_POWER_STATE_ID_MASK        (BIT(28) - 1)
169 #define SCMI_POWER_STATE_PARAM(type, id) \
170         ((((type) & BIT(0)) << SCMI_POWER_STATE_TYPE_SHIFT) | \
171                 ((id) & SCMI_POWER_STATE_ID_MASK))
172 #define SCMI_POWER_STATE_GENERIC_ON     SCMI_POWER_STATE_PARAM(0, 0)
173 #define SCMI_POWER_STATE_GENERIC_OFF    SCMI_POWER_STATE_PARAM(1, 0)
174         int (*state_set)(const struct scmi_handle *handle, u32 domain,
175                          u32 state);
176         int (*state_get)(const struct scmi_handle *handle, u32 domain,
177                          u32 *state);
178 };
179
180 /**
181  * scmi_sensor_reading  - represent a timestamped read
182  *
183  * Used by @reading_get_timestamped method.
184  *
185  * @value: The signed value sensor read.
186  * @timestamp: An unsigned timestamp for the sensor read, as provided by
187  *             SCMI platform. Set to zero when not available.
188  */
189 struct scmi_sensor_reading {
190         long long value;
191         unsigned long long timestamp;
192 };
193
194 /**
195  * scmi_range_attrs  - specifies a sensor or axis values' range
196  * @min_range: The minimum value which can be represented by the sensor/axis.
197  * @max_range: The maximum value which can be represented by the sensor/axis.
198  */
199 struct scmi_range_attrs {
200         long long min_range;
201         long long max_range;
202 };
203
204 /**
205  * scmi_sensor_axis_info  - describes one sensor axes
206  * @id: The axes ID.
207  * @type: Axes type. Chosen amongst one of @enum scmi_sensor_class.
208  * @scale: Power-of-10 multiplier applied to the axis unit.
209  * @name: NULL-terminated string representing axes name as advertised by
210  *        SCMI platform.
211  * @extended_attrs: Flag to indicate the presence of additional extended
212  *                  attributes for this axes.
213  * @resolution: Extended attribute representing the resolution of the axes.
214  *              Set to 0 if not reported by this axes.
215  * @exponent: Extended attribute representing the power-of-10 multiplier that
216  *            is applied to the resolution field. Set to 0 if not reported by
217  *            this axes.
218  * @attrs: Extended attributes representing minimum and maximum values
219  *         measurable by this axes. Set to 0 if not reported by this sensor.
220  */
221 struct scmi_sensor_axis_info {
222         unsigned int id;
223         unsigned int type;
224         int scale;
225         char name[SCMI_MAX_STR_SIZE];
226         bool extended_attrs;
227         unsigned int resolution;
228         int exponent;
229         struct scmi_range_attrs attrs;
230 };
231
232 /**
233  * scmi_sensor_intervals_info  - describes number and type of available update
234  * intervals
235  * @segmented: Flag for segmented intervals' representation. When True there
236  *             will be exactly 3 intervals in @desc, with each entry
237  *             representing a member of a segment in this order:
238  *             {lowest update interval, highest update interval, step size}
239  * @count: Number of intervals described in @desc.
240  * @desc: Array of @count interval descriptor bitmask represented as detailed in
241  *        the SCMI specification: it can be accessed using the accompanying
242  *        macros.
243  * @prealloc_pool: A minimal preallocated pool of desc entries used to avoid
244  *                 lesser-than-64-bytes dynamic allocation for small @count
245  *                 values.
246  */
247 struct scmi_sensor_intervals_info {
248         bool segmented;
249         unsigned int count;
250 #define SCMI_SENS_INTVL_SEGMENT_LOW     0
251 #define SCMI_SENS_INTVL_SEGMENT_HIGH    1
252 #define SCMI_SENS_INTVL_SEGMENT_STEP    2
253         unsigned int *desc;
254 #define SCMI_SENS_INTVL_GET_SECS(x)             FIELD_GET(GENMASK(20, 5), (x))
255 #define SCMI_SENS_INTVL_GET_EXP(x)                                      \
256         ({                                                              \
257                 int __signed_exp = FIELD_GET(GENMASK(4, 0), (x));       \
258                                                                         \
259                 if (__signed_exp & BIT(4))                              \
260                         __signed_exp |= GENMASK(31, 5);                 \
261                 __signed_exp;                                           \
262         })
263 #define SCMI_MAX_PREALLOC_POOL                  16
264         unsigned int prealloc_pool[SCMI_MAX_PREALLOC_POOL];
265 };
266
267 /**
268  * struct scmi_sensor_info - represents information related to one of the
269  * available sensors.
270  * @id: Sensor ID.
271  * @type: Sensor type. Chosen amongst one of @enum scmi_sensor_class.
272  * @scale: Power-of-10 multiplier applied to the sensor unit.
273  * @num_trip_points: Number of maximum configurable trip points.
274  * @async: Flag for asynchronous read support.
275  * @update: Flag for continuouos update notification support.
276  * @timestamped: Flag for timestamped read support.
277  * @tstamp_scale: Power-of-10 multiplier applied to the sensor timestamps to
278  *                represent it in seconds.
279  * @num_axis: Number of supported axis if any. Reported as 0 for scalar sensors.
280  * @axis: Pointer to an array of @num_axis descriptors.
281  * @intervals: Descriptor of available update intervals.
282  * @sensor_config: A bitmask reporting the current sensor configuration as
283  *                 detailed in the SCMI specification: it can accessed and
284  *                 modified through the accompanying macros.
285  * @name: NULL-terminated string representing sensor name as advertised by
286  *        SCMI platform.
287  * @extended_scalar_attrs: Flag to indicate the presence of additional extended
288  *                         attributes for this sensor.
289  * @sensor_power: Extended attribute representing the average power
290  *                consumed by the sensor in microwatts (uW) when it is active.
291  *                Reported here only for scalar sensors.
292  *                Set to 0 if not reported by this sensor.
293  * @resolution: Extended attribute representing the resolution of the sensor.
294  *              Reported here only for scalar sensors.
295  *              Set to 0 if not reported by this sensor.
296  * @exponent: Extended attribute representing the power-of-10 multiplier that is
297  *            applied to the resolution field.
298  *            Reported here only for scalar sensors.
299  *            Set to 0 if not reported by this sensor.
300  * @scalar_attrs: Extended attributes representing minimum and maximum
301  *                measurable values by this sensor.
302  *                Reported here only for scalar sensors.
303  *                Set to 0 if not reported by this sensor.
304  */
305 struct scmi_sensor_info {
306         unsigned int id;
307         unsigned int type;
308         int scale;
309         unsigned int num_trip_points;
310         bool async;
311         bool update;
312         bool timestamped;
313         int tstamp_scale;
314         unsigned int num_axis;
315         struct scmi_sensor_axis_info *axis;
316         struct scmi_sensor_intervals_info intervals;
317         unsigned int sensor_config;
318 #define SCMI_SENS_CFG_UPDATE_SECS_MASK          GENMASK(31, 16)
319 #define SCMI_SENS_CFG_GET_UPDATE_SECS(x)                                \
320         FIELD_GET(SCMI_SENS_CFG_UPDATE_SECS_MASK, (x))
321
322 #define SCMI_SENS_CFG_UPDATE_EXP_MASK           GENMASK(15, 11)
323 #define SCMI_SENS_CFG_GET_UPDATE_EXP(x)                                 \
324         ({                                                              \
325                 int __signed_exp =                                      \
326                         FIELD_GET(SCMI_SENS_CFG_UPDATE_EXP_MASK, (x));  \
327                                                                         \
328                 if (__signed_exp & BIT(4))                              \
329                         __signed_exp |= GENMASK(31, 5);                 \
330                 __signed_exp;                                           \
331         })
332
333 #define SCMI_SENS_CFG_ROUND_MASK                GENMASK(10, 9)
334 #define SCMI_SENS_CFG_ROUND_AUTO                2
335 #define SCMI_SENS_CFG_ROUND_UP                  1
336 #define SCMI_SENS_CFG_ROUND_DOWN                0
337
338 #define SCMI_SENS_CFG_TSTAMP_ENABLED_MASK       BIT(1)
339 #define SCMI_SENS_CFG_TSTAMP_ENABLE             1
340 #define SCMI_SENS_CFG_TSTAMP_DISABLE            0
341 #define SCMI_SENS_CFG_IS_TSTAMP_ENABLED(x)                              \
342         FIELD_GET(SCMI_SENS_CFG_TSTAMP_ENABLED_MASK, (x))
343
344 #define SCMI_SENS_CFG_SENSOR_ENABLED_MASK       BIT(0)
345 #define SCMI_SENS_CFG_SENSOR_ENABLE             1
346 #define SCMI_SENS_CFG_SENSOR_DISABLE            0
347         char name[SCMI_MAX_STR_SIZE];
348 #define SCMI_SENS_CFG_IS_ENABLED(x)             FIELD_GET(BIT(0), (x))
349         bool extended_scalar_attrs;
350         unsigned int sensor_power;
351         unsigned int resolution;
352         int exponent;
353         struct scmi_range_attrs scalar_attrs;
354 };
355
356 /*
357  * Partial list from Distributed Management Task Force (DMTF) specification:
358  * DSP0249 (Platform Level Data Model specification)
359  */
360 enum scmi_sensor_class {
361         NONE = 0x0,
362         UNSPEC = 0x1,
363         TEMPERATURE_C = 0x2,
364         TEMPERATURE_F = 0x3,
365         TEMPERATURE_K = 0x4,
366         VOLTAGE = 0x5,
367         CURRENT = 0x6,
368         POWER = 0x7,
369         ENERGY = 0x8,
370         CHARGE = 0x9,
371         VOLTAMPERE = 0xA,
372         NITS = 0xB,
373         LUMENS = 0xC,
374         LUX = 0xD,
375         CANDELAS = 0xE,
376         KPA = 0xF,
377         PSI = 0x10,
378         NEWTON = 0x11,
379         CFM = 0x12,
380         RPM = 0x13,
381         HERTZ = 0x14,
382         SECS = 0x15,
383         MINS = 0x16,
384         HOURS = 0x17,
385         DAYS = 0x18,
386         WEEKS = 0x19,
387         MILS = 0x1A,
388         INCHES = 0x1B,
389         FEET = 0x1C,
390         CUBIC_INCHES = 0x1D,
391         CUBIC_FEET = 0x1E,
392         METERS = 0x1F,
393         CUBIC_CM = 0x20,
394         CUBIC_METERS = 0x21,
395         LITERS = 0x22,
396         FLUID_OUNCES = 0x23,
397         RADIANS = 0x24,
398         STERADIANS = 0x25,
399         REVOLUTIONS = 0x26,
400         CYCLES = 0x27,
401         GRAVITIES = 0x28,
402         OUNCES = 0x29,
403         POUNDS = 0x2A,
404         FOOT_POUNDS = 0x2B,
405         OUNCE_INCHES = 0x2C,
406         GAUSS = 0x2D,
407         GILBERTS = 0x2E,
408         HENRIES = 0x2F,
409         FARADS = 0x30,
410         OHMS = 0x31,
411         SIEMENS = 0x32,
412         MOLES = 0x33,
413         BECQUERELS = 0x34,
414         PPM = 0x35,
415         DECIBELS = 0x36,
416         DBA = 0x37,
417         DBC = 0x38,
418         GRAYS = 0x39,
419         SIEVERTS = 0x3A,
420         COLOR_TEMP_K = 0x3B,
421         BITS = 0x3C,
422         BYTES = 0x3D,
423         WORDS = 0x3E,
424         DWORDS = 0x3F,
425         QWORDS = 0x40,
426         PERCENTAGE = 0x41,
427         PASCALS = 0x42,
428         COUNTS = 0x43,
429         GRAMS = 0x44,
430         NEWTON_METERS = 0x45,
431         HITS = 0x46,
432         MISSES = 0x47,
433         RETRIES = 0x48,
434         OVERRUNS = 0x49,
435         UNDERRUNS = 0x4A,
436         COLLISIONS = 0x4B,
437         PACKETS = 0x4C,
438         MESSAGES = 0x4D,
439         CHARS = 0x4E,
440         ERRORS = 0x4F,
441         CORRECTED_ERRS = 0x50,
442         UNCORRECTABLE_ERRS = 0x51,
443         SQ_MILS = 0x52,
444         SQ_INCHES = 0x53,
445         SQ_FEET = 0x54,
446         SQ_CM = 0x55,
447         SQ_METERS = 0x56,
448         RADIANS_SEC = 0x57,
449         BPM = 0x58,
450         METERS_SEC_SQUARED = 0x59,
451         METERS_SEC = 0x5A,
452         CUBIC_METERS_SEC = 0x5B,
453         MM_MERCURY = 0x5C,
454         RADIANS_SEC_SQUARED = 0x5D,
455         OEM_UNIT = 0xFF
456 };
457
458 /**
459  * struct scmi_sensor_ops - represents the various operations provided
460  *      by SCMI Sensor Protocol
461  *
462  * @count_get: get the count of sensors provided by SCMI
463  * @info_get: get the information of the specified sensor
464  * @trip_point_config: selects and configures a trip-point of interest
465  * @reading_get: gets the current value of the sensor
466  * @reading_get_timestamped: gets the current value and timestamp, when
467  *                           available, of the sensor. (as of v3.0 spec)
468  *                           Supports multi-axis sensors for sensors which
469  *                           supports it and if the @reading array size of
470  *                           @count entry equals the sensor num_axis
471  * @config_get: Get sensor current configuration
472  * @config_set: Set sensor current configuration
473  */
474 struct scmi_sensor_ops {
475         int (*count_get)(const struct scmi_handle *handle);
476         const struct scmi_sensor_info *(*info_get)
477                 (const struct scmi_handle *handle, u32 sensor_id);
478         int (*trip_point_config)(const struct scmi_handle *handle,
479                                  u32 sensor_id, u8 trip_id, u64 trip_value);
480         int (*reading_get)(const struct scmi_handle *handle, u32 sensor_id,
481                            u64 *value);
482         int (*reading_get_timestamped)(const struct scmi_handle *handle,
483                                        u32 sensor_id, u8 count,
484                                        struct scmi_sensor_reading *readings);
485         int (*config_get)(const struct scmi_handle *handle,
486                           u32 sensor_id, u32 *sensor_config);
487         int (*config_set)(const struct scmi_handle *handle,
488                           u32 sensor_id, u32 sensor_config);
489 };
490
491 /**
492  * struct scmi_reset_ops - represents the various operations provided
493  *      by SCMI Reset Protocol
494  *
495  * @num_domains_get: get the count of reset domains provided by SCMI
496  * @name_get: gets the name of a reset domain
497  * @latency_get: gets the reset latency for the specified reset domain
498  * @reset: resets the specified reset domain
499  * @assert: explicitly assert reset signal of the specified reset domain
500  * @deassert: explicitly deassert reset signal of the specified reset domain
501  */
502 struct scmi_reset_ops {
503         int (*num_domains_get)(const struct scmi_handle *handle);
504         char *(*name_get)(const struct scmi_handle *handle, u32 domain);
505         int (*latency_get)(const struct scmi_handle *handle, u32 domain);
506         int (*reset)(const struct scmi_handle *handle, u32 domain);
507         int (*assert)(const struct scmi_handle *handle, u32 domain);
508         int (*deassert)(const struct scmi_handle *handle, u32 domain);
509 };
510
511 /**
512  * struct scmi_voltage_info - describe one available SCMI Voltage Domain
513  *
514  * @id: the domain ID as advertised by the platform
515  * @segmented: defines the layout of the entries of array @levels_uv.
516  *             - when True the entries are to be interpreted as triplets,
517  *               each defining a segment representing a range of equally
518  *               space voltages: <lowest_volts>, <highest_volt>, <step_uV>
519  *             - when False the entries simply represent a single discrete
520  *               supported voltage level
521  * @negative_volts_allowed: True if any of the entries of @levels_uv represent
522  *                          a negative voltage.
523  * @attributes: represents Voltage Domain advertised attributes
524  * @name: name assigned to the Voltage Domain by platform
525  * @num_levels: number of total entries in @levels_uv.
526  * @levels_uv: array of entries describing the available voltage levels for
527  *             this domain.
528  */
529 struct scmi_voltage_info {
530         unsigned int id;
531         bool segmented;
532         bool negative_volts_allowed;
533         unsigned int attributes;
534         char name[SCMI_MAX_STR_SIZE];
535         unsigned int num_levels;
536 #define SCMI_VOLTAGE_SEGMENT_LOW        0
537 #define SCMI_VOLTAGE_SEGMENT_HIGH       1
538 #define SCMI_VOLTAGE_SEGMENT_STEP       2
539         int *levels_uv;
540 };
541
542 /**
543  * struct scmi_voltage_ops - represents the various operations provided
544  * by SCMI Voltage Protocol
545  *
546  * @num_domains_get: get the count of voltage domains provided by SCMI
547  * @info_get: get the information of the specified domain
548  * @config_set: set the config for the specified domain
549  * @config_get: get the config of the specified domain
550  * @level_set: set the voltage level for the specified domain
551  * @level_get: get the voltage level of the specified domain
552  */
553 struct scmi_voltage_ops {
554         int (*num_domains_get)(const struct scmi_handle *handle);
555         const struct scmi_voltage_info __must_check *(*info_get)
556                 (const struct scmi_handle *handle, u32 domain_id);
557         int (*config_set)(const struct scmi_handle *handle, u32 domain_id,
558                           u32 config);
559 #define SCMI_VOLTAGE_ARCH_STATE_OFF             0x0
560 #define SCMI_VOLTAGE_ARCH_STATE_ON              0x7
561         int (*config_get)(const struct scmi_handle *handle, u32 domain_id,
562                           u32 *config);
563         int (*level_set)(const struct scmi_handle *handle, u32 domain_id,
564                          u32 flags, s32 volt_uV);
565         int (*level_get)(const struct scmi_handle *handle, u32 domain_id,
566                          s32 *volt_uV);
567 };
568
569 /**
570  * struct scmi_notify_ops  - represents notifications' operations provided by
571  * SCMI core
572  * @devm_event_notifier_register: Managed registration of a notifier_block for
573  *                                the requested event
574  * @devm_event_notifier_unregister: Managed unregistration of a notifier_block
575  *                                  for the requested event
576  * @register_event_notifier: Register a notifier_block for the requested event
577  * @unregister_event_notifier: Unregister a notifier_block for the requested
578  *                             event
579  *
580  * A user can register/unregister its own notifier_block against the wanted
581  * platform instance regarding the desired event identified by the
582  * tuple: (proto_id, evt_id, src_id) using the provided register/unregister
583  * interface where:
584  *
585  * @sdev: The scmi_device to use when calling the devres managed ops devm_
586  * @handle: The handle identifying the platform instance to use, when not
587  *          calling the managed ops devm_
588  * @proto_id: The protocol ID as in SCMI Specification
589  * @evt_id: The message ID of the desired event as in SCMI Specification
590  * @src_id: A pointer to the desired source ID if different sources are
591  *          possible for the protocol (like domain_id, sensor_id...etc)
592  *
593  * @src_id can be provided as NULL if it simply does NOT make sense for
594  * the protocol at hand, OR if the user is explicitly interested in
595  * receiving notifications from ANY existent source associated to the
596  * specified proto_id / evt_id.
597  *
598  * Received notifications are finally delivered to the registered users,
599  * invoking the callback provided with the notifier_block *nb as follows:
600  *
601  *      int user_cb(nb, evt_id, report)
602  *
603  * with:
604  *
605  * @nb: The notifier block provided by the user
606  * @evt_id: The message ID of the delivered event
607  * @report: A custom struct describing the specific event delivered
608  */
609 struct scmi_notify_ops {
610         int (*devm_event_notifier_register)(struct scmi_device *sdev,
611                                             u8 proto_id, u8 evt_id,
612                                             const u32 *src_id,
613                                             struct notifier_block *nb);
614         int (*devm_event_notifier_unregister)(struct scmi_device *sdev,
615                                               u8 proto_id, u8 evt_id,
616                                               const u32 *src_id,
617                                               struct notifier_block *nb);
618         int (*register_event_notifier)(const struct scmi_handle *handle,
619                                        u8 proto_id, u8 evt_id,
620                                        const u32 *src_id,
621                                        struct notifier_block *nb);
622         int (*unregister_event_notifier)(const struct scmi_handle *handle,
623                                          u8 proto_id, u8 evt_id,
624                                          const u32 *src_id,
625                                          struct notifier_block *nb);
626 };
627
628 /**
629  * struct scmi_handle - Handle returned to ARM SCMI clients for usage.
630  *
631  * @dev: pointer to the SCMI device
632  * @version: pointer to the structure containing SCMI version information
633  * @power_ops: pointer to set of power protocol operations
634  * @perf_ops: pointer to set of performance protocol operations
635  * @clk_ops: pointer to set of clock protocol operations
636  * @sensor_ops: pointer to set of sensor protocol operations
637  * @reset_ops: pointer to set of reset protocol operations
638  * @voltage_ops: pointer to set of voltage protocol operations
639  * @devm_protocol_get: devres managed method to acquire a protocol and get specific
640  *                     operations and a dedicated protocol handler
641  * @devm_protocol_put: devres managed method to release a protocol
642  * @notify_ops: pointer to set of notifications related operations
643  * @clk_priv: pointer to private data structure specific to clock
644  *      protocol(for internal use only)
645  * @power_priv: pointer to private data structure specific to power
646  *      protocol(for internal use only)
647  * @sensor_priv: pointer to private data structure specific to sensors
648  *      protocol(for internal use only)
649  * @reset_priv: pointer to private data structure specific to reset
650  *      protocol(for internal use only)
651  * @voltage_priv: pointer to private data structure specific to voltage
652  *      protocol(for internal use only)
653  * @notify_priv: pointer to private data structure specific to notifications
654  *      (for internal use only)
655  */
656 struct scmi_handle {
657         struct device *dev;
658         struct scmi_revision_info *version;
659         const struct scmi_perf_ops *perf_ops;
660         const struct scmi_clk_ops *clk_ops;
661         const struct scmi_power_ops *power_ops;
662         const struct scmi_sensor_ops *sensor_ops;
663         const struct scmi_reset_ops *reset_ops;
664         const struct scmi_voltage_ops *voltage_ops;
665
666         const void __must_check *
667                 (*devm_protocol_get)(struct scmi_device *sdev, u8 proto,
668                                      struct scmi_protocol_handle **ph);
669         void (*devm_protocol_put)(struct scmi_device *sdev, u8 proto);
670
671         const struct scmi_notify_ops *notify_ops;
672         /* for protocol internal use */
673         void *clk_priv;
674         void *power_priv;
675         void *sensor_priv;
676         void *reset_priv;
677         void *voltage_priv;
678         void *notify_priv;
679         void *system_priv;
680 };
681
682 enum scmi_std_protocol {
683         SCMI_PROTOCOL_BASE = 0x10,
684         SCMI_PROTOCOL_POWER = 0x11,
685         SCMI_PROTOCOL_SYSTEM = 0x12,
686         SCMI_PROTOCOL_PERF = 0x13,
687         SCMI_PROTOCOL_CLOCK = 0x14,
688         SCMI_PROTOCOL_SENSOR = 0x15,
689         SCMI_PROTOCOL_RESET = 0x16,
690         SCMI_PROTOCOL_VOLTAGE = 0x17,
691 };
692
693 enum scmi_system_events {
694         SCMI_SYSTEM_SHUTDOWN,
695         SCMI_SYSTEM_COLDRESET,
696         SCMI_SYSTEM_WARMRESET,
697         SCMI_SYSTEM_POWERUP,
698         SCMI_SYSTEM_SUSPEND,
699         SCMI_SYSTEM_MAX
700 };
701
702 struct scmi_device {
703         u32 id;
704         u8 protocol_id;
705         const char *name;
706         struct device dev;
707         struct scmi_handle *handle;
708 };
709
710 #define to_scmi_dev(d) container_of(d, struct scmi_device, dev)
711
712 struct scmi_device *
713 scmi_device_create(struct device_node *np, struct device *parent, int protocol,
714                    const char *name);
715 void scmi_device_destroy(struct scmi_device *scmi_dev);
716
717 struct scmi_device_id {
718         u8 protocol_id;
719         const char *name;
720 };
721
722 struct scmi_driver {
723         const char *name;
724         int (*probe)(struct scmi_device *sdev);
725         void (*remove)(struct scmi_device *sdev);
726         const struct scmi_device_id *id_table;
727
728         struct device_driver driver;
729 };
730
731 #define to_scmi_driver(d) container_of(d, struct scmi_driver, driver)
732
733 #if IS_REACHABLE(CONFIG_ARM_SCMI_PROTOCOL)
734 int scmi_driver_register(struct scmi_driver *driver,
735                          struct module *owner, const char *mod_name);
736 void scmi_driver_unregister(struct scmi_driver *driver);
737 #else
738 static inline int
739 scmi_driver_register(struct scmi_driver *driver, struct module *owner,
740                      const char *mod_name)
741 {
742         return -EINVAL;
743 }
744
745 static inline void scmi_driver_unregister(struct scmi_driver *driver) {}
746 #endif /* CONFIG_ARM_SCMI_PROTOCOL */
747
748 #define scmi_register(driver) \
749         scmi_driver_register(driver, THIS_MODULE, KBUILD_MODNAME)
750 #define scmi_unregister(driver) \
751         scmi_driver_unregister(driver)
752
753 /**
754  * module_scmi_driver() - Helper macro for registering a scmi driver
755  * @__scmi_driver: scmi_driver structure
756  *
757  * Helper macro for scmi drivers to set up proper module init / exit
758  * functions.  Replaces module_init() and module_exit() and keeps people from
759  * printing pointless things to the kernel log when their driver is loaded.
760  */
761 #define module_scmi_driver(__scmi_driver)       \
762         module_driver(__scmi_driver, scmi_register, scmi_unregister)
763
764 struct scmi_protocol;
765 int scmi_protocol_register(const struct scmi_protocol *proto);
766 void scmi_protocol_unregister(const struct scmi_protocol *proto);
767
768 /* SCMI Notification API - Custom Event Reports */
769 enum scmi_notification_events {
770         SCMI_EVENT_POWER_STATE_CHANGED = 0x0,
771         SCMI_EVENT_PERFORMANCE_LIMITS_CHANGED = 0x0,
772         SCMI_EVENT_PERFORMANCE_LEVEL_CHANGED = 0x1,
773         SCMI_EVENT_SENSOR_TRIP_POINT_EVENT = 0x0,
774         SCMI_EVENT_SENSOR_UPDATE = 0x1,
775         SCMI_EVENT_RESET_ISSUED = 0x0,
776         SCMI_EVENT_BASE_ERROR_EVENT = 0x0,
777         SCMI_EVENT_SYSTEM_POWER_STATE_NOTIFIER = 0x0,
778 };
779
780 struct scmi_power_state_changed_report {
781         ktime_t         timestamp;
782         unsigned int    agent_id;
783         unsigned int    domain_id;
784         unsigned int    power_state;
785 };
786
787 struct scmi_system_power_state_notifier_report {
788         ktime_t         timestamp;
789         unsigned int    agent_id;
790         unsigned int    flags;
791         unsigned int    system_state;
792 };
793
794 struct scmi_perf_limits_report {
795         ktime_t         timestamp;
796         unsigned int    agent_id;
797         unsigned int    domain_id;
798         unsigned int    range_max;
799         unsigned int    range_min;
800 };
801
802 struct scmi_perf_level_report {
803         ktime_t         timestamp;
804         unsigned int    agent_id;
805         unsigned int    domain_id;
806         unsigned int    performance_level;
807 };
808
809 struct scmi_sensor_trip_point_report {
810         ktime_t         timestamp;
811         unsigned int    agent_id;
812         unsigned int    sensor_id;
813         unsigned int    trip_point_desc;
814 };
815
816 struct scmi_sensor_update_report {
817         ktime_t                         timestamp;
818         unsigned int                    agent_id;
819         unsigned int                    sensor_id;
820         unsigned int                    readings_count;
821         struct scmi_sensor_reading      readings[];
822 };
823
824 struct scmi_reset_issued_report {
825         ktime_t         timestamp;
826         unsigned int    agent_id;
827         unsigned int    domain_id;
828         unsigned int    reset_state;
829 };
830
831 struct scmi_base_error_report {
832         ktime_t                 timestamp;
833         unsigned int            agent_id;
834         bool                    fatal;
835         unsigned int            cmd_count;
836         unsigned long long      reports[];
837 };
838
839 #endif /* _LINUX_SCMI_PROTOCOL_H */