1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * SCMI Message Protocol driver header
5 * Copyright (C) 2018-2021 ARM Ltd.
8 #ifndef _LINUX_SCMI_PROTOCOL_H
9 #define _LINUX_SCMI_PROTOCOL_H
11 #include <linux/bitfield.h>
12 #include <linux/device.h>
13 #include <linux/notifier.h>
14 #include <linux/types.h>
16 #define SCMI_MAX_STR_SIZE 64
17 #define SCMI_SHORT_NAME_MAX_SIZE 16
18 #define SCMI_MAX_NUM_RATES 16
21 * struct scmi_revision_info - version information structure
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
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)
34 struct scmi_revision_info {
40 char vendor_id[SCMI_SHORT_NAME_MAX_SIZE];
41 char sub_vendor_id[SCMI_SHORT_NAME_MAX_SIZE];
44 struct scmi_clock_info {
45 char name[SCMI_MAX_STR_SIZE];
46 unsigned int enable_latency;
48 bool rate_changed_notifications;
49 bool rate_change_requested_notifications;
50 bool state_ctrl_forbidden;
51 bool rate_ctrl_forbidden;
52 bool parent_ctrl_forbidden;
57 u64 rates[SCMI_MAX_NUM_RATES];
69 enum scmi_power_scale {
71 SCMI_POWER_MILLIWATTS,
77 struct scmi_protocol_handle;
79 enum scmi_clock_oem_config {
80 SCMI_CLOCK_CFG_DUTY_CYCLE = 0x1,
82 SCMI_CLOCK_CFG_OEM_START = 0x80,
83 SCMI_CLOCK_CFG_OEM_END = 0xFF,
87 * struct scmi_clk_proto_ops - represents the various operations provided
88 * by SCMI Clock Protocol
90 * @count_get: get the count of clocks provided by SCMI
91 * @info_get: get the information of the specified clock
92 * @rate_get: request the current clock rate of a clock
93 * @rate_set: set the clock rate of a clock
94 * @enable: enables the specified clock
95 * @disable: disables the specified clock
96 * @state_get: get the status of the specified clock
97 * @config_oem_get: get the value of an OEM specific clock config
98 * @config_oem_set: set the value of an OEM specific clock config
99 * @parent_get: get the parent id of a clk
100 * @parent_set: set the parent of a clock
102 struct scmi_clk_proto_ops {
103 int (*count_get)(const struct scmi_protocol_handle *ph);
105 const struct scmi_clock_info __must_check *(*info_get)
106 (const struct scmi_protocol_handle *ph, u32 clk_id);
107 int (*rate_get)(const struct scmi_protocol_handle *ph, u32 clk_id,
109 int (*rate_set)(const struct scmi_protocol_handle *ph, u32 clk_id,
111 int (*enable)(const struct scmi_protocol_handle *ph, u32 clk_id,
113 int (*disable)(const struct scmi_protocol_handle *ph, u32 clk_id,
115 int (*state_get)(const struct scmi_protocol_handle *ph, u32 clk_id,
116 bool *enabled, bool atomic);
117 int (*config_oem_get)(const struct scmi_protocol_handle *ph, u32 clk_id,
118 enum scmi_clock_oem_config oem_type,
119 u32 *oem_val, u32 *attributes, bool atomic);
120 int (*config_oem_set)(const struct scmi_protocol_handle *ph, u32 clk_id,
121 enum scmi_clock_oem_config oem_type,
122 u32 oem_val, bool atomic);
123 int (*parent_get)(const struct scmi_protocol_handle *ph, u32 clk_id, u32 *parent_id);
124 int (*parent_set)(const struct scmi_protocol_handle *ph, u32 clk_id, u32 parent_id);
127 struct scmi_perf_domain_info {
128 char name[SCMI_MAX_STR_SIZE];
133 * struct scmi_perf_proto_ops - represents the various operations provided
134 * by SCMI Performance Protocol
136 * @num_domains_get: gets the number of supported performance domains
137 * @info_get: get the information of a performance domain
138 * @limits_set: sets limits on the performance level of a domain
139 * @limits_get: gets limits on the performance level of a domain
140 * @level_set: sets the performance level of a domain
141 * @level_get: gets the performance level of a domain
142 * @transition_latency_get: gets the DVFS transition latency for a given device
143 * @rate_limit_get: gets the minimum time (us) required between successive
145 * @device_opps_add: adds all the OPPs for a given device
146 * @freq_set: sets the frequency for a given device using sustained frequency
147 * to sustained performance level mapping
148 * @freq_get: gets the frequency for a given device using sustained frequency
149 * to sustained performance level mapping
150 * @est_power_get: gets the estimated power cost for a given performance domain
151 * at a given frequency
152 * @fast_switch_possible: indicates if fast DVFS switching is possible or not
154 * @fast_switch_rate_limit: gets the minimum time (us) required between
155 * successive fast_switching requests
156 * @power_scale_mw_get: indicates if the power values provided are in milliWatts
157 * or in some other (abstract) scale
159 struct scmi_perf_proto_ops {
160 int (*num_domains_get)(const struct scmi_protocol_handle *ph);
161 const struct scmi_perf_domain_info __must_check *(*info_get)
162 (const struct scmi_protocol_handle *ph, u32 domain);
163 int (*limits_set)(const struct scmi_protocol_handle *ph, u32 domain,
164 u32 max_perf, u32 min_perf);
165 int (*limits_get)(const struct scmi_protocol_handle *ph, u32 domain,
166 u32 *max_perf, u32 *min_perf);
167 int (*level_set)(const struct scmi_protocol_handle *ph, u32 domain,
168 u32 level, bool poll);
169 int (*level_get)(const struct scmi_protocol_handle *ph, u32 domain,
170 u32 *level, bool poll);
171 int (*transition_latency_get)(const struct scmi_protocol_handle *ph,
173 int (*rate_limit_get)(const struct scmi_protocol_handle *ph,
174 u32 domain, u32 *rate_limit);
175 int (*device_opps_add)(const struct scmi_protocol_handle *ph,
176 struct device *dev, u32 domain);
177 int (*freq_set)(const struct scmi_protocol_handle *ph, u32 domain,
178 unsigned long rate, bool poll);
179 int (*freq_get)(const struct scmi_protocol_handle *ph, u32 domain,
180 unsigned long *rate, bool poll);
181 int (*est_power_get)(const struct scmi_protocol_handle *ph, u32 domain,
182 unsigned long *rate, unsigned long *power);
183 bool (*fast_switch_possible)(const struct scmi_protocol_handle *ph,
185 int (*fast_switch_rate_limit)(const struct scmi_protocol_handle *ph,
186 u32 domain, u32 *rate_limit);
187 enum scmi_power_scale (*power_scale_get)(const struct scmi_protocol_handle *ph);
191 * struct scmi_power_proto_ops - represents the various operations provided
192 * by SCMI Power Protocol
194 * @num_domains_get: get the count of power domains provided by SCMI
195 * @name_get: gets the name of a power domain
196 * @state_set: sets the power state of a power domain
197 * @state_get: gets the power state of a power domain
199 struct scmi_power_proto_ops {
200 int (*num_domains_get)(const struct scmi_protocol_handle *ph);
201 const char *(*name_get)(const struct scmi_protocol_handle *ph,
203 #define SCMI_POWER_STATE_TYPE_SHIFT 30
204 #define SCMI_POWER_STATE_ID_MASK (BIT(28) - 1)
205 #define SCMI_POWER_STATE_PARAM(type, id) \
206 ((((type) & BIT(0)) << SCMI_POWER_STATE_TYPE_SHIFT) | \
207 ((id) & SCMI_POWER_STATE_ID_MASK))
208 #define SCMI_POWER_STATE_GENERIC_ON SCMI_POWER_STATE_PARAM(0, 0)
209 #define SCMI_POWER_STATE_GENERIC_OFF SCMI_POWER_STATE_PARAM(1, 0)
210 int (*state_set)(const struct scmi_protocol_handle *ph, u32 domain,
212 int (*state_get)(const struct scmi_protocol_handle *ph, u32 domain,
217 * struct scmi_sensor_reading - represent a timestamped read
219 * Used by @reading_get_timestamped method.
221 * @value: The signed value sensor read.
222 * @timestamp: An unsigned timestamp for the sensor read, as provided by
223 * SCMI platform. Set to zero when not available.
225 struct scmi_sensor_reading {
227 unsigned long long timestamp;
231 * struct scmi_range_attrs - specifies a sensor or axis values' range
232 * @min_range: The minimum value which can be represented by the sensor/axis.
233 * @max_range: The maximum value which can be represented by the sensor/axis.
235 struct scmi_range_attrs {
241 * struct scmi_sensor_axis_info - describes one sensor axes
243 * @type: Axes type. Chosen amongst one of @enum scmi_sensor_class.
244 * @scale: Power-of-10 multiplier applied to the axis unit.
245 * @name: NULL-terminated string representing axes name as advertised by
247 * @extended_attrs: Flag to indicate the presence of additional extended
248 * attributes for this axes.
249 * @resolution: Extended attribute representing the resolution of the axes.
250 * Set to 0 if not reported by this axes.
251 * @exponent: Extended attribute representing the power-of-10 multiplier that
252 * is applied to the resolution field. Set to 0 if not reported by
254 * @attrs: Extended attributes representing minimum and maximum values
255 * measurable by this axes. Set to 0 if not reported by this sensor.
257 struct scmi_sensor_axis_info {
261 char name[SCMI_MAX_STR_SIZE];
263 unsigned int resolution;
265 struct scmi_range_attrs attrs;
269 * struct scmi_sensor_intervals_info - describes number and type of available
271 * @segmented: Flag for segmented intervals' representation. When True there
272 * will be exactly 3 intervals in @desc, with each entry
273 * representing a member of a segment in this order:
274 * {lowest update interval, highest update interval, step size}
275 * @count: Number of intervals described in @desc.
276 * @desc: Array of @count interval descriptor bitmask represented as detailed in
277 * the SCMI specification: it can be accessed using the accompanying
279 * @prealloc_pool: A minimal preallocated pool of desc entries used to avoid
280 * lesser-than-64-bytes dynamic allocation for small @count
283 struct scmi_sensor_intervals_info {
286 #define SCMI_SENS_INTVL_SEGMENT_LOW 0
287 #define SCMI_SENS_INTVL_SEGMENT_HIGH 1
288 #define SCMI_SENS_INTVL_SEGMENT_STEP 2
290 #define SCMI_SENS_INTVL_GET_SECS(x) FIELD_GET(GENMASK(20, 5), (x))
291 #define SCMI_SENS_INTVL_GET_EXP(x) \
293 int __signed_exp = FIELD_GET(GENMASK(4, 0), (x)); \
295 if (__signed_exp & BIT(4)) \
296 __signed_exp |= GENMASK(31, 5); \
299 #define SCMI_MAX_PREALLOC_POOL 16
300 unsigned int prealloc_pool[SCMI_MAX_PREALLOC_POOL];
304 * struct scmi_sensor_info - represents information related to one of the
307 * @type: Sensor type. Chosen amongst one of @enum scmi_sensor_class.
308 * @scale: Power-of-10 multiplier applied to the sensor unit.
309 * @num_trip_points: Number of maximum configurable trip points.
310 * @async: Flag for asynchronous read support.
311 * @update: Flag for continuouos update notification support.
312 * @timestamped: Flag for timestamped read support.
313 * @tstamp_scale: Power-of-10 multiplier applied to the sensor timestamps to
314 * represent it in seconds.
315 * @num_axis: Number of supported axis if any. Reported as 0 for scalar sensors.
316 * @axis: Pointer to an array of @num_axis descriptors.
317 * @intervals: Descriptor of available update intervals.
318 * @sensor_config: A bitmask reporting the current sensor configuration as
319 * detailed in the SCMI specification: it can accessed and
320 * modified through the accompanying macros.
321 * @name: NULL-terminated string representing sensor name as advertised by
323 * @extended_scalar_attrs: Flag to indicate the presence of additional extended
324 * attributes for this sensor.
325 * @sensor_power: Extended attribute representing the average power
326 * consumed by the sensor in microwatts (uW) when it is active.
327 * Reported here only for scalar sensors.
328 * Set to 0 if not reported by this sensor.
329 * @resolution: Extended attribute representing the resolution of the sensor.
330 * Reported here only for scalar sensors.
331 * Set to 0 if not reported by this sensor.
332 * @exponent: Extended attribute representing the power-of-10 multiplier that is
333 * applied to the resolution field.
334 * Reported here only for scalar sensors.
335 * Set to 0 if not reported by this sensor.
336 * @scalar_attrs: Extended attributes representing minimum and maximum
337 * measurable values by this sensor.
338 * Reported here only for scalar sensors.
339 * Set to 0 if not reported by this sensor.
341 struct scmi_sensor_info {
345 unsigned int num_trip_points;
350 unsigned int num_axis;
351 struct scmi_sensor_axis_info *axis;
352 struct scmi_sensor_intervals_info intervals;
353 unsigned int sensor_config;
354 #define SCMI_SENS_CFG_UPDATE_SECS_MASK GENMASK(31, 16)
355 #define SCMI_SENS_CFG_GET_UPDATE_SECS(x) \
356 FIELD_GET(SCMI_SENS_CFG_UPDATE_SECS_MASK, (x))
358 #define SCMI_SENS_CFG_UPDATE_EXP_MASK GENMASK(15, 11)
359 #define SCMI_SENS_CFG_GET_UPDATE_EXP(x) \
362 FIELD_GET(SCMI_SENS_CFG_UPDATE_EXP_MASK, (x)); \
364 if (__signed_exp & BIT(4)) \
365 __signed_exp |= GENMASK(31, 5); \
369 #define SCMI_SENS_CFG_ROUND_MASK GENMASK(10, 9)
370 #define SCMI_SENS_CFG_ROUND_AUTO 2
371 #define SCMI_SENS_CFG_ROUND_UP 1
372 #define SCMI_SENS_CFG_ROUND_DOWN 0
374 #define SCMI_SENS_CFG_TSTAMP_ENABLED_MASK BIT(1)
375 #define SCMI_SENS_CFG_TSTAMP_ENABLE 1
376 #define SCMI_SENS_CFG_TSTAMP_DISABLE 0
377 #define SCMI_SENS_CFG_IS_TSTAMP_ENABLED(x) \
378 FIELD_GET(SCMI_SENS_CFG_TSTAMP_ENABLED_MASK, (x))
380 #define SCMI_SENS_CFG_SENSOR_ENABLED_MASK BIT(0)
381 #define SCMI_SENS_CFG_SENSOR_ENABLE 1
382 #define SCMI_SENS_CFG_SENSOR_DISABLE 0
383 char name[SCMI_MAX_STR_SIZE];
384 #define SCMI_SENS_CFG_IS_ENABLED(x) FIELD_GET(BIT(0), (x))
385 bool extended_scalar_attrs;
386 unsigned int sensor_power;
387 unsigned int resolution;
389 struct scmi_range_attrs scalar_attrs;
393 * Partial list from Distributed Management Task Force (DMTF) specification:
394 * DSP0249 (Platform Level Data Model specification)
396 enum scmi_sensor_class {
466 NEWTON_METERS = 0x45,
477 CORRECTED_ERRS = 0x50,
478 UNCORRECTABLE_ERRS = 0x51,
486 METERS_SEC_SQUARED = 0x59,
488 CUBIC_METERS_SEC = 0x5B,
490 RADIANS_SEC_SQUARED = 0x5D,
495 * struct scmi_sensor_proto_ops - represents the various operations provided
496 * by SCMI Sensor Protocol
498 * @count_get: get the count of sensors provided by SCMI
499 * @info_get: get the information of the specified sensor
500 * @trip_point_config: selects and configures a trip-point of interest
501 * @reading_get: gets the current value of the sensor
502 * @reading_get_timestamped: gets the current value and timestamp, when
503 * available, of the sensor. (as of v3.0 spec)
504 * Supports multi-axis sensors for sensors which
505 * supports it and if the @reading array size of
506 * @count entry equals the sensor num_axis
507 * @config_get: Get sensor current configuration
508 * @config_set: Set sensor current configuration
510 struct scmi_sensor_proto_ops {
511 int (*count_get)(const struct scmi_protocol_handle *ph);
512 const struct scmi_sensor_info __must_check *(*info_get)
513 (const struct scmi_protocol_handle *ph, u32 sensor_id);
514 int (*trip_point_config)(const struct scmi_protocol_handle *ph,
515 u32 sensor_id, u8 trip_id, u64 trip_value);
516 int (*reading_get)(const struct scmi_protocol_handle *ph, u32 sensor_id,
518 int (*reading_get_timestamped)(const struct scmi_protocol_handle *ph,
519 u32 sensor_id, u8 count,
520 struct scmi_sensor_reading *readings);
521 int (*config_get)(const struct scmi_protocol_handle *ph,
522 u32 sensor_id, u32 *sensor_config);
523 int (*config_set)(const struct scmi_protocol_handle *ph,
524 u32 sensor_id, u32 sensor_config);
528 * struct scmi_reset_proto_ops - represents the various operations provided
529 * by SCMI Reset Protocol
531 * @num_domains_get: get the count of reset domains provided by SCMI
532 * @name_get: gets the name of a reset domain
533 * @latency_get: gets the reset latency for the specified reset domain
534 * @reset: resets the specified reset domain
535 * @assert: explicitly assert reset signal of the specified reset domain
536 * @deassert: explicitly deassert reset signal of the specified reset domain
538 struct scmi_reset_proto_ops {
539 int (*num_domains_get)(const struct scmi_protocol_handle *ph);
540 const char *(*name_get)(const struct scmi_protocol_handle *ph,
542 int (*latency_get)(const struct scmi_protocol_handle *ph, u32 domain);
543 int (*reset)(const struct scmi_protocol_handle *ph, u32 domain);
544 int (*assert)(const struct scmi_protocol_handle *ph, u32 domain);
545 int (*deassert)(const struct scmi_protocol_handle *ph, u32 domain);
548 enum scmi_voltage_level_mode {
549 SCMI_VOLTAGE_LEVEL_SET_AUTO,
550 SCMI_VOLTAGE_LEVEL_SET_SYNC,
554 * struct scmi_voltage_info - describe one available SCMI Voltage Domain
556 * @id: the domain ID as advertised by the platform
557 * @segmented: defines the layout of the entries of array @levels_uv.
558 * - when True the entries are to be interpreted as triplets,
559 * each defining a segment representing a range of equally
560 * space voltages: <lowest_volts>, <highest_volt>, <step_uV>
561 * - when False the entries simply represent a single discrete
562 * supported voltage level
563 * @negative_volts_allowed: True if any of the entries of @levels_uv represent
564 * a negative voltage.
565 * @async_level_set: True when the voltage domain supports asynchronous level
567 * @name: name assigned to the Voltage Domain by platform
568 * @num_levels: number of total entries in @levels_uv.
569 * @levels_uv: array of entries describing the available voltage levels for
572 struct scmi_voltage_info {
575 bool negative_volts_allowed;
576 bool async_level_set;
577 char name[SCMI_MAX_STR_SIZE];
578 unsigned int num_levels;
579 #define SCMI_VOLTAGE_SEGMENT_LOW 0
580 #define SCMI_VOLTAGE_SEGMENT_HIGH 1
581 #define SCMI_VOLTAGE_SEGMENT_STEP 2
586 * struct scmi_voltage_proto_ops - represents the various operations provided
587 * by SCMI Voltage Protocol
589 * @num_domains_get: get the count of voltage domains provided by SCMI
590 * @info_get: get the information of the specified domain
591 * @config_set: set the config for the specified domain
592 * @config_get: get the config of the specified domain
593 * @level_set: set the voltage level for the specified domain
594 * @level_get: get the voltage level of the specified domain
596 struct scmi_voltage_proto_ops {
597 int (*num_domains_get)(const struct scmi_protocol_handle *ph);
598 const struct scmi_voltage_info __must_check *(*info_get)
599 (const struct scmi_protocol_handle *ph, u32 domain_id);
600 int (*config_set)(const struct scmi_protocol_handle *ph, u32 domain_id,
602 #define SCMI_VOLTAGE_ARCH_STATE_OFF 0x0
603 #define SCMI_VOLTAGE_ARCH_STATE_ON 0x7
604 int (*config_get)(const struct scmi_protocol_handle *ph, u32 domain_id,
606 int (*level_set)(const struct scmi_protocol_handle *ph, u32 domain_id,
607 enum scmi_voltage_level_mode mode, s32 volt_uV);
608 int (*level_get)(const struct scmi_protocol_handle *ph, u32 domain_id,
613 * struct scmi_powercap_info - Describe one available Powercap domain
615 * @id: Domain ID as advertised by the platform.
616 * @notify_powercap_cap_change: CAP change notification support.
617 * @notify_powercap_measurement_change: MEASUREMENTS change notifications
619 * @async_powercap_cap_set: Asynchronous CAP set support.
620 * @powercap_cap_config: CAP configuration support.
621 * @powercap_monitoring: Monitoring (measurements) support.
622 * @powercap_pai_config: PAI configuration support.
623 * @powercap_scale_mw: Domain reports power data in milliwatt units.
624 * @powercap_scale_uw: Domain reports power data in microwatt units.
625 * Note that, when both @powercap_scale_mw and
626 * @powercap_scale_uw are set to false, the domain
627 * reports power data on an abstract linear scale.
628 * @name: name assigned to the Powercap Domain by platform.
629 * @min_pai: Minimum configurable PAI.
630 * @max_pai: Maximum configurable PAI.
631 * @pai_step: Step size between two consecutive PAI values.
632 * @min_power_cap: Minimum configurable CAP.
633 * @max_power_cap: Maximum configurable CAP.
634 * @power_cap_step: Step size between two consecutive CAP values.
635 * @sustainable_power: Maximum sustainable power consumption for this domain
636 * under normal conditions.
637 * @accuracy: The accuracy with which the power is measured and reported in
638 * integral multiples of 0.001 percent.
639 * @parent_id: Identifier of the containing parent power capping domain, or the
640 * value 0xFFFFFFFF if this powercap domain is a root domain not
641 * contained in any other domain.
643 struct scmi_powercap_info {
645 bool notify_powercap_cap_change;
646 bool notify_powercap_measurement_change;
647 bool async_powercap_cap_set;
648 bool powercap_cap_config;
649 bool powercap_monitoring;
650 bool powercap_pai_config;
651 bool powercap_scale_mw;
652 bool powercap_scale_uw;
654 char name[SCMI_MAX_STR_SIZE];
655 unsigned int min_pai;
656 unsigned int max_pai;
657 unsigned int pai_step;
658 unsigned int min_power_cap;
659 unsigned int max_power_cap;
660 unsigned int power_cap_step;
661 unsigned int sustainable_power;
662 unsigned int accuracy;
663 #define SCMI_POWERCAP_ROOT_ZONE_ID 0xFFFFFFFFUL
664 unsigned int parent_id;
665 struct scmi_fc_info *fc_info;
669 * struct scmi_powercap_proto_ops - represents the various operations provided
670 * by SCMI Powercap Protocol
672 * @num_domains_get: get the count of powercap domains provided by SCMI.
673 * @info_get: get the information for the specified domain.
674 * @cap_get: get the current CAP value for the specified domain.
675 * On SCMI platforms supporting powercap zone disabling, this could
676 * report a zero value for a zone where powercapping is disabled.
677 * @cap_set: set the CAP value for the specified domain to the provided value;
678 * if the domain supports setting the CAP with an asynchronous command
679 * this request will finally trigger an asynchronous transfer, but, if
680 * @ignore_dresp here is set to true, this call will anyway return
681 * immediately without waiting for the related delayed response.
682 * Note that the powercap requested value must NOT be zero, even if
683 * the platform supports disabling a powercap by setting its cap to
684 * zero (since SCMI v3.2): there are dedicated operations that should
685 * be used for that. (@cap_enable_set/get)
686 * @cap_enable_set: enable or disable the powercapping on the specified domain,
687 * if supported by the SCMI platform implementation.
688 * Note that, by the SCMI specification, the platform can
689 * silently ignore our disable request and decide to enforce
690 * anyway some other powercap value requested by another agent
691 * on the system: for this reason @cap_get and @cap_enable_get
692 * will always report the final platform view of the powercaps.
693 * @cap_enable_get: get the current CAP enable status for the specified domain.
694 * @pai_get: get the current PAI value for the specified domain.
695 * @pai_set: set the PAI value for the specified domain to the provided value.
696 * @measurements_get: retrieve the current average power measurements for the
697 * specified domain and the related PAI upon which is
699 * @measurements_threshold_set: set the desired low and high power thresholds
700 * to be used when registering for notification
701 * of type POWERCAP_MEASUREMENTS_NOTIFY with this
703 * Note that this must be called at least once
704 * before registering any callback with the usual
705 * @scmi_notify_ops; moreover, in case this method
706 * is called with measurement notifications already
707 * enabled it will also trigger, transparently, a
708 * proper update of the power thresholds configured
709 * in the SCMI backend server.
710 * @measurements_threshold_get: get the currently configured low and high power
711 * thresholds used when registering callbacks for
712 * notification POWERCAP_MEASUREMENTS_NOTIFY.
714 struct scmi_powercap_proto_ops {
715 int (*num_domains_get)(const struct scmi_protocol_handle *ph);
716 const struct scmi_powercap_info __must_check *(*info_get)
717 (const struct scmi_protocol_handle *ph, u32 domain_id);
718 int (*cap_get)(const struct scmi_protocol_handle *ph, u32 domain_id,
720 int (*cap_set)(const struct scmi_protocol_handle *ph, u32 domain_id,
721 u32 power_cap, bool ignore_dresp);
722 int (*cap_enable_set)(const struct scmi_protocol_handle *ph,
723 u32 domain_id, bool enable);
724 int (*cap_enable_get)(const struct scmi_protocol_handle *ph,
725 u32 domain_id, bool *enable);
726 int (*pai_get)(const struct scmi_protocol_handle *ph, u32 domain_id,
728 int (*pai_set)(const struct scmi_protocol_handle *ph, u32 domain_id,
730 int (*measurements_get)(const struct scmi_protocol_handle *ph,
731 u32 domain_id, u32 *average_power, u32 *pai);
732 int (*measurements_threshold_set)(const struct scmi_protocol_handle *ph,
733 u32 domain_id, u32 power_thresh_low,
734 u32 power_thresh_high);
735 int (*measurements_threshold_get)(const struct scmi_protocol_handle *ph,
736 u32 domain_id, u32 *power_thresh_low,
737 u32 *power_thresh_high);
741 * struct scmi_notify_ops - represents notifications' operations provided by
743 * @devm_event_notifier_register: Managed registration of a notifier_block for
744 * the requested event
745 * @devm_event_notifier_unregister: Managed unregistration of a notifier_block
746 * for the requested event
747 * @event_notifier_register: Register a notifier_block for the requested event
748 * @event_notifier_unregister: Unregister a notifier_block for the requested
751 * A user can register/unregister its own notifier_block against the wanted
752 * platform instance regarding the desired event identified by the
753 * tuple: (proto_id, evt_id, src_id) using the provided register/unregister
756 * @sdev: The scmi_device to use when calling the devres managed ops devm_
757 * @handle: The handle identifying the platform instance to use, when not
758 * calling the managed ops devm_
759 * @proto_id: The protocol ID as in SCMI Specification
760 * @evt_id: The message ID of the desired event as in SCMI Specification
761 * @src_id: A pointer to the desired source ID if different sources are
762 * possible for the protocol (like domain_id, sensor_id...etc)
764 * @src_id can be provided as NULL if it simply does NOT make sense for
765 * the protocol at hand, OR if the user is explicitly interested in
766 * receiving notifications from ANY existent source associated to the
767 * specified proto_id / evt_id.
769 * Received notifications are finally delivered to the registered users,
770 * invoking the callback provided with the notifier_block *nb as follows:
772 * int user_cb(nb, evt_id, report)
776 * @nb: The notifier block provided by the user
777 * @evt_id: The message ID of the delivered event
778 * @report: A custom struct describing the specific event delivered
780 struct scmi_notify_ops {
781 int (*devm_event_notifier_register)(struct scmi_device *sdev,
782 u8 proto_id, u8 evt_id,
784 struct notifier_block *nb);
785 int (*devm_event_notifier_unregister)(struct scmi_device *sdev,
786 u8 proto_id, u8 evt_id,
788 struct notifier_block *nb);
789 int (*event_notifier_register)(const struct scmi_handle *handle,
790 u8 proto_id, u8 evt_id,
792 struct notifier_block *nb);
793 int (*event_notifier_unregister)(const struct scmi_handle *handle,
794 u8 proto_id, u8 evt_id,
796 struct notifier_block *nb);
800 * struct scmi_handle - Handle returned to ARM SCMI clients for usage.
802 * @dev: pointer to the SCMI device
803 * @version: pointer to the structure containing SCMI version information
804 * @devm_protocol_acquire: devres managed method to get hold of a protocol,
805 * causing its initialization and related resource
807 * @devm_protocol_get: devres managed method to acquire a protocol and get specific
808 * operations and a dedicated protocol handler
809 * @devm_protocol_put: devres managed method to release a protocol
810 * @is_transport_atomic: method to check if the underlying transport for this
811 * instance handle is configured to support atomic
812 * transactions for commands.
813 * Some users of the SCMI stack in the upper layers could
814 * be interested to know if they can assume SCMI
815 * command transactions associated to this handle will
816 * never sleep and act accordingly.
817 * An optional atomic threshold value could be returned
819 * @notify_ops: pointer to set of notifications related operations
823 struct scmi_revision_info *version;
825 int __must_check (*devm_protocol_acquire)(struct scmi_device *sdev,
827 const void __must_check *
828 (*devm_protocol_get)(struct scmi_device *sdev, u8 proto,
829 struct scmi_protocol_handle **ph);
830 void (*devm_protocol_put)(struct scmi_device *sdev, u8 proto);
831 bool (*is_transport_atomic)(const struct scmi_handle *handle,
832 unsigned int *atomic_threshold);
834 const struct scmi_notify_ops *notify_ops;
837 enum scmi_std_protocol {
838 SCMI_PROTOCOL_BASE = 0x10,
839 SCMI_PROTOCOL_POWER = 0x11,
840 SCMI_PROTOCOL_SYSTEM = 0x12,
841 SCMI_PROTOCOL_PERF = 0x13,
842 SCMI_PROTOCOL_CLOCK = 0x14,
843 SCMI_PROTOCOL_SENSOR = 0x15,
844 SCMI_PROTOCOL_RESET = 0x16,
845 SCMI_PROTOCOL_VOLTAGE = 0x17,
846 SCMI_PROTOCOL_POWERCAP = 0x18,
849 enum scmi_system_events {
850 SCMI_SYSTEM_SHUTDOWN,
851 SCMI_SYSTEM_COLDRESET,
852 SCMI_SYSTEM_WARMRESET,
863 struct scmi_handle *handle;
866 #define to_scmi_dev(d) container_of(d, struct scmi_device, dev)
868 struct scmi_device_id {
875 int (*probe)(struct scmi_device *sdev);
876 void (*remove)(struct scmi_device *sdev);
877 const struct scmi_device_id *id_table;
879 struct device_driver driver;
882 #define to_scmi_driver(d) container_of(d, struct scmi_driver, driver)
884 #if IS_REACHABLE(CONFIG_ARM_SCMI_PROTOCOL)
885 int scmi_driver_register(struct scmi_driver *driver,
886 struct module *owner, const char *mod_name);
887 void scmi_driver_unregister(struct scmi_driver *driver);
890 scmi_driver_register(struct scmi_driver *driver, struct module *owner,
891 const char *mod_name)
896 static inline void scmi_driver_unregister(struct scmi_driver *driver) {}
897 #endif /* CONFIG_ARM_SCMI_PROTOCOL */
899 #define scmi_register(driver) \
900 scmi_driver_register(driver, THIS_MODULE, KBUILD_MODNAME)
901 #define scmi_unregister(driver) \
902 scmi_driver_unregister(driver)
905 * module_scmi_driver() - Helper macro for registering a scmi driver
906 * @__scmi_driver: scmi_driver structure
908 * Helper macro for scmi drivers to set up proper module init / exit
909 * functions. Replaces module_init() and module_exit() and keeps people from
910 * printing pointless things to the kernel log when their driver is loaded.
912 #define module_scmi_driver(__scmi_driver) \
913 module_driver(__scmi_driver, scmi_register, scmi_unregister)
916 * module_scmi_protocol() - Helper macro for registering a scmi protocol
917 * @__scmi_protocol: scmi_protocol structure
919 * Helper macro for scmi drivers to set up proper module init / exit
920 * functions. Replaces module_init() and module_exit() and keeps people from
921 * printing pointless things to the kernel log when their driver is loaded.
923 #define module_scmi_protocol(__scmi_protocol) \
924 module_driver(__scmi_protocol, \
925 scmi_protocol_register, scmi_protocol_unregister)
927 struct scmi_protocol;
928 int scmi_protocol_register(const struct scmi_protocol *proto);
929 void scmi_protocol_unregister(const struct scmi_protocol *proto);
931 /* SCMI Notification API - Custom Event Reports */
932 enum scmi_notification_events {
933 SCMI_EVENT_POWER_STATE_CHANGED = 0x0,
934 SCMI_EVENT_CLOCK_RATE_CHANGED = 0x0,
935 SCMI_EVENT_CLOCK_RATE_CHANGE_REQUESTED = 0x1,
936 SCMI_EVENT_PERFORMANCE_LIMITS_CHANGED = 0x0,
937 SCMI_EVENT_PERFORMANCE_LEVEL_CHANGED = 0x1,
938 SCMI_EVENT_SENSOR_TRIP_POINT_EVENT = 0x0,
939 SCMI_EVENT_SENSOR_UPDATE = 0x1,
940 SCMI_EVENT_RESET_ISSUED = 0x0,
941 SCMI_EVENT_BASE_ERROR_EVENT = 0x0,
942 SCMI_EVENT_SYSTEM_POWER_STATE_NOTIFIER = 0x0,
943 SCMI_EVENT_POWERCAP_CAP_CHANGED = 0x0,
944 SCMI_EVENT_POWERCAP_MEASUREMENTS_CHANGED = 0x1,
947 struct scmi_power_state_changed_report {
949 unsigned int agent_id;
950 unsigned int domain_id;
951 unsigned int power_state;
954 struct scmi_clock_rate_notif_report {
956 unsigned int agent_id;
957 unsigned int clock_id;
958 unsigned long long rate;
961 struct scmi_system_power_state_notifier_report {
963 unsigned int agent_id;
964 #define SCMI_SYSPOWER_IS_REQUEST_GRACEFUL(flags) ((flags) & BIT(0))
966 unsigned int system_state;
967 unsigned int timeout;
970 struct scmi_perf_limits_report {
972 unsigned int agent_id;
973 unsigned int domain_id;
974 unsigned int range_max;
975 unsigned int range_min;
976 unsigned long range_max_freq;
977 unsigned long range_min_freq;
980 struct scmi_perf_level_report {
982 unsigned int agent_id;
983 unsigned int domain_id;
984 unsigned int performance_level;
985 unsigned long performance_level_freq;
988 struct scmi_sensor_trip_point_report {
990 unsigned int agent_id;
991 unsigned int sensor_id;
992 unsigned int trip_point_desc;
995 struct scmi_sensor_update_report {
997 unsigned int agent_id;
998 unsigned int sensor_id;
999 unsigned int readings_count;
1000 struct scmi_sensor_reading readings[];
1003 struct scmi_reset_issued_report {
1005 unsigned int agent_id;
1006 unsigned int domain_id;
1007 unsigned int reset_state;
1010 struct scmi_base_error_report {
1012 unsigned int agent_id;
1014 unsigned int cmd_count;
1015 unsigned long long reports[];
1018 struct scmi_powercap_cap_changed_report {
1020 unsigned int agent_id;
1021 unsigned int domain_id;
1022 unsigned int power_cap;
1026 struct scmi_powercap_meas_changed_report {
1028 unsigned int agent_id;
1029 unsigned int domain_id;
1032 #endif /* _LINUX_SCMI_PROTOCOL_H */