Lines Matching full:ips
43 * - ref 26037, 26641 - IPS BIOS spec
228 #define thm_readb(off) readb(ips->regmap + (off))
229 #define thm_readw(off) readw(ips->regmap + (off))
230 #define thm_readl(off) readl(ips->regmap + (off))
231 #define thm_readq(off) readq(ips->regmap + (off))
233 #define thm_writeb(off, val) writeb((val), ips->regmap + (off))
234 #define thm_writew(off, val) writew((val), ips->regmap + (off))
235 #define thm_writel(off, val) writel((val), ips->regmap + (off))
335 ips_gpu_turbo_enabled(struct ips_driver *ips);
339 * @ips: IPS driver struct
346 static bool ips_cpu_busy(struct ips_driver *ips) in ips_cpu_busy() argument
356 * @ips: IPS driver struct
364 static void ips_cpu_raise(struct ips_driver *ips) in ips_cpu_raise() argument
369 if (!ips->cpu_turbo_enabled) in ips_cpu_raise()
378 if (((new_tdp_limit * 10) / 8) > ips->core_power_limit) in ips_cpu_raise()
394 * @ips: IPS driver struct
402 static void ips_cpu_lower(struct ips_driver *ips) in ips_cpu_lower() argument
413 if (new_limit < (ips->orig_turbo_limit & TURBO_TDP_MASK)) in ips_cpu_lower()
414 new_limit = ips->orig_turbo_limit & TURBO_TDP_MASK; in ips_cpu_lower()
448 * @ips: IPS driver struct
453 static void ips_enable_cpu_turbo(struct ips_driver *ips) in ips_enable_cpu_turbo() argument
456 if (ips->__cpu_turbo_on) in ips_enable_cpu_turbo()
459 if (ips->turbo_toggle_allowed) in ips_enable_cpu_turbo()
460 on_each_cpu(do_enable_cpu_turbo, ips, 1); in ips_enable_cpu_turbo()
462 ips->__cpu_turbo_on = true; in ips_enable_cpu_turbo()
486 * @ips: IPS driver struct
491 static void ips_disable_cpu_turbo(struct ips_driver *ips) in ips_disable_cpu_turbo() argument
494 if (!ips->__cpu_turbo_on) in ips_disable_cpu_turbo()
497 if (ips->turbo_toggle_allowed) in ips_disable_cpu_turbo()
498 on_each_cpu(do_disable_cpu_turbo, ips, 1); in ips_disable_cpu_turbo()
500 ips->__cpu_turbo_on = false; in ips_disable_cpu_turbo()
505 * @ips: IPS driver struct
513 static bool ips_gpu_busy(struct ips_driver *ips) in ips_gpu_busy() argument
515 if (!ips_gpu_turbo_enabled(ips)) in ips_gpu_busy()
518 return ips->gpu_busy(); in ips_gpu_busy()
523 * @ips: IPS driver struct
528 static void ips_gpu_raise(struct ips_driver *ips) in ips_gpu_raise() argument
530 if (!ips_gpu_turbo_enabled(ips)) in ips_gpu_raise()
533 if (!ips->gpu_raise()) in ips_gpu_raise()
534 ips->gpu_turbo_enabled = false; in ips_gpu_raise()
541 * @ips: IPS driver struct
545 static void ips_gpu_lower(struct ips_driver *ips) in ips_gpu_lower() argument
547 if (!ips_gpu_turbo_enabled(ips)) in ips_gpu_lower()
550 if (!ips->gpu_lower()) in ips_gpu_lower()
551 ips->gpu_turbo_enabled = false; in ips_gpu_lower()
558 * @ips: IPS driver struct
563 static void ips_enable_gpu_turbo(struct ips_driver *ips) in ips_enable_gpu_turbo() argument
565 if (ips->__gpu_turbo_on) in ips_enable_gpu_turbo()
567 ips->__gpu_turbo_on = true; in ips_enable_gpu_turbo()
572 * @ips: IPS driver struct
576 static void ips_disable_gpu_turbo(struct ips_driver *ips) in ips_disable_gpu_turbo() argument
579 if (!ips->__gpu_turbo_on) in ips_disable_gpu_turbo()
582 if (!ips->gpu_turbo_disable()) in ips_disable_gpu_turbo()
583 dev_err(ips->dev, "failed to disable graphics turbo\n"); in ips_disable_gpu_turbo()
585 ips->__gpu_turbo_on = false; in ips_disable_gpu_turbo()
590 * @ips: IPS driver struct
594 static bool mcp_exceeded(struct ips_driver *ips) in mcp_exceeded() argument
601 spin_lock_irqsave(&ips->turbo_status_lock, flags); in mcp_exceeded()
603 temp_limit = ips->mcp_temp_limit * 100; in mcp_exceeded()
604 if (ips->mcp_avg_temp > temp_limit) in mcp_exceeded()
607 avg_power = ips->cpu_avg_power + ips->mch_avg_power; in mcp_exceeded()
608 if (avg_power > ips->mcp_power_limit) in mcp_exceeded()
611 spin_unlock_irqrestore(&ips->turbo_status_lock, flags); in mcp_exceeded()
618 * @ips: IPS driver struct
623 static bool cpu_exceeded(struct ips_driver *ips, int cpu) in cpu_exceeded() argument
629 spin_lock_irqsave(&ips->turbo_status_lock, flags); in cpu_exceeded()
630 avg = cpu ? ips->ctv2_avg_temp : ips->ctv1_avg_temp; in cpu_exceeded()
631 if (avg > (ips->limits->core_temp_limit * 100)) in cpu_exceeded()
633 if (ips->cpu_avg_power > ips->core_power_limit * 100) in cpu_exceeded()
635 spin_unlock_irqrestore(&ips->turbo_status_lock, flags); in cpu_exceeded()
638 dev_info(ips->dev, "CPU power or thermal limit exceeded\n"); in cpu_exceeded()
645 * @ips: IPS driver struct
649 static bool mch_exceeded(struct ips_driver *ips) in mch_exceeded() argument
654 spin_lock_irqsave(&ips->turbo_status_lock, flags); in mch_exceeded()
655 if (ips->mch_avg_temp > (ips->limits->mch_temp_limit * 100)) in mch_exceeded()
657 if (ips->mch_avg_power > ips->mch_power_limit) in mch_exceeded()
659 spin_unlock_irqrestore(&ips->turbo_status_lock, flags); in mch_exceeded()
666 * @ips: IPS structure
672 static void verify_limits(struct ips_driver *ips) in verify_limits() argument
674 if (ips->mcp_power_limit < ips->limits->mcp_power_limit || in verify_limits()
675 ips->mcp_power_limit > 35000) in verify_limits()
676 ips->mcp_power_limit = ips->limits->mcp_power_limit; in verify_limits()
678 if (ips->mcp_temp_limit < ips->limits->core_temp_limit || in verify_limits()
679 ips->mcp_temp_limit < ips->limits->mch_temp_limit || in verify_limits()
680 ips->mcp_temp_limit > 150) in verify_limits()
681 ips->mcp_temp_limit = min(ips->limits->core_temp_limit, in verify_limits()
682 ips->limits->mch_temp_limit); in verify_limits()
687 * @ips: IPS driver struct
689 * Update the IPS power & temp limits, along with turbo enable flags,
698 static void update_turbo_limits(struct ips_driver *ips) in update_turbo_limits() argument
702 ips->cpu_turbo_enabled = !(hts & HTS_PCTD_DIS); in update_turbo_limits()
707 ips->cpu_turbo_enabled = false; in update_turbo_limits()
709 if (ips->gpu_busy) in update_turbo_limits()
710 ips->gpu_turbo_enabled = !(hts & HTS_GTD_DIS); in update_turbo_limits()
712 ips->core_power_limit = thm_readw(THM_MPCPC); in update_turbo_limits()
713 ips->mch_power_limit = thm_readw(THM_MMGPC); in update_turbo_limits()
714 ips->mcp_temp_limit = thm_readw(THM_PTL); in update_turbo_limits()
715 ips->mcp_power_limit = thm_readw(THM_MPPC); in update_turbo_limits()
717 verify_limits(ips); in update_turbo_limits()
723 * @data: ips driver structure
754 struct ips_driver *ips = data; in ips_adjust() local
757 dev_dbg(ips->dev, "starting ips-adjust thread\n"); in ips_adjust()
764 bool cpu_busy = ips_cpu_busy(ips); in ips_adjust()
765 bool gpu_busy = ips_gpu_busy(ips); in ips_adjust()
767 spin_lock_irqsave(&ips->turbo_status_lock, flags); in ips_adjust()
768 if (ips->poll_turbo_status) in ips_adjust()
769 update_turbo_limits(ips); in ips_adjust()
770 spin_unlock_irqrestore(&ips->turbo_status_lock, flags); in ips_adjust()
773 if (ips->cpu_turbo_enabled) in ips_adjust()
774 ips_enable_cpu_turbo(ips); in ips_adjust()
776 ips_disable_cpu_turbo(ips); in ips_adjust()
778 if (ips->gpu_turbo_enabled) in ips_adjust()
779 ips_enable_gpu_turbo(ips); in ips_adjust()
781 ips_disable_gpu_turbo(ips); in ips_adjust()
784 if (mcp_exceeded(ips)) { in ips_adjust()
785 ips_cpu_lower(ips); in ips_adjust()
786 ips_gpu_lower(ips); in ips_adjust()
790 if (!cpu_exceeded(ips, 0) && cpu_busy) in ips_adjust()
791 ips_cpu_raise(ips); in ips_adjust()
793 ips_cpu_lower(ips); in ips_adjust()
795 if (!mch_exceeded(ips) && gpu_busy) in ips_adjust()
796 ips_gpu_raise(ips); in ips_adjust()
798 ips_gpu_lower(ips); in ips_adjust()
804 dev_dbg(ips->dev, "ips-adjust thread stopped\n"); in ips_adjust()
814 static u16 calc_avg_temp(struct ips_driver *ips, u16 *array) in calc_avg_temp() argument
830 static u16 read_mgtv(struct ips_driver *ips) in read_mgtv() argument
848 static u16 read_ptv(struct ips_driver *ips) in read_ptv() argument
857 static u16 read_ctv(struct ips_driver *ips, int cpu) in read_ctv() argument
871 static u32 get_cpu_power(struct ips_driver *ips, u32 *last, int period) in get_cpu_power() argument
912 static u32 calc_avg_power(struct ips_driver *ips, u32 *array) in calc_avg_power() argument
929 struct ips_driver *ips = from_timer(ips, t, timer); in monitor_timeout() local
930 wake_up_process(ips->monitor); in monitor_timeout()
935 * @data: ips driver structure
937 * This is the main function for the IPS driver. It monitors power and
946 struct ips_driver *ips = data; in ips_monitor() local
961 dev_err(ips->dev, in ips_monitor()
962 "failed to allocate sample array, ips disabled\n"); in ips_monitor()
984 mcp_samples[i] = read_ptv(ips); in ips_monitor()
986 val = read_ctv(ips, 0); in ips_monitor()
989 val = read_ctv(ips, 1); in ips_monitor()
992 val = read_mgtv(ips); in ips_monitor()
995 cpu_power = get_cpu_power(ips, &old_cpu_power, in ips_monitor()
999 if (ips->read_mch_val) { in ips_monitor()
1000 mchp = ips->read_mch_val(); in ips_monitor()
1009 ips->mcp_avg_temp = calc_avg_temp(ips, mcp_samples); in ips_monitor()
1010 ips->ctv1_avg_temp = calc_avg_temp(ips, ctv1_samples); in ips_monitor()
1011 ips->ctv2_avg_temp = calc_avg_temp(ips, ctv2_samples); in ips_monitor()
1012 ips->mch_avg_temp = calc_avg_temp(ips, mch_samples); in ips_monitor()
1013 ips->cpu_avg_power = calc_avg_power(ips, cpu_samples); in ips_monitor()
1014 ips->mch_avg_power = calc_avg_power(ips, mchp_samples); in ips_monitor()
1023 wake_up_process(ips->adjust); in ips_monitor()
1034 timer_setup(&ips->timer, monitor_timeout, TIMER_DEFERRABLE); in ips_monitor()
1040 val = read_ptv(ips); in ips_monitor()
1041 ips->mcp_avg_temp = update_average_temp(ips->mcp_avg_temp, val); in ips_monitor()
1044 val = read_ctv(ips, 0); in ips_monitor()
1045 ips->ctv1_avg_temp = in ips_monitor()
1046 update_average_temp(ips->ctv1_avg_temp, val); in ips_monitor()
1048 cpu_val = get_cpu_power(ips, &old_cpu_power, in ips_monitor()
1050 ips->cpu_avg_power = in ips_monitor()
1051 update_average_power(ips->cpu_avg_power, cpu_val); in ips_monitor()
1053 if (ips->second_cpu) { in ips_monitor()
1055 val = read_ctv(ips, 1); in ips_monitor()
1056 ips->ctv2_avg_temp = in ips_monitor()
1057 update_average_temp(ips->ctv2_avg_temp, val); in ips_monitor()
1061 val = read_mgtv(ips); in ips_monitor()
1062 ips->mch_avg_temp = update_average_temp(ips->mch_avg_temp, val); in ips_monitor()
1064 if (ips->read_mch_val) { in ips_monitor()
1065 mch_val = ips->read_mch_val(); in ips_monitor()
1066 ips->mch_avg_power = in ips_monitor()
1067 update_average_power(ips->mch_avg_power, in ips_monitor()
1081 dev_warn(ips->dev, in ips_monitor()
1092 mod_timer(&ips->timer, expire); in ips_monitor()
1101 del_timer_sync(&ips->timer); in ips_monitor()
1103 dev_dbg(ips->dev, "ips-monitor thread stopped\n"); in ips_monitor()
1112 dev_dbg(ips->dev, #reg ": 0x%04x\n", val); \
1117 dev_dbg(ips->dev, #reg ": 0x%08x\n", val); \
1122 dev_dbg(ips->dev, #reg ": 0x%016x\n", val); \
1125 static void dump_thermal_info(struct ips_driver *ips)
1130 dev_dbg(ips->dev, "Processor temp limit: %d\n", ptl);
1142 * ips_irq_handler - handle temperature triggers and other IPS events
1152 struct ips_driver *ips = arg; in ips_irq_handler() local
1159 dev_info(ips->dev, "TSES: 0x%02x\n", tses); in ips_irq_handler()
1160 dev_info(ips->dev, "TES: 0x%02x\n", tes); in ips_irq_handler()
1170 spin_lock(&ips->turbo_status_lock); in ips_irq_handler()
1171 ips->core_power_limit = (sts & STS_PCPL_MASK) >> in ips_irq_handler()
1173 ips->mch_power_limit = (sts & STS_GPL_MASK) >> in ips_irq_handler()
1176 ips->cpu_turbo_enabled = !(sts & STS_PCTD_DIS); in ips_irq_handler()
1181 ips->cpu_turbo_enabled = false; in ips_irq_handler()
1182 if (ips->gpu_busy) in ips_irq_handler()
1183 ips->gpu_turbo_enabled = !(sts & STS_GTD_DIS); in ips_irq_handler()
1184 ips->mcp_temp_limit = (sts & STS_PTL_MASK) >> in ips_irq_handler()
1186 ips->mcp_power_limit = (tc1 & STS_PPL_MASK) >> in ips_irq_handler()
1188 verify_limits(ips); in ips_irq_handler()
1189 spin_unlock(&ips->turbo_status_lock); in ips_irq_handler()
1198 dev_warn(ips->dev, "thermal trip occurred, tses: 0x%04x\n", in ips_irq_handler()
1207 static void ips_debugfs_init(struct ips_driver *ips) { return; } in ips_debugfs_init() argument
1208 static void ips_debugfs_cleanup(struct ips_driver *ips) { return; } in ips_debugfs_cleanup() argument
1215 struct ips_driver *ips = m->private; in cpu_temp_show() local
1217 seq_printf(m, "%d.%02d\n", ips->ctv1_avg_temp / 100, in cpu_temp_show()
1218 ips->ctv1_avg_temp % 100); in cpu_temp_show()
1226 struct ips_driver *ips = m->private; in cpu_power_show() local
1228 seq_printf(m, "%dmW\n", ips->cpu_avg_power); in cpu_power_show()
1258 struct ips_driver *ips = m->private; in mch_temp_show() local
1260 seq_printf(m, "%d.%02d\n", ips->mch_avg_temp / 100, in mch_temp_show()
1261 ips->mch_avg_temp % 100); in mch_temp_show()
1269 struct ips_driver *ips = m->private; in mch_power_show() local
1271 seq_printf(m, "%dmW\n", ips->mch_avg_power); in mch_power_show()
1277 static void ips_debugfs_cleanup(struct ips_driver *ips) in ips_debugfs_cleanup() argument
1279 debugfs_remove_recursive(ips->debug_root); in ips_debugfs_cleanup()
1282 static void ips_debugfs_init(struct ips_driver *ips) in ips_debugfs_init() argument
1284 ips->debug_root = debugfs_create_dir("ips", NULL); in ips_debugfs_init()
1286 debugfs_create_file("cpu_temp", 0444, ips->debug_root, ips, &cpu_temp_fops); in ips_debugfs_init()
1287 debugfs_create_file("cpu_power", 0444, ips->debug_root, ips, &cpu_power_fops); in ips_debugfs_init()
1288 debugfs_create_file("cpu_clamp", 0444, ips->debug_root, ips, &cpu_clamp_fops); in ips_debugfs_init()
1289 debugfs_create_file("mch_temp", 0444, ips->debug_root, ips, &mch_temp_fops); in ips_debugfs_init()
1290 debugfs_create_file("mch_power", 0444, ips->debug_root, ips, &mch_power_fops); in ips_debugfs_init()
1295 * ips_detect_cpu - detect whether CPU supports IPS
1300 static struct ips_mcp_limits *ips_detect_cpu(struct ips_driver *ips) in ips_detect_cpu() argument
1307 dev_info(ips->dev, "Non-IPS CPU detected.\n"); in ips_detect_cpu()
1318 ips->turbo_toggle_allowed = true; in ips_detect_cpu()
1320 ips->turbo_toggle_allowed = false; in ips_detect_cpu()
1329 dev_info(ips->dev, "No CPUID match found.\n"); in ips_detect_cpu()
1338 dev_info(ips->dev, in ips_detect_cpu()
1349 * @ips: IPS driver
1351 * The i915 driver exports several interfaces to allow the IPS driver to
1356 static bool ips_get_i915_syms(struct ips_driver *ips) in ips_get_i915_syms() argument
1358 ips->read_mch_val = symbol_get(i915_read_mch_val); in ips_get_i915_syms()
1359 if (!ips->read_mch_val) in ips_get_i915_syms()
1361 ips->gpu_raise = symbol_get(i915_gpu_raise); in ips_get_i915_syms()
1362 if (!ips->gpu_raise) in ips_get_i915_syms()
1364 ips->gpu_lower = symbol_get(i915_gpu_lower); in ips_get_i915_syms()
1365 if (!ips->gpu_lower) in ips_get_i915_syms()
1367 ips->gpu_busy = symbol_get(i915_gpu_busy); in ips_get_i915_syms()
1368 if (!ips->gpu_busy) in ips_get_i915_syms()
1370 ips->gpu_turbo_disable = symbol_get(i915_gpu_turbo_disable); in ips_get_i915_syms()
1371 if (!ips->gpu_turbo_disable) in ips_get_i915_syms()
1389 ips_gpu_turbo_enabled(struct ips_driver *ips) in ips_gpu_turbo_enabled() argument
1391 if (!ips->gpu_busy && late_i915_load) { in ips_gpu_turbo_enabled()
1392 if (ips_get_i915_syms(ips)) { in ips_gpu_turbo_enabled()
1393 dev_info(ips->dev, in ips_gpu_turbo_enabled()
1395 ips->gpu_turbo_enabled = !(thm_readl(THM_HTS) & HTS_GTD_DIS); in ips_gpu_turbo_enabled()
1399 return ips->gpu_turbo_enabled; in ips_gpu_turbo_enabled()
1441 struct ips_driver *ips; in ips_probe() local
1450 ips = devm_kzalloc(&dev->dev, sizeof(*ips), GFP_KERNEL); in ips_probe()
1451 if (!ips) in ips_probe()
1454 spin_lock_init(&ips->turbo_status_lock); in ips_probe()
1455 ips->dev = &dev->dev; in ips_probe()
1457 ips->limits = ips_detect_cpu(ips); in ips_probe()
1458 if (!ips->limits) { in ips_probe()
1459 dev_info(&dev->dev, "IPS not supported on this CPU\n"); in ips_probe()
1474 ips->regmap = pcim_iomap_table(dev)[0]; in ips_probe()
1476 pci_set_drvdata(dev, ips); in ips_probe()
1492 ips->second_cpu = true; in ips_probe()
1494 update_turbo_limits(ips); in ips_probe()
1496 ips->mcp_power_limit / 10); in ips_probe()
1498 ips->core_power_limit / 10); in ips_probe()
1501 ips->poll_turbo_status = true; in ips_probe()
1503 if (!ips_get_i915_syms(ips)) { in ips_probe()
1505 ips->gpu_turbo_enabled = false; in ips_probe()
1508 ips->gpu_turbo_enabled = true; in ips_probe()
1529 ips->irq = pci_irq_vector(dev, 0); in ips_probe()
1531 ret = request_irq(ips->irq, ips_irq_handler, IRQF_SHARED, "ips", ips); in ips_probe()
1543 ips->cta_val = thm_readw(THM_CTA); in ips_probe()
1544 ips->pta_val = thm_readw(THM_PTA); in ips_probe()
1545 ips->mgta_val = thm_readw(THM_MGTA); in ips_probe()
1548 rdmsrl(TURBO_POWER_CURRENT_LIMIT, ips->orig_turbo_limit); in ips_probe()
1550 ips_disable_cpu_turbo(ips); in ips_probe()
1551 ips->cpu_turbo_enabled = false; in ips_probe()
1554 ips->adjust = kthread_create(ips_adjust, ips, "ips-adjust"); in ips_probe()
1555 if (IS_ERR(ips->adjust)) { in ips_probe()
1567 ips->monitor = kthread_run(ips_monitor, ips, "ips-monitor"); in ips_probe()
1568 if (IS_ERR(ips->monitor)) { in ips_probe()
1575 hts = (ips->core_power_limit << HTS_PCPL_SHIFT) | in ips_probe()
1576 (ips->mcp_temp_limit << HTS_PTL_SHIFT) | HTS_NVV; in ips_probe()
1582 ips_debugfs_init(ips); in ips_probe()
1584 dev_info(&dev->dev, "IPS driver initialized, MCP temp limit %d\n", in ips_probe()
1585 ips->mcp_temp_limit); in ips_probe()
1589 kthread_stop(ips->adjust); in ips_probe()
1591 free_irq(ips->irq, ips); in ips_probe()
1598 struct ips_driver *ips = pci_get_drvdata(dev); in ips_remove() local
1601 ips_debugfs_cleanup(ips); in ips_remove()
1604 if (ips->read_mch_val) in ips_remove()
1606 if (ips->gpu_raise) in ips_remove()
1608 if (ips->gpu_lower) in ips_remove()
1610 if (ips->gpu_busy) in ips_remove()
1612 if (ips->gpu_turbo_disable) in ips_remove()
1618 wrmsrl(TURBO_POWER_CURRENT_LIMIT, ips->orig_turbo_limit); in ips_remove()
1620 free_irq(ips->irq, ips); in ips_remove()
1622 if (ips->adjust) in ips_remove()
1623 kthread_stop(ips->adjust); in ips_remove()
1624 if (ips->monitor) in ips_remove()
1625 kthread_stop(ips->monitor); in ips_remove()
1626 dev_dbg(&dev->dev, "IPS driver removed\n"); in ips_remove()
1630 .name = "intel ips",