Lines Matching full:ips
54 * - ref 26037, 26641 - IPS BIOS spec
239 #define thm_readb(off) readb(ips->regmap + (off))
240 #define thm_readw(off) readw(ips->regmap + (off))
241 #define thm_readl(off) readl(ips->regmap + (off))
242 #define thm_readq(off) readq(ips->regmap + (off))
244 #define thm_writeb(off, val) writeb((val), ips->regmap + (off))
245 #define thm_writew(off, val) writew((val), ips->regmap + (off))
246 #define thm_writel(off, val) writel((val), ips->regmap + (off))
346 ips_gpu_turbo_enabled(struct ips_driver *ips);
350 * @ips: IPS driver struct
357 static bool ips_cpu_busy(struct ips_driver *ips) in ips_cpu_busy() argument
367 * @ips: IPS driver struct
375 static void ips_cpu_raise(struct ips_driver *ips) in ips_cpu_raise() argument
380 if (!ips->cpu_turbo_enabled) in ips_cpu_raise()
389 if (((new_tdp_limit * 10) / 8) > ips->core_power_limit) in ips_cpu_raise()
405 * @ips: IPS driver struct
413 static void ips_cpu_lower(struct ips_driver *ips) in ips_cpu_lower() argument
424 if (new_limit < (ips->orig_turbo_limit & TURBO_TDP_MASK)) in ips_cpu_lower()
425 new_limit = ips->orig_turbo_limit & TURBO_TDP_MASK; in ips_cpu_lower()
459 * @ips: IPS driver struct
464 static void ips_enable_cpu_turbo(struct ips_driver *ips) in ips_enable_cpu_turbo() argument
467 if (ips->__cpu_turbo_on) in ips_enable_cpu_turbo()
470 if (ips->turbo_toggle_allowed) in ips_enable_cpu_turbo()
471 on_each_cpu(do_enable_cpu_turbo, ips, 1); in ips_enable_cpu_turbo()
473 ips->__cpu_turbo_on = true; in ips_enable_cpu_turbo()
497 * @ips: IPS driver struct
502 static void ips_disable_cpu_turbo(struct ips_driver *ips) in ips_disable_cpu_turbo() argument
505 if (!ips->__cpu_turbo_on) in ips_disable_cpu_turbo()
508 if (ips->turbo_toggle_allowed) in ips_disable_cpu_turbo()
509 on_each_cpu(do_disable_cpu_turbo, ips, 1); in ips_disable_cpu_turbo()
511 ips->__cpu_turbo_on = false; in ips_disable_cpu_turbo()
516 * @ips: IPS driver struct
524 static bool ips_gpu_busy(struct ips_driver *ips) in ips_gpu_busy() argument
526 if (!ips_gpu_turbo_enabled(ips)) in ips_gpu_busy()
529 return ips->gpu_busy(); in ips_gpu_busy()
534 * @ips: IPS driver struct
539 static void ips_gpu_raise(struct ips_driver *ips) in ips_gpu_raise() argument
541 if (!ips_gpu_turbo_enabled(ips)) in ips_gpu_raise()
544 if (!ips->gpu_raise()) in ips_gpu_raise()
545 ips->gpu_turbo_enabled = false; in ips_gpu_raise()
552 * @ips: IPS driver struct
556 static void ips_gpu_lower(struct ips_driver *ips) in ips_gpu_lower() argument
558 if (!ips_gpu_turbo_enabled(ips)) in ips_gpu_lower()
561 if (!ips->gpu_lower()) in ips_gpu_lower()
562 ips->gpu_turbo_enabled = false; in ips_gpu_lower()
569 * @ips: IPS driver struct
574 static void ips_enable_gpu_turbo(struct ips_driver *ips) in ips_enable_gpu_turbo() argument
576 if (ips->__gpu_turbo_on) in ips_enable_gpu_turbo()
578 ips->__gpu_turbo_on = true; in ips_enable_gpu_turbo()
583 * @ips: IPS driver struct
587 static void ips_disable_gpu_turbo(struct ips_driver *ips) in ips_disable_gpu_turbo() argument
590 if (!ips->__gpu_turbo_on) in ips_disable_gpu_turbo()
593 if (!ips->gpu_turbo_disable()) in ips_disable_gpu_turbo()
594 dev_err(ips->dev, "failed to disable graphics turbo\n"); in ips_disable_gpu_turbo()
596 ips->__gpu_turbo_on = false; in ips_disable_gpu_turbo()
601 * @ips: IPS driver struct
605 static bool mcp_exceeded(struct ips_driver *ips) in mcp_exceeded() argument
612 spin_lock_irqsave(&ips->turbo_status_lock, flags); in mcp_exceeded()
614 temp_limit = ips->mcp_temp_limit * 100; in mcp_exceeded()
615 if (ips->mcp_avg_temp > temp_limit) in mcp_exceeded()
618 avg_power = ips->cpu_avg_power + ips->mch_avg_power; in mcp_exceeded()
619 if (avg_power > ips->mcp_power_limit) in mcp_exceeded()
622 spin_unlock_irqrestore(&ips->turbo_status_lock, flags); in mcp_exceeded()
629 * @ips: IPS driver struct
634 static bool cpu_exceeded(struct ips_driver *ips, int cpu) in cpu_exceeded() argument
640 spin_lock_irqsave(&ips->turbo_status_lock, flags); in cpu_exceeded()
641 avg = cpu ? ips->ctv2_avg_temp : ips->ctv1_avg_temp; in cpu_exceeded()
642 if (avg > (ips->limits->core_temp_limit * 100)) in cpu_exceeded()
644 if (ips->cpu_avg_power > ips->core_power_limit * 100) in cpu_exceeded()
646 spin_unlock_irqrestore(&ips->turbo_status_lock, flags); in cpu_exceeded()
649 dev_info(ips->dev, "CPU power or thermal limit exceeded\n"); in cpu_exceeded()
656 * @ips: IPS driver struct
660 static bool mch_exceeded(struct ips_driver *ips) in mch_exceeded() argument
665 spin_lock_irqsave(&ips->turbo_status_lock, flags); in mch_exceeded()
666 if (ips->mch_avg_temp > (ips->limits->mch_temp_limit * 100)) in mch_exceeded()
668 if (ips->mch_avg_power > ips->mch_power_limit) in mch_exceeded()
670 spin_unlock_irqrestore(&ips->turbo_status_lock, flags); in mch_exceeded()
677 * @ips: IPS structure
683 static void verify_limits(struct ips_driver *ips) in verify_limits() argument
685 if (ips->mcp_power_limit < ips->limits->mcp_power_limit || in verify_limits()
686 ips->mcp_power_limit > 35000) in verify_limits()
687 ips->mcp_power_limit = ips->limits->mcp_power_limit; in verify_limits()
689 if (ips->mcp_temp_limit < ips->limits->core_temp_limit || in verify_limits()
690 ips->mcp_temp_limit < ips->limits->mch_temp_limit || in verify_limits()
691 ips->mcp_temp_limit > 150) in verify_limits()
692 ips->mcp_temp_limit = min(ips->limits->core_temp_limit, in verify_limits()
693 ips->limits->mch_temp_limit); in verify_limits()
698 * @ips: IPS driver struct
700 * Update the IPS power & temp limits, along with turbo enable flags,
709 static void update_turbo_limits(struct ips_driver *ips) in update_turbo_limits() argument
713 ips->cpu_turbo_enabled = !(hts & HTS_PCTD_DIS); in update_turbo_limits()
718 ips->cpu_turbo_enabled = false; in update_turbo_limits()
720 if (ips->gpu_busy) in update_turbo_limits()
721 ips->gpu_turbo_enabled = !(hts & HTS_GTD_DIS); in update_turbo_limits()
723 ips->core_power_limit = thm_readw(THM_MPCPC); in update_turbo_limits()
724 ips->mch_power_limit = thm_readw(THM_MMGPC); in update_turbo_limits()
725 ips->mcp_temp_limit = thm_readw(THM_PTL); in update_turbo_limits()
726 ips->mcp_power_limit = thm_readw(THM_MPPC); in update_turbo_limits()
728 verify_limits(ips); in update_turbo_limits()
734 * @data: ips driver structure
765 struct ips_driver *ips = data; in ips_adjust() local
768 dev_dbg(ips->dev, "starting ips-adjust thread\n"); in ips_adjust()
775 bool cpu_busy = ips_cpu_busy(ips); in ips_adjust()
776 bool gpu_busy = ips_gpu_busy(ips); in ips_adjust()
778 spin_lock_irqsave(&ips->turbo_status_lock, flags); in ips_adjust()
779 if (ips->poll_turbo_status) in ips_adjust()
780 update_turbo_limits(ips); in ips_adjust()
781 spin_unlock_irqrestore(&ips->turbo_status_lock, flags); in ips_adjust()
784 if (ips->cpu_turbo_enabled) in ips_adjust()
785 ips_enable_cpu_turbo(ips); in ips_adjust()
787 ips_disable_cpu_turbo(ips); in ips_adjust()
789 if (ips->gpu_turbo_enabled) in ips_adjust()
790 ips_enable_gpu_turbo(ips); in ips_adjust()
792 ips_disable_gpu_turbo(ips); in ips_adjust()
795 if (mcp_exceeded(ips)) { in ips_adjust()
796 ips_cpu_lower(ips); in ips_adjust()
797 ips_gpu_lower(ips); in ips_adjust()
801 if (!cpu_exceeded(ips, 0) && cpu_busy) in ips_adjust()
802 ips_cpu_raise(ips); in ips_adjust()
804 ips_cpu_lower(ips); in ips_adjust()
806 if (!mch_exceeded(ips) && gpu_busy) in ips_adjust()
807 ips_gpu_raise(ips); in ips_adjust()
809 ips_gpu_lower(ips); in ips_adjust()
815 dev_dbg(ips->dev, "ips-adjust thread stopped\n"); in ips_adjust()
825 static u16 calc_avg_temp(struct ips_driver *ips, u16 *array) in calc_avg_temp() argument
841 static u16 read_mgtv(struct ips_driver *ips) in read_mgtv() argument
859 static u16 read_ptv(struct ips_driver *ips) in read_ptv() argument
868 static u16 read_ctv(struct ips_driver *ips, int cpu) in read_ctv() argument
882 static u32 get_cpu_power(struct ips_driver *ips, u32 *last, int period) in get_cpu_power() argument
923 static u32 calc_avg_power(struct ips_driver *ips, u32 *array) in calc_avg_power() argument
940 struct ips_driver *ips = from_timer(ips, t, timer); in monitor_timeout() local
941 wake_up_process(ips->monitor); in monitor_timeout()
946 * @data: ips driver structure
948 * This is the main function for the IPS driver. It monitors power and
957 struct ips_driver *ips = data; in ips_monitor() local
972 dev_err(ips->dev, in ips_monitor()
973 "failed to allocate sample array, ips disabled\n"); in ips_monitor()
995 mcp_samples[i] = read_ptv(ips); in ips_monitor()
997 val = read_ctv(ips, 0); in ips_monitor()
1000 val = read_ctv(ips, 1); in ips_monitor()
1003 val = read_mgtv(ips); in ips_monitor()
1006 cpu_power = get_cpu_power(ips, &old_cpu_power, in ips_monitor()
1010 if (ips->read_mch_val) { in ips_monitor()
1011 mchp = ips->read_mch_val(); in ips_monitor()
1020 ips->mcp_avg_temp = calc_avg_temp(ips, mcp_samples); in ips_monitor()
1021 ips->ctv1_avg_temp = calc_avg_temp(ips, ctv1_samples); in ips_monitor()
1022 ips->ctv2_avg_temp = calc_avg_temp(ips, ctv2_samples); in ips_monitor()
1023 ips->mch_avg_temp = calc_avg_temp(ips, mch_samples); in ips_monitor()
1024 ips->cpu_avg_power = calc_avg_power(ips, cpu_samples); in ips_monitor()
1025 ips->mch_avg_power = calc_avg_power(ips, mchp_samples); in ips_monitor()
1034 wake_up_process(ips->adjust); in ips_monitor()
1045 timer_setup(&ips->timer, monitor_timeout, TIMER_DEFERRABLE); in ips_monitor()
1051 val = read_ptv(ips); in ips_monitor()
1052 ips->mcp_avg_temp = update_average_temp(ips->mcp_avg_temp, val); in ips_monitor()
1055 val = read_ctv(ips, 0); in ips_monitor()
1056 ips->ctv1_avg_temp = in ips_monitor()
1057 update_average_temp(ips->ctv1_avg_temp, val); in ips_monitor()
1059 cpu_val = get_cpu_power(ips, &old_cpu_power, in ips_monitor()
1061 ips->cpu_avg_power = in ips_monitor()
1062 update_average_power(ips->cpu_avg_power, cpu_val); in ips_monitor()
1064 if (ips->second_cpu) { in ips_monitor()
1066 val = read_ctv(ips, 1); in ips_monitor()
1067 ips->ctv2_avg_temp = in ips_monitor()
1068 update_average_temp(ips->ctv2_avg_temp, val); in ips_monitor()
1072 val = read_mgtv(ips); in ips_monitor()
1073 ips->mch_avg_temp = update_average_temp(ips->mch_avg_temp, val); in ips_monitor()
1075 if (ips->read_mch_val) { in ips_monitor()
1076 mch_val = ips->read_mch_val(); in ips_monitor()
1077 ips->mch_avg_power = in ips_monitor()
1078 update_average_power(ips->mch_avg_power, in ips_monitor()
1092 dev_warn(ips->dev, in ips_monitor()
1103 mod_timer(&ips->timer, expire); in ips_monitor()
1112 del_timer_sync(&ips->timer); in ips_monitor()
1114 dev_dbg(ips->dev, "ips-monitor thread stopped\n"); in ips_monitor()
1123 dev_dbg(ips->dev, #reg ": 0x%04x\n", val); \
1128 dev_dbg(ips->dev, #reg ": 0x%08x\n", val); \
1133 dev_dbg(ips->dev, #reg ": 0x%016x\n", val); \
1136 static void dump_thermal_info(struct ips_driver *ips)
1141 dev_dbg(ips->dev, "Processor temp limit: %d\n", ptl);
1153 * ips_irq_handler - handle temperature triggers and other IPS events
1163 struct ips_driver *ips = arg; in ips_irq_handler() local
1170 dev_info(ips->dev, "TSES: 0x%02x\n", tses); in ips_irq_handler()
1171 dev_info(ips->dev, "TES: 0x%02x\n", tes); in ips_irq_handler()
1181 spin_lock(&ips->turbo_status_lock); in ips_irq_handler()
1182 ips->core_power_limit = (sts & STS_PCPL_MASK) >> in ips_irq_handler()
1184 ips->mch_power_limit = (sts & STS_GPL_MASK) >> in ips_irq_handler()
1187 ips->cpu_turbo_enabled = !(sts & STS_PCTD_DIS); in ips_irq_handler()
1192 ips->cpu_turbo_enabled = false; in ips_irq_handler()
1193 if (ips->gpu_busy) in ips_irq_handler()
1194 ips->gpu_turbo_enabled = !(sts & STS_GTD_DIS); in ips_irq_handler()
1195 ips->mcp_temp_limit = (sts & STS_PTL_MASK) >> in ips_irq_handler()
1197 ips->mcp_power_limit = (tc1 & STS_PPL_MASK) >> in ips_irq_handler()
1199 verify_limits(ips); in ips_irq_handler()
1200 spin_unlock(&ips->turbo_status_lock); in ips_irq_handler()
1209 dev_warn(ips->dev, "thermal trip occurred, tses: 0x%04x\n", in ips_irq_handler()
1218 static void ips_debugfs_init(struct ips_driver *ips) { return; } in ips_debugfs_init() argument
1219 static void ips_debugfs_cleanup(struct ips_driver *ips) { return; } in ips_debugfs_cleanup() argument
1225 struct ips_driver *ips; member
1232 struct ips_driver *ips = m->private; in show_cpu_temp() local
1234 seq_printf(m, "%d.%02d\n", ips->ctv1_avg_temp / 100, in show_cpu_temp()
1235 ips->ctv1_avg_temp % 100); in show_cpu_temp()
1242 struct ips_driver *ips = m->private; in show_cpu_power() local
1244 seq_printf(m, "%dmW\n", ips->cpu_avg_power); in show_cpu_power()
1272 struct ips_driver *ips = m->private; in show_mch_temp() local
1274 seq_printf(m, "%d.%02d\n", ips->mch_avg_temp / 100, in show_mch_temp()
1275 ips->mch_avg_temp % 100); in show_mch_temp()
1282 struct ips_driver *ips = m->private; in show_mch_power() local
1284 seq_printf(m, "%dmW\n", ips->mch_avg_power); in show_mch_power()
1301 return single_open(file, node->show, node->ips); in ips_debugfs_open()
1312 static void ips_debugfs_cleanup(struct ips_driver *ips) in ips_debugfs_cleanup() argument
1314 if (ips->debug_root) in ips_debugfs_cleanup()
1315 debugfs_remove_recursive(ips->debug_root); in ips_debugfs_cleanup()
1319 static void ips_debugfs_init(struct ips_driver *ips) in ips_debugfs_init() argument
1323 ips->debug_root = debugfs_create_dir("ips", NULL); in ips_debugfs_init()
1324 if (!ips->debug_root) { in ips_debugfs_init()
1325 dev_err(ips->dev, "failed to create debugfs entries: %ld\n", in ips_debugfs_init()
1326 PTR_ERR(ips->debug_root)); in ips_debugfs_init()
1334 node->ips = ips; in ips_debugfs_init()
1336 ips->debug_root, node, in ips_debugfs_init()
1339 dev_err(ips->dev, "failed to create debug file: %ld\n", in ips_debugfs_init()
1348 ips_debugfs_cleanup(ips); in ips_debugfs_init()
1354 * ips_detect_cpu - detect whether CPU supports IPS
1359 static struct ips_mcp_limits *ips_detect_cpu(struct ips_driver *ips) in ips_detect_cpu() argument
1366 dev_info(ips->dev, "Non-IPS CPU detected.\n"); in ips_detect_cpu()
1377 ips->turbo_toggle_allowed = true; in ips_detect_cpu()
1379 ips->turbo_toggle_allowed = false; in ips_detect_cpu()
1388 dev_info(ips->dev, "No CPUID match found.\n"); in ips_detect_cpu()
1397 dev_info(ips->dev, in ips_detect_cpu()
1408 * @ips: IPS driver
1410 * The i915 driver exports several interfaces to allow the IPS driver to
1415 static bool ips_get_i915_syms(struct ips_driver *ips) in ips_get_i915_syms() argument
1417 ips->read_mch_val = symbol_get(i915_read_mch_val); in ips_get_i915_syms()
1418 if (!ips->read_mch_val) in ips_get_i915_syms()
1420 ips->gpu_raise = symbol_get(i915_gpu_raise); in ips_get_i915_syms()
1421 if (!ips->gpu_raise) in ips_get_i915_syms()
1423 ips->gpu_lower = symbol_get(i915_gpu_lower); in ips_get_i915_syms()
1424 if (!ips->gpu_lower) in ips_get_i915_syms()
1426 ips->gpu_busy = symbol_get(i915_gpu_busy); in ips_get_i915_syms()
1427 if (!ips->gpu_busy) in ips_get_i915_syms()
1429 ips->gpu_turbo_disable = symbol_get(i915_gpu_turbo_disable); in ips_get_i915_syms()
1430 if (!ips->gpu_turbo_disable) in ips_get_i915_syms()
1448 ips_gpu_turbo_enabled(struct ips_driver *ips) in ips_gpu_turbo_enabled() argument
1450 if (!ips->gpu_busy && late_i915_load) { in ips_gpu_turbo_enabled()
1451 if (ips_get_i915_syms(ips)) { in ips_gpu_turbo_enabled()
1452 dev_info(ips->dev, in ips_gpu_turbo_enabled()
1454 ips->gpu_turbo_enabled = !(thm_readl(THM_HTS) & HTS_GTD_DIS); in ips_gpu_turbo_enabled()
1458 return ips->gpu_turbo_enabled; in ips_gpu_turbo_enabled()
1500 struct ips_driver *ips; in ips_probe() local
1509 ips = devm_kzalloc(&dev->dev, sizeof(*ips), GFP_KERNEL); in ips_probe()
1510 if (!ips) in ips_probe()
1513 spin_lock_init(&ips->turbo_status_lock); in ips_probe()
1514 ips->dev = &dev->dev; in ips_probe()
1516 ips->limits = ips_detect_cpu(ips); in ips_probe()
1517 if (!ips->limits) { in ips_probe()
1518 dev_info(&dev->dev, "IPS not supported on this CPU\n"); in ips_probe()
1533 ips->regmap = pcim_iomap_table(dev)[0]; in ips_probe()
1535 pci_set_drvdata(dev, ips); in ips_probe()
1551 ips->second_cpu = true; in ips_probe()
1553 update_turbo_limits(ips); in ips_probe()
1555 ips->mcp_power_limit / 10); in ips_probe()
1557 ips->core_power_limit / 10); in ips_probe()
1560 ips->poll_turbo_status = true; in ips_probe()
1562 if (!ips_get_i915_syms(ips)) { in ips_probe()
1564 ips->gpu_turbo_enabled = false; in ips_probe()
1567 ips->gpu_turbo_enabled = true; in ips_probe()
1588 ips->irq = pci_irq_vector(dev, 0); in ips_probe()
1590 ret = request_irq(ips->irq, ips_irq_handler, IRQF_SHARED, "ips", ips); in ips_probe()
1602 ips->cta_val = thm_readw(THM_CTA); in ips_probe()
1603 ips->pta_val = thm_readw(THM_PTA); in ips_probe()
1604 ips->mgta_val = thm_readw(THM_MGTA); in ips_probe()
1607 rdmsrl(TURBO_POWER_CURRENT_LIMIT, ips->orig_turbo_limit); in ips_probe()
1609 ips_disable_cpu_turbo(ips); in ips_probe()
1610 ips->cpu_turbo_enabled = false; in ips_probe()
1613 ips->adjust = kthread_create(ips_adjust, ips, "ips-adjust"); in ips_probe()
1614 if (IS_ERR(ips->adjust)) { in ips_probe()
1626 ips->monitor = kthread_run(ips_monitor, ips, "ips-monitor"); in ips_probe()
1627 if (IS_ERR(ips->monitor)) { in ips_probe()
1634 hts = (ips->core_power_limit << HTS_PCPL_SHIFT) | in ips_probe()
1635 (ips->mcp_temp_limit << HTS_PTL_SHIFT) | HTS_NVV; in ips_probe()
1641 ips_debugfs_init(ips); in ips_probe()
1643 dev_info(&dev->dev, "IPS driver initialized, MCP temp limit %d\n", in ips_probe()
1644 ips->mcp_temp_limit); in ips_probe()
1648 kthread_stop(ips->adjust); in ips_probe()
1650 free_irq(ips->irq, ips); in ips_probe()
1657 struct ips_driver *ips = pci_get_drvdata(dev); in ips_remove() local
1660 if (!ips) in ips_remove()
1663 ips_debugfs_cleanup(ips); in ips_remove()
1666 if (ips->read_mch_val) in ips_remove()
1668 if (ips->gpu_raise) in ips_remove()
1670 if (ips->gpu_lower) in ips_remove()
1672 if (ips->gpu_busy) in ips_remove()
1674 if (ips->gpu_turbo_disable) in ips_remove()
1680 wrmsrl(TURBO_POWER_CURRENT_LIMIT, ips->orig_turbo_limit); in ips_remove()
1682 free_irq(ips->irq, ips); in ips_remove()
1684 if (ips->adjust) in ips_remove()
1685 kthread_stop(ips->adjust); in ips_remove()
1686 if (ips->monitor) in ips_remove()
1687 kthread_stop(ips->monitor); in ips_remove()
1688 dev_dbg(&dev->dev, "IPS driver removed\n"); in ips_remove()
1692 .name = "intel ips",