scmi_protocol.h 33 KB

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