2 * Copyright (c) 2009-2010 Intel Corporation
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * You should have received a copy of the GNU General Public License along with
14 * this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
17 * The full GNU General Public License is included in this distribution in
18 * the file called "COPYING".
21 * Jesse Barnes <jbarnes@virtuousgeek.org>
25 * Some Intel Ibex Peak based platforms support so-called "intelligent
26 * power sharing", which allows the CPU and GPU to cooperate to maximize
27 * performance within a given TDP (thermal design point). This driver
28 * performs the coordination between the CPU and GPU, monitors thermal and
29 * power statistics in the platform, and initializes power monitoring
30 * hardware. It also provides a few tunables to control behavior. Its
31 * primary purpose is to safely allow CPU and GPU turbo modes to be enabled
32 * by tracking power and thermal budget; secondarily it can boost turbo
33 * performance by allocating more power or thermal budget to the CPU or GPU
34 * based on available headroom and activity.
36 * The basic algorithm is driven by a 5s moving average of tempurature. If
37 * thermal headroom is available, the CPU and/or GPU power clamps may be
38 * adjusted upwards. If we hit the thermal ceiling or a thermal trigger,
39 * we scale back the clamp. Aside from trigger events (when we're critically
40 * close or over our TDP) we don't adjust the clamps more than once every
43 * The thermal device (device 31, function 6) has a set of registers that
44 * are updated by the ME firmware. The ME should also take the clamp values
45 * written to those registers and write them to the CPU, but we currently
46 * bypass that functionality and write the CPU MSR directly.
52 * - handle CPU hotplug
53 * - provide turbo enable/disable api
56 * - CDI 403777, 403778 - Auburndale EDS vol 1 & 2
57 * - CDI 401376 - Ibex Peak EDS
58 * - ref 26037, 26641 - IPS BIOS spec
59 * - ref 26489 - Nehalem BIOS writer's guide
60 * - ref 26921 - Ibex Peak BIOS Specification
63 #include <linux/debugfs.h>
64 #include <linux/delay.h>
65 #include <linux/interrupt.h>
66 #include <linux/kernel.h>
67 #include <linux/kthread.h>
68 #include <linux/module.h>
69 #include <linux/pci.h>
70 #include <linux/sched.h>
71 #include <linux/seq_file.h>
72 #include <linux/string.h>
73 #include <linux/tick.h>
74 #include <linux/timer.h>
75 #include <drm/i915_drm.h>
77 #include <asm/processor.h>
79 #define PCI_DEVICE_ID_INTEL_THERMAL_SENSOR 0x3b32
82 * Package level MSRs for monitor/control
84 #define PLATFORM_INFO 0xce
85 #define PLATFORM_TDP (1<<29)
86 #define PLATFORM_RATIO (1<<28)
88 #define IA32_MISC_ENABLE 0x1a0
89 #define IA32_MISC_TURBO_EN (1ULL<<38)
91 #define TURBO_POWER_CURRENT_LIMIT 0x1ac
92 #define TURBO_TDC_OVR_EN (1UL<<31)
93 #define TURBO_TDC_MASK (0x000000007fff0000UL)
94 #define TURBO_TDC_SHIFT (16)
95 #define TURBO_TDP_OVR_EN (1UL<<15)
96 #define TURBO_TDP_MASK (0x0000000000003fffUL)
99 * Core/thread MSRs for monitoring
101 #define IA32_PERF_CTL 0x199
102 #define IA32_PERF_TURBO_DIS (1ULL<<32)
105 * Thermal PCI device regs
107 #define THM_CFG_TBAR 0x10
108 #define THM_CFG_TBAR_HI 0x14
110 #define THM_TSIU 0x00
114 #define THM_TSTR 0x03
115 #define THM_TSTTP 0x04
116 #define THM_TSCO 0x08
117 #define THM_TSES 0x0c
118 #define THM_TSGPEN 0x0d
119 #define TSGPEN_HOT_LOHI (1<<1)
120 #define TSGPEN_CRIT_LOHI (1<<2)
121 #define THM_TSPC 0x0e
122 #define THM_PPEC 0x10
125 #define PTA_SLOPE_MASK (0xff00)
126 #define PTA_SLOPE_SHIFT 8
127 #define PTA_OFFSET_MASK (0x00ff)
128 #define THM_MGTA 0x16
129 #define MGTA_SLOPE_MASK (0xff00)
130 #define MGTA_SLOPE_SHIFT 8
131 #define MGTA_OFFSET_MASK (0x00ff)
133 #define TRC_CORE2_EN (1<<15)
134 #define TRC_THM_EN (1<<12)
135 #define TRC_C6_WAR (1<<8)
136 #define TRC_CORE1_EN (1<<7)
137 #define TRC_CORE_PWR (1<<6)
138 #define TRC_PCH_EN (1<<5)
139 #define TRC_MCH_EN (1<<4)
140 #define TRC_DIMM4 (1<<3)
141 #define TRC_DIMM3 (1<<2)
142 #define TRC_DIMM2 (1<<1)
143 #define TRC_DIMM1 (1<<0)
146 #define TEN_UPDATE_EN 1
148 #define PSC_NTG (1<<0) /* No GFX turbo support */
149 #define PSC_NTPC (1<<1) /* No CPU turbo support */
150 #define PSC_PP_DEF (0<<2) /* Perf policy up to driver */
151 #define PSP_PP_PC (1<<2) /* BIOS prefers CPU perf */
152 #define PSP_PP_BAL (2<<2) /* BIOS wants balanced perf */
153 #define PSP_PP_GFX (3<<2) /* BIOS prefers GFX perf */
154 #define PSP_PBRT (1<<4) /* BIOS run time support */
155 #define THM_CTV1 0x30
156 #define CTV_TEMP_ERROR (1<<15)
157 #define CTV_TEMP_MASK 0x3f
159 #define THM_CTV2 0x32
160 #define THM_CEC 0x34 /* undocumented power accumulator in joules */
162 #define THM_HTS 0x50 /* 32 bits */
163 #define HTS_PCPL_MASK (0x7fe00000)
164 #define HTS_PCPL_SHIFT 21
165 #define HTS_GPL_MASK (0x001ff000)
166 #define HTS_GPL_SHIFT 12
167 #define HTS_PP_MASK (0x00000c00)
168 #define HTS_PP_SHIFT 10
170 #define HTS_PP_PROC 1
173 #define HTS_PCTD_DIS (1<<9)
174 #define HTS_GTD_DIS (1<<8)
175 #define HTS_PTL_MASK (0x000000fe)
176 #define HTS_PTL_SHIFT 1
177 #define HTS_NVV (1<<0)
178 #define THM_HTSHI 0x54 /* 16 bits */
179 #define HTS2_PPL_MASK (0x03ff)
180 #define HTS2_PRST_MASK (0x3c00)
181 #define HTS2_PRST_SHIFT 10
182 #define HTS2_PRST_UNLOADED 0
183 #define HTS2_PRST_RUNNING 1
184 #define HTS2_PRST_TDISOP 2 /* turbo disabled due to power */
185 #define HTS2_PRST_TDISHT 3 /* turbo disabled due to high temp */
186 #define HTS2_PRST_TDISUSR 4 /* user disabled turbo */
187 #define HTS2_PRST_TDISPLAT 5 /* platform disabled turbo */
188 #define HTS2_PRST_TDISPM 6 /* power management disabled turbo */
189 #define HTS2_PRST_TDISERR 7 /* some kind of error disabled turbo */
191 #define THM_MGTV 0x58
192 #define TV_MASK 0x000000000000ff00
195 #define PTV_MASK 0x00ff
196 #define THM_MMGPC 0x64
197 #define THM_MPPC 0x66
198 #define THM_MPCPC 0x68
199 #define THM_TSPIEN 0x82
200 #define TSPIEN_AUX_LOHI (1<<0)
201 #define TSPIEN_HOT_LOHI (1<<1)
202 #define TSPIEN_CRIT_LOHI (1<<2)
203 #define TSPIEN_AUX2_LOHI (1<<3)
204 #define THM_TSLOCK 0x83
208 #define STS_PCPL_MASK (0x7fe00000)
209 #define STS_PCPL_SHIFT 21
210 #define STS_GPL_MASK (0x001ff000)
211 #define STS_GPL_SHIFT 12
212 #define STS_PP_MASK (0x00000c00)
213 #define STS_PP_SHIFT 10
215 #define STS_PP_PROC 1
218 #define STS_PCTD_DIS (1<<9)
219 #define STS_GTD_DIS (1<<8)
220 #define STS_PTL_MASK (0x000000fe)
221 #define STS_PTL_SHIFT 1
222 #define STS_NVV (1<<0)
224 #define SEC_ACK (1<<0)
227 #define STS_PPL_MASK (0x0003ff00)
228 #define STS_PPL_SHIFT 16
232 #define ITV_ME_SEQNO_MASK 0x00ff0000 /* ME should update every ~200ms */
233 #define ITV_ME_SEQNO_SHIFT (16)
234 #define ITV_MCH_TEMP_MASK 0x0000ff00
235 #define ITV_MCH_TEMP_SHIFT (8)
236 #define ITV_PCH_TEMP_MASK 0x000000ff
238 #define thm_readb(off) readb(ips->regmap + (off))
239 #define thm_readw(off) readw(ips->regmap + (off))
240 #define thm_readl(off) readl(ips->regmap + (off))
241 #define thm_readq(off) readq(ips->regmap + (off))
243 #define thm_writeb(off, val) writeb((val), ips->regmap + (off))
244 #define thm_writew(off, val) writew((val), ips->regmap + (off))
245 #define thm_writel(off, val) writel((val), ips->regmap + (off))
247 static const int IPS_ADJUST_PERIOD = 5000; /* ms */
249 /* For initial average collection */
250 static const int IPS_SAMPLE_PERIOD = 200; /* ms */
251 static const int IPS_SAMPLE_WINDOW = 5000; /* 5s moving window of samples */
252 #define IPS_SAMPLE_COUNT (IPS_SAMPLE_WINDOW / IPS_SAMPLE_PERIOD)
255 struct ips_mcp_limits {
257 int cpu_model; /* includes extended model... */
258 int mcp_power_limit; /* mW units */
259 int core_power_limit;
261 int core_temp_limit; /* degrees C */
265 /* Max temps are -10 degrees C to avoid PROCHOT# */
267 struct ips_mcp_limits ips_sv_limits = {
268 .mcp_power_limit = 35000,
269 .core_power_limit = 29000,
270 .mch_power_limit = 20000,
271 .core_temp_limit = 95,
275 struct ips_mcp_limits ips_lv_limits = {
276 .mcp_power_limit = 25000,
277 .core_power_limit = 21000,
278 .mch_power_limit = 13000,
279 .core_temp_limit = 95,
283 struct ips_mcp_limits ips_ulv_limits = {
284 .mcp_power_limit = 18000,
285 .core_power_limit = 14000,
286 .mch_power_limit = 11000,
287 .core_temp_limit = 95,
294 struct task_struct *monitor;
295 struct task_struct *adjust;
296 struct dentry *debug_root;
298 /* Average CPU core temps (all averages in .01 degrees C for precision) */
303 /* Average for the CPU (both cores?) */
305 /* Average power consumption (in mW) */
314 /* Maximums & prefs, protected by turbo status lock */
315 spinlock_t turbo_status_lock;
318 u16 core_power_limit;
320 bool cpu_turbo_enabled;
322 bool gpu_turbo_enabled;
325 bool poll_turbo_status;
327 bool turbo_toggle_allowed;
328 struct ips_mcp_limits *limits;
330 /* Optional MCH interfaces for if i915 is in use */
331 unsigned long (*read_mch_val)(void);
332 bool (*gpu_raise)(void);
333 bool (*gpu_lower)(void);
334 bool (*gpu_busy)(void);
335 bool (*gpu_turbo_disable)(void);
337 /* For restoration at unload */
338 u64 orig_turbo_limit;
339 u64 orig_turbo_ratios;
343 * ips_cpu_busy - is CPU busy?
344 * @ips: IPS driver struct
346 * Check CPU for load to see whether we should increase its thermal budget.
349 * True if the CPU could use more power, false otherwise.
351 static bool ips_cpu_busy(struct ips_driver *ips)
353 if ((avenrun[0] >> FSHIFT) > 1)
360 * ips_cpu_raise - raise CPU power clamp
361 * @ips: IPS driver struct
363 * Raise the CPU power clamp by %IPS_CPU_STEP, in accordance with TDP for
366 * We do this by adjusting the TURBO_POWER_CURRENT_LIMIT MSR upwards (as
367 * long as we haven't hit the TDP limit for the SKU).
369 static void ips_cpu_raise(struct ips_driver *ips)
372 u16 cur_tdp_limit, new_tdp_limit;
374 if (!ips->cpu_turbo_enabled)
377 rdmsrl(TURBO_POWER_CURRENT_LIMIT, turbo_override);
379 cur_tdp_limit = turbo_override & TURBO_TDP_MASK;
380 new_tdp_limit = cur_tdp_limit + 8; /* 1W increase */
382 /* Clamp to SKU TDP limit */
383 if (((new_tdp_limit * 10) / 8) > ips->core_power_limit)
384 new_tdp_limit = cur_tdp_limit;
386 thm_writew(THM_MPCPC, (new_tdp_limit * 10) / 8);
388 turbo_override |= TURBO_TDC_OVR_EN | TURBO_TDC_OVR_EN;
389 wrmsrl(TURBO_POWER_CURRENT_LIMIT, turbo_override);
391 turbo_override &= ~TURBO_TDP_MASK;
392 turbo_override |= new_tdp_limit;
394 wrmsrl(TURBO_POWER_CURRENT_LIMIT, turbo_override);
398 * ips_cpu_lower - lower CPU power clamp
399 * @ips: IPS driver struct
401 * Lower CPU power clamp b %IPS_CPU_STEP if possible.
403 * We do this by adjusting the TURBO_POWER_CURRENT_LIMIT MSR down, going
404 * as low as the platform limits will allow (though we could go lower there
405 * wouldn't be much point).
407 static void ips_cpu_lower(struct ips_driver *ips)
410 u16 cur_limit, new_limit;
412 rdmsrl(TURBO_POWER_CURRENT_LIMIT, turbo_override);
414 cur_limit = turbo_override & TURBO_TDP_MASK;
415 new_limit = cur_limit - 8; /* 1W decrease */
417 /* Clamp to SKU TDP limit */
418 if (((new_limit * 10) / 8) < (ips->orig_turbo_limit & TURBO_TDP_MASK))
419 new_limit = ips->orig_turbo_limit & TURBO_TDP_MASK;
421 thm_writew(THM_MPCPC, (new_limit * 10) / 8);
423 turbo_override |= TURBO_TDC_OVR_EN | TURBO_TDC_OVR_EN;
424 wrmsrl(TURBO_POWER_CURRENT_LIMIT, turbo_override);
426 turbo_override &= ~TURBO_TDP_MASK;
427 turbo_override |= new_limit;
429 wrmsrl(TURBO_POWER_CURRENT_LIMIT, turbo_override);
433 * do_enable_cpu_turbo - internal turbo enable function
436 * Internal function for actually updating MSRs. When we enable/disable
437 * turbo, we need to do it on each CPU; this function is the one called
438 * by on_each_cpu() when needed.
440 static void do_enable_cpu_turbo(void *data)
444 rdmsrl(IA32_PERF_CTL, perf_ctl);
445 if (perf_ctl & IA32_PERF_TURBO_DIS) {
446 perf_ctl &= ~IA32_PERF_TURBO_DIS;
447 wrmsrl(IA32_PERF_CTL, perf_ctl);
452 * ips_enable_cpu_turbo - enable turbo mode on all CPUs
453 * @ips: IPS driver struct
455 * Enable turbo mode by clearing the disable bit in IA32_PERF_CTL on
456 * all logical threads.
458 static void ips_enable_cpu_turbo(struct ips_driver *ips)
460 /* Already on, no need to mess with MSRs */
461 if (ips->__cpu_turbo_on)
464 if (ips->turbo_toggle_allowed)
465 on_each_cpu(do_enable_cpu_turbo, ips, 1);
467 ips->__cpu_turbo_on = true;
471 * do_disable_cpu_turbo - internal turbo disable function
474 * Internal function for actually updating MSRs. When we enable/disable
475 * turbo, we need to do it on each CPU; this function is the one called
476 * by on_each_cpu() when needed.
478 static void do_disable_cpu_turbo(void *data)
482 rdmsrl(IA32_PERF_CTL, perf_ctl);
483 if (!(perf_ctl & IA32_PERF_TURBO_DIS)) {
484 perf_ctl |= IA32_PERF_TURBO_DIS;
485 wrmsrl(IA32_PERF_CTL, perf_ctl);
490 * ips_disable_cpu_turbo - disable turbo mode on all CPUs
491 * @ips: IPS driver struct
493 * Disable turbo mode by setting the disable bit in IA32_PERF_CTL on
494 * all logical threads.
496 static void ips_disable_cpu_turbo(struct ips_driver *ips)
498 /* Already off, leave it */
499 if (!ips->__cpu_turbo_on)
502 if (ips->turbo_toggle_allowed)
503 on_each_cpu(do_disable_cpu_turbo, ips, 1);
505 ips->__cpu_turbo_on = false;
509 * ips_gpu_busy - is GPU busy?
510 * @ips: IPS driver struct
512 * Check GPU for load to see whether we should increase its thermal budget.
513 * We need to call into the i915 driver in this case.
516 * True if the GPU could use more power, false otherwise.
518 static bool ips_gpu_busy(struct ips_driver *ips)
520 if (!ips->gpu_turbo_enabled)
523 return ips->gpu_busy();
527 * ips_gpu_raise - raise GPU power clamp
528 * @ips: IPS driver struct
530 * Raise the GPU frequency/power if possible. We need to call into the
531 * i915 driver in this case.
533 static void ips_gpu_raise(struct ips_driver *ips)
535 if (!ips->gpu_turbo_enabled)
538 if (!ips->gpu_raise())
539 ips->gpu_turbo_enabled = false;
545 * ips_gpu_lower - lower GPU power clamp
546 * @ips: IPS driver struct
548 * Lower GPU frequency/power if possible. Need to call i915.
550 static void ips_gpu_lower(struct ips_driver *ips)
552 if (!ips->gpu_turbo_enabled)
555 if (!ips->gpu_lower())
556 ips->gpu_turbo_enabled = false;
562 * ips_enable_gpu_turbo - notify the gfx driver turbo is available
563 * @ips: IPS driver struct
565 * Call into the graphics driver indicating that it can safely use
568 static void ips_enable_gpu_turbo(struct ips_driver *ips)
570 if (ips->__gpu_turbo_on)
572 ips->__gpu_turbo_on = true;
576 * ips_disable_gpu_turbo - notify the gfx driver to disable turbo mode
577 * @ips: IPS driver struct
579 * Request that the graphics driver disable turbo mode.
581 static void ips_disable_gpu_turbo(struct ips_driver *ips)
583 /* Avoid calling i915 if turbo is already disabled */
584 if (!ips->__gpu_turbo_on)
587 if (!ips->gpu_turbo_disable())
588 dev_err(&ips->dev->dev, "failed to disable graphis turbo\n");
590 ips->__gpu_turbo_on = false;
594 * mcp_exceeded - check whether we're outside our thermal & power limits
595 * @ips: IPS driver struct
597 * Check whether the MCP is over its thermal or power budget.
599 static bool mcp_exceeded(struct ips_driver *ips)
604 spin_lock_irqsave(&ips->turbo_status_lock, flags);
605 if (ips->mcp_avg_temp > (ips->mcp_temp_limit * 100))
607 if (ips->cpu_avg_power + ips->mch_avg_power > ips->mcp_power_limit)
609 spin_unlock_irqrestore(&ips->turbo_status_lock, flags);
612 dev_info(&ips->dev->dev,
613 "MCP power or thermal limit exceeded\n");
619 * cpu_exceeded - check whether a CPU core is outside its limits
620 * @ips: IPS driver struct
621 * @cpu: CPU number to check
623 * Check a given CPU's average temp or power is over its limit.
625 static bool cpu_exceeded(struct ips_driver *ips, int cpu)
631 spin_lock_irqsave(&ips->turbo_status_lock, flags);
632 avg = cpu ? ips->ctv2_avg_temp : ips->ctv1_avg_temp;
633 if (avg > (ips->limits->core_temp_limit * 100))
635 if (ips->cpu_avg_power > ips->core_power_limit * 100)
637 spin_unlock_irqrestore(&ips->turbo_status_lock, flags);
640 dev_info(&ips->dev->dev,
641 "CPU power or thermal limit exceeded\n");
647 * mch_exceeded - check whether the GPU is over budget
648 * @ips: IPS driver struct
650 * Check the MCH temp & power against their maximums.
652 static bool mch_exceeded(struct ips_driver *ips)
657 spin_lock_irqsave(&ips->turbo_status_lock, flags);
658 if (ips->mch_avg_temp > (ips->limits->mch_temp_limit * 100))
660 if (ips->mch_avg_power > ips->mch_power_limit)
662 spin_unlock_irqrestore(&ips->turbo_status_lock, flags);
668 * verify_limits - verify BIOS provided limits
669 * @ips: IPS structure
671 * BIOS can optionally provide non-default limits for power and temp. Check
672 * them here and use the defaults if the BIOS values are not provided or
673 * are otherwise unusable.
675 static void verify_limits(struct ips_driver *ips)
677 if (ips->mcp_power_limit < ips->limits->mcp_power_limit ||
678 ips->mcp_power_limit > 35000)
679 ips->mcp_power_limit = ips->limits->mcp_power_limit;
681 if (ips->mcp_temp_limit < ips->limits->core_temp_limit ||
682 ips->mcp_temp_limit < ips->limits->mch_temp_limit ||
683 ips->mcp_temp_limit > 150)
684 ips->mcp_temp_limit = min(ips->limits->core_temp_limit,
685 ips->limits->mch_temp_limit);
689 * update_turbo_limits - get various limits & settings from regs
690 * @ips: IPS driver struct
692 * Update the IPS power & temp limits, along with turbo enable flags,
693 * based on latest register contents.
695 * Used at init time and for runtime BIOS support, which requires polling
696 * the regs for updates (as a result of AC->DC transition for example).
699 * Caller must hold turbo_status_lock (outside of init)
701 static void update_turbo_limits(struct ips_driver *ips)
703 u32 hts = thm_readl(THM_HTS);
705 ips->cpu_turbo_enabled = !(hts & HTS_PCTD_DIS);
706 ips->gpu_turbo_enabled = !(hts & HTS_GTD_DIS);
707 ips->core_power_limit = thm_readw(THM_MPCPC);
708 ips->mch_power_limit = thm_readw(THM_MMGPC);
709 ips->mcp_temp_limit = thm_readw(THM_PTL);
710 ips->mcp_power_limit = thm_readw(THM_MPPC);
713 /* Ignore BIOS CPU vs GPU pref */
717 * ips_adjust - adjust power clamp based on thermal state
718 * @data: ips driver structure
720 * Wake up every 5s or so and check whether we should adjust the power clamp.
721 * Check CPU and GPU load to determine which needs adjustment. There are
722 * several things to consider here:
723 * - do we need to adjust up or down?
728 * - is CPU or GPU preferred? (CPU is default)
730 * So, given the above, we do the following:
731 * - up (TDP available)
732 * - CPU not busy, GPU not busy - nothing
733 * - CPU busy, GPU not busy - adjust CPU up
734 * - CPU not busy, GPU busy - adjust GPU up
735 * - CPU busy, GPU busy - adjust preferred unit up, taking headroom from
736 * non-preferred unit if necessary
737 * - down (at TDP limit)
738 * - adjust both CPU and GPU down if possible
740 cpu+ gpu+ cpu+gpu- cpu-gpu+ cpu-gpu-
741 cpu < gpu < cpu+gpu+ cpu+ gpu+ nothing
742 cpu < gpu >= cpu+gpu-(mcp<) cpu+gpu-(mcp<) gpu- gpu-
743 cpu >= gpu < cpu-gpu+(mcp<) cpu- cpu-gpu+(mcp<) cpu-
744 cpu >= gpu >= cpu-gpu- cpu-gpu- cpu-gpu- cpu-gpu-
747 static int ips_adjust(void *data)
749 struct ips_driver *ips = data;
752 dev_dbg(&ips->dev->dev, "starting ips-adjust thread\n");
755 * Adjust CPU and GPU clamps every 5s if needed. Doing it more
756 * often isn't recommended due to ME interaction.
759 bool cpu_busy = ips_cpu_busy(ips);
760 bool gpu_busy = ips_gpu_busy(ips);
762 spin_lock_irqsave(&ips->turbo_status_lock, flags);
763 if (ips->poll_turbo_status)
764 update_turbo_limits(ips);
765 spin_unlock_irqrestore(&ips->turbo_status_lock, flags);
767 /* Update turbo status if necessary */
768 if (ips->cpu_turbo_enabled)
769 ips_enable_cpu_turbo(ips);
771 ips_disable_cpu_turbo(ips);
773 if (ips->gpu_turbo_enabled)
774 ips_enable_gpu_turbo(ips);
776 ips_disable_gpu_turbo(ips);
778 /* We're outside our comfort zone, crank them down */
779 if (mcp_exceeded(ips)) {
785 if (!cpu_exceeded(ips, 0) && cpu_busy)
790 if (!mch_exceeded(ips) && gpu_busy)
796 schedule_timeout_interruptible(msecs_to_jiffies(IPS_ADJUST_PERIOD));
797 } while (!kthread_should_stop());
799 dev_dbg(&ips->dev->dev, "ips-adjust thread stopped\n");
805 * Helpers for reading out temp/power values and calculating their
806 * averages for the decision making and monitoring functions.
809 static u16 calc_avg_temp(struct ips_driver *ips, u16 *array)
815 for (i = 0; i < IPS_SAMPLE_COUNT; i++)
816 total += (u64)(array[i] * 100);
818 do_div(total, IPS_SAMPLE_COUNT);
825 static u16 read_mgtv(struct ips_driver *ips)
831 val = thm_readq(THM_MGTV);
832 val = (val & TV_MASK) >> TV_SHIFT;
834 slope = offset = thm_readw(THM_MGTA);
835 slope = (slope & MGTA_SLOPE_MASK) >> MGTA_SLOPE_SHIFT;
836 offset = offset & MGTA_OFFSET_MASK;
838 ret = ((val * slope + 0x40) >> 7) + offset;
840 return 0; /* MCH temp reporting buggy */
843 static u16 read_ptv(struct ips_driver *ips)
845 u16 val, slope, offset;
847 slope = (ips->pta_val & PTA_SLOPE_MASK) >> PTA_SLOPE_SHIFT;
848 offset = ips->pta_val & PTA_OFFSET_MASK;
850 val = thm_readw(THM_PTV) & PTV_MASK;
855 static u16 read_ctv(struct ips_driver *ips, int cpu)
857 int reg = cpu ? THM_CTV2 : THM_CTV1;
860 val = thm_readw(reg);
861 if (!(val & CTV_TEMP_ERROR))
862 val = (val) >> 6; /* discard fractional component */
869 static u32 get_cpu_power(struct ips_driver *ips, u32 *last, int period)
875 * CEC is in joules/65535. Take difference over time to
878 val = thm_readl(THM_CEC);
880 /* period is in ms and we want mW */
881 ret = (((val - *last) * 1000) / period);
882 ret = (ret * 1000) / 65535;
888 static const u16 temp_decay_factor = 2;
889 static u16 update_average_temp(u16 avg, u16 val)
893 /* Multiply by 100 for extra precision */
894 ret = (val * 100 / temp_decay_factor) +
895 (((temp_decay_factor - 1) * avg) / temp_decay_factor);
899 static const u16 power_decay_factor = 2;
900 static u16 update_average_power(u32 avg, u32 val)
904 ret = (val / power_decay_factor) +
905 (((power_decay_factor - 1) * avg) / power_decay_factor);
910 static u32 calc_avg_power(struct ips_driver *ips, u32 *array)
916 for (i = 0; i < IPS_SAMPLE_COUNT; i++)
919 do_div(total, IPS_SAMPLE_COUNT);
925 static void monitor_timeout(unsigned long arg)
927 wake_up_process((struct task_struct *)arg);
931 * ips_monitor - temp/power monitoring thread
932 * @data: ips driver structure
934 * This is the main function for the IPS driver. It monitors power and
935 * tempurature in the MCP and adjusts CPU and GPU power clams accordingly.
937 * We keep a 5s moving average of power consumption and tempurature. Using
938 * that data, along with CPU vs GPU preference, we adjust the power clamps
941 static int ips_monitor(void *data)
943 struct ips_driver *ips = data;
944 struct timer_list timer;
945 unsigned long seqno_timestamp, expire, last_msecs, last_sample_period;
947 u32 *cpu_samples, *mchp_samples, old_cpu_power;
948 u16 *mcp_samples, *ctv1_samples, *ctv2_samples, *mch_samples;
949 u8 cur_seqno, last_seqno;
951 mcp_samples = kzalloc(sizeof(u16) * IPS_SAMPLE_COUNT, GFP_KERNEL);
952 ctv1_samples = kzalloc(sizeof(u16) * IPS_SAMPLE_COUNT, GFP_KERNEL);
953 ctv2_samples = kzalloc(sizeof(u16) * IPS_SAMPLE_COUNT, GFP_KERNEL);
954 mch_samples = kzalloc(sizeof(u16) * IPS_SAMPLE_COUNT, GFP_KERNEL);
955 cpu_samples = kzalloc(sizeof(u32) * IPS_SAMPLE_COUNT, GFP_KERNEL);
956 mchp_samples = kzalloc(sizeof(u32) * IPS_SAMPLE_COUNT, GFP_KERNEL);
957 if (!mcp_samples || !ctv1_samples || !ctv2_samples || !mch_samples ||
958 !cpu_samples || !mchp_samples) {
959 dev_err(&ips->dev->dev,
960 "failed to allocate sample array, ips disabled\n");
970 last_seqno = (thm_readl(THM_ITV) & ITV_ME_SEQNO_MASK) >>
972 seqno_timestamp = get_jiffies_64();
974 old_cpu_power = thm_readl(THM_CEC);
975 schedule_timeout_interruptible(msecs_to_jiffies(IPS_SAMPLE_PERIOD));
977 /* Collect an initial average */
978 for (i = 0; i < IPS_SAMPLE_COUNT; i++) {
982 mcp_samples[i] = read_ptv(ips);
984 val = read_ctv(ips, 0);
985 ctv1_samples[i] = val;
987 val = read_ctv(ips, 1);
988 ctv2_samples[i] = val;
990 val = read_mgtv(ips);
991 mch_samples[i] = val;
993 cpu_power = get_cpu_power(ips, &old_cpu_power,
995 cpu_samples[i] = cpu_power;
997 if (ips->read_mch_val) {
998 mchp = ips->read_mch_val();
999 mchp_samples[i] = mchp;
1002 schedule_timeout_interruptible(msecs_to_jiffies(IPS_SAMPLE_PERIOD));
1003 if (kthread_should_stop())
1007 ips->mcp_avg_temp = calc_avg_temp(ips, mcp_samples);
1008 ips->ctv1_avg_temp = calc_avg_temp(ips, ctv1_samples);
1009 ips->ctv2_avg_temp = calc_avg_temp(ips, ctv2_samples);
1010 ips->mch_avg_temp = calc_avg_temp(ips, mch_samples);
1011 ips->cpu_avg_power = calc_avg_power(ips, cpu_samples);
1012 ips->mch_avg_power = calc_avg_power(ips, mchp_samples);
1014 kfree(ctv1_samples);
1015 kfree(ctv2_samples);
1018 kfree(mchp_samples);
1020 /* Start the adjustment thread now that we have data */
1021 wake_up_process(ips->adjust);
1024 * Ok, now we have an initial avg. From here on out, we track the
1025 * running avg using a decaying average calculation. This allows
1026 * us to reduce the sample frequency if the CPU and GPU are idle.
1028 old_cpu_power = thm_readl(THM_CEC);
1029 schedule_timeout_interruptible(msecs_to_jiffies(IPS_SAMPLE_PERIOD));
1030 last_sample_period = IPS_SAMPLE_PERIOD;
1032 setup_deferrable_timer_on_stack(&timer, monitor_timeout,
1033 (unsigned long)current);
1035 u32 cpu_val, mch_val;
1039 val = read_ptv(ips);
1040 ips->mcp_avg_temp = update_average_temp(ips->mcp_avg_temp, val);
1043 val = read_ctv(ips, 0);
1044 ips->ctv1_avg_temp =
1045 update_average_temp(ips->ctv1_avg_temp, val);
1047 cpu_val = get_cpu_power(ips, &old_cpu_power,
1048 last_sample_period);
1049 ips->cpu_avg_power =
1050 update_average_power(ips->cpu_avg_power, cpu_val);
1052 if (ips->second_cpu) {
1054 val = read_ctv(ips, 1);
1055 ips->ctv2_avg_temp =
1056 update_average_temp(ips->ctv2_avg_temp, val);
1060 val = read_mgtv(ips);
1061 ips->mch_avg_temp = update_average_temp(ips->mch_avg_temp, val);
1063 if (ips->read_mch_val) {
1064 mch_val = ips->read_mch_val();
1065 ips->mch_avg_power =
1066 update_average_power(ips->mch_avg_power,
1071 * Make sure ME is updating thermal regs.
1073 * If it's been more than a second since the last update,
1074 * the ME is probably hung.
1076 cur_seqno = (thm_readl(THM_ITV) & ITV_ME_SEQNO_MASK) >>
1078 if (cur_seqno == last_seqno &&
1079 time_after(jiffies, seqno_timestamp + HZ)) {
1080 dev_warn(&ips->dev->dev, "ME failed to update for more than 1s, likely hung\n");
1082 seqno_timestamp = get_jiffies_64();
1083 last_seqno = cur_seqno;
1086 last_msecs = jiffies_to_msecs(jiffies);
1087 expire = jiffies + msecs_to_jiffies(IPS_SAMPLE_PERIOD);
1089 __set_current_state(TASK_UNINTERRUPTIBLE);
1090 mod_timer(&timer, expire);
1093 /* Calculate actual sample period for power averaging */
1094 last_sample_period = jiffies_to_msecs(jiffies) - last_msecs;
1095 if (!last_sample_period)
1096 last_sample_period = 1;
1097 } while (!kthread_should_stop());
1099 del_timer_sync(&timer);
1100 destroy_timer_on_stack(&timer);
1102 dev_dbg(&ips->dev->dev, "ips-monitor thread stopped\n");
1108 #define THM_DUMPW(reg) \
1110 u16 val = thm_readw(reg); \
1111 dev_dbg(&ips->dev->dev, #reg ": 0x%04x\n", val); \
1113 #define THM_DUMPL(reg) \
1115 u32 val = thm_readl(reg); \
1116 dev_dbg(&ips->dev->dev, #reg ": 0x%08x\n", val); \
1118 #define THM_DUMPQ(reg) \
1120 u64 val = thm_readq(reg); \
1121 dev_dbg(&ips->dev->dev, #reg ": 0x%016x\n", val); \
1124 static void dump_thermal_info(struct ips_driver *ips)
1128 ptl = thm_readw(THM_PTL);
1129 dev_dbg(&ips->dev->dev, "Processor temp limit: %d\n", ptl);
1133 THM_DUMPW(THM_CTV1);
1136 THM_DUMPQ(THM_MGTV);
1141 * ips_irq_handler - handle temperature triggers and other IPS events
1145 * Handle temperature limit trigger events, generally by lowering the clamps.
1146 * If we're at a critical limit, we clamp back to the lowest possible value
1147 * to prevent emergency shutdown.
1149 static irqreturn_t ips_irq_handler(int irq, void *arg)
1151 struct ips_driver *ips = arg;
1152 u8 tses = thm_readb(THM_TSES);
1153 u8 tes = thm_readb(THM_TES);
1158 dev_info(&ips->dev->dev, "TSES: 0x%02x\n", tses);
1159 dev_info(&ips->dev->dev, "TES: 0x%02x\n", tes);
1161 /* STS update from EC? */
1165 sts = thm_readl(THM_STS);
1166 tc1 = thm_readl(THM_TC1);
1168 if (sts & STS_NVV) {
1169 spin_lock(&ips->turbo_status_lock);
1170 ips->core_power_limit = (sts & STS_PCPL_MASK) >>
1172 ips->mch_power_limit = (sts & STS_GPL_MASK) >>
1174 /* ignore EC CPU vs GPU pref */
1175 ips->cpu_turbo_enabled = !(sts & STS_PCTD_DIS);
1176 ips->gpu_turbo_enabled = !(sts & STS_GTD_DIS);
1177 ips->mcp_temp_limit = (sts & STS_PTL_MASK) >>
1179 ips->mcp_power_limit = (tc1 & STS_PPL_MASK) >>
1182 spin_unlock(&ips->turbo_status_lock);
1184 thm_writeb(THM_SEC, SEC_ACK);
1186 thm_writeb(THM_TES, tes);
1191 dev_warn(&ips->dev->dev,
1192 "thermal trip occurred, tses: 0x%04x\n", tses);
1193 thm_writeb(THM_TSES, tses);
1199 #ifndef CONFIG_DEBUG_FS
1200 static void ips_debugfs_init(struct ips_driver *ips) { return; }
1201 static void ips_debugfs_cleanup(struct ips_driver *ips) { return; }
1204 /* Expose current state and limits in debugfs if possible */
1206 struct ips_debugfs_node {
1207 struct ips_driver *ips;
1209 int (*show)(struct seq_file *m, void *data);
1212 static int show_cpu_temp(struct seq_file *m, void *data)
1214 struct ips_driver *ips = m->private;
1216 seq_printf(m, "%d.%02d\n", ips->ctv1_avg_temp / 100,
1217 ips->ctv1_avg_temp % 100);
1222 static int show_cpu_power(struct seq_file *m, void *data)
1224 struct ips_driver *ips = m->private;
1226 seq_printf(m, "%dmW\n", ips->cpu_avg_power);
1231 static int show_cpu_clamp(struct seq_file *m, void *data)
1236 rdmsrl(TURBO_POWER_CURRENT_LIMIT, turbo_override);
1238 tdp = (int)(turbo_override & TURBO_TDP_MASK);
1239 tdc = (int)((turbo_override & TURBO_TDC_MASK) >> TURBO_TDC_SHIFT);
1241 /* Convert to .1W/A units */
1246 seq_printf(m, "%d.%dW %d.%dA\n", tdp / 10, tdp % 10,
1247 tdc / 10, tdc % 10);
1252 static int show_mch_temp(struct seq_file *m, void *data)
1254 struct ips_driver *ips = m->private;
1256 seq_printf(m, "%d.%02d\n", ips->mch_avg_temp / 100,
1257 ips->mch_avg_temp % 100);
1262 static int show_mch_power(struct seq_file *m, void *data)
1264 struct ips_driver *ips = m->private;
1266 seq_printf(m, "%dmW\n", ips->mch_avg_power);
1271 static struct ips_debugfs_node ips_debug_files[] = {
1272 { NULL, "cpu_temp", show_cpu_temp },
1273 { NULL, "cpu_power", show_cpu_power },
1274 { NULL, "cpu_clamp", show_cpu_clamp },
1275 { NULL, "mch_temp", show_mch_temp },
1276 { NULL, "mch_power", show_mch_power },
1279 static int ips_debugfs_open(struct inode *inode, struct file *file)
1281 struct ips_debugfs_node *node = inode->i_private;
1283 return single_open(file, node->show, node->ips);
1286 static const struct file_operations ips_debugfs_ops = {
1287 .owner = THIS_MODULE,
1288 .open = ips_debugfs_open,
1290 .llseek = seq_lseek,
1291 .release = single_release,
1294 static void ips_debugfs_cleanup(struct ips_driver *ips)
1296 if (ips->debug_root)
1297 debugfs_remove_recursive(ips->debug_root);
1301 static void ips_debugfs_init(struct ips_driver *ips)
1305 ips->debug_root = debugfs_create_dir("ips", NULL);
1306 if (!ips->debug_root) {
1307 dev_err(&ips->dev->dev,
1308 "failed to create debugfs entries: %ld\n",
1309 PTR_ERR(ips->debug_root));
1313 for (i = 0; i < ARRAY_SIZE(ips_debug_files); i++) {
1315 struct ips_debugfs_node *node = &ips_debug_files[i];
1318 ent = debugfs_create_file(node->name, S_IFREG | S_IRUGO,
1319 ips->debug_root, node,
1322 dev_err(&ips->dev->dev,
1323 "failed to create debug file: %ld\n",
1332 ips_debugfs_cleanup(ips);
1335 #endif /* CONFIG_DEBUG_FS */
1338 * ips_detect_cpu - detect whether CPU supports IPS
1340 * Walk our list and see if we're on a supported CPU. If we find one,
1341 * return the limits for it.
1343 static struct ips_mcp_limits *ips_detect_cpu(struct ips_driver *ips)
1345 u64 turbo_power, misc_en;
1346 struct ips_mcp_limits *limits = NULL;
1349 if (!(boot_cpu_data.x86 == 6 && boot_cpu_data.x86_model == 37)) {
1350 dev_info(&ips->dev->dev, "Non-IPS CPU detected.\n");
1354 rdmsrl(IA32_MISC_ENABLE, misc_en);
1356 * If the turbo enable bit isn't set, we shouldn't try to enable/disable
1357 * turbo manually or we'll get an illegal MSR access, even though
1358 * turbo will still be available.
1360 if (misc_en & IA32_MISC_TURBO_EN)
1361 ips->turbo_toggle_allowed = true;
1363 ips->turbo_toggle_allowed = false;
1365 if (strstr(boot_cpu_data.x86_model_id, "CPU M"))
1366 limits = &ips_sv_limits;
1367 else if (strstr(boot_cpu_data.x86_model_id, "CPU L"))
1368 limits = &ips_lv_limits;
1369 else if (strstr(boot_cpu_data.x86_model_id, "CPU U"))
1370 limits = &ips_ulv_limits;
1372 dev_info(&ips->dev->dev, "No CPUID match found.\n");
1376 rdmsrl(TURBO_POWER_CURRENT_LIMIT, turbo_power);
1377 tdp = turbo_power & TURBO_TDP_MASK;
1379 /* Sanity check TDP against CPU */
1380 if (limits->mcp_power_limit != (tdp / 8) * 1000) {
1381 dev_warn(&ips->dev->dev, "Warning: CPU TDP doesn't match expected value (found %d, expected %d)\n",
1382 tdp / 8, limits->mcp_power_limit / 1000);
1390 * ips_get_i915_syms - try to get GPU control methods from i915 driver
1393 * The i915 driver exports several interfaces to allow the IPS driver to
1394 * monitor and control graphics turbo mode. If we can find them, we can
1395 * enable graphics turbo, otherwise we must disable it to avoid exceeding
1396 * thermal and power limits in the MCP.
1398 static bool ips_get_i915_syms(struct ips_driver *ips)
1400 ips->read_mch_val = symbol_get(i915_read_mch_val);
1401 if (!ips->read_mch_val)
1403 ips->gpu_raise = symbol_get(i915_gpu_raise);
1404 if (!ips->gpu_raise)
1406 ips->gpu_lower = symbol_get(i915_gpu_lower);
1407 if (!ips->gpu_lower)
1409 ips->gpu_busy = symbol_get(i915_gpu_busy);
1412 ips->gpu_turbo_disable = symbol_get(i915_gpu_turbo_disable);
1413 if (!ips->gpu_turbo_disable)
1419 symbol_put(i915_gpu_busy);
1421 symbol_put(i915_gpu_lower);
1423 symbol_put(i915_gpu_raise);
1425 symbol_put(i915_read_mch_val);
1430 static DEFINE_PCI_DEVICE_TABLE(ips_id_table) = {
1431 { PCI_DEVICE(PCI_VENDOR_ID_INTEL,
1432 PCI_DEVICE_ID_INTEL_THERMAL_SENSOR), },
1436 MODULE_DEVICE_TABLE(pci, ips_id_table);
1438 static int ips_probe(struct pci_dev *dev, const struct pci_device_id *id)
1441 struct ips_driver *ips;
1444 u16 htshi, trc, trc_required_mask;
1447 ips = kzalloc(sizeof(struct ips_driver), GFP_KERNEL);
1451 pci_set_drvdata(dev, ips);
1454 ips->limits = ips_detect_cpu(ips);
1456 dev_info(&dev->dev, "IPS not supported on this CPU\n");
1461 spin_lock_init(&ips->turbo_status_lock);
1463 ret = pci_enable_device(dev);
1465 dev_err(&dev->dev, "can't enable PCI device, aborting\n");
1469 if (!pci_resource_start(dev, 0)) {
1470 dev_err(&dev->dev, "TBAR not assigned, aborting\n");
1475 ret = pci_request_regions(dev, "ips thermal sensor");
1477 dev_err(&dev->dev, "thermal resource busy, aborting\n");
1482 ips->regmap = ioremap(pci_resource_start(dev, 0),
1483 pci_resource_len(dev, 0));
1485 dev_err(&dev->dev, "failed to map thermal regs, aborting\n");
1490 tse = thm_readb(THM_TSE);
1491 if (tse != TSE_EN) {
1492 dev_err(&dev->dev, "thermal device not enabled (0x%02x), aborting\n", tse);
1497 trc = thm_readw(THM_TRC);
1498 trc_required_mask = TRC_CORE1_EN | TRC_CORE_PWR | TRC_MCH_EN;
1499 if ((trc & trc_required_mask) != trc_required_mask) {
1500 dev_err(&dev->dev, "thermal reporting for required devices not enabled, aborting\n");
1505 if (trc & TRC_CORE2_EN)
1506 ips->second_cpu = true;
1508 update_turbo_limits(ips);
1509 dev_dbg(&dev->dev, "max cpu power clamp: %dW\n",
1510 ips->mcp_power_limit / 10);
1511 dev_dbg(&dev->dev, "max core power clamp: %dW\n",
1512 ips->core_power_limit / 10);
1513 /* BIOS may update limits at runtime */
1514 if (thm_readl(THM_PSC) & PSP_PBRT)
1515 ips->poll_turbo_status = true;
1517 if (!ips_get_i915_syms(ips)) {
1518 dev_err(&dev->dev, "failed to get i915 symbols, graphics turbo disabled\n");
1519 ips->gpu_turbo_enabled = false;
1521 dev_dbg(&dev->dev, "graphics turbo enabled\n");
1522 ips->gpu_turbo_enabled = true;
1526 * Check PLATFORM_INFO MSR to make sure this chip is
1529 rdmsrl(PLATFORM_INFO, platform_info);
1530 if (!(platform_info & PLATFORM_TDP)) {
1531 dev_err(&dev->dev, "platform indicates TDP override unavailable, aborting\n");
1537 * IRQ handler for ME interaction
1538 * Note: don't use MSI here as the PCH has bugs.
1540 pci_disable_msi(dev);
1541 ret = request_irq(dev->irq, ips_irq_handler, IRQF_SHARED, "ips",
1544 dev_err(&dev->dev, "request irq failed, aborting\n");
1548 /* Enable aux, hot & critical interrupts */
1549 thm_writeb(THM_TSPIEN, TSPIEN_AUX2_LOHI | TSPIEN_CRIT_LOHI |
1550 TSPIEN_HOT_LOHI | TSPIEN_AUX_LOHI);
1551 thm_writeb(THM_TEN, TEN_UPDATE_EN);
1553 /* Collect adjustment values */
1554 ips->cta_val = thm_readw(THM_CTA);
1555 ips->pta_val = thm_readw(THM_PTA);
1556 ips->mgta_val = thm_readw(THM_MGTA);
1558 /* Save turbo limits & ratios */
1559 rdmsrl(TURBO_POWER_CURRENT_LIMIT, ips->orig_turbo_limit);
1561 ips_enable_cpu_turbo(ips);
1562 ips->cpu_turbo_enabled = true;
1564 /* Create thermal adjust thread */
1565 ips->adjust = kthread_create(ips_adjust, ips, "ips-adjust");
1566 if (IS_ERR(ips->adjust)) {
1568 "failed to create thermal adjust thread, aborting\n");
1570 goto error_free_irq;
1575 * Set up the work queue and monitor thread. The monitor thread
1576 * will wake up ips_adjust thread.
1578 ips->monitor = kthread_run(ips_monitor, ips, "ips-monitor");
1579 if (IS_ERR(ips->monitor)) {
1581 "failed to create thermal monitor thread, aborting\n");
1583 goto error_thread_cleanup;
1586 hts = (ips->core_power_limit << HTS_PCPL_SHIFT) |
1587 (ips->mcp_temp_limit << HTS_PTL_SHIFT) | HTS_NVV;
1588 htshi = HTS2_PRST_RUNNING << HTS2_PRST_SHIFT;
1590 thm_writew(THM_HTSHI, htshi);
1591 thm_writel(THM_HTS, hts);
1593 ips_debugfs_init(ips);
1595 dev_info(&dev->dev, "IPS driver initialized, MCP temp limit %d\n",
1596 ips->mcp_temp_limit);
1599 error_thread_cleanup:
1600 kthread_stop(ips->adjust);
1602 free_irq(ips->dev->irq, ips);
1604 iounmap(ips->regmap);
1606 pci_release_regions(dev);
1612 static void ips_remove(struct pci_dev *dev)
1614 struct ips_driver *ips = pci_get_drvdata(dev);
1620 ips_debugfs_cleanup(ips);
1622 /* Release i915 driver */
1623 if (ips->read_mch_val)
1624 symbol_put(i915_read_mch_val);
1626 symbol_put(i915_gpu_raise);
1628 symbol_put(i915_gpu_lower);
1630 symbol_put(i915_gpu_busy);
1631 if (ips->gpu_turbo_disable)
1632 symbol_put(i915_gpu_turbo_disable);
1634 rdmsrl(TURBO_POWER_CURRENT_LIMIT, turbo_override);
1635 turbo_override &= ~(TURBO_TDC_OVR_EN | TURBO_TDP_OVR_EN);
1636 wrmsrl(TURBO_POWER_CURRENT_LIMIT, turbo_override);
1637 wrmsrl(TURBO_POWER_CURRENT_LIMIT, ips->orig_turbo_limit);
1639 free_irq(ips->dev->irq, ips);
1641 kthread_stop(ips->adjust);
1643 kthread_stop(ips->monitor);
1644 iounmap(ips->regmap);
1645 pci_release_regions(dev);
1647 dev_dbg(&dev->dev, "IPS driver removed\n");
1651 static int ips_suspend(struct pci_dev *dev, pm_message_t state)
1656 static int ips_resume(struct pci_dev *dev)
1661 #define ips_suspend NULL
1662 #define ips_resume NULL
1663 #endif /* CONFIG_PM */
1665 static void ips_shutdown(struct pci_dev *dev)
1669 static struct pci_driver ips_pci_driver = {
1670 .name = "intel ips",
1671 .id_table = ips_id_table,
1673 .remove = ips_remove,
1674 .suspend = ips_suspend,
1675 .resume = ips_resume,
1676 .shutdown = ips_shutdown,
1679 static int __init ips_init(void)
1681 return pci_register_driver(&ips_pci_driver);
1683 module_init(ips_init);
1685 static void ips_exit(void)
1687 pci_unregister_driver(&ips_pci_driver);
1690 module_exit(ips_exit);
1692 MODULE_LICENSE("GPL");
1693 MODULE_AUTHOR("Jesse Barnes <jbarnes@virtuousgeek.org>");
1694 MODULE_DESCRIPTION("Intelligent Power Sharing Driver");