scmi_protocol.h 26 KB

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