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