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