Lines Matching full:ips
43 * - ref 26037, 26641 - IPS BIOS spec
229 #define thm_readb(off) readb(ips->regmap + (off))
230 #define thm_readw(off) readw(ips->regmap + (off))
231 #define thm_readl(off) readl(ips->regmap + (off))
232 #define thm_readq(off) readq(ips->regmap + (off))
234 #define thm_writeb(off, val) writeb((val), ips->regmap + (off))
235 #define thm_writew(off, val) writew((val), ips->regmap + (off))
236 #define thm_writel(off, val) writel((val), ips->regmap + (off))
336 ips_gpu_turbo_enabled(struct ips_driver *ips);
340 * @ips: IPS driver struct
347 static bool ips_cpu_busy(struct ips_driver *ips) in ips_cpu_busy() argument
357 * @ips: IPS driver struct
365 static void ips_cpu_raise(struct ips_driver *ips) in ips_cpu_raise() argument
370 if (!ips->cpu_turbo_enabled) in ips_cpu_raise()
379 if (((new_tdp_limit * 10) / 8) > ips->core_power_limit) in ips_cpu_raise()
395 * @ips: IPS driver struct
403 static void ips_cpu_lower(struct ips_driver *ips) in ips_cpu_lower() argument
414 if (new_limit < (ips->orig_turbo_limit & TURBO_TDP_MASK)) in ips_cpu_lower()
415 new_limit = ips->orig_turbo_limit & TURBO_TDP_MASK; in ips_cpu_lower()
449 * @ips: IPS driver struct
454 static void ips_enable_cpu_turbo(struct ips_driver *ips) in ips_enable_cpu_turbo() argument
457 if (ips->__cpu_turbo_on) in ips_enable_cpu_turbo()
460 if (ips->turbo_toggle_allowed) in ips_enable_cpu_turbo()
461 on_each_cpu(do_enable_cpu_turbo, ips, 1); in ips_enable_cpu_turbo()
463 ips->__cpu_turbo_on = true; in ips_enable_cpu_turbo()
487 * @ips: IPS driver struct
492 static void ips_disable_cpu_turbo(struct ips_driver *ips) in ips_disable_cpu_turbo() argument
495 if (!ips->__cpu_turbo_on) in ips_disable_cpu_turbo()
498 if (ips->turbo_toggle_allowed) in ips_disable_cpu_turbo()
499 on_each_cpu(do_disable_cpu_turbo, ips, 1); in ips_disable_cpu_turbo()
501 ips->__cpu_turbo_on = false; in ips_disable_cpu_turbo()
506 * @ips: IPS driver struct
514 static bool ips_gpu_busy(struct ips_driver *ips) in ips_gpu_busy() argument
516 if (!ips_gpu_turbo_enabled(ips)) in ips_gpu_busy()
519 return ips->gpu_busy(); in ips_gpu_busy()
524 * @ips: IPS driver struct
529 static void ips_gpu_raise(struct ips_driver *ips) in ips_gpu_raise() argument
531 if (!ips_gpu_turbo_enabled(ips)) in ips_gpu_raise()
534 if (!ips->gpu_raise()) in ips_gpu_raise()
535 ips->gpu_turbo_enabled = false; in ips_gpu_raise()
542 * @ips: IPS driver struct
546 static void ips_gpu_lower(struct ips_driver *ips) in ips_gpu_lower() argument
548 if (!ips_gpu_turbo_enabled(ips)) in ips_gpu_lower()
551 if (!ips->gpu_lower()) in ips_gpu_lower()
552 ips->gpu_turbo_enabled = false; in ips_gpu_lower()
559 * @ips: IPS driver struct
564 static void ips_enable_gpu_turbo(struct ips_driver *ips) in ips_enable_gpu_turbo() argument
566 if (ips->__gpu_turbo_on) in ips_enable_gpu_turbo()
568 ips->__gpu_turbo_on = true; in ips_enable_gpu_turbo()
573 * @ips: IPS driver struct
577 static void ips_disable_gpu_turbo(struct ips_driver *ips) in ips_disable_gpu_turbo() argument
580 if (!ips->__gpu_turbo_on) in ips_disable_gpu_turbo()
583 if (!ips->gpu_turbo_disable()) in ips_disable_gpu_turbo()
584 dev_err(ips->dev, "failed to disable graphics turbo\n"); in ips_disable_gpu_turbo()
586 ips->__gpu_turbo_on = false; in ips_disable_gpu_turbo()
591 * @ips: IPS driver struct
597 static bool mcp_exceeded(struct ips_driver *ips) in mcp_exceeded() argument
604 spin_lock_irqsave(&ips->turbo_status_lock, flags); in mcp_exceeded()
606 temp_limit = ips->mcp_temp_limit * 100; in mcp_exceeded()
607 if (ips->mcp_avg_temp > temp_limit) in mcp_exceeded()
610 avg_power = ips->cpu_avg_power + ips->mch_avg_power; in mcp_exceeded()
611 if (avg_power > ips->mcp_power_limit) in mcp_exceeded()
614 spin_unlock_irqrestore(&ips->turbo_status_lock, flags); in mcp_exceeded()
621 * @ips: IPS driver struct
628 static bool cpu_exceeded(struct ips_driver *ips, int cpu) in cpu_exceeded() argument
634 spin_lock_irqsave(&ips->turbo_status_lock, flags); in cpu_exceeded()
635 avg = cpu ? ips->ctv2_avg_temp : ips->ctv1_avg_temp; in cpu_exceeded()
636 if (avg > (ips->limits->core_temp_limit * 100)) in cpu_exceeded()
638 if (ips->cpu_avg_power > ips->core_power_limit * 100) in cpu_exceeded()
640 spin_unlock_irqrestore(&ips->turbo_status_lock, flags); in cpu_exceeded()
643 dev_info(ips->dev, "CPU power or thermal limit exceeded\n"); in cpu_exceeded()
650 * @ips: IPS driver struct
656 static bool mch_exceeded(struct ips_driver *ips) in mch_exceeded() argument
661 spin_lock_irqsave(&ips->turbo_status_lock, flags); in mch_exceeded()
662 if (ips->mch_avg_temp > (ips->limits->mch_temp_limit * 100)) in mch_exceeded()
664 if (ips->mch_avg_power > ips->mch_power_limit) in mch_exceeded()
666 spin_unlock_irqrestore(&ips->turbo_status_lock, flags); in mch_exceeded()
673 * @ips: IPS structure
679 static void verify_limits(struct ips_driver *ips) in verify_limits() argument
681 if (ips->mcp_power_limit < ips->limits->mcp_power_limit || in verify_limits()
682 ips->mcp_power_limit > 35000) in verify_limits()
683 ips->mcp_power_limit = ips->limits->mcp_power_limit; in verify_limits()
685 if (ips->mcp_temp_limit < ips->limits->core_temp_limit || in verify_limits()
686 ips->mcp_temp_limit < ips->limits->mch_temp_limit || in verify_limits()
687 ips->mcp_temp_limit > 150) in verify_limits()
688 ips->mcp_temp_limit = min(ips->limits->core_temp_limit, in verify_limits()
689 ips->limits->mch_temp_limit); in verify_limits()
694 * @ips: IPS driver struct
696 * Update the IPS power & temp limits, along with turbo enable flags,
705 static void update_turbo_limits(struct ips_driver *ips) in update_turbo_limits() argument
709 ips->cpu_turbo_enabled = !(hts & HTS_PCTD_DIS); in update_turbo_limits()
714 ips->cpu_turbo_enabled = false; in update_turbo_limits()
716 if (ips->gpu_busy) in update_turbo_limits()
717 ips->gpu_turbo_enabled = !(hts & HTS_GTD_DIS); in update_turbo_limits()
719 ips->core_power_limit = thm_readw(THM_MPCPC); in update_turbo_limits()
720 ips->mch_power_limit = thm_readw(THM_MMGPC); in update_turbo_limits()
721 ips->mcp_temp_limit = thm_readw(THM_PTL); in update_turbo_limits()
722 ips->mcp_power_limit = thm_readw(THM_MPPC); in update_turbo_limits()
724 verify_limits(ips); in update_turbo_limits()
730 * @data: ips driver structure
762 struct ips_driver *ips = data; in ips_adjust() local
765 dev_dbg(ips->dev, "starting ips-adjust thread\n"); in ips_adjust()
772 bool cpu_busy = ips_cpu_busy(ips); in ips_adjust()
773 bool gpu_busy = ips_gpu_busy(ips); in ips_adjust()
775 spin_lock_irqsave(&ips->turbo_status_lock, flags); in ips_adjust()
776 if (ips->poll_turbo_status) in ips_adjust()
777 update_turbo_limits(ips); in ips_adjust()
778 spin_unlock_irqrestore(&ips->turbo_status_lock, flags); in ips_adjust()
781 if (ips->cpu_turbo_enabled) in ips_adjust()
782 ips_enable_cpu_turbo(ips); in ips_adjust()
784 ips_disable_cpu_turbo(ips); in ips_adjust()
786 if (ips->gpu_turbo_enabled) in ips_adjust()
787 ips_enable_gpu_turbo(ips); in ips_adjust()
789 ips_disable_gpu_turbo(ips); in ips_adjust()
792 if (mcp_exceeded(ips)) { in ips_adjust()
793 ips_cpu_lower(ips); in ips_adjust()
794 ips_gpu_lower(ips); in ips_adjust()
798 if (!cpu_exceeded(ips, 0) && cpu_busy) in ips_adjust()
799 ips_cpu_raise(ips); in ips_adjust()
801 ips_cpu_lower(ips); in ips_adjust()
803 if (!mch_exceeded(ips) && gpu_busy) in ips_adjust()
804 ips_gpu_raise(ips); in ips_adjust()
806 ips_gpu_lower(ips); in ips_adjust()
812 dev_dbg(ips->dev, "ips-adjust thread stopped\n"); in ips_adjust()
822 static u16 calc_avg_temp(struct ips_driver *ips, u16 *array) in calc_avg_temp() argument
838 static u16 read_mgtv(struct ips_driver *ips) in read_mgtv() argument
856 static u16 read_ptv(struct ips_driver *ips) in read_ptv() argument
865 static u16 read_ctv(struct ips_driver *ips, int cpu) in read_ctv() argument
879 static u32 get_cpu_power(struct ips_driver *ips, u32 *last, int period) in get_cpu_power() argument
920 static u32 calc_avg_power(struct ips_driver *ips, u32 *array) in calc_avg_power() argument
937 struct ips_driver *ips = from_timer(ips, t, timer); in monitor_timeout() local
938 wake_up_process(ips->monitor); in monitor_timeout()
943 * @data: ips driver structure
945 * This is the main function for the IPS driver. It monitors power and
956 struct ips_driver *ips = data; in ips_monitor() local
971 dev_err(ips->dev, in ips_monitor()
972 "failed to allocate sample array, ips disabled\n"); in ips_monitor()
994 mcp_samples[i] = read_ptv(ips); in ips_monitor()
996 val = read_ctv(ips, 0); in ips_monitor()
999 val = read_ctv(ips, 1); in ips_monitor()
1002 val = read_mgtv(ips); in ips_monitor()
1005 cpu_power = get_cpu_power(ips, &old_cpu_power, in ips_monitor()
1009 if (ips->read_mch_val) { in ips_monitor()
1010 mchp = ips->read_mch_val(); in ips_monitor()
1019 ips->mcp_avg_temp = calc_avg_temp(ips, mcp_samples); in ips_monitor()
1020 ips->ctv1_avg_temp = calc_avg_temp(ips, ctv1_samples); in ips_monitor()
1021 ips->ctv2_avg_temp = calc_avg_temp(ips, ctv2_samples); in ips_monitor()
1022 ips->mch_avg_temp = calc_avg_temp(ips, mch_samples); in ips_monitor()
1023 ips->cpu_avg_power = calc_avg_power(ips, cpu_samples); in ips_monitor()
1024 ips->mch_avg_power = calc_avg_power(ips, mchp_samples); in ips_monitor()
1033 wake_up_process(ips->adjust); in ips_monitor()
1044 timer_setup(&ips->timer, monitor_timeout, TIMER_DEFERRABLE); in ips_monitor()
1050 val = read_ptv(ips); in ips_monitor()
1051 ips->mcp_avg_temp = update_average_temp(ips->mcp_avg_temp, val); in ips_monitor()
1054 val = read_ctv(ips, 0); in ips_monitor()
1055 ips->ctv1_avg_temp = in ips_monitor()
1056 update_average_temp(ips->ctv1_avg_temp, val); in ips_monitor()
1058 cpu_val = get_cpu_power(ips, &old_cpu_power, in ips_monitor()
1060 ips->cpu_avg_power = in ips_monitor()
1061 update_average_power(ips->cpu_avg_power, cpu_val); in ips_monitor()
1063 if (ips->second_cpu) { in ips_monitor()
1065 val = read_ctv(ips, 1); in ips_monitor()
1066 ips->ctv2_avg_temp = in ips_monitor()
1067 update_average_temp(ips->ctv2_avg_temp, val); in ips_monitor()
1071 val = read_mgtv(ips); in ips_monitor()
1072 ips->mch_avg_temp = update_average_temp(ips->mch_avg_temp, val); in ips_monitor()
1074 if (ips->read_mch_val) { in ips_monitor()
1075 mch_val = ips->read_mch_val(); in ips_monitor()
1076 ips->mch_avg_power = in ips_monitor()
1077 update_average_power(ips->mch_avg_power, in ips_monitor()
1091 dev_warn(ips->dev, in ips_monitor()
1102 mod_timer(&ips->timer, expire); in ips_monitor()
1111 del_timer_sync(&ips->timer); in ips_monitor()
1113 dev_dbg(ips->dev, "ips-monitor thread stopped\n"); in ips_monitor()
1119 * ips_irq_handler - handle temperature triggers and other IPS events
1131 struct ips_driver *ips = arg; in ips_irq_handler() local
1138 dev_info(ips->dev, "TSES: 0x%02x\n", tses); in ips_irq_handler()
1139 dev_info(ips->dev, "TES: 0x%02x\n", tes); in ips_irq_handler()
1149 spin_lock(&ips->turbo_status_lock); in ips_irq_handler()
1150 ips->core_power_limit = (sts & STS_PCPL_MASK) >> in ips_irq_handler()
1152 ips->mch_power_limit = (sts & STS_GPL_MASK) >> in ips_irq_handler()
1155 ips->cpu_turbo_enabled = !(sts & STS_PCTD_DIS); in ips_irq_handler()
1160 ips->cpu_turbo_enabled = false; in ips_irq_handler()
1161 if (ips->gpu_busy) in ips_irq_handler()
1162 ips->gpu_turbo_enabled = !(sts & STS_GTD_DIS); in ips_irq_handler()
1163 ips->mcp_temp_limit = (sts & STS_PTL_MASK) >> in ips_irq_handler()
1165 ips->mcp_power_limit = (tc1 & STS_PPL_MASK) >> in ips_irq_handler()
1167 verify_limits(ips); in ips_irq_handler()
1168 spin_unlock(&ips->turbo_status_lock); in ips_irq_handler()
1177 dev_warn(ips->dev, "thermal trip occurred, tses: 0x%04x\n", in ips_irq_handler()
1186 static void ips_debugfs_init(struct ips_driver *ips) { return; } in ips_debugfs_init() argument
1187 static void ips_debugfs_cleanup(struct ips_driver *ips) { return; } in ips_debugfs_cleanup() argument
1194 struct ips_driver *ips = m->private; in cpu_temp_show() local
1196 seq_printf(m, "%d.%02d\n", ips->ctv1_avg_temp / 100, in cpu_temp_show()
1197 ips->ctv1_avg_temp % 100); in cpu_temp_show()
1205 struct ips_driver *ips = m->private; in cpu_power_show() local
1207 seq_printf(m, "%dmW\n", ips->cpu_avg_power); in cpu_power_show()
1237 struct ips_driver *ips = m->private; in mch_temp_show() local
1239 seq_printf(m, "%d.%02d\n", ips->mch_avg_temp / 100, in mch_temp_show()
1240 ips->mch_avg_temp % 100); in mch_temp_show()
1248 struct ips_driver *ips = m->private; in mch_power_show() local
1250 seq_printf(m, "%dmW\n", ips->mch_avg_power); in mch_power_show()
1256 static void ips_debugfs_cleanup(struct ips_driver *ips) in ips_debugfs_cleanup() argument
1258 debugfs_remove_recursive(ips->debug_root); in ips_debugfs_cleanup()
1261 static void ips_debugfs_init(struct ips_driver *ips) in ips_debugfs_init() argument
1263 ips->debug_root = debugfs_create_dir("ips", NULL); in ips_debugfs_init()
1265 debugfs_create_file("cpu_temp", 0444, ips->debug_root, ips, &cpu_temp_fops); in ips_debugfs_init()
1266 debugfs_create_file("cpu_power", 0444, ips->debug_root, ips, &cpu_power_fops); in ips_debugfs_init()
1267 debugfs_create_file("cpu_clamp", 0444, ips->debug_root, ips, &cpu_clamp_fops); in ips_debugfs_init()
1268 debugfs_create_file("mch_temp", 0444, ips->debug_root, ips, &mch_temp_fops); in ips_debugfs_init()
1269 debugfs_create_file("mch_power", 0444, ips->debug_root, ips, &mch_power_fops); in ips_debugfs_init()
1274 * ips_detect_cpu - detect whether CPU supports IPS
1275 * @ips: IPS driver struct
1282 static struct ips_mcp_limits *ips_detect_cpu(struct ips_driver *ips) in ips_detect_cpu() argument
1289 dev_info(ips->dev, "Non-IPS CPU detected.\n"); in ips_detect_cpu()
1300 ips->turbo_toggle_allowed = true; in ips_detect_cpu()
1302 ips->turbo_toggle_allowed = false; in ips_detect_cpu()
1311 dev_info(ips->dev, "No CPUID match found.\n"); in ips_detect_cpu()
1320 dev_info(ips->dev, in ips_detect_cpu()
1331 * @ips: IPS driver
1333 * The i915 driver exports several interfaces to allow the IPS driver to
1340 static bool ips_get_i915_syms(struct ips_driver *ips) in ips_get_i915_syms() argument
1342 ips->read_mch_val = symbol_get(i915_read_mch_val); in ips_get_i915_syms()
1343 if (!ips->read_mch_val) in ips_get_i915_syms()
1345 ips->gpu_raise = symbol_get(i915_gpu_raise); in ips_get_i915_syms()
1346 if (!ips->gpu_raise) in ips_get_i915_syms()
1348 ips->gpu_lower = symbol_get(i915_gpu_lower); in ips_get_i915_syms()
1349 if (!ips->gpu_lower) in ips_get_i915_syms()
1351 ips->gpu_busy = symbol_get(i915_gpu_busy); in ips_get_i915_syms()
1352 if (!ips->gpu_busy) in ips_get_i915_syms()
1354 ips->gpu_turbo_disable = symbol_get(i915_gpu_turbo_disable); in ips_get_i915_syms()
1355 if (!ips->gpu_turbo_disable) in ips_get_i915_syms()
1373 ips_gpu_turbo_enabled(struct ips_driver *ips) in ips_gpu_turbo_enabled() argument
1375 if (!ips->gpu_busy && late_i915_load) { in ips_gpu_turbo_enabled()
1376 if (ips_get_i915_syms(ips)) { in ips_gpu_turbo_enabled()
1377 dev_info(ips->dev, in ips_gpu_turbo_enabled()
1379 ips->gpu_turbo_enabled = !(thm_readl(THM_HTS) & HTS_GTD_DIS); in ips_gpu_turbo_enabled()
1383 return ips->gpu_turbo_enabled; in ips_gpu_turbo_enabled()
1425 struct ips_driver *ips; in ips_probe() local
1434 ips = devm_kzalloc(&dev->dev, sizeof(*ips), GFP_KERNEL); in ips_probe()
1435 if (!ips) in ips_probe()
1438 spin_lock_init(&ips->turbo_status_lock); in ips_probe()
1439 ips->dev = &dev->dev; in ips_probe()
1441 ips->limits = ips_detect_cpu(ips); in ips_probe()
1442 if (!ips->limits) { in ips_probe()
1443 dev_info(&dev->dev, "IPS not supported on this CPU\n"); in ips_probe()
1458 ips->regmap = pcim_iomap_table(dev)[0]; in ips_probe()
1460 pci_set_drvdata(dev, ips); in ips_probe()
1476 ips->second_cpu = true; in ips_probe()
1478 update_turbo_limits(ips); in ips_probe()
1480 ips->mcp_power_limit / 10); in ips_probe()
1482 ips->core_power_limit / 10); in ips_probe()
1485 ips->poll_turbo_status = true; in ips_probe()
1487 if (!ips_get_i915_syms(ips)) { in ips_probe()
1489 ips->gpu_turbo_enabled = false; in ips_probe()
1492 ips->gpu_turbo_enabled = true; in ips_probe()
1513 ips->irq = pci_irq_vector(dev, 0); in ips_probe()
1515 ret = request_irq(ips->irq, ips_irq_handler, IRQF_SHARED, "ips", ips); in ips_probe()
1527 ips->cta_val = thm_readw(THM_CTA); in ips_probe()
1528 ips->pta_val = thm_readw(THM_PTA); in ips_probe()
1529 ips->mgta_val = thm_readw(THM_MGTA); in ips_probe()
1532 rdmsrl(TURBO_POWER_CURRENT_LIMIT, ips->orig_turbo_limit); in ips_probe()
1534 ips_disable_cpu_turbo(ips); in ips_probe()
1535 ips->cpu_turbo_enabled = false; in ips_probe()
1538 ips->adjust = kthread_create(ips_adjust, ips, "ips-adjust"); in ips_probe()
1539 if (IS_ERR(ips->adjust)) { in ips_probe()
1551 ips->monitor = kthread_run(ips_monitor, ips, "ips-monitor"); in ips_probe()
1552 if (IS_ERR(ips->monitor)) { in ips_probe()
1559 hts = (ips->core_power_limit << HTS_PCPL_SHIFT) | in ips_probe()
1560 (ips->mcp_temp_limit << HTS_PTL_SHIFT) | HTS_NVV; in ips_probe()
1566 ips_debugfs_init(ips); in ips_probe()
1568 dev_info(&dev->dev, "IPS driver initialized, MCP temp limit %d\n", in ips_probe()
1569 ips->mcp_temp_limit); in ips_probe()
1573 kthread_stop(ips->adjust); in ips_probe()
1575 free_irq(ips->irq, ips); in ips_probe()
1582 struct ips_driver *ips = pci_get_drvdata(dev); in ips_remove() local
1585 ips_debugfs_cleanup(ips); in ips_remove()
1588 if (ips->read_mch_val) in ips_remove()
1590 if (ips->gpu_raise) in ips_remove()
1592 if (ips->gpu_lower) in ips_remove()
1594 if (ips->gpu_busy) in ips_remove()
1596 if (ips->gpu_turbo_disable) in ips_remove()
1602 wrmsrl(TURBO_POWER_CURRENT_LIMIT, ips->orig_turbo_limit); in ips_remove()
1604 free_irq(ips->irq, ips); in ips_remove()
1606 if (ips->adjust) in ips_remove()
1607 kthread_stop(ips->adjust); in ips_remove()
1608 if (ips->monitor) in ips_remove()
1609 kthread_stop(ips->monitor); in ips_remove()
1610 dev_dbg(&dev->dev, "IPS driver removed\n"); in ips_remove()
1614 .name = "intel ips",