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