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