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