1 // SPDX-License-Identifier: GPL-2.0
3 * Intel Speed Select -- Enumerate and control features for Mailbox Interface
4 * Copyright (c) 2023 Intel Corporation.
9 static int mbox_retries = 3;
11 #define MAX_TRL_LEVELS_EMR 5
13 static int mbox_get_disp_freq_multiplier(void)
15 return DISP_FREQ_MULTIPLIER;
18 static int mbox_get_trl_max_levels(void)
20 if (is_emr_platform())
21 return MAX_TRL_LEVELS_EMR;
26 static char *mbox_get_trl_level_name(int level)
28 if (is_emr_platform()) {
29 static char level_str[18];
31 if (level >= MAX_TRL_LEVELS_EMR)
34 snprintf(level_str, sizeof(level_str), "level-%d", level);
50 static void mbox_update_platform_param(enum isst_platform_param param, int value)
53 case ISST_PARAM_MBOX_DELAY:
56 case ISST_PARAM_MBOX_RETRIES:
64 static int mbox_is_punit_valid(struct isst_id *id)
69 if (id->pkg < 0 || id->die < 0 || id->punit)
75 static int _send_mmio_command(unsigned int cpu, unsigned int reg, int write,
78 struct isst_if_io_regs io_regs;
79 const char *pathname = "/dev/isst_interface";
81 FILE *outf = get_output_file();
84 debug_printf("mmio_cmd cpu:%d reg:%d write:%d\n", cpu, reg, write);
86 fd = open(pathname, O_RDWR);
88 err(-1, "%s open failed", pathname);
90 io_regs.req_count = 1;
91 io_regs.io_reg[0].logical_cpu = cpu;
92 io_regs.io_reg[0].reg = reg;
95 io_regs.io_reg[0].read_write = 1;
96 io_regs.io_reg[0].value = *value;
98 io_regs.io_reg[0].read_write = 0;
101 if (ioctl(fd, cmd, &io_regs) == -1) {
102 if (errno == ENOTTY) {
103 perror("ISST_IF_IO_COMMAND\n");
104 fprintf(stderr, "Check presence of kernel modules: isst_if_mmio\n");
107 fprintf(outf, "Error: mmio_cmd cpu:%d reg:%x read_write:%x\n",
111 *value = io_regs.io_reg[0].value;
114 "mmio_cmd response: cpu:%d reg:%x rd_write:%x resp:%x\n",
115 cpu, reg, write, *value);
123 int _send_mbox_command(unsigned int cpu, unsigned char command,
124 unsigned char sub_command, unsigned int parameter,
125 unsigned int req_data, unsigned int *resp)
127 const char *pathname = "/dev/isst_interface";
129 struct isst_if_mbox_cmds mbox_cmds = { 0 };
132 "mbox_send: cpu:%d command:%x sub_command:%x parameter:%x req_data:%x\n",
133 cpu, command, sub_command, parameter, req_data);
135 if (!is_skx_based_platform() && command == CONFIG_CLOS &&
136 sub_command != CLOS_PM_QOS_CONFIG) {
139 int clos_id, core_id, ret = 0;
141 debug_printf("CPU %d\n", cpu);
143 if (parameter & BIT(MBOX_CMD_WRITE_BIT)) {
148 switch (sub_command) {
150 core_id = parameter & 0xff;
151 ret = _send_mmio_command(
152 cpu, PQR_ASSOC_OFFSET + core_id * 4, write,
158 clos_id = parameter & 0x03;
159 ret = _send_mmio_command(
160 cpu, PM_CLOS_OFFSET + clos_id * 4, write,
173 mbox_cmds.cmd_count = 1;
174 mbox_cmds.mbox_cmd[0].logical_cpu = cpu;
175 mbox_cmds.mbox_cmd[0].command = command;
176 mbox_cmds.mbox_cmd[0].sub_command = sub_command;
177 mbox_cmds.mbox_cmd[0].parameter = parameter;
178 mbox_cmds.mbox_cmd[0].req_data = req_data;
181 usleep(mbox_delay * 1000);
183 fd = open(pathname, O_RDWR);
185 err(-1, "%s open failed", pathname);
187 retry = mbox_retries;
189 if (ioctl(fd, ISST_IF_MBOX_COMMAND, &mbox_cmds) == -1) {
190 if (errno == ENOTTY) {
191 perror("ISST_IF_MBOX_COMMAND\n");
192 fprintf(stderr, "Check presence of kernel modules: isst_if_mbox_pci or isst_if_mbox_msr\n");
196 "Error: mbox_cmd cpu:%d command:%x sub_command:%x parameter:%x req_data:%x errorno:%d\n",
197 cpu, command, sub_command, parameter, req_data, errno);
200 *resp = mbox_cmds.mbox_cmd[0].resp_data;
202 "mbox_cmd response: cpu:%d command:%x sub_command:%x parameter:%x req_data:%x resp:%x\n",
203 cpu, command, sub_command, parameter, req_data, *resp);
211 debug_printf("Failed mbox command even after retries\n");
219 static int mbox_read_pm_config(struct isst_id *id, int *cp_state, int *cp_cap)
224 ret = _send_mbox_command(id->cpu, READ_PM_CONFIG, PM_FEATURE, 0, 0,
229 debug_printf("cpu:%d READ_PM_CONFIG resp:%x\n", id->cpu, resp);
231 *cp_state = resp & BIT(16);
232 *cp_cap = resp & BIT(0) ? 1 : 0;
237 static int mbox_get_config_levels(struct isst_id *id, struct isst_pkg_ctdp *pkg_dev)
242 ret = _send_mbox_command(id->cpu, CONFIG_TDP,
243 CONFIG_TDP_GET_LEVELS_INFO, 0, 0, &resp);
247 pkg_dev->current_level = 0;
248 pkg_dev->version = 0;
249 pkg_dev->enabled = 0;
253 debug_printf("cpu:%d CONFIG_TDP_GET_LEVELS_INFO resp:%x\n", id->cpu, resp);
255 pkg_dev->version = resp & 0xff;
256 pkg_dev->levels = (resp >> 8) & 0xff;
257 pkg_dev->current_level = (resp >> 16) & 0xff;
258 pkg_dev->locked = !!(resp & BIT(24));
259 pkg_dev->enabled = !!(resp & BIT(31));
264 static int mbox_get_ctdp_control(struct isst_id *id, int config_index,
265 struct isst_pkg_ctdp_level_info *ctdp_level)
267 int cp_state, cp_cap;
271 ret = _send_mbox_command(id->cpu, CONFIG_TDP,
272 CONFIG_TDP_GET_TDP_CONTROL, 0,
273 config_index, &resp);
277 ctdp_level->fact_support = resp & BIT(0);
278 ctdp_level->pbf_support = !!(resp & BIT(1));
279 ctdp_level->fact_enabled = !!(resp & BIT(16));
280 ctdp_level->pbf_enabled = !!(resp & BIT(17));
282 ret = isst_read_pm_config(id, &cp_state, &cp_cap);
284 debug_printf("cpu:%d pm_config is not supported\n", id->cpu);
286 debug_printf("cpu:%d pm_config SST-CP state:%d cap:%d\n", id->cpu, cp_state, cp_cap);
287 ctdp_level->sst_cp_support = cp_cap;
288 ctdp_level->sst_cp_enabled = cp_state;
292 "cpu:%d CONFIG_TDP_GET_TDP_CONTROL resp:%x fact_support:%d pbf_support: %d fact_enabled:%d pbf_enabled:%d\n",
293 id->cpu, resp, ctdp_level->fact_support, ctdp_level->pbf_support,
294 ctdp_level->fact_enabled, ctdp_level->pbf_enabled);
299 static void _get_uncore_p0_p1_info(struct isst_id *id, int config_index,
300 struct isst_pkg_ctdp_level_info *ctdp_level)
305 ctdp_level->uncore_pm = 0;
306 ctdp_level->uncore_p0 = 0;
307 ctdp_level->uncore_p1 = 0;
309 ret = _send_mbox_command(id->cpu, CONFIG_TDP,
310 CONFIG_TDP_GET_RATIO_INFO, 0,
311 (BIT(16) | config_index) , &resp);
313 goto try_uncore_mbox;
316 ctdp_level->uncore_p0 = resp & GENMASK(7, 0);
317 ctdp_level->uncore_p1 = (resp & GENMASK(15, 8)) >> 8;
318 ctdp_level->uncore_pm = (resp & GENMASK(31, 24)) >> 24;
321 "cpu:%d ctdp:%d CONFIG_TDP_GET_RATIO_INFO resp:%x uncore p0:%d uncore p1:%d uncore pm:%d\n",
322 id->cpu, config_index, resp, ctdp_level->uncore_p0, ctdp_level->uncore_p1,
323 ctdp_level->uncore_pm);
328 ret = _send_mbox_command(id->cpu, CONFIG_TDP,
329 CONFIG_TDP_GET_UNCORE_P0_P1_INFO, 0,
330 config_index, &resp);
332 ctdp_level->uncore_p0 = 0;
333 ctdp_level->uncore_p1 = 0;
337 ctdp_level->uncore_p0 = resp & GENMASK(7, 0);
338 ctdp_level->uncore_p1 = (resp & GENMASK(15, 8)) >> 8;
340 "cpu:%d ctdp:%d CONFIG_TDP_GET_UNCORE_P0_P1_INFO resp:%x uncore p0:%d uncore p1:%d\n",
341 id->cpu, config_index, resp, ctdp_level->uncore_p0,
342 ctdp_level->uncore_p1);
345 static int _set_uncore_min_max(struct isst_id *id, int max, int freq)
347 char buffer[128], freq_str[16];
351 snprintf(buffer, sizeof(buffer),
352 "/sys/devices/system/cpu/intel_uncore_frequency/package_%02d_die_%02d/max_freq_khz", id->pkg, id->die);
354 snprintf(buffer, sizeof(buffer),
355 "/sys/devices/system/cpu/intel_uncore_frequency/package_%02d_die_%02d/min_freq_khz", id->pkg, id->die);
357 fd = open(buffer, O_WRONLY);
361 snprintf(freq_str, sizeof(freq_str), "%d", freq);
362 len = strlen(freq_str);
363 ret = write(fd, freq_str, len);
373 static void mbox_adjust_uncore_freq(struct isst_id *id, int config_index,
374 struct isst_pkg_ctdp_level_info *ctdp_level)
376 _get_uncore_p0_p1_info(id, config_index, ctdp_level);
377 if (ctdp_level->uncore_pm)
378 _set_uncore_min_max(id, 0, ctdp_level->uncore_pm * 100000);
380 if (ctdp_level->uncore_p0)
381 _set_uncore_min_max(id, 1, ctdp_level->uncore_p0 * 100000);
384 static void _get_p1_info(struct isst_id *id, int config_index,
385 struct isst_pkg_ctdp_level_info *ctdp_level)
389 ret = _send_mbox_command(id->cpu, CONFIG_TDP, CONFIG_TDP_GET_P1_INFO, 0,
390 config_index, &resp);
392 ctdp_level->sse_p1 = 0;
393 ctdp_level->avx2_p1 = 0;
394 ctdp_level->avx512_p1 = 0;
398 ctdp_level->sse_p1 = resp & GENMASK(7, 0);
399 ctdp_level->avx2_p1 = (resp & GENMASK(15, 8)) >> 8;
400 ctdp_level->avx512_p1 = (resp & GENMASK(23, 16)) >> 16;
401 ctdp_level->amx_p1 = (resp & GENMASK(31, 24)) >> 24;
403 "cpu:%d ctdp:%d CONFIG_TDP_GET_P1_INFO resp:%x sse_p1:%d avx2_p1:%d avx512_p1:%d amx_p1:%d\n",
404 id->cpu, config_index, resp, ctdp_level->sse_p1,
405 ctdp_level->avx2_p1, ctdp_level->avx512_p1, ctdp_level->amx_p1);
408 static void _get_uncore_mem_freq(struct isst_id *id, int config_index,
409 struct isst_pkg_ctdp_level_info *ctdp_level)
414 ret = _send_mbox_command(id->cpu, CONFIG_TDP, CONFIG_TDP_GET_MEM_FREQ,
415 0, config_index, &resp);
417 ctdp_level->mem_freq = 0;
421 ctdp_level->mem_freq = resp & GENMASK(7, 0);
422 if (is_spr_platform() || is_emr_platform()) {
423 ctdp_level->mem_freq *= 200;
424 } else if (is_icx_platform()) {
425 if (ctdp_level->mem_freq < 7) {
426 ctdp_level->mem_freq = (12 - ctdp_level->mem_freq) * 133.33 * 2 * 10;
427 ctdp_level->mem_freq /= 10;
428 if (ctdp_level->mem_freq % 10 > 5)
429 ctdp_level->mem_freq++;
431 ctdp_level->mem_freq = 0;
434 ctdp_level->mem_freq = 0;
437 "cpu:%d ctdp:%d CONFIG_TDP_GET_MEM_FREQ resp:%x uncore mem_freq:%d\n",
438 id->cpu, config_index, resp, ctdp_level->mem_freq);
441 static int mbox_get_tdp_info(struct isst_id *id, int config_index,
442 struct isst_pkg_ctdp_level_info *ctdp_level)
447 ret = _send_mbox_command(id->cpu, CONFIG_TDP, CONFIG_TDP_GET_TDP_INFO,
448 0, config_index, &resp);
450 isst_display_error_info_message(1, "Invalid level, Can't get TDP information at level", 1, config_index);
454 ctdp_level->pkg_tdp = resp & GENMASK(14, 0);
455 ctdp_level->tdp_ratio = (resp & GENMASK(23, 16)) >> 16;
458 "cpu:%d ctdp:%d CONFIG_TDP_GET_TDP_INFO resp:%x tdp_ratio:%d pkg_tdp:%d\n",
459 id->cpu, config_index, resp, ctdp_level->tdp_ratio,
460 ctdp_level->pkg_tdp);
462 ret = _send_mbox_command(id->cpu, CONFIG_TDP, CONFIG_TDP_GET_TJMAX_INFO,
463 0, config_index, &resp);
467 ctdp_level->t_proc_hot = resp & GENMASK(7, 0);
469 _get_uncore_p0_p1_info(id, config_index, ctdp_level);
470 _get_p1_info(id, config_index, ctdp_level);
471 _get_uncore_mem_freq(id, config_index, ctdp_level);
474 "cpu:%d ctdp:%d CONFIG_TDP_GET_TJMAX_INFO resp:%x t_proc_hot:%d\n",
475 id->cpu, config_index, resp, ctdp_level->t_proc_hot);
480 static int mbox_get_pwr_info(struct isst_id *id, int config_index,
481 struct isst_pkg_ctdp_level_info *ctdp_level)
486 ret = _send_mbox_command(id->cpu, CONFIG_TDP, CONFIG_TDP_GET_PWR_INFO,
487 0, config_index, &resp);
491 ctdp_level->pkg_max_power = resp & GENMASK(14, 0);
492 ctdp_level->pkg_min_power = (resp & GENMASK(30, 16)) >> 16;
495 "cpu:%d ctdp:%d CONFIG_TDP_GET_PWR_INFO resp:%x pkg_max_power:%d pkg_min_power:%d\n",
496 id->cpu, config_index, resp, ctdp_level->pkg_max_power,
497 ctdp_level->pkg_min_power);
502 static int mbox_get_coremask_info(struct isst_id *id, int config_index,
503 struct isst_pkg_ctdp_level_info *ctdp_level)
508 ctdp_level->cpu_count = 0;
509 for (i = 0; i < 2; ++i) {
510 unsigned long long mask;
513 ret = _send_mbox_command(id->cpu, CONFIG_TDP,
514 CONFIG_TDP_GET_CORE_MASK, 0,
515 (i << 8) | config_index, &resp);
520 "cpu:%d ctdp:%d mask:%d CONFIG_TDP_GET_CORE_MASK resp:%x\n",
521 id->cpu, config_index, i, resp);
523 mask = (unsigned long long)resp << (32 * i);
524 set_cpu_mask_from_punit_coremask(id, mask,
525 ctdp_level->core_cpumask_size,
526 ctdp_level->core_cpumask,
528 ctdp_level->cpu_count += cpu_count;
529 debug_printf("cpu:%d ctdp:%d mask:%d cpu count:%d\n", id->cpu,
530 config_index, i, ctdp_level->cpu_count);
536 static int mbox_get_get_trl(struct isst_id *id, int level, int avx_level, int *trl)
538 unsigned int req, resp;
541 req = level | (avx_level << 16);
542 ret = _send_mbox_command(id->cpu, CONFIG_TDP,
543 CONFIG_TDP_GET_TURBO_LIMIT_RATIOS, 0, req,
549 "cpu:%d CONFIG_TDP_GET_TURBO_LIMIT_RATIOS req:%x resp:%x\n",
552 trl[0] = resp & GENMASK(7, 0);
553 trl[1] = (resp & GENMASK(15, 8)) >> 8;
554 trl[2] = (resp & GENMASK(23, 16)) >> 16;
555 trl[3] = (resp & GENMASK(31, 24)) >> 24;
557 req = level | BIT(8) | (avx_level << 16);
558 ret = _send_mbox_command(id->cpu, CONFIG_TDP,
559 CONFIG_TDP_GET_TURBO_LIMIT_RATIOS, 0, req,
564 debug_printf("cpu:%d CONFIG_TDP_GET_TURBO_LIMIT req:%x resp:%x\n", id->cpu,
567 trl[4] = resp & GENMASK(7, 0);
568 trl[5] = (resp & GENMASK(15, 8)) >> 8;
569 trl[6] = (resp & GENMASK(23, 16)) >> 16;
570 trl[7] = (resp & GENMASK(31, 24)) >> 24;
575 static int mbox_get_get_trls(struct isst_id *id, int level, struct isst_pkg_ctdp_level_info *ctdp_level)
577 int trl_max_levels = isst_get_trl_max_levels();
580 for (i = 0; i < trl_max_levels; i++) {
581 ret = mbox_get_get_trl(id, level, i, ctdp_level->trl_ratios[i]);
588 static int mbox_get_trl_bucket_info(struct isst_id *id, int level, unsigned long long *buckets_info)
592 debug_printf("cpu:%d bucket info via MSR\n", id->cpu);
596 ret = isst_send_msr_command(id->cpu, 0x1ae, 0, buckets_info);
600 debug_printf("cpu:%d bucket info via MSR successful 0x%llx\n", id->cpu,
606 static int mbox_set_tdp_level(struct isst_id *id, int tdp_level)
612 if (isst_get_config_tdp_lock_status(id)) {
613 isst_display_error_info_message(1, "TDP is locked", 0, 0);
618 ret = _send_mbox_command(id->cpu, CONFIG_TDP, CONFIG_TDP_SET_LEVEL, 0,
621 isst_display_error_info_message(1, "Set TDP level failed for level", 1, tdp_level);
628 static int mbox_get_pbf_info(struct isst_id *id, int level, struct isst_pbf_info *pbf_info)
630 int max_punit_core, max_mask_index;
631 unsigned int req, resp;
634 max_punit_core = get_max_punit_core_id(id);
635 max_mask_index = max_punit_core > 32 ? 2 : 1;
637 for (i = 0; i < max_mask_index; ++i) {
638 unsigned long long mask;
641 ret = _send_mbox_command(id->cpu, CONFIG_TDP,
642 CONFIG_TDP_PBF_GET_CORE_MASK_INFO,
643 0, (i << 8) | level, &resp);
648 "cpu:%d CONFIG_TDP_PBF_GET_CORE_MASK_INFO resp:%x\n",
651 mask = (unsigned long long)resp << (32 * i);
652 set_cpu_mask_from_punit_coremask(id, mask,
653 pbf_info->core_cpumask_size,
654 pbf_info->core_cpumask,
659 ret = _send_mbox_command(id->cpu, CONFIG_TDP,
660 CONFIG_TDP_PBF_GET_P1HI_P1LO_INFO, 0, req,
665 debug_printf("cpu:%d CONFIG_TDP_PBF_GET_P1HI_P1LO_INFO resp:%x\n", id->cpu,
668 pbf_info->p1_low = resp & 0xff;
669 pbf_info->p1_high = (resp & GENMASK(15, 8)) >> 8;
672 ret = _send_mbox_command(
673 id->cpu, CONFIG_TDP, CONFIG_TDP_PBF_GET_TDP_INFO, 0, req, &resp);
677 debug_printf("cpu:%d CONFIG_TDP_PBF_GET_TDP_INFO resp:%x\n", id->cpu, resp);
679 pbf_info->tdp = resp & 0xffff;
682 ret = _send_mbox_command(
683 id->cpu, CONFIG_TDP, CONFIG_TDP_PBF_GET_TJ_MAX_INFO, 0, req, &resp);
687 debug_printf("cpu:%d CONFIG_TDP_PBF_GET_TJ_MAX_INFO resp:%x\n", id->cpu,
689 pbf_info->t_control = (resp >> 8) & 0xff;
690 pbf_info->t_prochot = resp & 0xff;
695 static int mbox_set_pbf_fact_status(struct isst_id *id, int pbf, int enable)
697 struct isst_pkg_ctdp pkg_dev;
698 struct isst_pkg_ctdp_level_info ctdp_level;
700 unsigned int req = 0, resp;
703 ret = isst_get_ctdp_levels(id, &pkg_dev);
705 debug_printf("cpu:%d No support for dynamic ISST\n", id->cpu);
707 current_level = pkg_dev.current_level;
709 ret = isst_get_ctdp_control(id, current_level, &ctdp_level);
714 if (ctdp_level.fact_enabled)
723 if (enable && !ctdp_level.sst_cp_enabled)
724 isst_display_error_info_message(0, "Make sure to execute before: core-power enable", 0, 0);
726 if (ctdp_level.pbf_enabled)
735 ret = _send_mbox_command(id->cpu, CONFIG_TDP,
736 CONFIG_TDP_SET_TDP_CONTROL, 0, req, &resp);
740 debug_printf("cpu:%d CONFIG_TDP_SET_TDP_CONTROL pbf/fact:%d req:%x\n",
746 static int _get_fact_bucket_info(struct isst_id *id, int level,
747 struct isst_fact_bucket_info *bucket_info)
752 for (i = 0; i < 2; ++i) {
755 ret = _send_mbox_command(
757 CONFIG_TDP_GET_FACT_HP_TURBO_LIMIT_NUMCORES, 0,
758 (i << 8) | level, &resp);
763 "cpu:%d CONFIG_TDP_GET_FACT_HP_TURBO_LIMIT_NUMCORES index:%d level:%d resp:%x\n",
764 id->cpu, i, level, resp);
766 for (j = 0; j < 4; ++j) {
767 bucket_info[j + (i * 4)].hp_cores =
768 (resp >> (j * 8)) & 0xff;
772 for (k = 0; k < 3; ++k) {
773 for (i = 0; i < 2; ++i) {
776 ret = _send_mbox_command(
778 CONFIG_TDP_GET_FACT_HP_TURBO_LIMIT_RATIOS, 0,
779 (k << 16) | (i << 8) | level, &resp);
784 "cpu:%d CONFIG_TDP_GET_FACT_HP_TURBO_LIMIT_RATIOS index:%d level:%d avx:%d resp:%x\n",
785 id->cpu, i, level, k, resp);
787 for (j = 0; j < 4; ++j) {
788 bucket_info[j + (i * 4)].hp_ratios[k] =
789 (resp >> (j * 8)) & 0xff;
797 static int mbox_get_fact_info(struct isst_id *id, int level, int fact_bucket, struct isst_fact_info *fact_info)
802 ret = _send_mbox_command(id->cpu, CONFIG_TDP,
803 CONFIG_TDP_GET_FACT_LP_CLIPPING_RATIO, 0,
808 debug_printf("cpu:%d CONFIG_TDP_GET_FACT_LP_CLIPPING_RATIO resp:%x\n",
811 fact_info->lp_ratios[0] = resp & 0xff;
812 fact_info->lp_ratios[1] = (resp >> 8) & 0xff;
813 fact_info->lp_ratios[2] = (resp >> 16) & 0xff;
815 ret = _get_fact_bucket_info(id, level, fact_info->bucket_info);
820 for (j = 0; j < ISST_FACT_MAX_BUCKETS; ++j) {
821 if (fact_bucket != 0xff && fact_bucket != j)
824 if (!fact_info->bucket_info[j].hp_cores)
830 isst_display_error_info_message(1, "Invalid bucket", 0, 0);
837 static int mbox_get_clos_information(struct isst_id *id, int *enable, int *type)
842 ret = _send_mbox_command(id->cpu, CONFIG_CLOS, CLOS_PM_QOS_CONFIG, 0, 0,
847 debug_printf("cpu:%d CLOS_PM_QOS_CONFIG resp:%x\n", id->cpu, resp);
862 static int _write_pm_config(struct isst_id *id, int cp_state)
864 unsigned int req, resp;
872 ret = _send_mbox_command(id->cpu, WRITE_PM_CONFIG, PM_FEATURE, 0, req,
877 debug_printf("cpu:%d WRITE_PM_CONFIG resp:%x\n", id->cpu, resp);
882 static int mbox_pm_qos_config(struct isst_id *id, int enable_clos, int priority_type)
884 unsigned int req, resp;
888 struct isst_pkg_ctdp pkg_dev;
889 struct isst_pkg_ctdp_level_info ctdp_level;
891 ret = isst_get_ctdp_levels(id, &pkg_dev);
893 debug_printf("isst_get_ctdp_levels\n");
897 ret = isst_get_ctdp_control(id, pkg_dev.current_level,
902 if (ctdp_level.fact_enabled) {
903 isst_display_error_info_message(1, "Ignoring request, turbo-freq feature is still enabled", 0, 0);
906 ret = _write_pm_config(id, 0);
908 isst_display_error_info_message(0, "WRITE_PM_CONFIG command failed, ignoring error", 0, 0);
910 ret = _write_pm_config(id, 1);
912 isst_display_error_info_message(0, "WRITE_PM_CONFIG command failed, ignoring error", 0, 0);
915 ret = _send_mbox_command(id->cpu, CONFIG_CLOS, CLOS_PM_QOS_CONFIG, 0, 0,
918 isst_display_error_info_message(1, "CLOS_PM_QOS_CONFIG command failed", 0, 0);
922 debug_printf("cpu:%d CLOS_PM_QOS_CONFIG resp:%x\n", id->cpu, resp);
931 if (priority_type > 1)
932 isst_display_error_info_message(1, "Invalid priority type: Changing type to ordered", 0, 0);
939 ret = _send_mbox_command(id->cpu, CONFIG_CLOS, CLOS_PM_QOS_CONFIG,
940 BIT(MBOX_CMD_WRITE_BIT), req, &resp);
944 debug_printf("cpu:%d CLOS_PM_QOS_CONFIG priority type:%d req:%x\n", id->cpu,
950 static int mbox_pm_get_clos(struct isst_id *id, int clos, struct isst_clos_config *clos_config)
955 ret = _send_mbox_command(id->cpu, CONFIG_CLOS, CLOS_PM_CLOS, clos, 0,
960 clos_config->epp = resp & 0x0f;
961 clos_config->clos_prop_prio = (resp >> 4) & 0x0f;
962 clos_config->clos_min = (resp >> 8) & 0xff;
963 clos_config->clos_max = (resp >> 16) & 0xff;
964 clos_config->clos_desired = (resp >> 24) & 0xff;
969 static int mbox_set_clos(struct isst_id *id, int clos, struct isst_clos_config *clos_config)
971 unsigned int req, resp;
975 req = clos_config->epp & 0x0f;
976 req |= (clos_config->clos_prop_prio & 0x0f) << 4;
977 req |= (clos_config->clos_min & 0xff) << 8;
978 req |= (clos_config->clos_max & 0xff) << 16;
979 req |= (clos_config->clos_desired & 0xff) << 24;
981 param = BIT(MBOX_CMD_WRITE_BIT) | clos;
983 ret = _send_mbox_command(id->cpu, CONFIG_CLOS, CLOS_PM_CLOS, param, req,
988 debug_printf("cpu:%d CLOS_PM_CLOS param:%x req:%x\n", id->cpu, param, req);
993 static int mbox_clos_get_assoc_status(struct isst_id *id, int *clos_id)
999 core_id = find_phy_core_num(id->cpu);
1002 ret = _send_mbox_command(id->cpu, CONFIG_CLOS, CLOS_PQR_ASSOC, param, 0,
1007 debug_printf("cpu:%d CLOS_PQR_ASSOC param:%x resp:%x\n", id->cpu, param,
1009 *clos_id = (resp >> 16) & 0x03;
1014 static int mbox_clos_associate(struct isst_id *id, int clos_id)
1016 unsigned int req, resp;
1020 req = (clos_id & 0x03) << 16;
1021 core_id = find_phy_core_num(id->cpu);
1022 param = BIT(MBOX_CMD_WRITE_BIT) | core_id;
1024 ret = _send_mbox_command(id->cpu, CONFIG_CLOS, CLOS_PQR_ASSOC, param,
1029 debug_printf("cpu:%d CLOS_PQR_ASSOC param:%x req:%x\n", id->cpu, param,
1035 static struct isst_platform_ops mbox_ops = {
1036 .get_disp_freq_multiplier = mbox_get_disp_freq_multiplier,
1037 .get_trl_max_levels = mbox_get_trl_max_levels,
1038 .get_trl_level_name = mbox_get_trl_level_name,
1039 .update_platform_param = mbox_update_platform_param,
1040 .is_punit_valid = mbox_is_punit_valid,
1041 .read_pm_config = mbox_read_pm_config,
1042 .get_config_levels = mbox_get_config_levels,
1043 .get_ctdp_control = mbox_get_ctdp_control,
1044 .get_tdp_info = mbox_get_tdp_info,
1045 .get_pwr_info = mbox_get_pwr_info,
1046 .get_coremask_info = mbox_get_coremask_info,
1047 .get_get_trl = mbox_get_get_trl,
1048 .get_get_trls = mbox_get_get_trls,
1049 .get_trl_bucket_info = mbox_get_trl_bucket_info,
1050 .set_tdp_level = mbox_set_tdp_level,
1051 .get_pbf_info = mbox_get_pbf_info,
1052 .set_pbf_fact_status = mbox_set_pbf_fact_status,
1053 .get_fact_info = mbox_get_fact_info,
1054 .adjust_uncore_freq = mbox_adjust_uncore_freq,
1055 .get_clos_information = mbox_get_clos_information,
1056 .pm_qos_config = mbox_pm_qos_config,
1057 .pm_get_clos = mbox_pm_get_clos,
1058 .set_clos = mbox_set_clos,
1059 .clos_get_assoc_status = mbox_clos_get_assoc_status,
1060 .clos_associate = mbox_clos_associate,
1063 struct isst_platform_ops *mbox_get_platform_ops(void)