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