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