hc
2023-12-08 01573e231f18eb2d99162747186f59511f56b64d
kernel/include/linux/scmi_protocol.h
....@@ -1,11 +1,18 @@
1
-// SPDX-License-Identifier: GPL-2.0
1
+/* SPDX-License-Identifier: GPL-2.0-only */
22 /*
33 * SCMI Message Protocol driver header
44 *
55 * Copyright (C) 2018 ARM Ltd.
66 */
7
+
8
+#ifndef _LINUX_SCMI_PROTOCOL_H
9
+#define _LINUX_SCMI_PROTOCOL_H
10
+
11
+#include <linux/bitfield.h>
712 #include <linux/device.h>
13
+#include <linux/notifier.h>
814 #include <linux/types.h>
15
+#include <linux/android_kabi.h>
916
1017 #define SCMI_MAX_STR_SIZE 16
1118 #define SCMI_MAX_NUM_RATES 16
....@@ -51,9 +58,11 @@
5158 };
5259
5360 struct scmi_handle;
61
+struct scmi_device;
62
+struct scmi_protocol_handle;
5463
5564 /**
56
- * struct scmi_clk_ops - represents the various operations provided
65
+ * struct scmi_clk_proto_ops - represents the various operations provided
5766 * by SCMI Clock Protocol
5867 *
5968 * @count_get: get the count of clocks provided by SCMI
....@@ -63,21 +72,23 @@
6372 * @enable: enables the specified clock
6473 * @disable: disables the specified clock
6574 */
66
-struct scmi_clk_ops {
67
- int (*count_get)(const struct scmi_handle *handle);
75
+struct scmi_clk_proto_ops {
76
+ int (*count_get)(const struct scmi_protocol_handle *ph);
6877
6978 const struct scmi_clock_info *(*info_get)
70
- (const struct scmi_handle *handle, u32 clk_id);
71
- int (*rate_get)(const struct scmi_handle *handle, u32 clk_id,
79
+ (const struct scmi_protocol_handle *ph, u32 clk_id);
80
+ int (*rate_get)(const struct scmi_protocol_handle *ph, u32 clk_id,
7281 u64 *rate);
73
- int (*rate_set)(const struct scmi_handle *handle, u32 clk_id,
82
+ int (*rate_set)(const struct scmi_protocol_handle *ph, u32 clk_id,
7483 u64 rate);
75
- int (*enable)(const struct scmi_handle *handle, u32 clk_id);
76
- int (*disable)(const struct scmi_handle *handle, u32 clk_id);
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
+
87
+ ANDROID_KABI_RESERVE(1);
7788 };
7889
7990 /**
80
- * struct scmi_perf_ops - represents the various operations provided
91
+ * struct scmi_perf_proto_ops - represents the various operations provided
8192 * by SCMI Performance Protocol
8293 *
8394 * @limits_set: sets limits on the performance level of a domain
....@@ -94,30 +105,35 @@
94105 * @est_power_get: gets the estimated power cost for a given performance domain
95106 * at a given frequency
96107 */
97
-struct scmi_perf_ops {
98
- int (*limits_set)(const struct scmi_handle *handle, u32 domain,
108
+struct scmi_perf_proto_ops {
109
+ int (*limits_set)(const struct scmi_protocol_handle *ph, u32 domain,
99110 u32 max_perf, u32 min_perf);
100
- int (*limits_get)(const struct scmi_handle *handle, u32 domain,
111
+ int (*limits_get)(const struct scmi_protocol_handle *ph, u32 domain,
101112 u32 *max_perf, u32 *min_perf);
102
- int (*level_set)(const struct scmi_handle *handle, u32 domain,
113
+ int (*level_set)(const struct scmi_protocol_handle *ph, u32 domain,
103114 u32 level, bool poll);
104
- int (*level_get)(const struct scmi_handle *handle, u32 domain,
115
+ int (*level_get)(const struct scmi_protocol_handle *ph, u32 domain,
105116 u32 *level, bool poll);
106117 int (*device_domain_id)(struct device *dev);
107
- int (*transition_latency_get)(const struct scmi_handle *handle,
118
+ int (*transition_latency_get)(const struct scmi_protocol_handle *ph,
108119 struct device *dev);
109
- int (*device_opps_add)(const struct scmi_handle *handle,
120
+ int (*device_opps_add)(const struct scmi_protocol_handle *ph,
110121 struct device *dev);
111
- int (*freq_set)(const struct scmi_handle *handle, u32 domain,
122
+ int (*freq_set)(const struct scmi_protocol_handle *ph, u32 domain,
112123 unsigned long rate, bool poll);
113
- int (*freq_get)(const struct scmi_handle *handle, u32 domain,
124
+ int (*freq_get)(const struct scmi_protocol_handle *ph, u32 domain,
114125 unsigned long *rate, bool poll);
115
- int (*est_power_get)(const struct scmi_handle *handle, u32 domain,
126
+ int (*est_power_get)(const struct scmi_protocol_handle *ph, u32 domain,
116127 unsigned long *rate, unsigned long *power);
128
+ bool (*fast_switch_possible)(const struct scmi_protocol_handle *ph,
129
+ struct device *dev);
130
+ bool (*power_scale_mw_get)(const struct scmi_protocol_handle *ph);
131
+
132
+ ANDROID_KABI_RESERVE(1);
117133 };
118134
119135 /**
120
- * struct scmi_power_ops - represents the various operations provided
136
+ * struct scmi_power_proto_ops - represents the various operations provided
121137 * by SCMI Power Protocol
122138 *
123139 * @num_domains_get: get the count of power domains provided by SCMI
....@@ -125,9 +141,9 @@
125141 * @state_set: sets the power state of a power domain
126142 * @state_get: gets the power state of a power domain
127143 */
128
-struct scmi_power_ops {
129
- int (*num_domains_get)(const struct scmi_handle *handle);
130
- char *(*name_get)(const struct scmi_handle *handle, u32 domain);
144
+struct scmi_power_proto_ops {
145
+ int (*num_domains_get)(const struct scmi_protocol_handle *ph);
146
+ char *(*name_get)(const struct scmi_protocol_handle *ph, u32 domain);
131147 #define SCMI_POWER_STATE_TYPE_SHIFT 30
132148 #define SCMI_POWER_STATE_ID_MASK (BIT(28) - 1)
133149 #define SCMI_POWER_STATE_PARAM(type, id) \
....@@ -135,19 +151,190 @@
135151 ((id) & SCMI_POWER_STATE_ID_MASK))
136152 #define SCMI_POWER_STATE_GENERIC_ON SCMI_POWER_STATE_PARAM(0, 0)
137153 #define SCMI_POWER_STATE_GENERIC_OFF SCMI_POWER_STATE_PARAM(1, 0)
138
- int (*state_set)(const struct scmi_handle *handle, u32 domain,
154
+ int (*state_set)(const struct scmi_protocol_handle *ph, u32 domain,
139155 u32 state);
140
- int (*state_get)(const struct scmi_handle *handle, u32 domain,
156
+ int (*state_get)(const struct scmi_protocol_handle *ph, u32 domain,
141157 u32 *state);
158
+
159
+ ANDROID_KABI_RESERVE(1);
142160 };
143161
144
-struct scmi_sensor_info {
145
- u32 id;
146
- u8 type;
147
- s8 scale;
148
- u8 num_trip_points;
149
- bool async;
162
+/**
163
+ * scmi_sensor_reading - represent a timestamped read
164
+ *
165
+ * Used by @reading_get_timestamped method.
166
+ *
167
+ * @value: The signed value sensor read.
168
+ * @timestamp: An unsigned timestamp for the sensor read, as provided by
169
+ * SCMI platform. Set to zero when not available.
170
+ */
171
+struct scmi_sensor_reading {
172
+ long long value;
173
+ unsigned long long timestamp;
174
+};
175
+
176
+/**
177
+ * scmi_range_attrs - specifies a sensor or axis values' range
178
+ * @min_range: The minimum value which can be represented by the sensor/axis.
179
+ * @max_range: The maximum value which can be represented by the sensor/axis.
180
+ */
181
+struct scmi_range_attrs {
182
+ long long min_range;
183
+ long long max_range;
184
+};
185
+
186
+/**
187
+ * scmi_sensor_axis_info - describes one sensor axes
188
+ * @id: The axes ID.
189
+ * @type: Axes type. Chosen amongst one of @enum scmi_sensor_class.
190
+ * @scale: Power-of-10 multiplier applied to the axis unit.
191
+ * @name: NULL-terminated string representing axes name as advertised by
192
+ * SCMI platform.
193
+ * @extended_attrs: Flag to indicate the presence of additional extended
194
+ * attributes for this axes.
195
+ * @resolution: Extended attribute representing the resolution of the axes.
196
+ * Set to 0 if not reported by this axes.
197
+ * @exponent: Extended attribute representing the power-of-10 multiplier that
198
+ * is applied to the resolution field. Set to 0 if not reported by
199
+ * this axes.
200
+ * @attrs: Extended attributes representing minimum and maximum values
201
+ * measurable by this axes. Set to 0 if not reported by this sensor.
202
+ */
203
+struct scmi_sensor_axis_info {
204
+ unsigned int id;
205
+ unsigned int type;
206
+ int scale;
150207 char name[SCMI_MAX_STR_SIZE];
208
+ bool extended_attrs;
209
+ unsigned int resolution;
210
+ int exponent;
211
+ struct scmi_range_attrs attrs;
212
+};
213
+
214
+/**
215
+ * scmi_sensor_intervals_info - describes number and type of available update
216
+ * intervals
217
+ * @segmented: Flag for segmented intervals' representation. When True there
218
+ * will be exactly 3 intervals in @desc, with each entry
219
+ * representing a member of a segment in this order:
220
+ * {lowest update interval, highest update interval, step size}
221
+ * @count: Number of intervals described in @desc.
222
+ * @desc: Array of @count interval descriptor bitmask represented as detailed in
223
+ * the SCMI specification: it can be accessed using the accompanying
224
+ * macros.
225
+ * @prealloc_pool: A minimal preallocated pool of desc entries used to avoid
226
+ * lesser-than-64-bytes dynamic allocation for small @count
227
+ * values.
228
+ */
229
+struct scmi_sensor_intervals_info {
230
+ bool segmented;
231
+ unsigned int count;
232
+#define SCMI_SENS_INTVL_SEGMENT_LOW 0
233
+#define SCMI_SENS_INTVL_SEGMENT_HIGH 1
234
+#define SCMI_SENS_INTVL_SEGMENT_STEP 2
235
+ unsigned int *desc;
236
+#define SCMI_SENS_INTVL_GET_SECS(x) FIELD_GET(GENMASK(20, 5), (x))
237
+#define SCMI_SENS_INTVL_GET_EXP(x) \
238
+ ({ \
239
+ int __signed_exp = FIELD_GET(GENMASK(4, 0), (x)); \
240
+ \
241
+ if (__signed_exp & BIT(4)) \
242
+ __signed_exp |= GENMASK(31, 5); \
243
+ __signed_exp; \
244
+ })
245
+#define SCMI_MAX_PREALLOC_POOL 16
246
+ unsigned int prealloc_pool[SCMI_MAX_PREALLOC_POOL];
247
+};
248
+
249
+/**
250
+ * struct scmi_sensor_info - represents information related to one of the
251
+ * available sensors.
252
+ * @id: Sensor ID.
253
+ * @type: Sensor type. Chosen amongst one of @enum scmi_sensor_class.
254
+ * @scale: Power-of-10 multiplier applied to the sensor unit.
255
+ * @num_trip_points: Number of maximum configurable trip points.
256
+ * @async: Flag for asynchronous read support.
257
+ * @update: Flag for continuouos update notification support.
258
+ * @timestamped: Flag for timestamped read support.
259
+ * @tstamp_scale: Power-of-10 multiplier applied to the sensor timestamps to
260
+ * represent it in seconds.
261
+ * @num_axis: Number of supported axis if any. Reported as 0 for scalar sensors.
262
+ * @axis: Pointer to an array of @num_axis descriptors.
263
+ * @intervals: Descriptor of available update intervals.
264
+ * @sensor_config: A bitmask reporting the current sensor configuration as
265
+ * detailed in the SCMI specification: it can accessed and
266
+ * modified through the accompanying macros.
267
+ * @name: NULL-terminated string representing sensor name as advertised by
268
+ * SCMI platform.
269
+ * @extended_scalar_attrs: Flag to indicate the presence of additional extended
270
+ * attributes for this sensor.
271
+ * @sensor_power: Extended attribute representing the average power
272
+ * consumed by the sensor in microwatts (uW) when it is active.
273
+ * Reported here only for scalar sensors.
274
+ * Set to 0 if not reported by this sensor.
275
+ * @resolution: Extended attribute representing the resolution of the sensor.
276
+ * Reported here only for scalar sensors.
277
+ * Set to 0 if not reported by this sensor.
278
+ * @exponent: Extended attribute representing the power-of-10 multiplier that is
279
+ * applied to the resolution field.
280
+ * Reported here only for scalar sensors.
281
+ * Set to 0 if not reported by this sensor.
282
+ * @scalar_attrs: Extended attributes representing minimum and maximum
283
+ * measurable values by this sensor.
284
+ * Reported here only for scalar sensors.
285
+ * Set to 0 if not reported by this sensor.
286
+ */
287
+struct scmi_sensor_info {
288
+ unsigned int id;
289
+ unsigned int type;
290
+ int scale;
291
+ unsigned int num_trip_points;
292
+ bool async;
293
+ bool update;
294
+ bool timestamped;
295
+ int tstamp_scale;
296
+ unsigned int num_axis;
297
+ struct scmi_sensor_axis_info *axis;
298
+ struct scmi_sensor_intervals_info intervals;
299
+ unsigned int sensor_config;
300
+#define SCMI_SENS_CFG_UPDATE_SECS_MASK GENMASK(31, 16)
301
+#define SCMI_SENS_CFG_GET_UPDATE_SECS(x) \
302
+ FIELD_GET(SCMI_SENS_CFG_UPDATE_SECS_MASK, (x))
303
+
304
+#define SCMI_SENS_CFG_UPDATE_EXP_MASK GENMASK(15, 11)
305
+#define SCMI_SENS_CFG_GET_UPDATE_EXP(x) \
306
+ ({ \
307
+ int __signed_exp = \
308
+ FIELD_GET(SCMI_SENS_CFG_UPDATE_EXP_MASK, (x)); \
309
+ \
310
+ if (__signed_exp & BIT(4)) \
311
+ __signed_exp |= GENMASK(31, 5); \
312
+ __signed_exp; \
313
+ })
314
+
315
+#define SCMI_SENS_CFG_ROUND_MASK GENMASK(10, 9)
316
+#define SCMI_SENS_CFG_ROUND_AUTO 2
317
+#define SCMI_SENS_CFG_ROUND_UP 1
318
+#define SCMI_SENS_CFG_ROUND_DOWN 0
319
+
320
+#define SCMI_SENS_CFG_TSTAMP_ENABLED_MASK BIT(1)
321
+#define SCMI_SENS_CFG_TSTAMP_ENABLE 1
322
+#define SCMI_SENS_CFG_TSTAMP_DISABLE 0
323
+#define SCMI_SENS_CFG_IS_TSTAMP_ENABLED(x) \
324
+ FIELD_GET(SCMI_SENS_CFG_TSTAMP_ENABLED_MASK, (x))
325
+
326
+#define SCMI_SENS_CFG_SENSOR_ENABLED_MASK BIT(0)
327
+#define SCMI_SENS_CFG_SENSOR_ENABLE 1
328
+#define SCMI_SENS_CFG_SENSOR_DISABLE 0
329
+ char name[SCMI_MAX_STR_SIZE];
330
+#define SCMI_SENS_CFG_IS_ENABLED(x) FIELD_GET(BIT(0), (x))
331
+ bool extended_scalar_attrs;
332
+ unsigned int sensor_power;
333
+ unsigned int resolution;
334
+ int exponent;
335
+ struct scmi_range_attrs scalar_attrs;
336
+
337
+ ANDROID_KABI_RESERVE(1);
151338 };
152339
153340 /*
....@@ -156,39 +343,139 @@
156343 */
157344 enum scmi_sensor_class {
158345 NONE = 0x0,
346
+ UNSPEC = 0x1,
159347 TEMPERATURE_C = 0x2,
348
+ TEMPERATURE_F = 0x3,
349
+ TEMPERATURE_K = 0x4,
160350 VOLTAGE = 0x5,
161351 CURRENT = 0x6,
162352 POWER = 0x7,
163353 ENERGY = 0x8,
354
+ CHARGE = 0x9,
355
+ VOLTAMPERE = 0xA,
356
+ NITS = 0xB,
357
+ LUMENS = 0xC,
358
+ LUX = 0xD,
359
+ CANDELAS = 0xE,
360
+ KPA = 0xF,
361
+ PSI = 0x10,
362
+ NEWTON = 0x11,
363
+ CFM = 0x12,
364
+ RPM = 0x13,
365
+ HERTZ = 0x14,
366
+ SECS = 0x15,
367
+ MINS = 0x16,
368
+ HOURS = 0x17,
369
+ DAYS = 0x18,
370
+ WEEKS = 0x19,
371
+ MILS = 0x1A,
372
+ INCHES = 0x1B,
373
+ FEET = 0x1C,
374
+ CUBIC_INCHES = 0x1D,
375
+ CUBIC_FEET = 0x1E,
376
+ METERS = 0x1F,
377
+ CUBIC_CM = 0x20,
378
+ CUBIC_METERS = 0x21,
379
+ LITERS = 0x22,
380
+ FLUID_OUNCES = 0x23,
381
+ RADIANS = 0x24,
382
+ STERADIANS = 0x25,
383
+ REVOLUTIONS = 0x26,
384
+ CYCLES = 0x27,
385
+ GRAVITIES = 0x28,
386
+ OUNCES = 0x29,
387
+ POUNDS = 0x2A,
388
+ FOOT_POUNDS = 0x2B,
389
+ OUNCE_INCHES = 0x2C,
390
+ GAUSS = 0x2D,
391
+ GILBERTS = 0x2E,
392
+ HENRIES = 0x2F,
393
+ FARADS = 0x30,
394
+ OHMS = 0x31,
395
+ SIEMENS = 0x32,
396
+ MOLES = 0x33,
397
+ BECQUERELS = 0x34,
398
+ PPM = 0x35,
399
+ DECIBELS = 0x36,
400
+ DBA = 0x37,
401
+ DBC = 0x38,
402
+ GRAYS = 0x39,
403
+ SIEVERTS = 0x3A,
404
+ COLOR_TEMP_K = 0x3B,
405
+ BITS = 0x3C,
406
+ BYTES = 0x3D,
407
+ WORDS = 0x3E,
408
+ DWORDS = 0x3F,
409
+ QWORDS = 0x40,
410
+ PERCENTAGE = 0x41,
411
+ PASCALS = 0x42,
412
+ COUNTS = 0x43,
413
+ GRAMS = 0x44,
414
+ NEWTON_METERS = 0x45,
415
+ HITS = 0x46,
416
+ MISSES = 0x47,
417
+ RETRIES = 0x48,
418
+ OVERRUNS = 0x49,
419
+ UNDERRUNS = 0x4A,
420
+ COLLISIONS = 0x4B,
421
+ PACKETS = 0x4C,
422
+ MESSAGES = 0x4D,
423
+ CHARS = 0x4E,
424
+ ERRORS = 0x4F,
425
+ CORRECTED_ERRS = 0x50,
426
+ UNCORRECTABLE_ERRS = 0x51,
427
+ SQ_MILS = 0x52,
428
+ SQ_INCHES = 0x53,
429
+ SQ_FEET = 0x54,
430
+ SQ_CM = 0x55,
431
+ SQ_METERS = 0x56,
432
+ RADIANS_SEC = 0x57,
433
+ BPM = 0x58,
434
+ METERS_SEC_SQUARED = 0x59,
435
+ METERS_SEC = 0x5A,
436
+ CUBIC_METERS_SEC = 0x5B,
437
+ MM_MERCURY = 0x5C,
438
+ RADIANS_SEC_SQUARED = 0x5D,
439
+ OEM_UNIT = 0xFF
164440 };
165441
166442 /**
167
- * struct scmi_sensor_ops - represents the various operations provided
443
+ * struct scmi_sensor_proto_ops - represents the various operations provided
168444 * by SCMI Sensor Protocol
169445 *
170446 * @count_get: get the count of sensors provided by SCMI
171447 * @info_get: get the information of the specified sensor
172
- * @trip_point_notify: control notifications on cross-over events for
173
- * the trip-points
174448 * @trip_point_config: selects and configures a trip-point of interest
175449 * @reading_get: gets the current value of the sensor
450
+ * @reading_get_timestamped: gets the current value and timestamp, when
451
+ * available, of the sensor. (as of v3.0 spec)
452
+ * Supports multi-axis sensors for sensors which
453
+ * supports it and if the @reading array size of
454
+ * @count entry equals the sensor num_axis
455
+ * @config_get: Get sensor current configuration
456
+ * @config_set: Set sensor current configuration
176457 */
177
-struct scmi_sensor_ops {
178
- int (*count_get)(const struct scmi_handle *handle);
179
-
458
+struct scmi_sensor_proto_ops {
459
+ int (*count_get)(const struct scmi_protocol_handle *ph);
180460 const struct scmi_sensor_info *(*info_get)
181
- (const struct scmi_handle *handle, u32 sensor_id);
182
- int (*trip_point_notify)(const struct scmi_handle *handle,
183
- u32 sensor_id, bool enable);
184
- int (*trip_point_config)(const struct scmi_handle *handle,
461
+ (const struct scmi_protocol_handle *ph, u32 sensor_id);
462
+ int (*trip_point_config)(const struct scmi_protocol_handle *ph,
185463 u32 sensor_id, u8 trip_id, u64 trip_value);
186
- int (*reading_get)(const struct scmi_handle *handle, u32 sensor_id,
464
+ int (*reading_get)(const struct scmi_protocol_handle *ph, u32 sensor_id,
187465 u64 *value);
466
+ int (*reading_get_timestamped)(const struct scmi_protocol_handle *ph,
467
+ u32 sensor_id, u8 count,
468
+ struct scmi_sensor_reading *readings);
469
+ int (*config_get)(const struct scmi_protocol_handle *ph,
470
+ u32 sensor_id, u32 *sensor_config);
471
+ int (*config_set)(const struct scmi_protocol_handle *ph,
472
+ u32 sensor_id, u32 sensor_config);
473
+
474
+ ANDROID_KABI_RESERVE(1);
188475 };
189476
190477 /**
191
- * struct scmi_reset_ops - represents the various operations provided
478
+ * struct scmi_reset_proto_ops - represents the various operations provided
192479 * by SCMI Reset Protocol
193480 *
194481 * @num_domains_get: get the count of reset domains provided by SCMI
....@@ -198,13 +485,129 @@
198485 * @assert: explicitly assert reset signal of the specified reset domain
199486 * @deassert: explicitly deassert reset signal of the specified reset domain
200487 */
201
-struct scmi_reset_ops {
202
- int (*num_domains_get)(const struct scmi_handle *handle);
203
- char *(*name_get)(const struct scmi_handle *handle, u32 domain);
204
- int (*latency_get)(const struct scmi_handle *handle, u32 domain);
205
- int (*reset)(const struct scmi_handle *handle, u32 domain);
206
- int (*assert)(const struct scmi_handle *handle, u32 domain);
207
- int (*deassert)(const struct scmi_handle *handle, u32 domain);
488
+struct scmi_reset_proto_ops {
489
+ int (*num_domains_get)(const struct scmi_protocol_handle *ph);
490
+ char *(*name_get)(const struct scmi_protocol_handle *ph, u32 domain);
491
+ int (*latency_get)(const struct scmi_protocol_handle *ph, u32 domain);
492
+ int (*reset)(const struct scmi_protocol_handle *ph, u32 domain);
493
+ int (*assert)(const struct scmi_protocol_handle *ph, u32 domain);
494
+ int (*deassert)(const struct scmi_protocol_handle *ph, u32 domain);
495
+
496
+ ANDROID_KABI_RESERVE(1);
497
+};
498
+
499
+/**
500
+ * struct scmi_voltage_info - describe one available SCMI Voltage Domain
501
+ *
502
+ * @id: the domain ID as advertised by the platform
503
+ * @segmented: defines the layout of the entries of array @levels_uv.
504
+ * - when True the entries are to be interpreted as triplets,
505
+ * each defining a segment representing a range of equally
506
+ * space voltages: <lowest_volts>, <highest_volt>, <step_uV>
507
+ * - when False the entries simply represent a single discrete
508
+ * supported voltage level
509
+ * @negative_volts_allowed: True if any of the entries of @levels_uv represent
510
+ * a negative voltage.
511
+ * @attributes: represents Voltage Domain advertised attributes
512
+ * @name: name assigned to the Voltage Domain by platform
513
+ * @num_levels: number of total entries in @levels_uv.
514
+ * @levels_uv: array of entries describing the available voltage levels for
515
+ * this domain.
516
+ */
517
+struct scmi_voltage_info {
518
+ unsigned int id;
519
+ bool segmented;
520
+ bool negative_volts_allowed;
521
+ unsigned int attributes;
522
+ char name[SCMI_MAX_STR_SIZE];
523
+ unsigned int num_levels;
524
+#define SCMI_VOLTAGE_SEGMENT_LOW 0
525
+#define SCMI_VOLTAGE_SEGMENT_HIGH 1
526
+#define SCMI_VOLTAGE_SEGMENT_STEP 2
527
+ int *levels_uv;
528
+};
529
+
530
+/**
531
+ * struct scmi_voltage_proto_ops - represents the various operations provided
532
+ * by SCMI Voltage Protocol
533
+ *
534
+ * @num_domains_get: get the count of voltage domains provided by SCMI
535
+ * @info_get: get the information of the specified domain
536
+ * @config_set: set the config for the specified domain
537
+ * @config_get: get the config of the specified domain
538
+ * @level_set: set the voltage level for the specified domain
539
+ * @level_get: get the voltage level of the specified domain
540
+ */
541
+struct scmi_voltage_proto_ops {
542
+ int (*num_domains_get)(const struct scmi_protocol_handle *ph);
543
+ const struct scmi_voltage_info __must_check *(*info_get)
544
+ (const struct scmi_protocol_handle *ph, u32 domain_id);
545
+ int (*config_set)(const struct scmi_protocol_handle *ph, u32 domain_id,
546
+ u32 config);
547
+#define SCMI_VOLTAGE_ARCH_STATE_OFF 0x0
548
+#define SCMI_VOLTAGE_ARCH_STATE_ON 0x7
549
+ int (*config_get)(const struct scmi_protocol_handle *ph, u32 domain_id,
550
+ u32 *config);
551
+ int (*level_set)(const struct scmi_protocol_handle *ph, u32 domain_id,
552
+ u32 flags, s32 volt_uV);
553
+ int (*level_get)(const struct scmi_protocol_handle *ph, u32 domain_id,
554
+ s32 *volt_uV);
555
+};
556
+
557
+/**
558
+ * struct scmi_notify_ops - represents notifications' operations provided by
559
+ * SCMI core
560
+ * @devm_register_event_notifier: Managed registration of a notifier_block for
561
+ * the requested event
562
+ * @devm_unregister_event_notifier: Managed unregistration of a notifier_block
563
+ * for the requested event
564
+ * @register_event_notifier: Register a notifier_block for the requested event
565
+ * @unregister_event_notifier: Unregister a notifier_block for the requested
566
+ * event
567
+ *
568
+ * A user can register/unregister its own notifier_block against the wanted
569
+ * platform instance regarding the desired event identified by the
570
+ * tuple: (proto_id, evt_id, src_id) using the provided register/unregister
571
+ * interface where:
572
+ *
573
+ * @sdev: The scmi_device to use when calling the devres managed ops devm_
574
+ * @handle: The handle identifying the platform instance to use, when not
575
+ * calling the managed ops devm_
576
+ * @proto_id: The protocol ID as in SCMI Specification
577
+ * @evt_id: The message ID of the desired event as in SCMI Specification
578
+ * @src_id: A pointer to the desired source ID if different sources are
579
+ * possible for the protocol (like domain_id, sensor_id...etc)
580
+ *
581
+ * @src_id can be provided as NULL if it simply does NOT make sense for
582
+ * the protocol at hand, OR if the user is explicitly interested in
583
+ * receiving notifications from ANY existent source associated to the
584
+ * specified proto_id / evt_id.
585
+ *
586
+ * Received notifications are finally delivered to the registered users,
587
+ * invoking the callback provided with the notifier_block *nb as follows:
588
+ *
589
+ * int user_cb(nb, evt_id, report)
590
+ *
591
+ * with:
592
+ *
593
+ * @nb: The notifier block provided by the user
594
+ * @evt_id: The message ID of the delivered event
595
+ * @report: A custom struct describing the specific event delivered
596
+ */
597
+struct scmi_notify_ops {
598
+ int (*devm_register_event_notifier)(struct scmi_device *sdev,
599
+ u8 proto_id, u8 evt_id, u32 *src_id,
600
+ struct notifier_block *nb);
601
+ int (*devm_unregister_event_notifier)(struct scmi_device *sdev,
602
+ u8 proto_id, u8 evt_id,
603
+ u32 *src_id,
604
+ struct notifier_block *nb);
605
+ int (*register_event_notifier)(const struct scmi_handle *handle,
606
+ u8 proto_id, u8 evt_id, u32 *src_id,
607
+ struct notifier_block *nb);
608
+ int (*unregister_event_notifier)(const struct scmi_handle *handle,
609
+ u8 proto_id, u8 evt_id, u32 *src_id,
610
+ struct notifier_block *nb);
208611 };
209612
210613 /**
....@@ -212,36 +615,31 @@
212615 *
213616 * @dev: pointer to the SCMI device
214617 * @version: pointer to the structure containing SCMI version information
215
- * @power_ops: pointer to set of power protocol operations
216
- * @perf_ops: pointer to set of performance protocol operations
217
- * @clk_ops: pointer to set of clock protocol operations
218
- * @sensor_ops: pointer to set of sensor protocol operations
219
- * @reset_ops: pointer to set of reset protocol operations
220
- * @perf_priv: pointer to private data structure specific to performance
221
- * protocol(for internal use only)
222
- * @clk_priv: pointer to private data structure specific to clock
223
- * protocol(for internal use only)
224
- * @power_priv: pointer to private data structure specific to power
225
- * protocol(for internal use only)
226
- * @sensor_priv: pointer to private data structure specific to sensors
227
- * protocol(for internal use only)
228
- * @reset_priv: pointer to private data structure specific to reset
229
- * protocol(for internal use only)
618
+ * @devm_acquire_protocol: devres managed method to get hold of a protocol,
619
+ * causing its initialization and related resource
620
+ * accounting
621
+ * @devm_get_protocol: devres managed method to acquire a protocol, causing
622
+ * its initialization and resource accounting, while getting
623
+ * protocol specific operations and a dedicated protocol
624
+ * handler
625
+ * @devm_put_protocol: devres managed method to release a protocol acquired
626
+ * with devm_acquire/get_protocol
627
+ * @notify_ops: pointer to set of notifications related operations
230628 */
231629 struct scmi_handle {
232630 struct device *dev;
233631 struct scmi_revision_info *version;
234
- struct scmi_perf_ops *perf_ops;
235
- struct scmi_clk_ops *clk_ops;
236
- struct scmi_power_ops *power_ops;
237
- struct scmi_sensor_ops *sensor_ops;
238
- struct scmi_reset_ops *reset_ops;
239
- /* for protocol internal use */
240
- void *perf_priv;
241
- void *clk_priv;
242
- void *power_priv;
243
- void *sensor_priv;
244
- void *reset_priv;
632
+
633
+ int __must_check (*devm_acquire_protocol)(struct scmi_device *sdev,
634
+ u8 proto);
635
+ const void __must_check *
636
+ (*devm_get_protocol)(struct scmi_device *sdev, u8 proto,
637
+ struct scmi_protocol_handle **ph);
638
+ void (*devm_put_protocol)(struct scmi_device *sdev, u8 proto);
639
+
640
+ const struct scmi_notify_ops *notify_ops;
641
+
642
+ ANDROID_KABI_RESERVE(1);
245643 };
246644
247645 enum scmi_std_protocol {
....@@ -252,6 +650,16 @@
252650 SCMI_PROTOCOL_CLOCK = 0x14,
253651 SCMI_PROTOCOL_SENSOR = 0x15,
254652 SCMI_PROTOCOL_RESET = 0x16,
653
+ SCMI_PROTOCOL_VOLTAGE = 0x17,
654
+};
655
+
656
+enum scmi_system_events {
657
+ SCMI_SYSTEM_SHUTDOWN,
658
+ SCMI_SYSTEM_COLDRESET,
659
+ SCMI_SYSTEM_WARMRESET,
660
+ SCMI_SYSTEM_POWERUP,
661
+ SCMI_SYSTEM_SUSPEND,
662
+ SCMI_SYSTEM_MAX
255663 };
256664
257665 struct scmi_device {
....@@ -260,6 +668,8 @@
260668 const char *name;
261669 struct device dev;
262670 struct scmi_handle *handle;
671
+
672
+ ANDROID_KABI_RESERVE(1);
263673 };
264674
265675 #define to_scmi_dev(d) container_of(d, struct scmi_device, dev)
....@@ -285,7 +695,7 @@
285695
286696 #define to_scmi_driver(d) container_of(d, struct scmi_driver, driver)
287697
288
-#ifdef CONFIG_ARM_SCMI_PROTOCOL
698
+#if IS_REACHABLE(CONFIG_ARM_SCMI_PROTOCOL)
289699 int scmi_driver_register(struct scmi_driver *driver,
290700 struct module *owner, const char *mod_name);
291701 void scmi_driver_unregister(struct scmi_driver *driver);
....@@ -316,6 +726,91 @@
316726 #define module_scmi_driver(__scmi_driver) \
317727 module_driver(__scmi_driver, scmi_register, scmi_unregister)
318728
319
-typedef int (*scmi_prot_init_fn_t)(struct scmi_handle *);
320
-int scmi_protocol_register(int protocol_id, scmi_prot_init_fn_t fn);
321
-void scmi_protocol_unregister(int protocol_id);
729
+/**
730
+ * module_scmi_protocol() - Helper macro for registering a scmi protocol
731
+ * @__scmi_protocol: scmi_protocol structure
732
+ *
733
+ * Helper macro for scmi drivers to set up proper module init / exit
734
+ * functions. Replaces module_init() and module_exit() and keeps people from
735
+ * printing pointless things to the kernel log when their driver is loaded.
736
+ */
737
+#define module_scmi_protocol(__scmi_protocol) \
738
+ module_driver(__scmi_protocol, \
739
+ scmi_protocol_register, scmi_protocol_unregister)
740
+
741
+struct scmi_protocol;
742
+int scmi_protocol_register(const struct scmi_protocol *proto);
743
+void scmi_protocol_unregister(const struct scmi_protocol *proto);
744
+
745
+/* SCMI Notification API - Custom Event Reports */
746
+enum scmi_notification_events {
747
+ SCMI_EVENT_POWER_STATE_CHANGED = 0x0,
748
+ SCMI_EVENT_PERFORMANCE_LIMITS_CHANGED = 0x0,
749
+ SCMI_EVENT_PERFORMANCE_LEVEL_CHANGED = 0x1,
750
+ SCMI_EVENT_SENSOR_TRIP_POINT_EVENT = 0x0,
751
+ SCMI_EVENT_SENSOR_UPDATE = 0x1,
752
+ SCMI_EVENT_RESET_ISSUED = 0x0,
753
+ SCMI_EVENT_BASE_ERROR_EVENT = 0x0,
754
+ SCMI_EVENT_SYSTEM_POWER_STATE_NOTIFIER = 0x0,
755
+};
756
+
757
+struct scmi_power_state_changed_report {
758
+ ktime_t timestamp;
759
+ unsigned int agent_id;
760
+ unsigned int domain_id;
761
+ unsigned int power_state;
762
+};
763
+
764
+struct scmi_system_power_state_notifier_report {
765
+ ktime_t timestamp;
766
+ unsigned int agent_id;
767
+ unsigned int flags;
768
+ unsigned int system_state;
769
+};
770
+
771
+struct scmi_perf_limits_report {
772
+ ktime_t timestamp;
773
+ unsigned int agent_id;
774
+ unsigned int domain_id;
775
+ unsigned int range_max;
776
+ unsigned int range_min;
777
+};
778
+
779
+struct scmi_perf_level_report {
780
+ ktime_t timestamp;
781
+ unsigned int agent_id;
782
+ unsigned int domain_id;
783
+ unsigned int performance_level;
784
+};
785
+
786
+struct scmi_sensor_trip_point_report {
787
+ ktime_t timestamp;
788
+ unsigned int agent_id;
789
+ unsigned int sensor_id;
790
+ unsigned int trip_point_desc;
791
+};
792
+
793
+struct scmi_sensor_update_report {
794
+ ktime_t timestamp;
795
+ unsigned int agent_id;
796
+ unsigned int sensor_id;
797
+ unsigned int readings_count;
798
+ struct scmi_sensor_reading readings[];
799
+};
800
+
801
+struct scmi_reset_issued_report {
802
+ ktime_t timestamp;
803
+ unsigned int agent_id;
804
+ unsigned int domain_id;
805
+ unsigned int reset_state;
806
+};
807
+
808
+struct scmi_base_error_report {
809
+ ktime_t timestamp;
810
+ unsigned int agent_id;
811
+ bool fatal;
812
+ unsigned int cmd_count;
813
+ unsigned long long reports[];
814
+};
815
+
816
+#endif /* _LINUX_SCMI_PROTOCOL_H */