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