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