1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3 * SCMI Message Protocol driver header
4 *
5 * Copyright (C) 2018 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 #include <linux/android_kabi.h>
16
17 #define SCMI_MAX_STR_SIZE 16
18 #define SCMI_MAX_NUM_RATES 16
19
20 /**
21 * struct scmi_revision_info - version information structure
22 *
23 * @major_ver: Major ABI version. Change here implies risk of backward
24 * compatibility break.
25 * @minor_ver: Minor ABI version. Change here implies new feature addition,
26 * or compatible change in ABI.
27 * @num_protocols: Number of protocols that are implemented, excluding the
28 * base protocol.
29 * @num_agents: Number of agents in the system.
30 * @impl_ver: A vendor-specific implementation version.
31 * @vendor_id: A vendor identifier(Null terminated ASCII string)
32 * @sub_vendor_id: A sub-vendor identifier(Null terminated ASCII string)
33 */
34 struct scmi_revision_info {
35 u16 major_ver;
36 u16 minor_ver;
37 u8 num_protocols;
38 u8 num_agents;
39 u32 impl_ver;
40 char vendor_id[SCMI_MAX_STR_SIZE];
41 char sub_vendor_id[SCMI_MAX_STR_SIZE];
42 };
43
44 struct scmi_clock_info {
45 char name[SCMI_MAX_STR_SIZE];
46 bool rate_discrete;
47 union {
48 struct {
49 int num_rates;
50 u64 rates[SCMI_MAX_NUM_RATES];
51 } list;
52 struct {
53 u64 min_rate;
54 u64 max_rate;
55 u64 step_size;
56 } range;
57 };
58 };
59
60 struct scmi_handle;
61 struct scmi_device;
62 struct scmi_protocol_handle;
63
64 /**
65 * struct scmi_clk_proto_ops - represents the various operations provided
66 * by SCMI Clock Protocol
67 *
68 * @count_get: get the count of clocks provided by SCMI
69 * @info_get: get the information of the specified clock
70 * @rate_get: request the current clock rate of a clock
71 * @rate_set: set the clock rate of a clock
72 * @enable: enables the specified clock
73 * @disable: disables the specified clock
74 */
75 struct scmi_clk_proto_ops {
76 int (*count_get)(const struct scmi_protocol_handle *ph);
77
78 const struct scmi_clock_info *(*info_get)
79 (const struct scmi_protocol_handle *ph, u32 clk_id);
80 int (*rate_get)(const struct scmi_protocol_handle *ph, u32 clk_id,
81 u64 *rate);
82 int (*rate_set)(const struct scmi_protocol_handle *ph, u32 clk_id,
83 u64 rate);
84 int (*enable)(const struct scmi_protocol_handle *ph, u32 clk_id);
85 int (*disable)(const struct scmi_protocol_handle *ph, u32 clk_id);
86
87 ANDROID_KABI_RESERVE(1);
88 };
89
90 /**
91 * struct scmi_perf_proto_ops - represents the various operations provided
92 * by SCMI Performance Protocol
93 *
94 * @limits_set: sets limits on the performance level of a domain
95 * @limits_get: gets limits on the performance level of a domain
96 * @level_set: sets the performance level of a domain
97 * @level_get: gets the performance level of a domain
98 * @device_domain_id: gets the scmi domain id for a given device
99 * @transition_latency_get: gets the DVFS transition latency for a given device
100 * @device_opps_add: adds all the OPPs for a given device
101 * @freq_set: sets the frequency for a given device using sustained frequency
102 * to sustained performance level mapping
103 * @freq_get: gets the frequency for a given device using sustained frequency
104 * to sustained performance level mapping
105 * @est_power_get: gets the estimated power cost for a given performance domain
106 * at a given frequency
107 */
108 struct scmi_perf_proto_ops {
109 int (*limits_set)(const struct scmi_protocol_handle *ph, u32 domain,
110 u32 max_perf, u32 min_perf);
111 int (*limits_get)(const struct scmi_protocol_handle *ph, u32 domain,
112 u32 *max_perf, u32 *min_perf);
113 int (*level_set)(const struct scmi_protocol_handle *ph, u32 domain,
114 u32 level, bool poll);
115 int (*level_get)(const struct scmi_protocol_handle *ph, u32 domain,
116 u32 *level, bool poll);
117 int (*device_domain_id)(struct device *dev);
118 int (*transition_latency_get)(const struct scmi_protocol_handle *ph,
119 struct device *dev);
120 int (*device_opps_add)(const struct scmi_protocol_handle *ph,
121 struct device *dev);
122 int (*freq_set)(const struct scmi_protocol_handle *ph, u32 domain,
123 unsigned long rate, bool poll);
124 int (*freq_get)(const struct scmi_protocol_handle *ph, u32 domain,
125 unsigned long *rate, bool poll);
126 int (*est_power_get)(const struct scmi_protocol_handle *ph, u32 domain,
127 unsigned long *rate, unsigned long *power);
128 bool (*fast_switch_possible)(const struct scmi_protocol_handle *ph,
129 struct device *dev);
130 bool (*power_scale_mw_get)(const struct scmi_protocol_handle *ph);
131
132 ANDROID_KABI_RESERVE(1);
133 };
134
135 /**
136 * struct scmi_power_proto_ops - represents the various operations provided
137 * by SCMI Power Protocol
138 *
139 * @num_domains_get: get the count of power domains provided by SCMI
140 * @name_get: gets the name of a power domain
141 * @state_set: sets the power state of a power domain
142 * @state_get: gets the power state of a power domain
143 */
144 struct scmi_power_proto_ops {
145 int (*num_domains_get)(const struct scmi_protocol_handle *ph);
146 char *(*name_get)(const struct scmi_protocol_handle *ph, u32 domain);
147 #define SCMI_POWER_STATE_TYPE_SHIFT 30
148 #define SCMI_POWER_STATE_ID_MASK (BIT(28) - 1)
149 #define SCMI_POWER_STATE_PARAM(type, id) \
150 ((((type) & BIT(0)) << SCMI_POWER_STATE_TYPE_SHIFT) | \
151 ((id) & SCMI_POWER_STATE_ID_MASK))
152 #define SCMI_POWER_STATE_GENERIC_ON SCMI_POWER_STATE_PARAM(0, 0)
153 #define SCMI_POWER_STATE_GENERIC_OFF SCMI_POWER_STATE_PARAM(1, 0)
154 int (*state_set)(const struct scmi_protocol_handle *ph, u32 domain,
155 u32 state);
156 int (*state_get)(const struct scmi_protocol_handle *ph, u32 domain,
157 u32 *state);
158
159 ANDROID_KABI_RESERVE(1);
160 };
161
162 /**
163 * scmi_sensor_reading - represent a timestamped read
164 *
165 * Used by @reading_get_timestamped method.
166 *
167 * @value: The signed value sensor read.
168 * @timestamp: An unsigned timestamp for the sensor read, as provided by
169 * SCMI platform. Set to zero when not available.
170 */
171 struct scmi_sensor_reading {
172 long long value;
173 unsigned long long timestamp;
174 };
175
176 /**
177 * scmi_range_attrs - specifies a sensor or axis values' range
178 * @min_range: The minimum value which can be represented by the sensor/axis.
179 * @max_range: The maximum value which can be represented by the sensor/axis.
180 */
181 struct scmi_range_attrs {
182 long long min_range;
183 long long max_range;
184 };
185
186 /**
187 * scmi_sensor_axis_info - describes one sensor axes
188 * @id: The axes ID.
189 * @type: Axes type. Chosen amongst one of @enum scmi_sensor_class.
190 * @scale: Power-of-10 multiplier applied to the axis unit.
191 * @name: NULL-terminated string representing axes name as advertised by
192 * SCMI platform.
193 * @extended_attrs: Flag to indicate the presence of additional extended
194 * attributes for this axes.
195 * @resolution: Extended attribute representing the resolution of the axes.
196 * Set to 0 if not reported by this axes.
197 * @exponent: Extended attribute representing the power-of-10 multiplier that
198 * is applied to the resolution field. Set to 0 if not reported by
199 * this axes.
200 * @attrs: Extended attributes representing minimum and maximum values
201 * measurable by this axes. Set to 0 if not reported by this sensor.
202 */
203 struct scmi_sensor_axis_info {
204 unsigned int id;
205 unsigned int type;
206 int scale;
207 char name[SCMI_MAX_STR_SIZE];
208 bool extended_attrs;
209 unsigned int resolution;
210 int exponent;
211 struct scmi_range_attrs attrs;
212 };
213
214 /**
215 * scmi_sensor_intervals_info - describes number and type of available update
216 * intervals
217 * @segmented: Flag for segmented intervals' representation. When True there
218 * will be exactly 3 intervals in @desc, with each entry
219 * representing a member of a segment in this order:
220 * {lowest update interval, highest update interval, step size}
221 * @count: Number of intervals described in @desc.
222 * @desc: Array of @count interval descriptor bitmask represented as detailed in
223 * the SCMI specification: it can be accessed using the accompanying
224 * macros.
225 * @prealloc_pool: A minimal preallocated pool of desc entries used to avoid
226 * lesser-than-64-bytes dynamic allocation for small @count
227 * values.
228 */
229 struct scmi_sensor_intervals_info {
230 bool segmented;
231 unsigned int count;
232 #define SCMI_SENS_INTVL_SEGMENT_LOW 0
233 #define SCMI_SENS_INTVL_SEGMENT_HIGH 1
234 #define SCMI_SENS_INTVL_SEGMENT_STEP 2
235 unsigned int *desc;
236 #define SCMI_SENS_INTVL_GET_SECS(x) FIELD_GET(GENMASK(20, 5), (x))
237 #define SCMI_SENS_INTVL_GET_EXP(x) \
238 ({ \
239 int __signed_exp = FIELD_GET(GENMASK(4, 0), (x)); \
240 \
241 if (__signed_exp & BIT(4)) \
242 __signed_exp |= GENMASK(31, 5); \
243 __signed_exp; \
244 })
245 #define SCMI_MAX_PREALLOC_POOL 16
246 unsigned int prealloc_pool[SCMI_MAX_PREALLOC_POOL];
247 };
248
249 /**
250 * struct scmi_sensor_info - represents information related to one of the
251 * available sensors.
252 * @id: Sensor ID.
253 * @type: Sensor type. Chosen amongst one of @enum scmi_sensor_class.
254 * @scale: Power-of-10 multiplier applied to the sensor unit.
255 * @num_trip_points: Number of maximum configurable trip points.
256 * @async: Flag for asynchronous read support.
257 * @update: Flag for continuouos update notification support.
258 * @timestamped: Flag for timestamped read support.
259 * @tstamp_scale: Power-of-10 multiplier applied to the sensor timestamps to
260 * represent it in seconds.
261 * @num_axis: Number of supported axis if any. Reported as 0 for scalar sensors.
262 * @axis: Pointer to an array of @num_axis descriptors.
263 * @intervals: Descriptor of available update intervals.
264 * @sensor_config: A bitmask reporting the current sensor configuration as
265 * detailed in the SCMI specification: it can accessed and
266 * modified through the accompanying macros.
267 * @name: NULL-terminated string representing sensor name as advertised by
268 * SCMI platform.
269 * @extended_scalar_attrs: Flag to indicate the presence of additional extended
270 * attributes for this sensor.
271 * @sensor_power: Extended attribute representing the average power
272 * consumed by the sensor in microwatts (uW) when it is active.
273 * Reported here only for scalar sensors.
274 * Set to 0 if not reported by this sensor.
275 * @resolution: Extended attribute representing the resolution of the sensor.
276 * Reported here only for scalar sensors.
277 * Set to 0 if not reported by this sensor.
278 * @exponent: Extended attribute representing the power-of-10 multiplier that is
279 * applied to the resolution field.
280 * Reported here only for scalar sensors.
281 * Set to 0 if not reported by this sensor.
282 * @scalar_attrs: Extended attributes representing minimum and maximum
283 * measurable values by this sensor.
284 * Reported here only for scalar sensors.
285 * Set to 0 if not reported by this sensor.
286 */
287 struct scmi_sensor_info {
288 unsigned int id;
289 unsigned int type;
290 int scale;
291 unsigned int num_trip_points;
292 bool async;
293 bool update;
294 bool timestamped;
295 int tstamp_scale;
296 unsigned int num_axis;
297 struct scmi_sensor_axis_info *axis;
298 struct scmi_sensor_intervals_info intervals;
299 unsigned int sensor_config;
300 #define SCMI_SENS_CFG_UPDATE_SECS_MASK GENMASK(31, 16)
301 #define SCMI_SENS_CFG_GET_UPDATE_SECS(x) \
302 FIELD_GET(SCMI_SENS_CFG_UPDATE_SECS_MASK, (x))
303
304 #define SCMI_SENS_CFG_UPDATE_EXP_MASK GENMASK(15, 11)
305 #define SCMI_SENS_CFG_GET_UPDATE_EXP(x) \
306 ({ \
307 int __signed_exp = \
308 FIELD_GET(SCMI_SENS_CFG_UPDATE_EXP_MASK, (x)); \
309 \
310 if (__signed_exp & BIT(4)) \
311 __signed_exp |= GENMASK(31, 5); \
312 __signed_exp; \
313 })
314
315 #define SCMI_SENS_CFG_ROUND_MASK GENMASK(10, 9)
316 #define SCMI_SENS_CFG_ROUND_AUTO 2
317 #define SCMI_SENS_CFG_ROUND_UP 1
318 #define SCMI_SENS_CFG_ROUND_DOWN 0
319
320 #define SCMI_SENS_CFG_TSTAMP_ENABLED_MASK BIT(1)
321 #define SCMI_SENS_CFG_TSTAMP_ENABLE 1
322 #define SCMI_SENS_CFG_TSTAMP_DISABLE 0
323 #define SCMI_SENS_CFG_IS_TSTAMP_ENABLED(x) \
324 FIELD_GET(SCMI_SENS_CFG_TSTAMP_ENABLED_MASK, (x))
325
326 #define SCMI_SENS_CFG_SENSOR_ENABLED_MASK BIT(0)
327 #define SCMI_SENS_CFG_SENSOR_ENABLE 1
328 #define SCMI_SENS_CFG_SENSOR_DISABLE 0
329 char name[SCMI_MAX_STR_SIZE];
330 #define SCMI_SENS_CFG_IS_ENABLED(x) FIELD_GET(BIT(0), (x))
331 bool extended_scalar_attrs;
332 unsigned int sensor_power;
333 unsigned int resolution;
334 int exponent;
335 struct scmi_range_attrs scalar_attrs;
336
337 ANDROID_KABI_RESERVE(1);
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_proto_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_proto_ops {
459 int (*count_get)(const struct scmi_protocol_handle *ph);
460 const struct scmi_sensor_info *(*info_get)
461 (const struct scmi_protocol_handle *ph, u32 sensor_id);
462 int (*trip_point_config)(const struct scmi_protocol_handle *ph,
463 u32 sensor_id, u8 trip_id, u64 trip_value);
464 int (*reading_get)(const struct scmi_protocol_handle *ph, u32 sensor_id,
465 u64 *value);
466 int (*reading_get_timestamped)(const struct scmi_protocol_handle *ph,
467 u32 sensor_id, u8 count,
468 struct scmi_sensor_reading *readings);
469 int (*config_get)(const struct scmi_protocol_handle *ph,
470 u32 sensor_id, u32 *sensor_config);
471 int (*config_set)(const struct scmi_protocol_handle *ph,
472 u32 sensor_id, u32 sensor_config);
473
474 ANDROID_KABI_RESERVE(1);
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 */
488 struct scmi_reset_proto_ops {
489 int (*num_domains_get)(const struct scmi_protocol_handle *ph);
490 char *(*name_get)(const struct scmi_protocol_handle *ph, u32 domain);
491 int (*latency_get)(const struct scmi_protocol_handle *ph, u32 domain);
492 int (*reset)(const struct scmi_protocol_handle *ph, u32 domain);
493 int (*assert)(const struct scmi_protocol_handle *ph, u32 domain);
494 int (*deassert)(const struct scmi_protocol_handle *ph, u32 domain);
495
496 ANDROID_KABI_RESERVE(1);
497 };
498
499 /**
500 * struct scmi_voltage_info - describe one available SCMI Voltage Domain
501 *
502 * @id: the domain ID as advertised by the platform
503 * @segmented: defines the layout of the entries of array @levels_uv.
504 * - when True the entries are to be interpreted as triplets,
505 * each defining a segment representing a range of equally
506 * space voltages: <lowest_volts>, <highest_volt>, <step_uV>
507 * - when False the entries simply represent a single discrete
508 * supported voltage level
509 * @negative_volts_allowed: True if any of the entries of @levels_uv represent
510 * a negative voltage.
511 * @attributes: represents Voltage Domain advertised attributes
512 * @name: name assigned to the Voltage Domain by platform
513 * @num_levels: number of total entries in @levels_uv.
514 * @levels_uv: array of entries describing the available voltage levels for
515 * this domain.
516 */
517 struct scmi_voltage_info {
518 unsigned int id;
519 bool segmented;
520 bool negative_volts_allowed;
521 unsigned int attributes;
522 char name[SCMI_MAX_STR_SIZE];
523 unsigned int num_levels;
524 #define SCMI_VOLTAGE_SEGMENT_LOW 0
525 #define SCMI_VOLTAGE_SEGMENT_HIGH 1
526 #define SCMI_VOLTAGE_SEGMENT_STEP 2
527 int *levels_uv;
528 };
529
530 /**
531 * struct scmi_voltage_proto_ops - represents the various operations provided
532 * by SCMI Voltage Protocol
533 *
534 * @num_domains_get: get the count of voltage domains provided by SCMI
535 * @info_get: get the information of the specified domain
536 * @config_set: set the config for the specified domain
537 * @config_get: get the config of the specified domain
538 * @level_set: set the voltage level for the specified domain
539 * @level_get: get the voltage level of the specified domain
540 */
541 struct scmi_voltage_proto_ops {
542 int (*num_domains_get)(const struct scmi_protocol_handle *ph);
543 const struct scmi_voltage_info __must_check *(*info_get)
544 (const struct scmi_protocol_handle *ph, u32 domain_id);
545 int (*config_set)(const struct scmi_protocol_handle *ph, u32 domain_id,
546 u32 config);
547 #define SCMI_VOLTAGE_ARCH_STATE_OFF 0x0
548 #define SCMI_VOLTAGE_ARCH_STATE_ON 0x7
549 int (*config_get)(const struct scmi_protocol_handle *ph, u32 domain_id,
550 u32 *config);
551 int (*level_set)(const struct scmi_protocol_handle *ph, u32 domain_id,
552 u32 flags, s32 volt_uV);
553 int (*level_get)(const struct scmi_protocol_handle *ph, u32 domain_id,
554 s32 *volt_uV);
555 };
556
557 /**
558 * struct scmi_notify_ops - represents notifications' operations provided by
559 * SCMI core
560 * @devm_register_event_notifier: Managed registration of a notifier_block for
561 * the requested event
562 * @devm_unregister_event_notifier: Managed unregistration of a notifier_block
563 * for the requested event
564 * @register_event_notifier: Register a notifier_block for the requested event
565 * @unregister_event_notifier: Unregister a notifier_block for the requested
566 * event
567 *
568 * A user can register/unregister its own notifier_block against the wanted
569 * platform instance regarding the desired event identified by the
570 * tuple: (proto_id, evt_id, src_id) using the provided register/unregister
571 * interface where:
572 *
573 * @sdev: The scmi_device to use when calling the devres managed ops devm_
574 * @handle: The handle identifying the platform instance to use, when not
575 * calling the managed ops devm_
576 * @proto_id: The protocol ID as in SCMI Specification
577 * @evt_id: The message ID of the desired event as in SCMI Specification
578 * @src_id: A pointer to the desired source ID if different sources are
579 * possible for the protocol (like domain_id, sensor_id...etc)
580 *
581 * @src_id can be provided as NULL if it simply does NOT make sense for
582 * the protocol at hand, OR if the user is explicitly interested in
583 * receiving notifications from ANY existent source associated to the
584 * specified proto_id / evt_id.
585 *
586 * Received notifications are finally delivered to the registered users,
587 * invoking the callback provided with the notifier_block *nb as follows:
588 *
589 * int user_cb(nb, evt_id, report)
590 *
591 * with:
592 *
593 * @nb: The notifier block provided by the user
594 * @evt_id: The message ID of the delivered event
595 * @report: A custom struct describing the specific event delivered
596 */
597 struct scmi_notify_ops {
598 int (*devm_register_event_notifier)(struct scmi_device *sdev,
599 u8 proto_id, u8 evt_id, u32 *src_id,
600 struct notifier_block *nb);
601 int (*devm_unregister_event_notifier)(struct scmi_device *sdev,
602 u8 proto_id, u8 evt_id,
603 u32 *src_id,
604 struct notifier_block *nb);
605 int (*register_event_notifier)(const struct scmi_handle *handle,
606 u8 proto_id, u8 evt_id, u32 *src_id,
607 struct notifier_block *nb);
608 int (*unregister_event_notifier)(const struct scmi_handle *handle,
609 u8 proto_id, u8 evt_id, u32 *src_id,
610 struct notifier_block *nb);
611 };
612
613 /**
614 * struct scmi_handle - Handle returned to ARM SCMI clients for usage.
615 *
616 * @dev: pointer to the SCMI device
617 * @version: pointer to the structure containing SCMI version information
618 * @devm_acquire_protocol: devres managed method to get hold of a protocol,
619 * causing its initialization and related resource
620 * accounting
621 * @devm_get_protocol: devres managed method to acquire a protocol, causing
622 * its initialization and resource accounting, while getting
623 * protocol specific operations and a dedicated protocol
624 * handler
625 * @devm_put_protocol: devres managed method to release a protocol acquired
626 * with devm_acquire/get_protocol
627 * @notify_ops: pointer to set of notifications related operations
628 */
629 struct scmi_handle {
630 struct device *dev;
631 struct scmi_revision_info *version;
632
633 int __must_check (*devm_acquire_protocol)(struct scmi_device *sdev,
634 u8 proto);
635 const void __must_check *
636 (*devm_get_protocol)(struct scmi_device *sdev, u8 proto,
637 struct scmi_protocol_handle **ph);
638 void (*devm_put_protocol)(struct scmi_device *sdev, u8 proto);
639
640 const struct scmi_notify_ops *notify_ops;
641
642 ANDROID_KABI_RESERVE(1);
643 };
644
645 enum scmi_std_protocol {
646 SCMI_PROTOCOL_BASE = 0x10,
647 SCMI_PROTOCOL_POWER = 0x11,
648 SCMI_PROTOCOL_SYSTEM = 0x12,
649 SCMI_PROTOCOL_PERF = 0x13,
650 SCMI_PROTOCOL_CLOCK = 0x14,
651 SCMI_PROTOCOL_SENSOR = 0x15,
652 SCMI_PROTOCOL_RESET = 0x16,
653 SCMI_PROTOCOL_VOLTAGE = 0x17,
654 };
655
656 enum scmi_system_events {
657 SCMI_SYSTEM_SHUTDOWN,
658 SCMI_SYSTEM_COLDRESET,
659 SCMI_SYSTEM_WARMRESET,
660 SCMI_SYSTEM_POWERUP,
661 SCMI_SYSTEM_SUSPEND,
662 SCMI_SYSTEM_MAX
663 };
664
665 struct scmi_device {
666 u32 id;
667 u8 protocol_id;
668 const char *name;
669 struct device dev;
670 struct scmi_handle *handle;
671
672 ANDROID_KABI_RESERVE(1);
673 };
674
675 #define to_scmi_dev(d) container_of(d, struct scmi_device, dev)
676
677 struct scmi_device *
678 scmi_device_create(struct device_node *np, struct device *parent, int protocol,
679 const char *name);
680 void scmi_device_destroy(struct scmi_device *scmi_dev);
681
682 struct scmi_device_id {
683 u8 protocol_id;
684 const char *name;
685 };
686
687 struct scmi_driver {
688 const char *name;
689 int (*probe)(struct scmi_device *sdev);
690 void (*remove)(struct scmi_device *sdev);
691 const struct scmi_device_id *id_table;
692
693 struct device_driver driver;
694 };
695
696 #define to_scmi_driver(d) container_of(d, struct scmi_driver, driver)
697
698 #if IS_REACHABLE(CONFIG_ARM_SCMI_PROTOCOL)
699 int scmi_driver_register(struct scmi_driver *driver,
700 struct module *owner, const char *mod_name);
701 void scmi_driver_unregister(struct scmi_driver *driver);
702 #else
703 static inline int
scmi_driver_register(struct scmi_driver * driver,struct module * owner,const char * mod_name)704 scmi_driver_register(struct scmi_driver *driver, struct module *owner,
705 const char *mod_name)
706 {
707 return -EINVAL;
708 }
709
scmi_driver_unregister(struct scmi_driver * driver)710 static inline void scmi_driver_unregister(struct scmi_driver *driver) {}
711 #endif /* CONFIG_ARM_SCMI_PROTOCOL */
712
713 #define scmi_register(driver) \
714 scmi_driver_register(driver, THIS_MODULE, KBUILD_MODNAME)
715 #define scmi_unregister(driver) \
716 scmi_driver_unregister(driver)
717
718 /**
719 * module_scmi_driver() - Helper macro for registering a scmi driver
720 * @__scmi_driver: scmi_driver structure
721 *
722 * Helper macro for scmi drivers to set up proper module init / exit
723 * functions. Replaces module_init() and module_exit() and keeps people from
724 * printing pointless things to the kernel log when their driver is loaded.
725 */
726 #define module_scmi_driver(__scmi_driver) \
727 module_driver(__scmi_driver, scmi_register, scmi_unregister)
728
729 /**
730 * module_scmi_protocol() - Helper macro for registering a scmi protocol
731 * @__scmi_protocol: scmi_protocol structure
732 *
733 * Helper macro for scmi drivers to set up proper module init / exit
734 * functions. Replaces module_init() and module_exit() and keeps people from
735 * printing pointless things to the kernel log when their driver is loaded.
736 */
737 #define module_scmi_protocol(__scmi_protocol) \
738 module_driver(__scmi_protocol, \
739 scmi_protocol_register, scmi_protocol_unregister)
740
741 struct scmi_protocol;
742 int scmi_protocol_register(const struct scmi_protocol *proto);
743 void scmi_protocol_unregister(const struct scmi_protocol *proto);
744
745 /* SCMI Notification API - Custom Event Reports */
746 enum scmi_notification_events {
747 SCMI_EVENT_POWER_STATE_CHANGED = 0x0,
748 SCMI_EVENT_PERFORMANCE_LIMITS_CHANGED = 0x0,
749 SCMI_EVENT_PERFORMANCE_LEVEL_CHANGED = 0x1,
750 SCMI_EVENT_SENSOR_TRIP_POINT_EVENT = 0x0,
751 SCMI_EVENT_SENSOR_UPDATE = 0x1,
752 SCMI_EVENT_RESET_ISSUED = 0x0,
753 SCMI_EVENT_BASE_ERROR_EVENT = 0x0,
754 SCMI_EVENT_SYSTEM_POWER_STATE_NOTIFIER = 0x0,
755 };
756
757 struct scmi_power_state_changed_report {
758 ktime_t timestamp;
759 unsigned int agent_id;
760 unsigned int domain_id;
761 unsigned int power_state;
762 };
763
764 struct scmi_system_power_state_notifier_report {
765 ktime_t timestamp;
766 unsigned int agent_id;
767 unsigned int flags;
768 unsigned int system_state;
769 };
770
771 struct scmi_perf_limits_report {
772 ktime_t timestamp;
773 unsigned int agent_id;
774 unsigned int domain_id;
775 unsigned int range_max;
776 unsigned int range_min;
777 };
778
779 struct scmi_perf_level_report {
780 ktime_t timestamp;
781 unsigned int agent_id;
782 unsigned int domain_id;
783 unsigned int performance_level;
784 };
785
786 struct scmi_sensor_trip_point_report {
787 ktime_t timestamp;
788 unsigned int agent_id;
789 unsigned int sensor_id;
790 unsigned int trip_point_desc;
791 };
792
793 struct scmi_sensor_update_report {
794 ktime_t timestamp;
795 unsigned int agent_id;
796 unsigned int sensor_id;
797 unsigned int readings_count;
798 struct scmi_sensor_reading readings[];
799 };
800
801 struct scmi_reset_issued_report {
802 ktime_t timestamp;
803 unsigned int agent_id;
804 unsigned int domain_id;
805 unsigned int reset_state;
806 };
807
808 struct scmi_base_error_report {
809 ktime_t timestamp;
810 unsigned int agent_id;
811 bool fatal;
812 unsigned int cmd_count;
813 unsigned long long reports[];
814 };
815
816 #endif /* _LINUX_SCMI_PROTOCOL_H */
817