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