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