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