]>
git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/blob - include/linux/scmi_protocol.h
1 // SPDX-License-Identifier: GPL-2.0
3 * SCMI Message Protocol driver header
5 * Copyright (C) 2018 ARM Ltd.
7 #include <linux/device.h>
8 #include <linux/types.h>
10 #define SCMI_MAX_STR_SIZE 16
11 #define SCMI_MAX_NUM_RATES 16
14 * struct scmi_revision_info - version information structure
16 * @major_ver: Major ABI version. Change here implies risk of backward
17 * compatibility break.
18 * @minor_ver: Minor ABI version. Change here implies new feature addition,
19 * or compatible change in ABI.
20 * @num_protocols: Number of protocols that are implemented, excluding the
22 * @num_agents: Number of agents in the system.
23 * @impl_ver: A vendor-specific implementation version.
24 * @vendor_id: A vendor identifier(Null terminated ASCII string)
25 * @sub_vendor_id: A sub-vendor identifier(Null terminated ASCII string)
27 struct scmi_revision_info
{
33 char vendor_id
[SCMI_MAX_STR_SIZE
];
34 char sub_vendor_id
[SCMI_MAX_STR_SIZE
];
37 struct scmi_clock_info
{
38 char name
[SCMI_MAX_STR_SIZE
];
43 u64 rates
[SCMI_MAX_NUM_RATES
];
56 * struct scmi_clk_ops - represents the various operations provided
57 * by SCMI Clock Protocol
59 * @count_get: get the count of clocks provided by SCMI
60 * @info_get: get the information of the specified clock
61 * @rate_get: request the current clock rate of a clock
62 * @rate_set: set the clock rate of a clock
63 * @enable: enables the specified clock
64 * @disable: disables the specified clock
67 int (*count_get
)(const struct scmi_handle
*handle
);
69 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
,
73 int (*rate_set
)(const struct scmi_handle
*handle
, u32 clk_id
,
74 u32 config
, u64 rate
);
75 int (*enable
)(const struct scmi_handle
*handle
, u32 clk_id
);
76 int (*disable
)(const struct scmi_handle
*handle
, u32 clk_id
);
80 * struct scmi_perf_ops - represents the various operations provided
81 * by SCMI Performance Protocol
83 * @limits_set: sets limits on the performance level of a domain
84 * @limits_get: gets limits on the performance level of a domain
85 * @level_set: sets the performance level of a domain
86 * @level_get: gets the performance level of a domain
87 * @device_domain_id: gets the scmi domain id for a given device
88 * @transition_latency_get: gets the DVFS transition latency for a given device
89 * @device_opps_add: adds all the OPPs for a given device
90 * @freq_set: sets the frequency for a given device using sustained frequency
91 * to sustained performance level mapping
92 * @freq_get: gets the frequency for a given device using sustained frequency
93 * to sustained performance level mapping
95 struct scmi_perf_ops
{
96 int (*limits_set
)(const struct scmi_handle
*handle
, u32 domain
,
97 u32 max_perf
, u32 min_perf
);
98 int (*limits_get
)(const struct scmi_handle
*handle
, u32 domain
,
99 u32
*max_perf
, u32
*min_perf
);
100 int (*level_set
)(const struct scmi_handle
*handle
, u32 domain
,
101 u32 level
, bool poll
);
102 int (*level_get
)(const struct scmi_handle
*handle
, u32 domain
,
103 u32
*level
, bool poll
);
104 int (*device_domain_id
)(struct device
*dev
);
105 int (*transition_latency_get
)(const struct scmi_handle
*handle
,
107 int (*device_opps_add
)(const struct scmi_handle
*handle
,
109 int (*freq_set
)(const struct scmi_handle
*handle
, u32 domain
,
110 unsigned long rate
, bool poll
);
111 int (*freq_get
)(const struct scmi_handle
*handle
, u32 domain
,
112 unsigned long *rate
, bool poll
);
116 * struct scmi_power_ops - represents the various operations provided
117 * by SCMI Power Protocol
119 * @num_domains_get: get the count of power domains provided by SCMI
120 * @name_get: gets the name of a power domain
121 * @state_set: sets the power state of a power domain
122 * @state_get: gets the power state of a power domain
124 struct scmi_power_ops
{
125 int (*num_domains_get
)(const struct scmi_handle
*handle
);
126 char *(*name_get
)(const struct scmi_handle
*handle
, u32 domain
);
127 #define SCMI_POWER_STATE_TYPE_SHIFT 30
128 #define SCMI_POWER_STATE_ID_MASK (BIT(28) - 1)
129 #define SCMI_POWER_STATE_PARAM(type, id) \
130 ((((type) & BIT(0)) << SCMI_POWER_STATE_TYPE_SHIFT) | \
131 ((id) & SCMI_POWER_STATE_ID_MASK))
132 #define SCMI_POWER_STATE_GENERIC_ON SCMI_POWER_STATE_PARAM(0, 0)
133 #define SCMI_POWER_STATE_GENERIC_OFF SCMI_POWER_STATE_PARAM(1, 0)
134 int (*state_set
)(const struct scmi_handle
*handle
, u32 domain
,
136 int (*state_get
)(const struct scmi_handle
*handle
, u32 domain
,
140 struct scmi_sensor_info
{
143 char name
[SCMI_MAX_STR_SIZE
];
147 * Partial list from Distributed Management Task Force (DMTF) specification:
148 * DSP0249 (Platform Level Data Model specification)
150 enum scmi_sensor_class
{
160 * struct scmi_sensor_ops - represents the various operations provided
161 * by SCMI Sensor Protocol
163 * @count_get: get the count of sensors provided by SCMI
164 * @info_get: get the information of the specified sensor
165 * @configuration_set: control notifications on cross-over events for
167 * @trip_point_set: selects and configures a trip-point of interest
168 * @reading_get: gets the current value of the sensor
170 struct scmi_sensor_ops
{
171 int (*count_get
)(const struct scmi_handle
*handle
);
173 const struct scmi_sensor_info
*(*info_get
)
174 (const struct scmi_handle
*handle
, u32 sensor_id
);
175 int (*configuration_set
)(const struct scmi_handle
*handle
,
177 int (*trip_point_set
)(const struct scmi_handle
*handle
, u32 sensor_id
,
178 u8 trip_id
, u64 trip_value
);
179 int (*reading_get
)(const struct scmi_handle
*handle
, u32 sensor_id
,
180 bool async
, u64
*value
);
184 * struct scmi_handle - Handle returned to ARM SCMI clients for usage.
186 * @dev: pointer to the SCMI device
187 * @version: pointer to the structure containing SCMI version information
188 * @power_ops: pointer to set of power protocol operations
189 * @perf_ops: pointer to set of performance protocol operations
190 * @clk_ops: pointer to set of clock protocol operations
191 * @sensor_ops: pointer to set of sensor protocol operations
192 * @perf_priv: pointer to private data structure specific to performance
193 * protocol(for internal use only)
194 * @clk_priv: pointer to private data structure specific to clock
195 * protocol(for internal use only)
196 * @power_priv: pointer to private data structure specific to power
197 * protocol(for internal use only)
198 * @sensor_priv: pointer to private data structure specific to sensors
199 * protocol(for internal use only)
203 struct scmi_revision_info
*version
;
204 struct scmi_perf_ops
*perf_ops
;
205 struct scmi_clk_ops
*clk_ops
;
206 struct scmi_power_ops
*power_ops
;
207 struct scmi_sensor_ops
*sensor_ops
;
208 /* for protocol internal use */
215 enum scmi_std_protocol
{
216 SCMI_PROTOCOL_BASE
= 0x10,
217 SCMI_PROTOCOL_POWER
= 0x11,
218 SCMI_PROTOCOL_SYSTEM
= 0x12,
219 SCMI_PROTOCOL_PERF
= 0x13,
220 SCMI_PROTOCOL_CLOCK
= 0x14,
221 SCMI_PROTOCOL_SENSOR
= 0x15,
228 struct scmi_handle
*handle
;
231 #define to_scmi_dev(d) container_of(d, struct scmi_device, dev)
234 scmi_device_create(struct device_node
*np
, struct device
*parent
, int protocol
);
235 void scmi_device_destroy(struct scmi_device
*scmi_dev
);
237 struct scmi_device_id
{
243 int (*probe
)(struct scmi_device
*sdev
);
244 void (*remove
)(struct scmi_device
*sdev
);
245 const struct scmi_device_id
*id_table
;
247 struct device_driver driver
;
250 #define to_scmi_driver(d) container_of(d, struct scmi_driver, driver)
252 #ifdef CONFIG_ARM_SCMI_PROTOCOL
253 int scmi_driver_register(struct scmi_driver
*driver
,
254 struct module
*owner
, const char *mod_name
);
255 void scmi_driver_unregister(struct scmi_driver
*driver
);
258 scmi_driver_register(struct scmi_driver
*driver
, struct module
*owner
,
259 const char *mod_name
)
264 static inline void scmi_driver_unregister(struct scmi_driver
*driver
) {}
265 #endif /* CONFIG_ARM_SCMI_PROTOCOL */
267 #define scmi_register(driver) \
268 scmi_driver_register(driver, THIS_MODULE, KBUILD_MODNAME)
269 #define scmi_unregister(driver) \
270 scmi_driver_unregister(driver)
273 * module_scmi_driver() - Helper macro for registering a scmi driver
274 * @__scmi_driver: scmi_driver structure
276 * Helper macro for scmi drivers to set up proper module init / exit
277 * functions. Replaces module_init() and module_exit() and keeps people from
278 * printing pointless things to the kernel log when their driver is loaded.
280 #define module_scmi_driver(__scmi_driver) \
281 module_driver(__scmi_driver, scmi_register, scmi_unregister)
283 typedef int (*scmi_prot_init_fn_t
)(struct scmi_handle
*);
284 int scmi_protocol_register(int protocol_id
, scmi_prot_init_fn_t fn
);
285 void scmi_protocol_unregister(int protocol_id
);