xref: /openbmc/linux/include/linux/scmi_protocol.h (revision dcabb06bf127b3e0d3fbc94a2b65dd56c2725851)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * SCMI Message Protocol driver header
4  *
5  * Copyright (C) 2018 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	16
17 #define SCMI_MAX_NUM_RATES	16
18 
19 /**
20  * struct scmi_revision_info - version information structure
21  *
22  * @major_ver: Major ABI version. Change here implies risk of backward
23  *	compatibility break.
24  * @minor_ver: Minor ABI version. Change here implies new feature addition,
25  *	or compatible change in ABI.
26  * @num_protocols: Number of protocols that are implemented, excluding the
27  *	base protocol.
28  * @num_agents: Number of agents in the system.
29  * @impl_ver: A vendor-specific implementation version.
30  * @vendor_id: A vendor identifier(Null terminated ASCII string)
31  * @sub_vendor_id: A sub-vendor identifier(Null terminated ASCII string)
32  */
33 struct scmi_revision_info {
34 	u16 major_ver;
35 	u16 minor_ver;
36 	u8 num_protocols;
37 	u8 num_agents;
38 	u32 impl_ver;
39 	char vendor_id[SCMI_MAX_STR_SIZE];
40 	char sub_vendor_id[SCMI_MAX_STR_SIZE];
41 };
42 
43 struct scmi_clock_info {
44 	char name[SCMI_MAX_STR_SIZE];
45 	bool rate_discrete;
46 	union {
47 		struct {
48 			int num_rates;
49 			u64 rates[SCMI_MAX_NUM_RATES];
50 		} list;
51 		struct {
52 			u64 min_rate;
53 			u64 max_rate;
54 			u64 step_size;
55 		} range;
56 	};
57 };
58 
59 struct scmi_handle;
60 
61 /**
62  * struct scmi_clk_ops - represents the various operations provided
63  *	by SCMI Clock Protocol
64  *
65  * @count_get: get the count of clocks provided by SCMI
66  * @info_get: get the information of the specified clock
67  * @rate_get: request the current clock rate of a clock
68  * @rate_set: set the clock rate of a clock
69  * @enable: enables the specified clock
70  * @disable: disables the specified clock
71  */
72 struct scmi_clk_ops {
73 	int (*count_get)(const struct scmi_handle *handle);
74 
75 	const struct scmi_clock_info *(*info_get)
76 		(const struct scmi_handle *handle, u32 clk_id);
77 	int (*rate_get)(const struct scmi_handle *handle, u32 clk_id,
78 			u64 *rate);
79 	int (*rate_set)(const struct scmi_handle *handle, u32 clk_id,
80 			u64 rate);
81 	int (*enable)(const struct scmi_handle *handle, u32 clk_id);
82 	int (*disable)(const struct scmi_handle *handle, u32 clk_id);
83 };
84 
85 /**
86  * struct scmi_perf_ops - represents the various operations provided
87  *	by SCMI Performance Protocol
88  *
89  * @limits_set: sets limits on the performance level of a domain
90  * @limits_get: gets limits on the performance level of a domain
91  * @level_set: sets the performance level of a domain
92  * @level_get: gets the performance level of a domain
93  * @device_domain_id: gets the scmi domain id for a given device
94  * @transition_latency_get: gets the DVFS transition latency for a given device
95  * @device_opps_add: adds all the OPPs for a given device
96  * @freq_set: sets the frequency for a given device using sustained frequency
97  *	to sustained performance level mapping
98  * @freq_get: gets the frequency for a given device using sustained frequency
99  *	to sustained performance level mapping
100  * @est_power_get: gets the estimated power cost for a given performance domain
101  *	at a given frequency
102  */
103 struct scmi_perf_ops {
104 	int (*limits_set)(const struct scmi_handle *handle, u32 domain,
105 			  u32 max_perf, u32 min_perf);
106 	int (*limits_get)(const struct scmi_handle *handle, u32 domain,
107 			  u32 *max_perf, u32 *min_perf);
108 	int (*level_set)(const struct scmi_handle *handle, u32 domain,
109 			 u32 level, bool poll);
110 	int (*level_get)(const struct scmi_handle *handle, u32 domain,
111 			 u32 *level, bool poll);
112 	int (*device_domain_id)(struct device *dev);
113 	int (*transition_latency_get)(const struct scmi_handle *handle,
114 				      struct device *dev);
115 	int (*device_opps_add)(const struct scmi_handle *handle,
116 			       struct device *dev);
117 	int (*freq_set)(const struct scmi_handle *handle, u32 domain,
118 			unsigned long rate, bool poll);
119 	int (*freq_get)(const struct scmi_handle *handle, u32 domain,
120 			unsigned long *rate, bool poll);
121 	int (*est_power_get)(const struct scmi_handle *handle, u32 domain,
122 			     unsigned long *rate, unsigned long *power);
123 	bool (*fast_switch_possible)(const struct scmi_handle *handle,
124 				     struct device *dev);
125 	bool (*power_scale_mw_get)(const struct scmi_handle *handle);
126 };
127 
128 /**
129  * struct scmi_power_ops - represents the various operations provided
130  *	by SCMI Power Protocol
131  *
132  * @num_domains_get: get the count of power domains provided by SCMI
133  * @name_get: gets the name of a power domain
134  * @state_set: sets the power state of a power domain
135  * @state_get: gets the power state of a power domain
136  */
137 struct scmi_power_ops {
138 	int (*num_domains_get)(const struct scmi_handle *handle);
139 	char *(*name_get)(const struct scmi_handle *handle, u32 domain);
140 #define SCMI_POWER_STATE_TYPE_SHIFT	30
141 #define SCMI_POWER_STATE_ID_MASK	(BIT(28) - 1)
142 #define SCMI_POWER_STATE_PARAM(type, id) \
143 	((((type) & BIT(0)) << SCMI_POWER_STATE_TYPE_SHIFT) | \
144 		((id) & SCMI_POWER_STATE_ID_MASK))
145 #define SCMI_POWER_STATE_GENERIC_ON	SCMI_POWER_STATE_PARAM(0, 0)
146 #define SCMI_POWER_STATE_GENERIC_OFF	SCMI_POWER_STATE_PARAM(1, 0)
147 	int (*state_set)(const struct scmi_handle *handle, u32 domain,
148 			 u32 state);
149 	int (*state_get)(const struct scmi_handle *handle, u32 domain,
150 			 u32 *state);
151 };
152 
153 /**
154  * scmi_sensor_reading  - represent a timestamped read
155  *
156  * Used by @reading_get_timestamped method.
157  *
158  * @value: The signed value sensor read.
159  * @timestamp: An unsigned timestamp for the sensor read, as provided by
160  *	       SCMI platform. Set to zero when not available.
161  */
162 struct scmi_sensor_reading {
163 	long long value;
164 	unsigned long long timestamp;
165 };
166 
167 /**
168  * scmi_range_attrs  - specifies a sensor or axis values' range
169  * @min_range: The minimum value which can be represented by the sensor/axis.
170  * @max_range: The maximum value which can be represented by the sensor/axis.
171  */
172 struct scmi_range_attrs {
173 	long long min_range;
174 	long long max_range;
175 };
176 
177 /**
178  * scmi_sensor_axis_info  - describes one sensor axes
179  * @id: The axes ID.
180  * @type: Axes type. Chosen amongst one of @enum scmi_sensor_class.
181  * @scale: Power-of-10 multiplier applied to the axis unit.
182  * @name: NULL-terminated string representing axes name as advertised by
183  *	  SCMI platform.
184  * @extended_attrs: Flag to indicate the presence of additional extended
185  *		    attributes for this axes.
186  * @resolution: Extended attribute representing the resolution of the axes.
187  *		Set to 0 if not reported by this axes.
188  * @exponent: Extended attribute representing the power-of-10 multiplier that
189  *	      is applied to the resolution field. Set to 0 if not reported by
190  *	      this axes.
191  * @attrs: Extended attributes representing minimum and maximum values
192  *	   measurable by this axes. Set to 0 if not reported by this sensor.
193  */
194 struct scmi_sensor_axis_info {
195 	unsigned int id;
196 	unsigned int type;
197 	int scale;
198 	char name[SCMI_MAX_STR_SIZE];
199 	bool extended_attrs;
200 	unsigned int resolution;
201 	int exponent;
202 	struct scmi_range_attrs attrs;
203 };
204 
205 /**
206  * scmi_sensor_intervals_info  - describes number and type of available update
207  * intervals
208  * @segmented: Flag for segmented intervals' representation. When True there
209  *	       will be exactly 3 intervals in @desc, with each entry
210  *	       representing a member of a segment in this order:
211  *	       {lowest update interval, highest update interval, step size}
212  * @count: Number of intervals described in @desc.
213  * @desc: Array of @count interval descriptor bitmask represented as detailed in
214  *	  the SCMI specification: it can be accessed using the accompanying
215  *	  macros.
216  * @prealloc_pool: A minimal preallocated pool of desc entries used to avoid
217  *		   lesser-than-64-bytes dynamic allocation for small @count
218  *		   values.
219  */
220 struct scmi_sensor_intervals_info {
221 	bool segmented;
222 	unsigned int count;
223 #define SCMI_SENS_INTVL_SEGMENT_LOW	0
224 #define SCMI_SENS_INTVL_SEGMENT_HIGH	1
225 #define SCMI_SENS_INTVL_SEGMENT_STEP	2
226 	unsigned int *desc;
227 #define SCMI_SENS_INTVL_GET_SECS(x)		FIELD_GET(GENMASK(20, 5), (x))
228 #define SCMI_SENS_INTVL_GET_EXP(x)					\
229 	({								\
230 		int __signed_exp = FIELD_GET(GENMASK(4, 0), (x));	\
231 									\
232 		if (__signed_exp & BIT(4))				\
233 			__signed_exp |= GENMASK(31, 5);			\
234 		__signed_exp;						\
235 	})
236 #define SCMI_MAX_PREALLOC_POOL			16
237 	unsigned int prealloc_pool[SCMI_MAX_PREALLOC_POOL];
238 };
239 
240 /**
241  * struct scmi_sensor_info - represents information related to one of the
242  * available sensors.
243  * @id: Sensor ID.
244  * @type: Sensor type. Chosen amongst one of @enum scmi_sensor_class.
245  * @scale: Power-of-10 multiplier applied to the sensor unit.
246  * @num_trip_points: Number of maximum configurable trip points.
247  * @async: Flag for asynchronous read support.
248  * @update: Flag for continuouos update notification support.
249  * @timestamped: Flag for timestamped read support.
250  * @tstamp_scale: Power-of-10 multiplier applied to the sensor timestamps to
251  *		  represent it in seconds.
252  * @num_axis: Number of supported axis if any. Reported as 0 for scalar sensors.
253  * @axis: Pointer to an array of @num_axis descriptors.
254  * @intervals: Descriptor of available update intervals.
255  * @sensor_config: A bitmask reporting the current sensor configuration as
256  *		   detailed in the SCMI specification: it can accessed and
257  *		   modified through the accompanying macros.
258  * @name: NULL-terminated string representing sensor name as advertised by
259  *	  SCMI platform.
260  * @extended_scalar_attrs: Flag to indicate the presence of additional extended
261  *			   attributes for this sensor.
262  * @sensor_power: Extended attribute representing the average power
263  *		  consumed by the sensor in microwatts (uW) when it is active.
264  *		  Reported here only for scalar sensors.
265  *		  Set to 0 if not reported by this sensor.
266  * @resolution: Extended attribute representing the resolution of the sensor.
267  *		Reported here only for scalar sensors.
268  *		Set to 0 if not reported by this sensor.
269  * @exponent: Extended attribute representing the power-of-10 multiplier that is
270  *	      applied to the resolution field.
271  *	      Reported here only for scalar sensors.
272  *	      Set to 0 if not reported by this sensor.
273  * @scalar_attrs: Extended attributes representing minimum and maximum
274  *		  measurable values by this sensor.
275  *		  Reported here only for scalar sensors.
276  *		  Set to 0 if not reported by this sensor.
277  */
278 struct scmi_sensor_info {
279 	unsigned int id;
280 	unsigned int type;
281 	int scale;
282 	unsigned int num_trip_points;
283 	bool async;
284 	bool update;
285 	bool timestamped;
286 	int tstamp_scale;
287 	unsigned int num_axis;
288 	struct scmi_sensor_axis_info *axis;
289 	struct scmi_sensor_intervals_info intervals;
290 	unsigned int sensor_config;
291 #define SCMI_SENS_CFG_UPDATE_SECS_MASK		GENMASK(31, 16)
292 #define SCMI_SENS_CFG_GET_UPDATE_SECS(x)				\
293 	FIELD_GET(SCMI_SENS_CFG_UPDATE_SECS_MASK, (x))
294 
295 #define SCMI_SENS_CFG_UPDATE_EXP_MASK		GENMASK(15, 11)
296 #define SCMI_SENS_CFG_GET_UPDATE_EXP(x)					\
297 	({								\
298 		int __signed_exp =					\
299 			FIELD_GET(SCMI_SENS_CFG_UPDATE_EXP_MASK, (x));	\
300 									\
301 		if (__signed_exp & BIT(4))				\
302 			__signed_exp |= GENMASK(31, 5);			\
303 		__signed_exp;						\
304 	})
305 
306 #define SCMI_SENS_CFG_ROUND_MASK		GENMASK(10, 9)
307 #define SCMI_SENS_CFG_ROUND_AUTO		2
308 #define SCMI_SENS_CFG_ROUND_UP			1
309 #define SCMI_SENS_CFG_ROUND_DOWN		0
310 
311 #define SCMI_SENS_CFG_TSTAMP_ENABLED_MASK	BIT(1)
312 #define SCMI_SENS_CFG_TSTAMP_ENABLE		1
313 #define SCMI_SENS_CFG_TSTAMP_DISABLE		0
314 #define SCMI_SENS_CFG_IS_TSTAMP_ENABLED(x)				\
315 	FIELD_GET(SCMI_SENS_CFG_TSTAMP_ENABLED_MASK, (x))
316 
317 #define SCMI_SENS_CFG_SENSOR_ENABLED_MASK	BIT(0)
318 #define SCMI_SENS_CFG_SENSOR_ENABLE		1
319 #define SCMI_SENS_CFG_SENSOR_DISABLE		0
320 	char name[SCMI_MAX_STR_SIZE];
321 #define SCMI_SENS_CFG_IS_ENABLED(x)		FIELD_GET(BIT(0), (x))
322 	bool extended_scalar_attrs;
323 	unsigned int sensor_power;
324 	unsigned int resolution;
325 	int exponent;
326 	struct scmi_range_attrs scalar_attrs;
327 };
328 
329 /*
330  * Partial list from Distributed Management Task Force (DMTF) specification:
331  * DSP0249 (Platform Level Data Model specification)
332  */
333 enum scmi_sensor_class {
334 	NONE = 0x0,
335 	UNSPEC = 0x1,
336 	TEMPERATURE_C = 0x2,
337 	TEMPERATURE_F = 0x3,
338 	TEMPERATURE_K = 0x4,
339 	VOLTAGE = 0x5,
340 	CURRENT = 0x6,
341 	POWER = 0x7,
342 	ENERGY = 0x8,
343 	CHARGE = 0x9,
344 	VOLTAMPERE = 0xA,
345 	NITS = 0xB,
346 	LUMENS = 0xC,
347 	LUX = 0xD,
348 	CANDELAS = 0xE,
349 	KPA = 0xF,
350 	PSI = 0x10,
351 	NEWTON = 0x11,
352 	CFM = 0x12,
353 	RPM = 0x13,
354 	HERTZ = 0x14,
355 	SECS = 0x15,
356 	MINS = 0x16,
357 	HOURS = 0x17,
358 	DAYS = 0x18,
359 	WEEKS = 0x19,
360 	MILS = 0x1A,
361 	INCHES = 0x1B,
362 	FEET = 0x1C,
363 	CUBIC_INCHES = 0x1D,
364 	CUBIC_FEET = 0x1E,
365 	METERS = 0x1F,
366 	CUBIC_CM = 0x20,
367 	CUBIC_METERS = 0x21,
368 	LITERS = 0x22,
369 	FLUID_OUNCES = 0x23,
370 	RADIANS = 0x24,
371 	STERADIANS = 0x25,
372 	REVOLUTIONS = 0x26,
373 	CYCLES = 0x27,
374 	GRAVITIES = 0x28,
375 	OUNCES = 0x29,
376 	POUNDS = 0x2A,
377 	FOOT_POUNDS = 0x2B,
378 	OUNCE_INCHES = 0x2C,
379 	GAUSS = 0x2D,
380 	GILBERTS = 0x2E,
381 	HENRIES = 0x2F,
382 	FARADS = 0x30,
383 	OHMS = 0x31,
384 	SIEMENS = 0x32,
385 	MOLES = 0x33,
386 	BECQUERELS = 0x34,
387 	PPM = 0x35,
388 	DECIBELS = 0x36,
389 	DBA = 0x37,
390 	DBC = 0x38,
391 	GRAYS = 0x39,
392 	SIEVERTS = 0x3A,
393 	COLOR_TEMP_K = 0x3B,
394 	BITS = 0x3C,
395 	BYTES = 0x3D,
396 	WORDS = 0x3E,
397 	DWORDS = 0x3F,
398 	QWORDS = 0x40,
399 	PERCENTAGE = 0x41,
400 	PASCALS = 0x42,
401 	COUNTS = 0x43,
402 	GRAMS = 0x44,
403 	NEWTON_METERS = 0x45,
404 	HITS = 0x46,
405 	MISSES = 0x47,
406 	RETRIES = 0x48,
407 	OVERRUNS = 0x49,
408 	UNDERRUNS = 0x4A,
409 	COLLISIONS = 0x4B,
410 	PACKETS = 0x4C,
411 	MESSAGES = 0x4D,
412 	CHARS = 0x4E,
413 	ERRORS = 0x4F,
414 	CORRECTED_ERRS = 0x50,
415 	UNCORRECTABLE_ERRS = 0x51,
416 	SQ_MILS = 0x52,
417 	SQ_INCHES = 0x53,
418 	SQ_FEET = 0x54,
419 	SQ_CM = 0x55,
420 	SQ_METERS = 0x56,
421 	RADIANS_SEC = 0x57,
422 	BPM = 0x58,
423 	METERS_SEC_SQUARED = 0x59,
424 	METERS_SEC = 0x5A,
425 	CUBIC_METERS_SEC = 0x5B,
426 	MM_MERCURY = 0x5C,
427 	RADIANS_SEC_SQUARED = 0x5D,
428 	OEM_UNIT = 0xFF
429 };
430 
431 /**
432  * struct scmi_sensor_ops - represents the various operations provided
433  *	by SCMI Sensor Protocol
434  *
435  * @count_get: get the count of sensors provided by SCMI
436  * @info_get: get the information of the specified sensor
437  * @trip_point_config: selects and configures a trip-point of interest
438  * @reading_get: gets the current value of the sensor
439  * @reading_get_timestamped: gets the current value and timestamp, when
440  *			     available, of the sensor. (as of v3.0 spec)
441  *			     Supports multi-axis sensors for sensors which
442  *			     supports it and if the @reading array size of
443  *			     @count entry equals the sensor num_axis
444  * @config_get: Get sensor current configuration
445  * @config_set: Set sensor current configuration
446  */
447 struct scmi_sensor_ops {
448 	int (*count_get)(const struct scmi_handle *handle);
449 	const struct scmi_sensor_info *(*info_get)
450 		(const struct scmi_handle *handle, u32 sensor_id);
451 	int (*trip_point_config)(const struct scmi_handle *handle,
452 				 u32 sensor_id, u8 trip_id, u64 trip_value);
453 	int (*reading_get)(const struct scmi_handle *handle, u32 sensor_id,
454 			   u64 *value);
455 	int (*reading_get_timestamped)(const struct scmi_handle *handle,
456 				       u32 sensor_id, u8 count,
457 				       struct scmi_sensor_reading *readings);
458 	int (*config_get)(const struct scmi_handle *handle,
459 			  u32 sensor_id, u32 *sensor_config);
460 	int (*config_set)(const struct scmi_handle *handle,
461 			  u32 sensor_id, u32 sensor_config);
462 };
463 
464 /**
465  * struct scmi_reset_ops - represents the various operations provided
466  *	by SCMI Reset Protocol
467  *
468  * @num_domains_get: get the count of reset domains provided by SCMI
469  * @name_get: gets the name of a reset domain
470  * @latency_get: gets the reset latency for the specified reset domain
471  * @reset: resets the specified reset domain
472  * @assert: explicitly assert reset signal of the specified reset domain
473  * @deassert: explicitly deassert reset signal of the specified reset domain
474  */
475 struct scmi_reset_ops {
476 	int (*num_domains_get)(const struct scmi_handle *handle);
477 	char *(*name_get)(const struct scmi_handle *handle, u32 domain);
478 	int (*latency_get)(const struct scmi_handle *handle, u32 domain);
479 	int (*reset)(const struct scmi_handle *handle, u32 domain);
480 	int (*assert)(const struct scmi_handle *handle, u32 domain);
481 	int (*deassert)(const struct scmi_handle *handle, u32 domain);
482 };
483 
484 /**
485  * struct scmi_voltage_info - describe one available SCMI Voltage Domain
486  *
487  * @id: the domain ID as advertised by the platform
488  * @segmented: defines the layout of the entries of array @levels_uv.
489  *	       - when True the entries are to be interpreted as triplets,
490  *	         each defining a segment representing a range of equally
491  *	         space voltages: <lowest_volts>, <highest_volt>, <step_uV>
492  *	       - when False the entries simply represent a single discrete
493  *	         supported voltage level
494  * @negative_volts_allowed: True if any of the entries of @levels_uv represent
495  *			    a negative voltage.
496  * @attributes: represents Voltage Domain advertised attributes
497  * @name: name assigned to the Voltage Domain by platform
498  * @num_levels: number of total entries in @levels_uv.
499  * @levels_uv: array of entries describing the available voltage levels for
500  *	       this domain.
501  */
502 struct scmi_voltage_info {
503 	unsigned int id;
504 	bool segmented;
505 	bool negative_volts_allowed;
506 	unsigned int attributes;
507 	char name[SCMI_MAX_STR_SIZE];
508 	unsigned int num_levels;
509 #define SCMI_VOLTAGE_SEGMENT_LOW	0
510 #define SCMI_VOLTAGE_SEGMENT_HIGH	1
511 #define SCMI_VOLTAGE_SEGMENT_STEP	2
512 	int *levels_uv;
513 };
514 
515 /**
516  * struct scmi_voltage_ops - represents the various operations provided
517  * by SCMI Voltage Protocol
518  *
519  * @num_domains_get: get the count of voltage domains provided by SCMI
520  * @info_get: get the information of the specified domain
521  * @config_set: set the config for the specified domain
522  * @config_get: get the config of the specified domain
523  * @level_set: set the voltage level for the specified domain
524  * @level_get: get the voltage level of the specified domain
525  */
526 struct scmi_voltage_ops {
527 	int (*num_domains_get)(const struct scmi_handle *handle);
528 	const struct scmi_voltage_info __must_check *(*info_get)
529 		(const struct scmi_handle *handle, u32 domain_id);
530 	int (*config_set)(const struct scmi_handle *handle, u32 domain_id,
531 			  u32 config);
532 #define	SCMI_VOLTAGE_ARCH_STATE_OFF		0x0
533 #define	SCMI_VOLTAGE_ARCH_STATE_ON		0x7
534 	int (*config_get)(const struct scmi_handle *handle, u32 domain_id,
535 			  u32 *config);
536 	int (*level_set)(const struct scmi_handle *handle, u32 domain_id,
537 			 u32 flags, s32 volt_uV);
538 	int (*level_get)(const struct scmi_handle *handle, u32 domain_id,
539 			 s32 *volt_uV);
540 };
541 
542 /**
543  * struct scmi_notify_ops  - represents notifications' operations provided by
544  * SCMI core
545  * @register_event_notifier: Register a notifier_block for the requested event
546  * @unregister_event_notifier: Unregister a notifier_block for the requested
547  *			       event
548  *
549  * A user can register/unregister its own notifier_block against the wanted
550  * platform instance regarding the desired event identified by the
551  * tuple: (proto_id, evt_id, src_id) using the provided register/unregister
552  * interface where:
553  *
554  * @handle: The handle identifying the platform instance to use
555  * @proto_id: The protocol ID as in SCMI Specification
556  * @evt_id: The message ID of the desired event as in SCMI Specification
557  * @src_id: A pointer to the desired source ID if different sources are
558  *	    possible for the protocol (like domain_id, sensor_id...etc)
559  *
560  * @src_id can be provided as NULL if it simply does NOT make sense for
561  * the protocol at hand, OR if the user is explicitly interested in
562  * receiving notifications from ANY existent source associated to the
563  * specified proto_id / evt_id.
564  *
565  * Received notifications are finally delivered to the registered users,
566  * invoking the callback provided with the notifier_block *nb as follows:
567  *
568  *	int user_cb(nb, evt_id, report)
569  *
570  * with:
571  *
572  * @nb: The notifier block provided by the user
573  * @evt_id: The message ID of the delivered event
574  * @report: A custom struct describing the specific event delivered
575  */
576 struct scmi_notify_ops {
577 	int (*register_event_notifier)(const struct scmi_handle *handle,
578 				       u8 proto_id, u8 evt_id, u32 *src_id,
579 				       struct notifier_block *nb);
580 	int (*unregister_event_notifier)(const struct scmi_handle *handle,
581 					 u8 proto_id, u8 evt_id, u32 *src_id,
582 					 struct notifier_block *nb);
583 };
584 
585 /**
586  * struct scmi_handle - Handle returned to ARM SCMI clients for usage.
587  *
588  * @dev: pointer to the SCMI device
589  * @version: pointer to the structure containing SCMI version information
590  * @power_ops: pointer to set of power protocol operations
591  * @perf_ops: pointer to set of performance protocol operations
592  * @clk_ops: pointer to set of clock protocol operations
593  * @sensor_ops: pointer to set of sensor protocol operations
594  * @reset_ops: pointer to set of reset protocol operations
595  * @voltage_ops: pointer to set of voltage protocol operations
596  * @notify_ops: pointer to set of notifications related operations
597  * @perf_priv: pointer to private data structure specific to performance
598  *	protocol(for internal use only)
599  * @clk_priv: pointer to private data structure specific to clock
600  *	protocol(for internal use only)
601  * @power_priv: pointer to private data structure specific to power
602  *	protocol(for internal use only)
603  * @sensor_priv: pointer to private data structure specific to sensors
604  *	protocol(for internal use only)
605  * @reset_priv: pointer to private data structure specific to reset
606  *	protocol(for internal use only)
607  * @voltage_priv: pointer to private data structure specific to voltage
608  *	protocol(for internal use only)
609  * @notify_priv: pointer to private data structure specific to notifications
610  *	(for internal use only)
611  */
612 struct scmi_handle {
613 	struct device *dev;
614 	struct scmi_revision_info *version;
615 	const struct scmi_perf_ops *perf_ops;
616 	const struct scmi_clk_ops *clk_ops;
617 	const struct scmi_power_ops *power_ops;
618 	const struct scmi_sensor_ops *sensor_ops;
619 	const struct scmi_reset_ops *reset_ops;
620 	const struct scmi_voltage_ops *voltage_ops;
621 	const struct scmi_notify_ops *notify_ops;
622 	/* for protocol internal use */
623 	void *perf_priv;
624 	void *clk_priv;
625 	void *power_priv;
626 	void *sensor_priv;
627 	void *reset_priv;
628 	void *voltage_priv;
629 	void *notify_priv;
630 	void *system_priv;
631 };
632 
633 enum scmi_std_protocol {
634 	SCMI_PROTOCOL_BASE = 0x10,
635 	SCMI_PROTOCOL_POWER = 0x11,
636 	SCMI_PROTOCOL_SYSTEM = 0x12,
637 	SCMI_PROTOCOL_PERF = 0x13,
638 	SCMI_PROTOCOL_CLOCK = 0x14,
639 	SCMI_PROTOCOL_SENSOR = 0x15,
640 	SCMI_PROTOCOL_RESET = 0x16,
641 	SCMI_PROTOCOL_VOLTAGE = 0x17,
642 };
643 
644 enum scmi_system_events {
645 	SCMI_SYSTEM_SHUTDOWN,
646 	SCMI_SYSTEM_COLDRESET,
647 	SCMI_SYSTEM_WARMRESET,
648 	SCMI_SYSTEM_POWERUP,
649 	SCMI_SYSTEM_SUSPEND,
650 	SCMI_SYSTEM_MAX
651 };
652 
653 struct scmi_device {
654 	u32 id;
655 	u8 protocol_id;
656 	const char *name;
657 	struct device dev;
658 	struct scmi_handle *handle;
659 };
660 
661 #define to_scmi_dev(d) container_of(d, struct scmi_device, dev)
662 
663 struct scmi_device *
664 scmi_device_create(struct device_node *np, struct device *parent, int protocol,
665 		   const char *name);
666 void scmi_device_destroy(struct scmi_device *scmi_dev);
667 
668 struct scmi_device_id {
669 	u8 protocol_id;
670 	const char *name;
671 };
672 
673 struct scmi_driver {
674 	const char *name;
675 	int (*probe)(struct scmi_device *sdev);
676 	void (*remove)(struct scmi_device *sdev);
677 	const struct scmi_device_id *id_table;
678 
679 	struct device_driver driver;
680 };
681 
682 #define to_scmi_driver(d) container_of(d, struct scmi_driver, driver)
683 
684 #if IS_REACHABLE(CONFIG_ARM_SCMI_PROTOCOL)
685 int scmi_driver_register(struct scmi_driver *driver,
686 			 struct module *owner, const char *mod_name);
687 void scmi_driver_unregister(struct scmi_driver *driver);
688 #else
689 static inline int
690 scmi_driver_register(struct scmi_driver *driver, struct module *owner,
691 		     const char *mod_name)
692 {
693 	return -EINVAL;
694 }
695 
696 static inline void scmi_driver_unregister(struct scmi_driver *driver) {}
697 #endif /* CONFIG_ARM_SCMI_PROTOCOL */
698 
699 #define scmi_register(driver) \
700 	scmi_driver_register(driver, THIS_MODULE, KBUILD_MODNAME)
701 #define scmi_unregister(driver) \
702 	scmi_driver_unregister(driver)
703 
704 /**
705  * module_scmi_driver() - Helper macro for registering a scmi driver
706  * @__scmi_driver: scmi_driver structure
707  *
708  * Helper macro for scmi drivers to set up proper module init / exit
709  * functions.  Replaces module_init() and module_exit() and keeps people from
710  * printing pointless things to the kernel log when their driver is loaded.
711  */
712 #define module_scmi_driver(__scmi_driver)	\
713 	module_driver(__scmi_driver, scmi_register, scmi_unregister)
714 
715 typedef int (*scmi_prot_init_fn_t)(struct scmi_handle *);
716 int scmi_protocol_register(int protocol_id, scmi_prot_init_fn_t fn);
717 void scmi_protocol_unregister(int protocol_id);
718 
719 /* SCMI Notification API - Custom Event Reports */
720 enum scmi_notification_events {
721 	SCMI_EVENT_POWER_STATE_CHANGED = 0x0,
722 	SCMI_EVENT_PERFORMANCE_LIMITS_CHANGED = 0x0,
723 	SCMI_EVENT_PERFORMANCE_LEVEL_CHANGED = 0x1,
724 	SCMI_EVENT_SENSOR_TRIP_POINT_EVENT = 0x0,
725 	SCMI_EVENT_SENSOR_UPDATE = 0x1,
726 	SCMI_EVENT_RESET_ISSUED = 0x0,
727 	SCMI_EVENT_BASE_ERROR_EVENT = 0x0,
728 	SCMI_EVENT_SYSTEM_POWER_STATE_NOTIFIER = 0x0,
729 };
730 
731 struct scmi_power_state_changed_report {
732 	ktime_t		timestamp;
733 	unsigned int	agent_id;
734 	unsigned int	domain_id;
735 	unsigned int	power_state;
736 };
737 
738 struct scmi_system_power_state_notifier_report {
739 	ktime_t		timestamp;
740 	unsigned int	agent_id;
741 	unsigned int	flags;
742 	unsigned int	system_state;
743 };
744 
745 struct scmi_perf_limits_report {
746 	ktime_t		timestamp;
747 	unsigned int	agent_id;
748 	unsigned int	domain_id;
749 	unsigned int	range_max;
750 	unsigned int	range_min;
751 };
752 
753 struct scmi_perf_level_report {
754 	ktime_t		timestamp;
755 	unsigned int	agent_id;
756 	unsigned int	domain_id;
757 	unsigned int	performance_level;
758 };
759 
760 struct scmi_sensor_trip_point_report {
761 	ktime_t		timestamp;
762 	unsigned int	agent_id;
763 	unsigned int	sensor_id;
764 	unsigned int	trip_point_desc;
765 };
766 
767 struct scmi_sensor_update_report {
768 	ktime_t				timestamp;
769 	unsigned int			agent_id;
770 	unsigned int			sensor_id;
771 	unsigned int			readings_count;
772 	struct scmi_sensor_reading	readings[];
773 };
774 
775 struct scmi_reset_issued_report {
776 	ktime_t		timestamp;
777 	unsigned int	agent_id;
778 	unsigned int	domain_id;
779 	unsigned int	reset_state;
780 };
781 
782 struct scmi_base_error_report {
783 	ktime_t			timestamp;
784 	unsigned int		agent_id;
785 	bool			fatal;
786 	unsigned int		cmd_count;
787 	unsigned long long	reports[];
788 };
789 
790 #endif /* _LINUX_SCMI_PROTOCOL_H */
791