1 // SPDX-License-Identifier: GPL-2.0
3 * Intel Speed Select -- Enumerate and control features for Mailbox Interface
4 * Copyright (c) 2023 Intel Corporation.
8 static int mbox_get_disp_freq_multiplier(void)
10 return DISP_FREQ_MULTIPLIER;
13 static int mbox_get_trl_max_levels(void)
18 static char *mbox_get_trl_level_name(int level)
32 static int mbox_is_punit_valid(struct isst_id *id)
37 if (id->pkg < 0 || id->die < 0 || id->punit)
43 static int mbox_get_config_levels(struct isst_id *id, struct isst_pkg_ctdp *pkg_dev)
48 ret = isst_send_mbox_command(id->cpu, CONFIG_TDP,
49 CONFIG_TDP_GET_LEVELS_INFO, 0, 0, &resp);
53 pkg_dev->current_level = 0;
59 debug_printf("cpu:%d CONFIG_TDP_GET_LEVELS_INFO resp:%x\n", id->cpu, resp);
61 pkg_dev->version = resp & 0xff;
62 pkg_dev->levels = (resp >> 8) & 0xff;
63 pkg_dev->current_level = (resp >> 16) & 0xff;
64 pkg_dev->locked = !!(resp & BIT(24));
65 pkg_dev->enabled = !!(resp & BIT(31));
70 static int mbox_get_ctdp_control(struct isst_id *id, int config_index,
71 struct isst_pkg_ctdp_level_info *ctdp_level)
77 ret = isst_send_mbox_command(id->cpu, CONFIG_TDP,
78 CONFIG_TDP_GET_TDP_CONTROL, 0,
83 ctdp_level->fact_support = resp & BIT(0);
84 ctdp_level->pbf_support = !!(resp & BIT(1));
85 ctdp_level->fact_enabled = !!(resp & BIT(16));
86 ctdp_level->pbf_enabled = !!(resp & BIT(17));
88 ret = isst_read_pm_config(id, &cp_state, &cp_cap);
90 debug_printf("cpu:%d pm_config is not supported\n", id->cpu);
92 debug_printf("cpu:%d pm_config SST-CP state:%d cap:%d\n", id->cpu, cp_state, cp_cap);
93 ctdp_level->sst_cp_support = cp_cap;
94 ctdp_level->sst_cp_enabled = cp_state;
98 "cpu:%d CONFIG_TDP_GET_TDP_CONTROL resp:%x fact_support:%d pbf_support: %d fact_enabled:%d pbf_enabled:%d\n",
99 id->cpu, resp, ctdp_level->fact_support, ctdp_level->pbf_support,
100 ctdp_level->fact_enabled, ctdp_level->pbf_enabled);
105 static void mbox_get_uncore_p0_p1_info(struct isst_id *id, int config_index,
106 struct isst_pkg_ctdp_level_info *ctdp_level)
111 ctdp_level->uncore_pm = 0;
112 ctdp_level->uncore_p0 = 0;
113 ctdp_level->uncore_p1 = 0;
115 ret = isst_send_mbox_command(id->cpu, CONFIG_TDP,
116 CONFIG_TDP_GET_RATIO_INFO, 0,
117 (BIT(16) | config_index) , &resp);
119 goto try_uncore_mbox;
122 ctdp_level->uncore_p0 = resp & GENMASK(7, 0);
123 ctdp_level->uncore_p1 = (resp & GENMASK(15, 8)) >> 8;
124 ctdp_level->uncore_pm = (resp & GENMASK(31, 24)) >> 24;
127 "cpu:%d ctdp:%d CONFIG_TDP_GET_RATIO_INFO resp:%x uncore p0:%d uncore p1:%d uncore pm:%d\n",
128 id->cpu, config_index, resp, ctdp_level->uncore_p0, ctdp_level->uncore_p1,
129 ctdp_level->uncore_pm);
134 ret = isst_send_mbox_command(id->cpu, CONFIG_TDP,
135 CONFIG_TDP_GET_UNCORE_P0_P1_INFO, 0,
136 config_index, &resp);
138 ctdp_level->uncore_p0 = 0;
139 ctdp_level->uncore_p1 = 0;
143 ctdp_level->uncore_p0 = resp & GENMASK(7, 0);
144 ctdp_level->uncore_p1 = (resp & GENMASK(15, 8)) >> 8;
146 "cpu:%d ctdp:%d CONFIG_TDP_GET_UNCORE_P0_P1_INFO resp:%x uncore p0:%d uncore p1:%d\n",
147 id->cpu, config_index, resp, ctdp_level->uncore_p0,
148 ctdp_level->uncore_p1);
151 static void _get_p1_info(struct isst_id *id, int config_index,
152 struct isst_pkg_ctdp_level_info *ctdp_level)
156 ret = isst_send_mbox_command(id->cpu, CONFIG_TDP, CONFIG_TDP_GET_P1_INFO, 0,
157 config_index, &resp);
159 ctdp_level->sse_p1 = 0;
160 ctdp_level->avx2_p1 = 0;
161 ctdp_level->avx512_p1 = 0;
165 ctdp_level->sse_p1 = resp & GENMASK(7, 0);
166 ctdp_level->avx2_p1 = (resp & GENMASK(15, 8)) >> 8;
167 ctdp_level->avx512_p1 = (resp & GENMASK(23, 16)) >> 16;
169 "cpu:%d ctdp:%d CONFIG_TDP_GET_P1_INFO resp:%x sse_p1:%d avx2_p1:%d avx512_p1:%d\n",
170 id->cpu, config_index, resp, ctdp_level->sse_p1,
171 ctdp_level->avx2_p1, ctdp_level->avx512_p1);
174 static void _get_uncore_mem_freq(struct isst_id *id, int config_index,
175 struct isst_pkg_ctdp_level_info *ctdp_level)
180 ret = isst_send_mbox_command(id->cpu, CONFIG_TDP, CONFIG_TDP_GET_MEM_FREQ,
181 0, config_index, &resp);
183 ctdp_level->mem_freq = 0;
187 ctdp_level->mem_freq = resp & GENMASK(7, 0);
188 if (is_spr_platform()) {
189 ctdp_level->mem_freq *= 200;
190 } else if (is_icx_platform()) {
191 if (ctdp_level->mem_freq < 7) {
192 ctdp_level->mem_freq = (12 - ctdp_level->mem_freq) * 133.33 * 2 * 10;
193 ctdp_level->mem_freq /= 10;
194 if (ctdp_level->mem_freq % 10 > 5)
195 ctdp_level->mem_freq++;
197 ctdp_level->mem_freq = 0;
200 ctdp_level->mem_freq = 0;
203 "cpu:%d ctdp:%d CONFIG_TDP_GET_MEM_FREQ resp:%x uncore mem_freq:%d\n",
204 id->cpu, config_index, resp, ctdp_level->mem_freq);
207 static int mbox_get_tdp_info(struct isst_id *id, int config_index,
208 struct isst_pkg_ctdp_level_info *ctdp_level)
213 ret = isst_send_mbox_command(id->cpu, CONFIG_TDP, CONFIG_TDP_GET_TDP_INFO,
214 0, config_index, &resp);
216 isst_display_error_info_message(1, "Invalid level, Can't get TDP information at level", 1, config_index);
220 ctdp_level->pkg_tdp = resp & GENMASK(14, 0);
221 ctdp_level->tdp_ratio = (resp & GENMASK(23, 16)) >> 16;
224 "cpu:%d ctdp:%d CONFIG_TDP_GET_TDP_INFO resp:%x tdp_ratio:%d pkg_tdp:%d\n",
225 id->cpu, config_index, resp, ctdp_level->tdp_ratio,
226 ctdp_level->pkg_tdp);
228 ret = isst_send_mbox_command(id->cpu, CONFIG_TDP, CONFIG_TDP_GET_TJMAX_INFO,
229 0, config_index, &resp);
233 ctdp_level->t_proc_hot = resp & GENMASK(7, 0);
235 mbox_get_uncore_p0_p1_info(id, config_index, ctdp_level);
236 _get_p1_info(id, config_index, ctdp_level);
237 _get_uncore_mem_freq(id, config_index, ctdp_level);
240 "cpu:%d ctdp:%d CONFIG_TDP_GET_TJMAX_INFO resp:%x t_proc_hot:%d\n",
241 id->cpu, config_index, resp, ctdp_level->t_proc_hot);
246 static int mbox_get_pwr_info(struct isst_id *id, int config_index,
247 struct isst_pkg_ctdp_level_info *ctdp_level)
252 ret = isst_send_mbox_command(id->cpu, CONFIG_TDP, CONFIG_TDP_GET_PWR_INFO,
253 0, config_index, &resp);
257 ctdp_level->pkg_max_power = resp & GENMASK(14, 0);
258 ctdp_level->pkg_min_power = (resp & GENMASK(30, 16)) >> 16;
261 "cpu:%d ctdp:%d CONFIG_TDP_GET_PWR_INFO resp:%x pkg_max_power:%d pkg_min_power:%d\n",
262 id->cpu, config_index, resp, ctdp_level->pkg_max_power,
263 ctdp_level->pkg_min_power);
268 static int mbox_get_coremask_info(struct isst_id *id, int config_index,
269 struct isst_pkg_ctdp_level_info *ctdp_level)
274 ctdp_level->cpu_count = 0;
275 for (i = 0; i < 2; ++i) {
276 unsigned long long mask;
279 ret = isst_send_mbox_command(id->cpu, CONFIG_TDP,
280 CONFIG_TDP_GET_CORE_MASK, 0,
281 (i << 8) | config_index, &resp);
286 "cpu:%d ctdp:%d mask:%d CONFIG_TDP_GET_CORE_MASK resp:%x\n",
287 id->cpu, config_index, i, resp);
289 mask = (unsigned long long)resp << (32 * i);
290 set_cpu_mask_from_punit_coremask(id, mask,
291 ctdp_level->core_cpumask_size,
292 ctdp_level->core_cpumask,
294 ctdp_level->cpu_count += cpu_count;
295 debug_printf("cpu:%d ctdp:%d mask:%d cpu count:%d\n", id->cpu,
296 config_index, i, ctdp_level->cpu_count);
302 static int mbox_get_get_trl(struct isst_id *id, int level, int avx_level, int *trl)
304 unsigned int req, resp;
307 req = level | (avx_level << 16);
308 ret = isst_send_mbox_command(id->cpu, CONFIG_TDP,
309 CONFIG_TDP_GET_TURBO_LIMIT_RATIOS, 0, req,
315 "cpu:%d CONFIG_TDP_GET_TURBO_LIMIT_RATIOS req:%x resp:%x\n",
318 trl[0] = resp & GENMASK(7, 0);
319 trl[1] = (resp & GENMASK(15, 8)) >> 8;
320 trl[2] = (resp & GENMASK(23, 16)) >> 16;
321 trl[3] = (resp & GENMASK(31, 24)) >> 24;
323 req = level | BIT(8) | (avx_level << 16);
324 ret = isst_send_mbox_command(id->cpu, CONFIG_TDP,
325 CONFIG_TDP_GET_TURBO_LIMIT_RATIOS, 0, req,
330 debug_printf("cpu:%d CONFIG_TDP_GET_TURBO_LIMIT req:%x resp:%x\n", id->cpu,
333 trl[4] = resp & GENMASK(7, 0);
334 trl[5] = (resp & GENMASK(15, 8)) >> 8;
335 trl[6] = (resp & GENMASK(23, 16)) >> 16;
336 trl[7] = (resp & GENMASK(31, 24)) >> 24;
341 static int mbox_get_get_trls(struct isst_id *id, int level, struct isst_pkg_ctdp_level_info *ctdp_level)
343 int trl_max_levels = isst_get_trl_max_levels();
346 for (i = 0; i < trl_max_levels; i++) {
347 ret = mbox_get_get_trl(id, level, i, ctdp_level->trl_ratios[i]);
354 static int mbox_get_trl_bucket_info(struct isst_id *id, int level, unsigned long long *buckets_info)
358 debug_printf("cpu:%d bucket info via MSR\n", id->cpu);
362 ret = isst_send_msr_command(id->cpu, 0x1ae, 0, buckets_info);
366 debug_printf("cpu:%d bucket info via MSR successful 0x%llx\n", id->cpu,
372 static int mbox_set_tdp_level(struct isst_id *id, int tdp_level)
378 if (isst_get_config_tdp_lock_status(id)) {
379 isst_display_error_info_message(1, "TDP is locked", 0, 0);
384 ret = isst_send_mbox_command(id->cpu, CONFIG_TDP, CONFIG_TDP_SET_LEVEL, 0,
387 isst_display_error_info_message(1, "Set TDP level failed for level", 1, tdp_level);
394 static int mbox_get_pbf_info(struct isst_id *id, int level, struct isst_pbf_info *pbf_info)
396 int max_punit_core, max_mask_index;
397 unsigned int req, resp;
400 max_punit_core = get_max_punit_core_id(id);
401 max_mask_index = max_punit_core > 32 ? 2 : 1;
403 for (i = 0; i < max_mask_index; ++i) {
404 unsigned long long mask;
407 ret = isst_send_mbox_command(id->cpu, CONFIG_TDP,
408 CONFIG_TDP_PBF_GET_CORE_MASK_INFO,
409 0, (i << 8) | level, &resp);
414 "cpu:%d CONFIG_TDP_PBF_GET_CORE_MASK_INFO resp:%x\n",
417 mask = (unsigned long long)resp << (32 * i);
418 set_cpu_mask_from_punit_coremask(id, mask,
419 pbf_info->core_cpumask_size,
420 pbf_info->core_cpumask,
425 ret = isst_send_mbox_command(id->cpu, CONFIG_TDP,
426 CONFIG_TDP_PBF_GET_P1HI_P1LO_INFO, 0, req,
431 debug_printf("cpu:%d CONFIG_TDP_PBF_GET_P1HI_P1LO_INFO resp:%x\n", id->cpu,
434 pbf_info->p1_low = resp & 0xff;
435 pbf_info->p1_high = (resp & GENMASK(15, 8)) >> 8;
438 ret = isst_send_mbox_command(
439 id->cpu, CONFIG_TDP, CONFIG_TDP_PBF_GET_TDP_INFO, 0, req, &resp);
443 debug_printf("cpu:%d CONFIG_TDP_PBF_GET_TDP_INFO resp:%x\n", id->cpu, resp);
445 pbf_info->tdp = resp & 0xffff;
448 ret = isst_send_mbox_command(
449 id->cpu, CONFIG_TDP, CONFIG_TDP_PBF_GET_TJ_MAX_INFO, 0, req, &resp);
453 debug_printf("cpu:%d CONFIG_TDP_PBF_GET_TJ_MAX_INFO resp:%x\n", id->cpu,
455 pbf_info->t_control = (resp >> 8) & 0xff;
456 pbf_info->t_prochot = resp & 0xff;
461 static int mbox_set_pbf_fact_status(struct isst_id *id, int pbf, int enable)
463 struct isst_pkg_ctdp pkg_dev;
464 struct isst_pkg_ctdp_level_info ctdp_level;
466 unsigned int req = 0, resp;
469 ret = isst_get_ctdp_levels(id, &pkg_dev);
471 debug_printf("cpu:%d No support for dynamic ISST\n", id->cpu);
473 current_level = pkg_dev.current_level;
475 ret = isst_get_ctdp_control(id, current_level, &ctdp_level);
480 if (ctdp_level.fact_enabled)
489 if (enable && !ctdp_level.sst_cp_enabled)
490 isst_display_error_info_message(0, "Make sure to execute before: core-power enable", 0, 0);
492 if (ctdp_level.pbf_enabled)
501 ret = isst_send_mbox_command(id->cpu, CONFIG_TDP,
502 CONFIG_TDP_SET_TDP_CONTROL, 0, req, &resp);
506 debug_printf("cpu:%d CONFIG_TDP_SET_TDP_CONTROL pbf/fact:%d req:%x\n",
512 static int _get_fact_bucket_info(struct isst_id *id, int level,
513 struct isst_fact_bucket_info *bucket_info)
518 for (i = 0; i < 2; ++i) {
521 ret = isst_send_mbox_command(
523 CONFIG_TDP_GET_FACT_HP_TURBO_LIMIT_NUMCORES, 0,
524 (i << 8) | level, &resp);
529 "cpu:%d CONFIG_TDP_GET_FACT_HP_TURBO_LIMIT_NUMCORES index:%d level:%d resp:%x\n",
530 id->cpu, i, level, resp);
532 for (j = 0; j < 4; ++j) {
533 bucket_info[j + (i * 4)].hp_cores =
534 (resp >> (j * 8)) & 0xff;
538 for (k = 0; k < 3; ++k) {
539 for (i = 0; i < 2; ++i) {
542 ret = isst_send_mbox_command(
544 CONFIG_TDP_GET_FACT_HP_TURBO_LIMIT_RATIOS, 0,
545 (k << 16) | (i << 8) | level, &resp);
550 "cpu:%d CONFIG_TDP_GET_FACT_HP_TURBO_LIMIT_RATIOS index:%d level:%d avx:%d resp:%x\n",
551 id->cpu, i, level, k, resp);
553 for (j = 0; j < 4; ++j) {
554 bucket_info[j + (i * 4)].hp_ratios[k] =
555 (resp >> (j * 8)) & 0xff;
563 static int mbox_get_fact_info(struct isst_id *id, int level, int fact_bucket, struct isst_fact_info *fact_info)
568 ret = isst_send_mbox_command(id->cpu, CONFIG_TDP,
569 CONFIG_TDP_GET_FACT_LP_CLIPPING_RATIO, 0,
574 debug_printf("cpu:%d CONFIG_TDP_GET_FACT_LP_CLIPPING_RATIO resp:%x\n",
577 fact_info->lp_ratios[0] = resp & 0xff;
578 fact_info->lp_ratios[1] = (resp >> 8) & 0xff;
579 fact_info->lp_ratios[2] = (resp >> 16) & 0xff;
581 ret = _get_fact_bucket_info(id, level, fact_info->bucket_info);
586 for (j = 0; j < ISST_FACT_MAX_BUCKETS; ++j) {
587 if (fact_bucket != 0xff && fact_bucket != j)
590 if (!fact_info->bucket_info[j].hp_cores)
596 isst_display_error_info_message(1, "Invalid bucket", 0, 0);
603 static int mbox_get_clos_information(struct isst_id *id, int *enable, int *type)
608 ret = isst_send_mbox_command(id->cpu, CONFIG_CLOS, CLOS_PM_QOS_CONFIG, 0, 0,
613 debug_printf("cpu:%d CLOS_PM_QOS_CONFIG resp:%x\n", id->cpu, resp);
627 static struct isst_platform_ops mbox_ops = {
628 .get_disp_freq_multiplier = mbox_get_disp_freq_multiplier,
629 .get_trl_max_levels = mbox_get_trl_max_levels,
630 .get_trl_level_name = mbox_get_trl_level_name,
631 .is_punit_valid = mbox_is_punit_valid,
632 .get_config_levels = mbox_get_config_levels,
633 .get_ctdp_control = mbox_get_ctdp_control,
634 .get_tdp_info = mbox_get_tdp_info,
635 .get_pwr_info = mbox_get_pwr_info,
636 .get_coremask_info = mbox_get_coremask_info,
637 .get_get_trl = mbox_get_get_trl,
638 .get_get_trls = mbox_get_get_trls,
639 .get_trl_bucket_info = mbox_get_trl_bucket_info,
640 .set_tdp_level = mbox_set_tdp_level,
641 .get_pbf_info = mbox_get_pbf_info,
642 .set_pbf_fact_status = mbox_set_pbf_fact_status,
643 .get_fact_info = mbox_get_fact_info,
644 .get_uncore_p0_p1_info = mbox_get_uncore_p0_p1_info,
645 .get_clos_information = mbox_get_clos_information,
648 struct isst_platform_ops *mbox_get_platform_ops(void)