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