SST registers are presented to OS in multi-layer structures starting with a SST header showing version information freezing current definition. For details on SST terminology refer to Documentation/admin-guide/pm/intel-speed-select.rst under the kernel documentation SST TPMI details are published in the following document: https://github.com/intel/tpmi_power_management/blob/main/SST_TPMI_public_disclosure_FINAL.docx SST MMIO structure layout follows: SST-HEADER SST-CP Header SST-CP CONTROL SST-CP STATUS SST-CP CONFIG0 SST-CP CONFIG1 ... ... SST-PP Header SST-PP OFFSET_0 SST-PP OFFSET_1 SST_PP_0_INFO SST_PP_1_INFO SST_PP_2_INFO SST_PP_3_INFO SST-PP CONTROL SST-PP STATUS Each register bank contains information to get to next lower level information. This information is parsed and stored in the struct tpmi_per_power_domain_info for each domain. This information is used to process each SST requests.
Unified · Split
| @@ -20,6 +20,7 @@ · 19 unmodified lines | ||
| 20 | 20 | #include <linux/auxiliary_bus.h> |
| 21 | 21 | #include <linux/intel_tpmi.h> |
| 22 | 22 | #include <linux/fs.h> |
| 23 | +#include <linux/io.h> | |
| 23 | 24 | #include <linux/kernel.h> |
| 24 | 25 | #include <linux/module.h> |
| 25 | 26 | #include <uapi/linux/isst_if.h> |
| @@ -27,10 +28,192 @@ · 1 unmodified line | ||
| 27 | 28 | #include "isst_tpmi_core.h" |
| 28 | 29 | #include "isst_if_common.h" |
| 29 | 30 | |
| 31 | +/* Supported SST hardware version by this driver */ | |
| 32 | +#define ISST_HEADER_VERSION 1 | |
| 33 | + | |
| 34 | +/** | |
| 35 | + * struct sst_header - SST main header | |
| 36 | + * @interface_version: Version number for this interface | |
| 37 | + * @cap_mask: Bitmask of the supported sub features. 1=the sub feature is enabled. | |
| 38 | + * 0=disabled. | |
| 39 | + * Bit[8]= SST_CP enable (1), disable (0) | |
| 40 | + * bit[9]= SST_PP enable (1), disable (0) | |
| 41 | + * other bits are reserved for future use | |
| 42 | + * @cp_offset: Qword (8 bytes) offset to the SST_CP register bank | |
| 43 | + * @pp_offset: Qword (8 bytes) offset to the SST_PP register bank | |
| 44 | + * @reserved: Reserved for future use | |
| 45 | + * | |
| 46 | + * This register allows SW to discover SST capability and the offsets to SST-CP | |
| 47 | + * and SST-PP register banks. | |
| 48 | + */ | |
| 49 | +struct sst_header { | |
| 50 | + u8 interface_version; | |
| 51 | + u8 cap_mask; | |
| 52 | + u8 cp_offset; | |
| 53 | + u8 pp_offset; | |
| 54 | + u32 reserved; | |
| 55 | +} __packed; | |
| 56 | + | |
| 57 | +/** | |
| 58 | + * struct cp_header - SST-CP (core-power) header | |
| 59 | + * @feature_id: 0=SST-CP, 1=SST-PP, 2=SST-BF, 3=SST-TF | |
| 60 | + * @feature_rev: Interface Version number for this SST feature | |
| 61 | + * @ratio_unit: Frequency ratio unit. 00: 100MHz. All others are reserved | |
| 62 | + * @reserved: Reserved for future use | |
| 63 | + * | |
| 64 | + * This structure is used store SST-CP header. This is packed to the same | |
| 65 | + * format as defined in the specifications. | |
| 66 | + */ | |
| 67 | +struct cp_header { | |
| 68 | + u64 feature_id :4; | |
| 69 | + u64 feature_rev :8; | |
| 70 | + u64 ratio_unit :2; | |
| 71 | + u64 reserved :50; | |
| 72 | +} __packed; | |
| 73 | + | |
| 74 | +/** | |
| 75 | + * struct pp_header - SST-PP (Perf profile) header | |
| 76 | + * @feature_id: 0=SST-CP, 1=SST-PP, 2=SST-BF, 3=SST-TF | |
| 77 | + * @feature_rev: Interface Version number for this SST feature | |
| 78 | + * @level_en_mask: SST-PP level enable/disable fuse mask | |
| 79 | + * @allowed_level_mask: Allowed level mask used for dynamic config level switching | |
| 80 | + * @reserved0: Reserved for future use | |
| 81 | + * @ratio_unit: Frequency ratio unit. 00: 100MHz. All others are reserved | |
| 82 | + * @block_size: Size of PP block in Qword unit (8 bytes) | |
| 83 | + * @dynamic_switch: If set (1), dynamic switching of SST PP is supported | |
| 84 | + * @memory_ratio_unit: Memory Controller frequency ratio unit. 00: 100MHz, others reserved | |
| 85 | + * @reserved1: Reserved for future use | |
| 86 | + * | |
| 87 | + * This structure is used store SST-PP header. This is packed to the same | |
| 88 | + * format as defined in the specifications. | |
| 89 | + */ | |
| 90 | +struct pp_header { | |
| 91 | + u64 feature_id :4; | |
| 92 | + u64 feature_rev :8; | |
| 93 | + u64 level_en_mask :8; | |
| 94 | + u64 allowed_level_mask :8; | |
| 95 | + u64 reserved0 :4; | |
| 96 | + u64 ratio_unit :2; | |
| 97 | + u64 block_size :8; | |
| 98 | + u64 dynamic_switch :1; | |
| 99 | + u64 memory_ratio_unit :2; | |
| 100 | + u64 reserved1 :19; | |
| 101 | +} __packed; | |
| 102 | + | |
| 103 | +/** | |
| 104 | + * struct feature_offset - Offsets to SST-PP features | |
| 105 | + * @pp_offset: Qword offset within PP level for the SST_PP register bank | |
| 106 | + * @bf_offset: Qword offset within PP level for the SST_BF register bank | |
| 107 | + * @tf_offset: Qword offset within PP level for the SST_TF register bank | |
| 108 | + * @reserved: Reserved for future use | |
| 109 | + * | |
| 110 | + * This structure is used store offsets for SST features in the register bank. | |
| 111 | + * This is packed to the same format as defined in the specifications. | |
| 112 | + */ | |
| 113 | +struct feature_offset { | |
| 114 | + u64 pp_offset :8; | |
| 115 | + u64 bf_offset :8; | |
| 116 | + u64 tf_offset :8; | |
| 117 | + u64 reserved :40; | |
| 118 | +} __packed; | |
| 119 | + | |
| 120 | +/** | |
| 121 | + * struct levels_offset - Offsets to each SST PP level | |
| 122 | + * @sst_pp_level0_offset: Qword offset to the register block of PP level 0 | |
| 123 | + * @sst_pp_level1_offset: Qword offset to the register block of PP level 1 | |
| 124 | + * @sst_pp_level2_offset: Qword offset to the register block of PP level 2 | |
| 125 | + * @sst_pp_level3_offset: Qword offset to the register block of PP level 3 | |
| 126 | + * @sst_pp_level4_offset: Qword offset to the register block of PP level 4 | |
| 127 | + * @reserved: Reserved for future use | |
| 128 | + * | |
| 129 | + * This structure is used store offsets of SST PP levels in the register bank. | |
| 130 | + * This is packed to the same format as defined in the specifications. | |
| 131 | + */ | |
| 132 | +struct levels_offset { | |
| 133 | + u64 sst_pp_level0_offset :8; | |
| 134 | + u64 sst_pp_level1_offset :8; | |
| 135 | + u64 sst_pp_level2_offset :8; | |
| 136 | + u64 sst_pp_level3_offset :8; | |
| 137 | + u64 sst_pp_level4_offset :8; | |
| 138 | + u64 reserved :24; | |
| 139 | +} __packed; | |
| 140 | + | |
| 141 | +/** | |
| 142 | + * struct pp_control_offset - Offsets for SST PP controls | |
| 143 | + * @perf_level: A SST-PP level that SW intends to switch to | |
| 144 | + * @perf_level_lock: SST-PP level select lock. 0 - unlocked. 1 - locked till next reset | |
| 145 | + * @resvd0: Reserved for future use | |
| 146 | + * @current_state: Bit mask to control the enable(1)/disable(0) state of each feature | |
| 147 | + * of the current PP level, bit 0 = BF, bit 1 = TF, bit 2-7 = reserved | |
| 148 | + * @reserved: Reserved for future use | |
| 149 | + * | |
| 150 | + * This structure is used store offsets of SST PP controls in the register bank. | |
| 151 | + * This is packed to the same format as defined in the specifications. | |
| 152 | + */ | |
| 153 | +struct pp_control_offset { | |
| 154 | + u64 perf_level :3; | |
| 155 | + u64 perf_level_lock :1; | |
| 156 | + u64 resvd0 :4; | |
| 157 | + u64 current_state :8; | |
| 158 | + u64 reserved :48; | |
| 159 | +} __packed; | |
| 160 | + | |
| 161 | +/** | |
| 162 | + * struct pp_status_offset - Offsets for SST PP status fields | |
| 163 | + * @sst_pp_level: Returns the current SST-PP level | |
| 164 | + * @sst_pp_lock: Returns the lock bit setting of perf_level_lock in pp_control_offset | |
| 165 | + * @error_type: Returns last error of SST-PP level change request. 0: no error, | |
| 166 | + * 1: level change not allowed, others: reserved | |
| 167 | + * @feature_state: Bit mask to indicate the enable(1)/disable(0) state of each feature of the | |
| 168 | + * current PP level. bit 0 = BF, bit 1 = TF, bit 2-7 reserved | |
| 169 | + * @reserved0: Reserved for future use | |
| 170 | + * @feature_error_type: Returns last error of the specific feature. Three error_type bits per | |
| 171 | + * feature. i.e. ERROR_TYPE[2:0] for BF, ERROR_TYPE[5:3] for TF, etc. | |
| 172 | + * 0x0: no error, 0x1: The specific feature is not supported by the hardware. | |
| 173 | + * 0x2-0x6: Reserved. 0x7: feature state change is not allowed. | |
| 174 | + * @reserved1: Reserved for future use | |
| 175 | + * | |
| 176 | + * This structure is used store offsets of SST PP status in the register bank. | |
| 177 | + * This is packed to the same format as defined in the specifications. | |
| 178 | + */ | |
| 179 | +struct pp_status_offset { | |
| 180 | + u64 sst_pp_level :3; | |
| 181 | + u64 sst_pp_lock :1; | |
| 182 | + u64 error_type :4; | |
| 183 | + u64 feature_state :8; | |
| 184 | + u64 reserved0 :16; | |
| 185 | + u64 feature_error_type : 24; | |
| 186 | + u64 reserved1 :8; | |
| 187 | +} __packed; | |
| 188 | + | |
| 189 | +/** | |
| 190 | + * struct perf_level - Used to store perf level and mmio offset | |
| 191 | + * @mmio_offset: mmio offset for a perf level | |
| 192 | + * @level: perf level for this offset | |
| 193 | + * | |
| 194 | + * This structure is used store final mmio offset of each perf level from the | |
| 195 | + * SST base mmio offset. | |
| 196 | + */ | |
| 197 | +struct perf_level { | |
| 198 | + int mmio_offset; | |
| 199 | + int level; | |
| 200 | +}; | |
| 201 | + | |
| 30 | 202 | /** |
| 31 | 203 | * struct tpmi_per_power_domain_info - Store per power_domain SST info |
| 32 | 204 | * @package_id: Package id for this power_domain |
| 33 | 205 | * @power_domain_id: Power domain id, Each entry from the SST-TPMI instance is a power_domain. |
| 206 | + * @max_level: Max possible PP level possible for this power_domain | |
| 207 | + * @ratio_unit: Ratio unit for converting to MHz | |
| 208 | + * @avx_levels: Number of AVX levels | |
| 209 | + * @pp_block_size: Block size from PP header | |
| 210 | + * @sst_header: Store SST header for this power_domain | |
| 211 | + * @cp_header: Store SST-CP header for this power_domain | |
| 212 | + * @pp_header: Store SST-PP header for this power_domain | |
| 213 | + * @perf_levels: Pointer to each perf level to map level to mmio offset | |
| 214 | + * @feature_offsets: Store feature offsets for each PP-level | |
| 215 | + * @control_offset: Store the control offset for each PP-level | |
| 216 | + * @status_offset: Store the status offset for each PP-level | |
| 34 | 217 | * @sst_base: Mapped SST base IO memory |
| 35 | 218 | * @auxdev: Auxiliary device instance enumerated this instance |
| 36 | 219 | * |
| @@ -41,6 +224,17 @@ · 4 unmodified lines | ||
| 41 | 224 | struct tpmi_per_power_domain_info { |
| 42 | 225 | int package_id; |
| 43 | 226 | int power_domain_id; |
| 227 | + int max_level; | |
| 228 | + int ratio_unit; | |
| 229 | + int avx_levels; | |
| 230 | + int pp_block_size; | |
| 231 | + struct sst_header sst_header; | |
| 232 | + struct cp_header cp_header; | |
| 233 | + struct pp_header pp_header; | |
| 234 | + struct perf_level *perf_levels; | |
| 235 | + struct feature_offset feature_offsets; | |
| 236 | + struct pp_control_offset control_offset; | |
| 237 | + struct pp_status_offset status_offset; | |
| 44 | 238 | void __iomem *sst_base; |
| 45 | 239 | struct auxiliary_device *auxdev; |
| 46 | 240 | }; |
| @@ -85,6 +279,86 @@ static int isst_core_usage_count; · 38 unmodified lines | ||
| 85 | 279 | /* Stores complete SST information for every package and power_domain */ |
| 86 | 280 | static struct tpmi_sst_common_struct isst_common; |
| 87 | 281 | |
| 282 | +#define SST_MAX_AVX_LEVELS 3 | |
| 283 | + | |
| 284 | +#define SST_PP_OFFSET_0 8 | |
| 285 | +#define SST_PP_OFFSET_1 16 | |
| 286 | +#define SST_PP_OFFSET_SIZE 8 | |
| 287 | + | |
| 288 | +static int sst_add_perf_profiles(struct auxiliary_device *auxdev, | |
| 289 | + struct tpmi_per_power_domain_info *pd_info, | |
| 290 | + int levels) | |
| 291 | +{ | |
| 292 | + u64 perf_level_offsets; | |
| 293 | + int i; | |
| 294 | + | |
| 295 | + pd_info->perf_levels = devm_kcalloc(&auxdev->dev, levels, | |
| 296 | + sizeof(struct perf_level), | |
| 297 | + GFP_KERNEL); | |
| 298 | + if (!pd_info->perf_levels) | |
| 299 | + return 0; | |
| 300 | + | |
| 301 | + pd_info->ratio_unit = pd_info->pp_header.ratio_unit; | |
| 302 | + pd_info->avx_levels = SST_MAX_AVX_LEVELS; | |
| 303 | + pd_info->pp_block_size = pd_info->pp_header.block_size; | |
| 304 | + | |
| 305 | + /* Read PP Offset 0: Get feature offset with PP level */ | |
| 306 | + *((u64 *)&pd_info->feature_offsets) = readq(pd_info->sst_base + | |
| 307 | + pd_info->sst_header.pp_offset + | |
| 308 | + SST_PP_OFFSET_0); | |
| 309 | + | |
| 310 | + perf_level_offsets = readq(pd_info->sst_base + pd_info->sst_header.pp_offset + | |
| 311 | + SST_PP_OFFSET_1); | |
| 312 | + | |
| 313 | + for (i = 0; i < levels; ++i) { | |
| 314 | + u64 offset; | |
| 315 | + | |
| 316 | + offset = perf_level_offsets & (0xff << (i * SST_PP_OFFSET_SIZE)); | |
| 317 | + offset >>= (i * 8); | |
| 318 | + offset &= 0xff; | |
| 319 | + offset *= 8; /* Convert to byte from QWORD offset */ | |
| 320 | + pd_info->perf_levels[i].mmio_offset = pd_info->sst_header.pp_offset + offset; | |
| 321 | + } | |
| 322 | + | |
| 323 | + return 0; | |
| 324 | +} | |
| 325 | + | |
| 326 | +static int sst_main(struct auxiliary_device *auxdev, struct tpmi_per_power_domain_info *pd_info) | |
| 327 | +{ | |
| 328 | + int i, mask, levels; | |
| 329 | + | |
| 330 | + *((u64 *)&pd_info->sst_header) = readq(pd_info->sst_base); | |
| 331 | + pd_info->sst_header.cp_offset *= 8; | |
| 332 | + pd_info->sst_header.pp_offset *= 8; | |
| 333 | + | |
| 334 | + if (pd_info->sst_header.interface_version != ISST_HEADER_VERSION) { | |
| 335 | + dev_err(&auxdev->dev, "SST: Unsupported version:%x\n", | |
| 336 | + pd_info->sst_header.interface_version); | |
| 337 | + return -ENODEV; | |
| 338 | + } | |
| 339 | + | |
| 340 | + /* Read SST CP Header */ | |
| 341 | + *((u64 *)&pd_info->cp_header) = readq(pd_info->sst_base + pd_info->sst_header.cp_offset); | |
| 342 | + | |
| 343 | + /* Read PP header */ | |
| 344 | + *((u64 *)&pd_info->pp_header) = readq(pd_info->sst_base + pd_info->sst_header.pp_offset); | |
| 345 | + | |
| 346 | + /* Force level_en_mask level 0 */ | |
| 347 | + pd_info->pp_header.level_en_mask |= 0x01; | |
| 348 | + | |
| 349 | + mask = 0x01; | |
| 350 | + levels = 0; | |
| 351 | + for (i = 0; i < 8; ++i) { | |
| 352 | + if (pd_info->pp_header.level_en_mask & mask) | |
| 353 | + levels = i; | |
| 354 | + mask <<= 1; | |
| 355 | + } | |
| 356 | + pd_info->max_level = levels; | |
| 357 | + sst_add_perf_profiles(auxdev, pd_info, levels + 1); | |
| 358 | + | |
| 359 | + return 0; | |
| 360 | +} | |
| 361 | + | |
| 88 | 362 | static int isst_if_get_tpmi_instance_count(void __user *argp) |
| 89 | 363 | { |
| 90 | 364 | struct isst_tpmi_instance_count tpmi_inst; |
| @@ -102,10 +376,10 @@ static int isst_if_get_tpmi_instance_count(void __user *argp) · 11 unmodified lines | ||
| 102 | 376 | sst_inst = isst_common.sst_inst[tpmi_inst.socket_id]; |
| 103 | 377 | tpmi_inst.valid_mask = 0; |
| 104 | 378 | for (i = 0; i < sst_inst->number_of_power_domains; ++i) { |
| 105 | − struct tpmi_per_power_domain_info *power_domain_info; | |
| 379 | + struct tpmi_per_power_domain_info *pd_info; | |
| 106 | 380 | |
| 107 | − power_domain_info = &sst_inst->power_domain_info[i]; | |
| 108 | − if (power_domain_info->sst_base) | |
| 381 | + pd_info = &sst_inst->power_domain_info[i]; | |
| 382 | + if (pd_info->sst_base) | |
| 109 | 383 | tpmi_inst.valid_mask |= BIT(i); |
| 110 | 384 | } |
| 111 | 385 | |
| @@ -134,11 +408,13 @@ static long isst_if_def_ioctl(struct file *file, unsigned int cmd, · 22 unmodified lines | ||
| 134 | 408 | return ret; |
| 135 | 409 | } |
| 136 | 410 | |
| 411 | +#define TPMI_SST_AUTO_SUSPEND_DELAY_MS 2000 | |
| 412 | + | |
| 137 | 413 | int tpmi_sst_dev_add(struct auxiliary_device *auxdev) |
| 138 | 414 | { |
| 139 | 415 | struct intel_tpmi_plat_info *plat_info; |
| 140 | 416 | struct tpmi_sst_struct *tpmi_sst; |
| 141 | − int i, pkg = 0, inst = 0; | |
| 417 | + int i, ret, pkg = 0, inst = 0; | |
| 142 | 418 | int num_resources; |
| 143 | 419 | |
| 144 | 420 | plat_info = tpmi_get_platform_data(auxdev); |
| @@ -189,6 +465,13 @@ int tpmi_sst_dev_add(struct auxiliary_device *auxdev) · 44 unmodified lines | ||
| 189 | 465 | if (IS_ERR(tpmi_sst->power_domain_info[i].sst_base)) |
| 190 | 466 | return PTR_ERR(tpmi_sst->power_domain_info[i].sst_base); |
| 191 | 467 | |
| 468 | + ret = sst_main(auxdev, &tpmi_sst->power_domain_info[i]); | |
| 469 | + if (ret) { | |
| 470 | + devm_iounmap(&auxdev->dev, tpmi_sst->power_domain_info[i].sst_base); | |
| 471 | + tpmi_sst->power_domain_info[i].sst_base = NULL; | |
| 472 | + continue; | |
| 473 | + } | |
| 474 | + | |
| 192 | 475 | ++inst; |
| 193 | 476 | } |
| 194 | 477 | |