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