1 // SPDX-License-Identifier: MIT
3 * Copyright © 2019 Intel Corporation
6 #include <linux/string_helpers.h>
8 #include <drm/i915_drm.h>
10 #include "display/intel_display.h"
13 #include "intel_breadcrumbs.h"
15 #include "intel_gt_clock_utils.h"
16 #include "intel_gt_irq.h"
17 #include "intel_gt_pm_irq.h"
18 #include "intel_gt_regs.h"
19 #include "intel_mchbar_regs.h"
20 #include "intel_pcode.h"
21 #include "intel_rps.h"
22 #include "vlv_sideband.h"
23 #include "../../../platform/x86/intel_ips.h"
25 #define BUSY_MAX_EI 20u /* ms */
28 * Lock protecting IPS related data structures
30 static DEFINE_SPINLOCK(mchdev_lock);
32 static struct intel_gt *rps_to_gt(struct intel_rps *rps)
34 return container_of(rps, struct intel_gt, rps);
37 static struct drm_i915_private *rps_to_i915(struct intel_rps *rps)
39 return rps_to_gt(rps)->i915;
42 static struct intel_uncore *rps_to_uncore(struct intel_rps *rps)
44 return rps_to_gt(rps)->uncore;
47 static struct intel_guc_slpc *rps_to_slpc(struct intel_rps *rps)
49 struct intel_gt *gt = rps_to_gt(rps);
51 return >->uc.guc.slpc;
54 static bool rps_uses_slpc(struct intel_rps *rps)
56 struct intel_gt *gt = rps_to_gt(rps);
58 return intel_uc_uses_guc_slpc(>->uc);
61 static u32 rps_pm_sanitize_mask(struct intel_rps *rps, u32 mask)
63 return mask & ~rps->pm_intrmsk_mbz;
66 static void set(struct intel_uncore *uncore, i915_reg_t reg, u32 val)
68 intel_uncore_write_fw(uncore, reg, val);
71 static void rps_timer(struct timer_list *t)
73 struct intel_rps *rps = from_timer(rps, t, timer);
74 struct intel_engine_cs *engine;
75 ktime_t dt, last, timestamp;
76 enum intel_engine_id id;
80 for_each_engine(engine, rps_to_gt(rps), id) {
84 dt = intel_engine_get_busy_time(engine, ×tamp);
85 last = engine->stats.rps;
86 engine->stats.rps = dt;
88 busy = ktime_to_ns(ktime_sub(dt, last));
89 for (i = 0; i < ARRAY_SIZE(max_busy); i++) {
90 if (busy > max_busy[i])
91 swap(busy, max_busy[i]);
94 last = rps->pm_timestamp;
95 rps->pm_timestamp = timestamp;
97 if (intel_rps_is_active(rps)) {
101 dt = ktime_sub(timestamp, last);
104 * Our goal is to evaluate each engine independently, so we run
105 * at the lowest clocks required to sustain the heaviest
106 * workload. However, a task may be split into sequential
107 * dependent operations across a set of engines, such that
108 * the independent contributions do not account for high load,
109 * but overall the task is GPU bound. For example, consider
110 * video decode on vcs followed by colour post-processing
111 * on vecs, followed by general post-processing on rcs.
112 * Since multi-engines being active does imply a single
113 * continuous workload across all engines, we hedge our
114 * bets by only contributing a factor of the distributed
115 * load into our busyness calculation.
118 for (i = 1; i < ARRAY_SIZE(max_busy); i++) {
122 busy += div_u64(max_busy[i], 1 << i);
124 GT_TRACE(rps_to_gt(rps),
125 "busy:%lld [%d%%], max:[%lld, %lld, %lld], interval:%d\n",
126 busy, (int)div64_u64(100 * busy, dt),
127 max_busy[0], max_busy[1], max_busy[2],
130 if (100 * busy > rps->power.up_threshold * dt &&
131 rps->cur_freq < rps->max_freq_softlimit) {
132 rps->pm_iir |= GEN6_PM_RP_UP_THRESHOLD;
133 rps->pm_interval = 1;
134 schedule_work(&rps->work);
135 } else if (100 * busy < rps->power.down_threshold * dt &&
136 rps->cur_freq > rps->min_freq_softlimit) {
137 rps->pm_iir |= GEN6_PM_RP_DOWN_THRESHOLD;
138 rps->pm_interval = 1;
139 schedule_work(&rps->work);
144 mod_timer(&rps->timer,
145 jiffies + msecs_to_jiffies(rps->pm_interval));
146 rps->pm_interval = min(rps->pm_interval * 2, BUSY_MAX_EI);
150 static void rps_start_timer(struct intel_rps *rps)
152 rps->pm_timestamp = ktime_sub(ktime_get(), rps->pm_timestamp);
153 rps->pm_interval = 1;
154 mod_timer(&rps->timer, jiffies + 1);
157 static void rps_stop_timer(struct intel_rps *rps)
159 del_timer_sync(&rps->timer);
160 rps->pm_timestamp = ktime_sub(ktime_get(), rps->pm_timestamp);
161 cancel_work_sync(&rps->work);
164 static u32 rps_pm_mask(struct intel_rps *rps, u8 val)
168 /* We use UP_EI_EXPIRED interrupts for both up/down in manual mode */
169 if (val > rps->min_freq_softlimit)
170 mask |= (GEN6_PM_RP_UP_EI_EXPIRED |
171 GEN6_PM_RP_DOWN_THRESHOLD |
172 GEN6_PM_RP_DOWN_TIMEOUT);
174 if (val < rps->max_freq_softlimit)
175 mask |= GEN6_PM_RP_UP_EI_EXPIRED | GEN6_PM_RP_UP_THRESHOLD;
177 mask &= rps->pm_events;
179 return rps_pm_sanitize_mask(rps, ~mask);
182 static void rps_reset_ei(struct intel_rps *rps)
184 memset(&rps->ei, 0, sizeof(rps->ei));
187 static void rps_enable_interrupts(struct intel_rps *rps)
189 struct intel_gt *gt = rps_to_gt(rps);
191 GEM_BUG_ON(rps_uses_slpc(rps));
193 GT_TRACE(gt, "interrupts:on rps->pm_events: %x, rps_pm_mask:%x\n",
194 rps->pm_events, rps_pm_mask(rps, rps->last_freq));
198 spin_lock_irq(gt->irq_lock);
199 gen6_gt_pm_enable_irq(gt, rps->pm_events);
200 spin_unlock_irq(gt->irq_lock);
202 intel_uncore_write(gt->uncore,
203 GEN6_PMINTRMSK, rps_pm_mask(rps, rps->last_freq));
206 static void gen6_rps_reset_interrupts(struct intel_rps *rps)
208 gen6_gt_pm_reset_iir(rps_to_gt(rps), GEN6_PM_RPS_EVENTS);
211 static void gen11_rps_reset_interrupts(struct intel_rps *rps)
213 while (gen11_gt_reset_one_iir(rps_to_gt(rps), 0, GEN11_GTPM))
217 static void rps_reset_interrupts(struct intel_rps *rps)
219 struct intel_gt *gt = rps_to_gt(rps);
221 spin_lock_irq(gt->irq_lock);
222 if (GRAPHICS_VER(gt->i915) >= 11)
223 gen11_rps_reset_interrupts(rps);
225 gen6_rps_reset_interrupts(rps);
228 spin_unlock_irq(gt->irq_lock);
231 static void rps_disable_interrupts(struct intel_rps *rps)
233 struct intel_gt *gt = rps_to_gt(rps);
235 intel_uncore_write(gt->uncore,
236 GEN6_PMINTRMSK, rps_pm_sanitize_mask(rps, ~0u));
238 spin_lock_irq(gt->irq_lock);
239 gen6_gt_pm_disable_irq(gt, GEN6_PM_RPS_EVENTS);
240 spin_unlock_irq(gt->irq_lock);
242 intel_synchronize_irq(gt->i915);
245 * Now that we will not be generating any more work, flush any
246 * outstanding tasks. As we are called on the RPS idle path,
247 * we will reset the GPU to minimum frequencies, so the current
248 * state of the worker can be discarded.
250 cancel_work_sync(&rps->work);
252 rps_reset_interrupts(rps);
253 GT_TRACE(gt, "interrupts:off\n");
256 static const struct cparams {
262 { 1, 1333, 301, 28664 },
263 { 1, 1066, 294, 24460 },
264 { 1, 800, 294, 25192 },
265 { 0, 1333, 276, 27605 },
266 { 0, 1066, 276, 27605 },
267 { 0, 800, 231, 23784 },
270 static void gen5_rps_init(struct intel_rps *rps)
272 struct drm_i915_private *i915 = rps_to_i915(rps);
273 struct intel_uncore *uncore = rps_to_uncore(rps);
274 u8 fmax, fmin, fstart;
278 if (i915->fsb_freq <= 3200)
280 else if (i915->fsb_freq <= 4800)
285 for (i = 0; i < ARRAY_SIZE(cparams); i++) {
286 if (cparams[i].i == c_m && cparams[i].t == i915->mem_freq) {
287 rps->ips.m = cparams[i].m;
288 rps->ips.c = cparams[i].c;
293 rgvmodectl = intel_uncore_read(uncore, MEMMODECTL);
295 /* Set up min, max, and cur for interrupt handling */
296 fmax = (rgvmodectl & MEMMODE_FMAX_MASK) >> MEMMODE_FMAX_SHIFT;
297 fmin = (rgvmodectl & MEMMODE_FMIN_MASK);
298 fstart = (rgvmodectl & MEMMODE_FSTART_MASK) >>
299 MEMMODE_FSTART_SHIFT;
300 drm_dbg(&i915->drm, "fmax: %d, fmin: %d, fstart: %d\n",
303 rps->min_freq = fmax;
304 rps->efficient_freq = fstart;
305 rps->max_freq = fmin;
309 __ips_chipset_val(struct intel_ips *ips)
311 struct intel_uncore *uncore =
312 rps_to_uncore(container_of(ips, struct intel_rps, ips));
313 unsigned long now = jiffies_to_msecs(jiffies), dt;
314 unsigned long result;
317 lockdep_assert_held(&mchdev_lock);
320 * Prevent division-by-zero if we are asking too fast.
321 * Also, we don't get interesting results if we are polling
322 * faster than once in 10ms, so just return the saved value
325 dt = now - ips->last_time1;
327 return ips->chipset_power;
329 /* FIXME: handle per-counter overflow */
330 total = intel_uncore_read(uncore, DMIEC);
331 total += intel_uncore_read(uncore, DDREC);
332 total += intel_uncore_read(uncore, CSIEC);
334 delta = total - ips->last_count1;
336 result = div_u64(div_u64(ips->m * delta, dt) + ips->c, 10);
338 ips->last_count1 = total;
339 ips->last_time1 = now;
341 ips->chipset_power = result;
346 static unsigned long ips_mch_val(struct intel_uncore *uncore)
348 unsigned int m, x, b;
351 tsfs = intel_uncore_read(uncore, TSFS);
352 x = intel_uncore_read8(uncore, TR1);
354 b = tsfs & TSFS_INTR_MASK;
355 m = (tsfs & TSFS_SLOPE_MASK) >> TSFS_SLOPE_SHIFT;
357 return m * x / 127 - b;
360 static int _pxvid_to_vd(u8 pxvid)
365 if (pxvid >= 8 && pxvid < 31)
368 return (pxvid + 2) * 125;
371 static u32 pvid_to_extvid(struct drm_i915_private *i915, u8 pxvid)
373 const int vd = _pxvid_to_vd(pxvid);
375 if (INTEL_INFO(i915)->is_mobile)
376 return max(vd - 1125, 0);
381 static void __gen5_ips_update(struct intel_ips *ips)
383 struct intel_uncore *uncore =
384 rps_to_uncore(container_of(ips, struct intel_rps, ips));
388 lockdep_assert_held(&mchdev_lock);
390 now = ktime_get_raw_ns();
391 dt = now - ips->last_time2;
392 do_div(dt, NSEC_PER_MSEC);
394 /* Don't divide by 0 */
398 count = intel_uncore_read(uncore, GFXEC);
399 delta = count - ips->last_count2;
401 ips->last_count2 = count;
402 ips->last_time2 = now;
404 /* More magic constants... */
405 ips->gfx_power = div_u64(delta * 1181, dt * 10);
408 static void gen5_rps_update(struct intel_rps *rps)
410 spin_lock_irq(&mchdev_lock);
411 __gen5_ips_update(&rps->ips);
412 spin_unlock_irq(&mchdev_lock);
415 static unsigned int gen5_invert_freq(struct intel_rps *rps,
418 /* Invert the frequency bin into an ips delay */
419 val = rps->max_freq - val;
420 val = rps->min_freq + val;
425 static int __gen5_rps_set(struct intel_rps *rps, u8 val)
427 struct intel_uncore *uncore = rps_to_uncore(rps);
430 lockdep_assert_held(&mchdev_lock);
432 rgvswctl = intel_uncore_read16(uncore, MEMSWCTL);
433 if (rgvswctl & MEMCTL_CMD_STS) {
434 drm_dbg(&rps_to_i915(rps)->drm,
435 "gpu busy, RCS change rejected\n");
436 return -EBUSY; /* still busy with another command */
439 /* Invert the frequency bin into an ips delay */
440 val = gen5_invert_freq(rps, val);
443 (MEMCTL_CMD_CHFREQ << MEMCTL_CMD_SHIFT) |
444 (val << MEMCTL_FREQ_SHIFT) |
446 intel_uncore_write16(uncore, MEMSWCTL, rgvswctl);
447 intel_uncore_posting_read16(uncore, MEMSWCTL);
449 rgvswctl |= MEMCTL_CMD_STS;
450 intel_uncore_write16(uncore, MEMSWCTL, rgvswctl);
455 static int gen5_rps_set(struct intel_rps *rps, u8 val)
459 spin_lock_irq(&mchdev_lock);
460 err = __gen5_rps_set(rps, val);
461 spin_unlock_irq(&mchdev_lock);
466 static unsigned long intel_pxfreq(u32 vidfreq)
468 int div = (vidfreq & 0x3f0000) >> 16;
469 int post = (vidfreq & 0x3000) >> 12;
470 int pre = (vidfreq & 0x7);
475 return div * 133333 / (pre << post);
478 static unsigned int init_emon(struct intel_uncore *uncore)
483 /* Disable to program */
484 intel_uncore_write(uncore, ECR, 0);
485 intel_uncore_posting_read(uncore, ECR);
487 /* Program energy weights for various events */
488 intel_uncore_write(uncore, SDEW, 0x15040d00);
489 intel_uncore_write(uncore, CSIEW0, 0x007f0000);
490 intel_uncore_write(uncore, CSIEW1, 0x1e220004);
491 intel_uncore_write(uncore, CSIEW2, 0x04000004);
493 for (i = 0; i < 5; i++)
494 intel_uncore_write(uncore, PEW(i), 0);
495 for (i = 0; i < 3; i++)
496 intel_uncore_write(uncore, DEW(i), 0);
498 /* Program P-state weights to account for frequency power adjustment */
499 for (i = 0; i < 16; i++) {
500 u32 pxvidfreq = intel_uncore_read(uncore, PXVFREQ(i));
501 unsigned int freq = intel_pxfreq(pxvidfreq);
503 (pxvidfreq & PXVFREQ_PX_MASK) >> PXVFREQ_PX_SHIFT;
506 val = vid * vid * freq / 1000 * 255;
507 val /= 127 * 127 * 900;
511 /* Render standby states get 0 weight */
515 for (i = 0; i < 4; i++) {
516 intel_uncore_write(uncore, PXW(i),
517 pxw[i * 4 + 0] << 24 |
518 pxw[i * 4 + 1] << 16 |
519 pxw[i * 4 + 2] << 8 |
520 pxw[i * 4 + 3] << 0);
523 /* Adjust magic regs to magic values (more experimental results) */
524 intel_uncore_write(uncore, OGW0, 0);
525 intel_uncore_write(uncore, OGW1, 0);
526 intel_uncore_write(uncore, EG0, 0x00007f00);
527 intel_uncore_write(uncore, EG1, 0x0000000e);
528 intel_uncore_write(uncore, EG2, 0x000e0000);
529 intel_uncore_write(uncore, EG3, 0x68000300);
530 intel_uncore_write(uncore, EG4, 0x42000000);
531 intel_uncore_write(uncore, EG5, 0x00140031);
532 intel_uncore_write(uncore, EG6, 0);
533 intel_uncore_write(uncore, EG7, 0);
535 for (i = 0; i < 8; i++)
536 intel_uncore_write(uncore, PXWL(i), 0);
538 /* Enable PMON + select events */
539 intel_uncore_write(uncore, ECR, 0x80000019);
541 return intel_uncore_read(uncore, LCFUSE02) & LCFUSE_HIV_MASK;
544 static bool gen5_rps_enable(struct intel_rps *rps)
546 struct drm_i915_private *i915 = rps_to_i915(rps);
547 struct intel_uncore *uncore = rps_to_uncore(rps);
551 spin_lock_irq(&mchdev_lock);
553 rgvmodectl = intel_uncore_read(uncore, MEMMODECTL);
555 /* Enable temp reporting */
556 intel_uncore_write16(uncore, PMMISC,
557 intel_uncore_read16(uncore, PMMISC) | MCPPCE_EN);
558 intel_uncore_write16(uncore, TSC1,
559 intel_uncore_read16(uncore, TSC1) | TSE);
561 /* 100ms RC evaluation intervals */
562 intel_uncore_write(uncore, RCUPEI, 100000);
563 intel_uncore_write(uncore, RCDNEI, 100000);
565 /* Set max/min thresholds to 90ms and 80ms respectively */
566 intel_uncore_write(uncore, RCBMAXAVG, 90000);
567 intel_uncore_write(uncore, RCBMINAVG, 80000);
569 intel_uncore_write(uncore, MEMIHYST, 1);
571 /* Set up min, max, and cur for interrupt handling */
572 fstart = (rgvmodectl & MEMMODE_FSTART_MASK) >>
573 MEMMODE_FSTART_SHIFT;
575 vstart = (intel_uncore_read(uncore, PXVFREQ(fstart)) &
576 PXVFREQ_PX_MASK) >> PXVFREQ_PX_SHIFT;
578 intel_uncore_write(uncore,
580 MEMINT_CX_SUPR_EN | MEMINT_EVAL_CHG_EN);
582 intel_uncore_write(uncore, VIDSTART, vstart);
583 intel_uncore_posting_read(uncore, VIDSTART);
585 rgvmodectl |= MEMMODE_SWMODE_EN;
586 intel_uncore_write(uncore, MEMMODECTL, rgvmodectl);
588 if (wait_for_atomic((intel_uncore_read(uncore, MEMSWCTL) &
589 MEMCTL_CMD_STS) == 0, 10))
590 drm_err(&uncore->i915->drm,
591 "stuck trying to change perf mode\n");
594 __gen5_rps_set(rps, rps->cur_freq);
596 rps->ips.last_count1 = intel_uncore_read(uncore, DMIEC);
597 rps->ips.last_count1 += intel_uncore_read(uncore, DDREC);
598 rps->ips.last_count1 += intel_uncore_read(uncore, CSIEC);
599 rps->ips.last_time1 = jiffies_to_msecs(jiffies);
601 rps->ips.last_count2 = intel_uncore_read(uncore, GFXEC);
602 rps->ips.last_time2 = ktime_get_raw_ns();
604 spin_lock(&i915->irq_lock);
605 ilk_enable_display_irq(i915, DE_PCU_EVENT);
606 spin_unlock(&i915->irq_lock);
608 spin_unlock_irq(&mchdev_lock);
610 rps->ips.corr = init_emon(uncore);
615 static void gen5_rps_disable(struct intel_rps *rps)
617 struct drm_i915_private *i915 = rps_to_i915(rps);
618 struct intel_uncore *uncore = rps_to_uncore(rps);
621 spin_lock_irq(&mchdev_lock);
623 spin_lock(&i915->irq_lock);
624 ilk_disable_display_irq(i915, DE_PCU_EVENT);
625 spin_unlock(&i915->irq_lock);
627 rgvswctl = intel_uncore_read16(uncore, MEMSWCTL);
629 /* Ack interrupts, disable EFC interrupt */
630 intel_uncore_rmw(uncore, MEMINTREN, MEMINT_EVAL_CHG_EN, 0);
631 intel_uncore_write(uncore, MEMINTRSTS, MEMINT_EVAL_CHG);
633 /* Go back to the starting frequency */
634 __gen5_rps_set(rps, rps->idle_freq);
636 rgvswctl |= MEMCTL_CMD_STS;
637 intel_uncore_write(uncore, MEMSWCTL, rgvswctl);
640 spin_unlock_irq(&mchdev_lock);
643 static u32 rps_limits(struct intel_rps *rps, u8 val)
648 * Only set the down limit when we've reached the lowest level to avoid
649 * getting more interrupts, otherwise leave this clear. This prevents a
650 * race in the hw when coming out of rc6: There's a tiny window where
651 * the hw runs at the minimal clock before selecting the desired
652 * frequency, if the down threshold expires in that window we will not
653 * receive a down interrupt.
655 if (GRAPHICS_VER(rps_to_i915(rps)) >= 9) {
656 limits = rps->max_freq_softlimit << 23;
657 if (val <= rps->min_freq_softlimit)
658 limits |= rps->min_freq_softlimit << 14;
660 limits = rps->max_freq_softlimit << 24;
661 if (val <= rps->min_freq_softlimit)
662 limits |= rps->min_freq_softlimit << 16;
668 static void rps_set_power(struct intel_rps *rps, int new_power)
670 struct intel_gt *gt = rps_to_gt(rps);
671 struct intel_uncore *uncore = gt->uncore;
672 u32 threshold_up = 0, threshold_down = 0; /* in % */
673 u32 ei_up = 0, ei_down = 0;
675 lockdep_assert_held(&rps->power.mutex);
677 if (new_power == rps->power.mode)
683 /* Note the units here are not exactly 1us, but 1280ns. */
701 /* When byt can survive without system hang with dynamic
702 * sw freq adjustments, this restriction can be lifted.
704 if (IS_VALLEYVIEW(gt->i915))
708 "changing power mode [%d], up %d%% @ %dus, down %d%% @ %dus\n",
709 new_power, threshold_up, ei_up, threshold_down, ei_down);
711 set(uncore, GEN6_RP_UP_EI,
712 intel_gt_ns_to_pm_interval(gt, ei_up * 1000));
713 set(uncore, GEN6_RP_UP_THRESHOLD,
714 intel_gt_ns_to_pm_interval(gt, ei_up * threshold_up * 10));
716 set(uncore, GEN6_RP_DOWN_EI,
717 intel_gt_ns_to_pm_interval(gt, ei_down * 1000));
718 set(uncore, GEN6_RP_DOWN_THRESHOLD,
719 intel_gt_ns_to_pm_interval(gt, ei_down * threshold_down * 10));
721 set(uncore, GEN6_RP_CONTROL,
722 (GRAPHICS_VER(gt->i915) > 9 ? 0 : GEN6_RP_MEDIA_TURBO) |
723 GEN6_RP_MEDIA_HW_NORMAL_MODE |
724 GEN6_RP_MEDIA_IS_GFX |
726 GEN6_RP_UP_BUSY_AVG |
727 GEN6_RP_DOWN_IDLE_AVG);
730 rps->power.mode = new_power;
731 rps->power.up_threshold = threshold_up;
732 rps->power.down_threshold = threshold_down;
735 static void gen6_rps_set_thresholds(struct intel_rps *rps, u8 val)
739 new_power = rps->power.mode;
740 switch (rps->power.mode) {
742 if (val > rps->efficient_freq + 1 &&
748 if (val <= rps->efficient_freq &&
750 new_power = LOW_POWER;
751 else if (val >= rps->rp0_freq &&
753 new_power = HIGH_POWER;
757 if (val < (rps->rp1_freq + rps->rp0_freq) >> 1 &&
762 /* Max/min bins are special */
763 if (val <= rps->min_freq_softlimit)
764 new_power = LOW_POWER;
765 if (val >= rps->max_freq_softlimit)
766 new_power = HIGH_POWER;
768 mutex_lock(&rps->power.mutex);
769 if (rps->power.interactive)
770 new_power = HIGH_POWER;
771 rps_set_power(rps, new_power);
772 mutex_unlock(&rps->power.mutex);
775 void intel_rps_mark_interactive(struct intel_rps *rps, bool interactive)
777 GT_TRACE(rps_to_gt(rps), "mark interactive: %s\n",
778 str_yes_no(interactive));
780 mutex_lock(&rps->power.mutex);
782 if (!rps->power.interactive++ && intel_rps_is_active(rps))
783 rps_set_power(rps, HIGH_POWER);
785 GEM_BUG_ON(!rps->power.interactive);
786 rps->power.interactive--;
788 mutex_unlock(&rps->power.mutex);
791 static int gen6_rps_set(struct intel_rps *rps, u8 val)
793 struct intel_uncore *uncore = rps_to_uncore(rps);
794 struct drm_i915_private *i915 = rps_to_i915(rps);
797 GEM_BUG_ON(rps_uses_slpc(rps));
799 if (GRAPHICS_VER(i915) >= 9)
800 swreq = GEN9_FREQUENCY(val);
801 else if (IS_HASWELL(i915) || IS_BROADWELL(i915))
802 swreq = HSW_FREQUENCY(val);
804 swreq = (GEN6_FREQUENCY(val) |
806 GEN6_AGGRESSIVE_TURBO);
807 set(uncore, GEN6_RPNSWREQ, swreq);
809 GT_TRACE(rps_to_gt(rps), "set val:%x, freq:%d, swreq:%x\n",
810 val, intel_gpu_freq(rps, val), swreq);
815 static int vlv_rps_set(struct intel_rps *rps, u8 val)
817 struct drm_i915_private *i915 = rps_to_i915(rps);
821 err = vlv_punit_write(i915, PUNIT_REG_GPU_FREQ_REQ, val);
824 GT_TRACE(rps_to_gt(rps), "set val:%x, freq:%d\n",
825 val, intel_gpu_freq(rps, val));
830 static int rps_set(struct intel_rps *rps, u8 val, bool update)
832 struct drm_i915_private *i915 = rps_to_i915(rps);
835 if (val == rps->last_freq)
838 if (IS_VALLEYVIEW(i915) || IS_CHERRYVIEW(i915))
839 err = vlv_rps_set(rps, val);
840 else if (GRAPHICS_VER(i915) >= 6)
841 err = gen6_rps_set(rps, val);
843 err = gen5_rps_set(rps, val);
847 if (update && GRAPHICS_VER(i915) >= 6)
848 gen6_rps_set_thresholds(rps, val);
849 rps->last_freq = val;
854 void intel_rps_unpark(struct intel_rps *rps)
856 if (!intel_rps_is_enabled(rps))
859 GT_TRACE(rps_to_gt(rps), "unpark:%x\n", rps->cur_freq);
862 * Use the user's desired frequency as a guide, but for better
863 * performance, jump directly to RPe as our starting frequency.
865 mutex_lock(&rps->lock);
867 intel_rps_set_active(rps);
870 rps->min_freq_softlimit,
871 rps->max_freq_softlimit));
873 mutex_unlock(&rps->lock);
876 if (intel_rps_has_interrupts(rps))
877 rps_enable_interrupts(rps);
878 if (intel_rps_uses_timer(rps))
879 rps_start_timer(rps);
881 if (GRAPHICS_VER(rps_to_i915(rps)) == 5)
882 gen5_rps_update(rps);
885 void intel_rps_park(struct intel_rps *rps)
889 if (!intel_rps_is_enabled(rps))
892 if (!intel_rps_clear_active(rps))
895 if (intel_rps_uses_timer(rps))
897 if (intel_rps_has_interrupts(rps))
898 rps_disable_interrupts(rps);
900 if (rps->last_freq <= rps->idle_freq)
904 * The punit delays the write of the frequency and voltage until it
905 * determines the GPU is awake. During normal usage we don't want to
906 * waste power changing the frequency if the GPU is sleeping (rc6).
907 * However, the GPU and driver is now idle and we do not want to delay
908 * switching to minimum voltage (reducing power whilst idle) as we do
909 * not expect to be woken in the near future and so must flush the
910 * change by waking the device.
912 * We choose to take the media powerwell (either would do to trick the
913 * punit into committing the voltage change) as that takes a lot less
914 * power than the render powerwell.
916 intel_uncore_forcewake_get(rps_to_uncore(rps), FORCEWAKE_MEDIA);
917 rps_set(rps, rps->idle_freq, false);
918 intel_uncore_forcewake_put(rps_to_uncore(rps), FORCEWAKE_MEDIA);
921 * Since we will try and restart from the previously requested
922 * frequency on unparking, treat this idle point as a downclock
923 * interrupt and reduce the frequency for resume. If we park/unpark
924 * more frequently than the rps worker can run, we will not respond
925 * to any EI and never see a change in frequency.
927 * (Note we accommodate Cherryview's limitation of only using an
928 * even bin by applying it to all.)
933 else /* CHV needs even encode values */
936 rps->cur_freq = max_t(int, rps->cur_freq + adj, rps->min_freq);
937 if (rps->cur_freq < rps->efficient_freq) {
938 rps->cur_freq = rps->efficient_freq;
942 GT_TRACE(rps_to_gt(rps), "park:%x\n", rps->cur_freq);
945 u32 intel_rps_get_boost_frequency(struct intel_rps *rps)
947 struct intel_guc_slpc *slpc;
949 if (rps_uses_slpc(rps)) {
950 slpc = rps_to_slpc(rps);
952 return slpc->boost_freq;
954 return intel_gpu_freq(rps, rps->boost_freq);
958 static int rps_set_boost_freq(struct intel_rps *rps, u32 val)
962 /* Validate against (static) hardware limits */
963 val = intel_freq_opcode(rps, val);
964 if (val < rps->min_freq || val > rps->max_freq)
967 mutex_lock(&rps->lock);
968 if (val != rps->boost_freq) {
969 rps->boost_freq = val;
970 boost = atomic_read(&rps->num_waiters);
972 mutex_unlock(&rps->lock);
974 schedule_work(&rps->work);
979 int intel_rps_set_boost_frequency(struct intel_rps *rps, u32 freq)
981 struct intel_guc_slpc *slpc;
983 if (rps_uses_slpc(rps)) {
984 slpc = rps_to_slpc(rps);
986 return intel_guc_slpc_set_boost_freq(slpc, freq);
988 return rps_set_boost_freq(rps, freq);
992 void intel_rps_dec_waiters(struct intel_rps *rps)
994 struct intel_guc_slpc *slpc;
996 if (rps_uses_slpc(rps)) {
997 slpc = rps_to_slpc(rps);
999 intel_guc_slpc_dec_waiters(slpc);
1001 atomic_dec(&rps->num_waiters);
1005 void intel_rps_boost(struct i915_request *rq)
1007 struct intel_guc_slpc *slpc;
1009 if (i915_request_signaled(rq) || i915_request_has_waitboost(rq))
1012 /* Serializes with i915_request_retire() */
1013 if (!test_and_set_bit(I915_FENCE_FLAG_BOOST, &rq->fence.flags)) {
1014 struct intel_rps *rps = &READ_ONCE(rq->engine)->gt->rps;
1016 if (rps_uses_slpc(rps)) {
1017 slpc = rps_to_slpc(rps);
1019 if (slpc->min_freq_softlimit >= slpc->boost_freq)
1022 /* Return if old value is non zero */
1023 if (!atomic_fetch_inc(&slpc->num_waiters)) {
1024 GT_TRACE(rps_to_gt(rps), "boost fence:%llx:%llx\n",
1025 rq->fence.context, rq->fence.seqno);
1026 schedule_work(&slpc->boost_work);
1032 if (atomic_fetch_inc(&rps->num_waiters))
1035 if (!intel_rps_is_active(rps))
1038 GT_TRACE(rps_to_gt(rps), "boost fence:%llx:%llx\n",
1039 rq->fence.context, rq->fence.seqno);
1041 if (READ_ONCE(rps->cur_freq) < rps->boost_freq)
1042 schedule_work(&rps->work);
1044 WRITE_ONCE(rps->boosts, rps->boosts + 1); /* debug only */
1048 int intel_rps_set(struct intel_rps *rps, u8 val)
1052 lockdep_assert_held(&rps->lock);
1053 GEM_BUG_ON(val > rps->max_freq);
1054 GEM_BUG_ON(val < rps->min_freq);
1056 if (intel_rps_is_active(rps)) {
1057 err = rps_set(rps, val, true);
1062 * Make sure we continue to get interrupts
1063 * until we hit the minimum or maximum frequencies.
1065 if (intel_rps_has_interrupts(rps)) {
1066 struct intel_uncore *uncore = rps_to_uncore(rps);
1069 GEN6_RP_INTERRUPT_LIMITS, rps_limits(rps, val));
1071 set(uncore, GEN6_PMINTRMSK, rps_pm_mask(rps, val));
1075 rps->cur_freq = val;
1079 static u32 intel_rps_read_state_cap(struct intel_rps *rps)
1081 struct drm_i915_private *i915 = rps_to_i915(rps);
1082 struct intel_uncore *uncore = rps_to_uncore(rps);
1084 if (IS_PONTEVECCHIO(i915))
1085 return intel_uncore_read(uncore, PVC_RP_STATE_CAP);
1086 else if (IS_XEHPSDV(i915))
1087 return intel_uncore_read(uncore, XEHPSDV_RP_STATE_CAP);
1088 else if (IS_GEN9_LP(i915))
1089 return intel_uncore_read(uncore, BXT_RP_STATE_CAP);
1091 return intel_uncore_read(uncore, GEN6_RP_STATE_CAP);
1095 mtl_get_freq_caps(struct intel_rps *rps, struct intel_rps_freq_caps *caps)
1097 struct intel_uncore *uncore = rps_to_uncore(rps);
1098 u32 rp_state_cap = rps_to_gt(rps)->type == GT_MEDIA ?
1099 intel_uncore_read(uncore, MTL_MEDIAP_STATE_CAP) :
1100 intel_uncore_read(uncore, MTL_RP_STATE_CAP);
1101 u32 rpe = rps_to_gt(rps)->type == GT_MEDIA ?
1102 intel_uncore_read(uncore, MTL_MPE_FREQUENCY) :
1103 intel_uncore_read(uncore, MTL_GT_RPE_FREQUENCY);
1105 /* MTL values are in units of 16.67 MHz */
1106 caps->rp0_freq = REG_FIELD_GET(MTL_RP0_CAP_MASK, rp_state_cap);
1107 caps->min_freq = REG_FIELD_GET(MTL_RPN_CAP_MASK, rp_state_cap);
1108 caps->rp1_freq = REG_FIELD_GET(MTL_RPE_MASK, rpe);
1112 __gen6_rps_get_freq_caps(struct intel_rps *rps, struct intel_rps_freq_caps *caps)
1114 struct drm_i915_private *i915 = rps_to_i915(rps);
1117 rp_state_cap = intel_rps_read_state_cap(rps);
1119 /* static values from HW: RP0 > RP1 > RPn (min_freq) */
1120 if (IS_GEN9_LP(i915)) {
1121 caps->rp0_freq = (rp_state_cap >> 16) & 0xff;
1122 caps->rp1_freq = (rp_state_cap >> 8) & 0xff;
1123 caps->min_freq = (rp_state_cap >> 0) & 0xff;
1125 caps->rp0_freq = (rp_state_cap >> 0) & 0xff;
1126 if (GRAPHICS_VER(i915) >= 10)
1127 caps->rp1_freq = REG_FIELD_GET(RPE_MASK,
1128 intel_uncore_read(to_gt(i915)->uncore,
1129 GEN10_FREQ_INFO_REC));
1131 caps->rp1_freq = (rp_state_cap >> 8) & 0xff;
1132 caps->min_freq = (rp_state_cap >> 16) & 0xff;
1135 if (IS_GEN9_BC(i915) || GRAPHICS_VER(i915) >= 11) {
1137 * In this case rp_state_cap register reports frequencies in
1138 * units of 50 MHz. Convert these to the actual "hw unit", i.e.
1139 * units of 16.67 MHz
1141 caps->rp0_freq *= GEN9_FREQ_SCALER;
1142 caps->rp1_freq *= GEN9_FREQ_SCALER;
1143 caps->min_freq *= GEN9_FREQ_SCALER;
1148 * gen6_rps_get_freq_caps - Get freq caps exposed by HW
1149 * @rps: the intel_rps structure
1150 * @caps: returned freq caps
1152 * Returned "caps" frequencies should be converted to MHz using
1155 void gen6_rps_get_freq_caps(struct intel_rps *rps, struct intel_rps_freq_caps *caps)
1157 struct drm_i915_private *i915 = rps_to_i915(rps);
1159 if (IS_METEORLAKE(i915))
1160 return mtl_get_freq_caps(rps, caps);
1162 return __gen6_rps_get_freq_caps(rps, caps);
1165 static void gen6_rps_init(struct intel_rps *rps)
1167 struct drm_i915_private *i915 = rps_to_i915(rps);
1168 struct intel_rps_freq_caps caps;
1170 gen6_rps_get_freq_caps(rps, &caps);
1171 rps->rp0_freq = caps.rp0_freq;
1172 rps->rp1_freq = caps.rp1_freq;
1173 rps->min_freq = caps.min_freq;
1175 /* hw_max = RP0 until we check for overclocking */
1176 rps->max_freq = rps->rp0_freq;
1178 rps->efficient_freq = rps->rp1_freq;
1179 if (IS_HASWELL(i915) || IS_BROADWELL(i915) ||
1180 IS_GEN9_BC(i915) || GRAPHICS_VER(i915) >= 11) {
1181 u32 ddcc_status = 0;
1184 if (IS_GEN9_BC(i915) || GRAPHICS_VER(i915) >= 11)
1185 mult = GEN9_FREQ_SCALER;
1186 if (snb_pcode_read(rps_to_gt(rps)->uncore,
1187 HSW_PCODE_DYNAMIC_DUTY_CYCLE_CONTROL,
1188 &ddcc_status, NULL) == 0)
1189 rps->efficient_freq =
1191 ((ddcc_status >> 8) & 0xff) * mult,
1197 static bool rps_reset(struct intel_rps *rps)
1199 struct drm_i915_private *i915 = rps_to_i915(rps);
1202 rps->power.mode = -1;
1203 rps->last_freq = -1;
1205 if (rps_set(rps, rps->min_freq, true)) {
1206 drm_err(&i915->drm, "Failed to reset RPS to initial values\n");
1210 rps->cur_freq = rps->min_freq;
1214 /* See the Gen9_GT_PM_Programming_Guide doc for the below */
1215 static bool gen9_rps_enable(struct intel_rps *rps)
1217 struct intel_gt *gt = rps_to_gt(rps);
1218 struct intel_uncore *uncore = gt->uncore;
1220 /* Program defaults and thresholds for RPS */
1221 if (GRAPHICS_VER(gt->i915) == 9)
1222 intel_uncore_write_fw(uncore, GEN6_RC_VIDEO_FREQ,
1223 GEN9_FREQUENCY(rps->rp1_freq));
1225 intel_uncore_write_fw(uncore, GEN6_RP_IDLE_HYSTERSIS, 0xa);
1227 rps->pm_events = GEN6_PM_RP_UP_THRESHOLD | GEN6_PM_RP_DOWN_THRESHOLD;
1229 return rps_reset(rps);
1232 static bool gen8_rps_enable(struct intel_rps *rps)
1234 struct intel_uncore *uncore = rps_to_uncore(rps);
1236 intel_uncore_write_fw(uncore, GEN6_RC_VIDEO_FREQ,
1237 HSW_FREQUENCY(rps->rp1_freq));
1239 intel_uncore_write_fw(uncore, GEN6_RP_IDLE_HYSTERSIS, 10);
1241 rps->pm_events = GEN6_PM_RP_UP_THRESHOLD | GEN6_PM_RP_DOWN_THRESHOLD;
1243 return rps_reset(rps);
1246 static bool gen6_rps_enable(struct intel_rps *rps)
1248 struct intel_uncore *uncore = rps_to_uncore(rps);
1250 /* Power down if completely idle for over 50ms */
1251 intel_uncore_write_fw(uncore, GEN6_RP_DOWN_TIMEOUT, 50000);
1252 intel_uncore_write_fw(uncore, GEN6_RP_IDLE_HYSTERSIS, 10);
1254 rps->pm_events = (GEN6_PM_RP_UP_THRESHOLD |
1255 GEN6_PM_RP_DOWN_THRESHOLD |
1256 GEN6_PM_RP_DOWN_TIMEOUT);
1258 return rps_reset(rps);
1261 static int chv_rps_max_freq(struct intel_rps *rps)
1263 struct drm_i915_private *i915 = rps_to_i915(rps);
1264 struct intel_gt *gt = rps_to_gt(rps);
1267 val = vlv_punit_read(i915, FB_GFX_FMAX_AT_VMAX_FUSE);
1269 switch (gt->info.sseu.eu_total) {
1271 /* (2 * 4) config */
1272 val >>= FB_GFX_FMAX_AT_VMAX_2SS4EU_FUSE_SHIFT;
1275 /* (2 * 6) config */
1276 val >>= FB_GFX_FMAX_AT_VMAX_2SS6EU_FUSE_SHIFT;
1279 /* (2 * 8) config */
1281 /* Setting (2 * 8) Min RP0 for any other combination */
1282 val >>= FB_GFX_FMAX_AT_VMAX_2SS8EU_FUSE_SHIFT;
1286 return val & FB_GFX_FREQ_FUSE_MASK;
1289 static int chv_rps_rpe_freq(struct intel_rps *rps)
1291 struct drm_i915_private *i915 = rps_to_i915(rps);
1294 val = vlv_punit_read(i915, PUNIT_GPU_DUTYCYCLE_REG);
1295 val >>= PUNIT_GPU_DUTYCYCLE_RPE_FREQ_SHIFT;
1297 return val & PUNIT_GPU_DUTYCYCLE_RPE_FREQ_MASK;
1300 static int chv_rps_guar_freq(struct intel_rps *rps)
1302 struct drm_i915_private *i915 = rps_to_i915(rps);
1305 val = vlv_punit_read(i915, FB_GFX_FMAX_AT_VMAX_FUSE);
1307 return val & FB_GFX_FREQ_FUSE_MASK;
1310 static u32 chv_rps_min_freq(struct intel_rps *rps)
1312 struct drm_i915_private *i915 = rps_to_i915(rps);
1315 val = vlv_punit_read(i915, FB_GFX_FMIN_AT_VMIN_FUSE);
1316 val >>= FB_GFX_FMIN_AT_VMIN_FUSE_SHIFT;
1318 return val & FB_GFX_FREQ_FUSE_MASK;
1321 static bool chv_rps_enable(struct intel_rps *rps)
1323 struct intel_uncore *uncore = rps_to_uncore(rps);
1324 struct drm_i915_private *i915 = rps_to_i915(rps);
1327 /* 1: Program defaults and thresholds for RPS*/
1328 intel_uncore_write_fw(uncore, GEN6_RP_DOWN_TIMEOUT, 1000000);
1329 intel_uncore_write_fw(uncore, GEN6_RP_UP_THRESHOLD, 59400);
1330 intel_uncore_write_fw(uncore, GEN6_RP_DOWN_THRESHOLD, 245000);
1331 intel_uncore_write_fw(uncore, GEN6_RP_UP_EI, 66000);
1332 intel_uncore_write_fw(uncore, GEN6_RP_DOWN_EI, 350000);
1334 intel_uncore_write_fw(uncore, GEN6_RP_IDLE_HYSTERSIS, 10);
1337 intel_uncore_write_fw(uncore, GEN6_RP_CONTROL,
1338 GEN6_RP_MEDIA_HW_NORMAL_MODE |
1339 GEN6_RP_MEDIA_IS_GFX |
1341 GEN6_RP_UP_BUSY_AVG |
1342 GEN6_RP_DOWN_IDLE_AVG);
1344 rps->pm_events = (GEN6_PM_RP_UP_THRESHOLD |
1345 GEN6_PM_RP_DOWN_THRESHOLD |
1346 GEN6_PM_RP_DOWN_TIMEOUT);
1348 /* Setting Fixed Bias */
1349 vlv_punit_get(i915);
1351 val = VLV_OVERRIDE_EN | VLV_SOC_TDP_EN | CHV_BIAS_CPU_50_SOC_50;
1352 vlv_punit_write(i915, VLV_TURBO_SOC_OVERRIDE, val);
1354 val = vlv_punit_read(i915, PUNIT_REG_GPU_FREQ_STS);
1356 vlv_punit_put(i915);
1358 /* RPS code assumes GPLL is used */
1359 drm_WARN_ONCE(&i915->drm, (val & GPLLENABLE) == 0,
1360 "GPLL not enabled\n");
1362 drm_dbg(&i915->drm, "GPLL enabled? %s\n",
1363 str_yes_no(val & GPLLENABLE));
1364 drm_dbg(&i915->drm, "GPU status: 0x%08x\n", val);
1366 return rps_reset(rps);
1369 static int vlv_rps_guar_freq(struct intel_rps *rps)
1371 struct drm_i915_private *i915 = rps_to_i915(rps);
1374 val = vlv_nc_read(i915, IOSF_NC_FB_GFX_FREQ_FUSE);
1376 rp1 = val & FB_GFX_FGUARANTEED_FREQ_FUSE_MASK;
1377 rp1 >>= FB_GFX_FGUARANTEED_FREQ_FUSE_SHIFT;
1382 static int vlv_rps_max_freq(struct intel_rps *rps)
1384 struct drm_i915_private *i915 = rps_to_i915(rps);
1387 val = vlv_nc_read(i915, IOSF_NC_FB_GFX_FREQ_FUSE);
1389 rp0 = (val & FB_GFX_MAX_FREQ_FUSE_MASK) >> FB_GFX_MAX_FREQ_FUSE_SHIFT;
1391 rp0 = min_t(u32, rp0, 0xea);
1396 static int vlv_rps_rpe_freq(struct intel_rps *rps)
1398 struct drm_i915_private *i915 = rps_to_i915(rps);
1401 val = vlv_nc_read(i915, IOSF_NC_FB_GFX_FMAX_FUSE_LO);
1402 rpe = (val & FB_FMAX_VMIN_FREQ_LO_MASK) >> FB_FMAX_VMIN_FREQ_LO_SHIFT;
1403 val = vlv_nc_read(i915, IOSF_NC_FB_GFX_FMAX_FUSE_HI);
1404 rpe |= (val & FB_FMAX_VMIN_FREQ_HI_MASK) << 5;
1409 static int vlv_rps_min_freq(struct intel_rps *rps)
1411 struct drm_i915_private *i915 = rps_to_i915(rps);
1414 val = vlv_punit_read(i915, PUNIT_REG_GPU_LFM) & 0xff;
1416 * According to the BYT Punit GPU turbo HAS 1.1.6.3 the minimum value
1417 * for the minimum frequency in GPLL mode is 0xc1. Contrary to this on
1418 * a BYT-M B0 the above register contains 0xbf. Moreover when setting
1419 * a frequency Punit will not allow values below 0xc0. Clamp it 0xc0
1420 * to make sure it matches what Punit accepts.
1422 return max_t(u32, val, 0xc0);
1425 static bool vlv_rps_enable(struct intel_rps *rps)
1427 struct intel_uncore *uncore = rps_to_uncore(rps);
1428 struct drm_i915_private *i915 = rps_to_i915(rps);
1431 intel_uncore_write_fw(uncore, GEN6_RP_DOWN_TIMEOUT, 1000000);
1432 intel_uncore_write_fw(uncore, GEN6_RP_UP_THRESHOLD, 59400);
1433 intel_uncore_write_fw(uncore, GEN6_RP_DOWN_THRESHOLD, 245000);
1434 intel_uncore_write_fw(uncore, GEN6_RP_UP_EI, 66000);
1435 intel_uncore_write_fw(uncore, GEN6_RP_DOWN_EI, 350000);
1437 intel_uncore_write_fw(uncore, GEN6_RP_IDLE_HYSTERSIS, 10);
1439 intel_uncore_write_fw(uncore, GEN6_RP_CONTROL,
1440 GEN6_RP_MEDIA_TURBO |
1441 GEN6_RP_MEDIA_HW_NORMAL_MODE |
1442 GEN6_RP_MEDIA_IS_GFX |
1444 GEN6_RP_UP_BUSY_AVG |
1445 GEN6_RP_DOWN_IDLE_CONT);
1447 /* WaGsvRC0ResidencyMethod:vlv */
1448 rps->pm_events = GEN6_PM_RP_UP_EI_EXPIRED;
1450 vlv_punit_get(i915);
1452 /* Setting Fixed Bias */
1453 val = VLV_OVERRIDE_EN | VLV_SOC_TDP_EN | VLV_BIAS_CPU_125_SOC_875;
1454 vlv_punit_write(i915, VLV_TURBO_SOC_OVERRIDE, val);
1456 val = vlv_punit_read(i915, PUNIT_REG_GPU_FREQ_STS);
1458 vlv_punit_put(i915);
1460 /* RPS code assumes GPLL is used */
1461 drm_WARN_ONCE(&i915->drm, (val & GPLLENABLE) == 0,
1462 "GPLL not enabled\n");
1464 drm_dbg(&i915->drm, "GPLL enabled? %s\n",
1465 str_yes_no(val & GPLLENABLE));
1466 drm_dbg(&i915->drm, "GPU status: 0x%08x\n", val);
1468 return rps_reset(rps);
1471 static unsigned long __ips_gfx_val(struct intel_ips *ips)
1473 struct intel_rps *rps = container_of(ips, typeof(*rps), ips);
1474 struct intel_uncore *uncore = rps_to_uncore(rps);
1475 unsigned int t, state1, state2;
1479 lockdep_assert_held(&mchdev_lock);
1481 pxvid = intel_uncore_read(uncore, PXVFREQ(rps->cur_freq));
1482 pxvid = (pxvid >> 24) & 0x7f;
1483 ext_v = pvid_to_extvid(rps_to_i915(rps), pxvid);
1487 /* Revel in the empirically derived constants */
1489 /* Correction factor in 1/100000 units */
1490 t = ips_mch_val(uncore);
1492 corr = t * 2349 + 135940;
1494 corr = t * 964 + 29317;
1496 corr = t * 301 + 1004;
1498 corr = div_u64(corr * 150142 * state1, 10000) - 78642;
1499 corr2 = div_u64(corr, 100000) * ips->corr;
1501 state2 = div_u64(corr2 * state1, 10000);
1502 state2 /= 100; /* convert to mW */
1504 __gen5_ips_update(ips);
1506 return ips->gfx_power + state2;
1509 static bool has_busy_stats(struct intel_rps *rps)
1511 struct intel_engine_cs *engine;
1512 enum intel_engine_id id;
1514 for_each_engine(engine, rps_to_gt(rps), id) {
1515 if (!intel_engine_supports_stats(engine))
1522 void intel_rps_enable(struct intel_rps *rps)
1524 struct drm_i915_private *i915 = rps_to_i915(rps);
1525 struct intel_uncore *uncore = rps_to_uncore(rps);
1526 bool enabled = false;
1531 if (rps_uses_slpc(rps))
1534 intel_gt_check_clock_frequency(rps_to_gt(rps));
1536 intel_uncore_forcewake_get(uncore, FORCEWAKE_ALL);
1537 if (rps->max_freq <= rps->min_freq)
1538 /* leave disabled, no room for dynamic reclocking */;
1539 else if (IS_CHERRYVIEW(i915))
1540 enabled = chv_rps_enable(rps);
1541 else if (IS_VALLEYVIEW(i915))
1542 enabled = vlv_rps_enable(rps);
1543 else if (GRAPHICS_VER(i915) >= 9)
1544 enabled = gen9_rps_enable(rps);
1545 else if (GRAPHICS_VER(i915) >= 8)
1546 enabled = gen8_rps_enable(rps);
1547 else if (GRAPHICS_VER(i915) >= 6)
1548 enabled = gen6_rps_enable(rps);
1549 else if (IS_IRONLAKE_M(i915))
1550 enabled = gen5_rps_enable(rps);
1552 MISSING_CASE(GRAPHICS_VER(i915));
1553 intel_uncore_forcewake_put(uncore, FORCEWAKE_ALL);
1557 GT_TRACE(rps_to_gt(rps),
1558 "min:%x, max:%x, freq:[%d, %d]\n",
1559 rps->min_freq, rps->max_freq,
1560 intel_gpu_freq(rps, rps->min_freq),
1561 intel_gpu_freq(rps, rps->max_freq));
1563 GEM_BUG_ON(rps->max_freq < rps->min_freq);
1564 GEM_BUG_ON(rps->idle_freq > rps->max_freq);
1566 GEM_BUG_ON(rps->efficient_freq < rps->min_freq);
1567 GEM_BUG_ON(rps->efficient_freq > rps->max_freq);
1569 if (has_busy_stats(rps))
1570 intel_rps_set_timer(rps);
1571 else if (GRAPHICS_VER(i915) >= 6 && GRAPHICS_VER(i915) <= 11)
1572 intel_rps_set_interrupts(rps);
1574 /* Ironlake currently uses intel_ips.ko */ {}
1576 intel_rps_set_enabled(rps);
1579 static void gen6_rps_disable(struct intel_rps *rps)
1581 set(rps_to_uncore(rps), GEN6_RP_CONTROL, 0);
1584 void intel_rps_disable(struct intel_rps *rps)
1586 struct drm_i915_private *i915 = rps_to_i915(rps);
1588 if (!intel_rps_is_enabled(rps))
1591 intel_rps_clear_enabled(rps);
1592 intel_rps_clear_interrupts(rps);
1593 intel_rps_clear_timer(rps);
1595 if (GRAPHICS_VER(i915) >= 6)
1596 gen6_rps_disable(rps);
1597 else if (IS_IRONLAKE_M(i915))
1598 gen5_rps_disable(rps);
1601 static int byt_gpu_freq(struct intel_rps *rps, int val)
1605 * Slow = Fast = GPLL ref * N
1607 return DIV_ROUND_CLOSEST(rps->gpll_ref_freq * (val - 0xb7), 1000);
1610 static int byt_freq_opcode(struct intel_rps *rps, int val)
1612 return DIV_ROUND_CLOSEST(1000 * val, rps->gpll_ref_freq) + 0xb7;
1615 static int chv_gpu_freq(struct intel_rps *rps, int val)
1619 * CU (slow) = CU2x (fast) / 2 = GPLL ref * N / 2
1621 return DIV_ROUND_CLOSEST(rps->gpll_ref_freq * val, 2 * 2 * 1000);
1624 static int chv_freq_opcode(struct intel_rps *rps, int val)
1626 /* CHV needs even values */
1627 return DIV_ROUND_CLOSEST(2 * 1000 * val, rps->gpll_ref_freq) * 2;
1630 int intel_gpu_freq(struct intel_rps *rps, int val)
1632 struct drm_i915_private *i915 = rps_to_i915(rps);
1634 if (GRAPHICS_VER(i915) >= 9)
1635 return DIV_ROUND_CLOSEST(val * GT_FREQUENCY_MULTIPLIER,
1637 else if (IS_CHERRYVIEW(i915))
1638 return chv_gpu_freq(rps, val);
1639 else if (IS_VALLEYVIEW(i915))
1640 return byt_gpu_freq(rps, val);
1641 else if (GRAPHICS_VER(i915) >= 6)
1642 return val * GT_FREQUENCY_MULTIPLIER;
1647 int intel_freq_opcode(struct intel_rps *rps, int val)
1649 struct drm_i915_private *i915 = rps_to_i915(rps);
1651 if (GRAPHICS_VER(i915) >= 9)
1652 return DIV_ROUND_CLOSEST(val * GEN9_FREQ_SCALER,
1653 GT_FREQUENCY_MULTIPLIER);
1654 else if (IS_CHERRYVIEW(i915))
1655 return chv_freq_opcode(rps, val);
1656 else if (IS_VALLEYVIEW(i915))
1657 return byt_freq_opcode(rps, val);
1658 else if (GRAPHICS_VER(i915) >= 6)
1659 return DIV_ROUND_CLOSEST(val, GT_FREQUENCY_MULTIPLIER);
1664 static void vlv_init_gpll_ref_freq(struct intel_rps *rps)
1666 struct drm_i915_private *i915 = rps_to_i915(rps);
1668 rps->gpll_ref_freq =
1669 vlv_get_cck_clock(i915, "GPLL ref",
1670 CCK_GPLL_CLOCK_CONTROL,
1673 drm_dbg(&i915->drm, "GPLL reference freq: %d kHz\n",
1674 rps->gpll_ref_freq);
1677 static void vlv_rps_init(struct intel_rps *rps)
1679 struct drm_i915_private *i915 = rps_to_i915(rps);
1681 vlv_iosf_sb_get(i915,
1682 BIT(VLV_IOSF_SB_PUNIT) |
1683 BIT(VLV_IOSF_SB_NC) |
1684 BIT(VLV_IOSF_SB_CCK));
1686 vlv_init_gpll_ref_freq(rps);
1688 rps->max_freq = vlv_rps_max_freq(rps);
1689 rps->rp0_freq = rps->max_freq;
1690 drm_dbg(&i915->drm, "max GPU freq: %d MHz (%u)\n",
1691 intel_gpu_freq(rps, rps->max_freq), rps->max_freq);
1693 rps->efficient_freq = vlv_rps_rpe_freq(rps);
1694 drm_dbg(&i915->drm, "RPe GPU freq: %d MHz (%u)\n",
1695 intel_gpu_freq(rps, rps->efficient_freq), rps->efficient_freq);
1697 rps->rp1_freq = vlv_rps_guar_freq(rps);
1698 drm_dbg(&i915->drm, "RP1(Guar Freq) GPU freq: %d MHz (%u)\n",
1699 intel_gpu_freq(rps, rps->rp1_freq), rps->rp1_freq);
1701 rps->min_freq = vlv_rps_min_freq(rps);
1702 drm_dbg(&i915->drm, "min GPU freq: %d MHz (%u)\n",
1703 intel_gpu_freq(rps, rps->min_freq), rps->min_freq);
1705 vlv_iosf_sb_put(i915,
1706 BIT(VLV_IOSF_SB_PUNIT) |
1707 BIT(VLV_IOSF_SB_NC) |
1708 BIT(VLV_IOSF_SB_CCK));
1711 static void chv_rps_init(struct intel_rps *rps)
1713 struct drm_i915_private *i915 = rps_to_i915(rps);
1715 vlv_iosf_sb_get(i915,
1716 BIT(VLV_IOSF_SB_PUNIT) |
1717 BIT(VLV_IOSF_SB_NC) |
1718 BIT(VLV_IOSF_SB_CCK));
1720 vlv_init_gpll_ref_freq(rps);
1722 rps->max_freq = chv_rps_max_freq(rps);
1723 rps->rp0_freq = rps->max_freq;
1724 drm_dbg(&i915->drm, "max GPU freq: %d MHz (%u)\n",
1725 intel_gpu_freq(rps, rps->max_freq), rps->max_freq);
1727 rps->efficient_freq = chv_rps_rpe_freq(rps);
1728 drm_dbg(&i915->drm, "RPe GPU freq: %d MHz (%u)\n",
1729 intel_gpu_freq(rps, rps->efficient_freq), rps->efficient_freq);
1731 rps->rp1_freq = chv_rps_guar_freq(rps);
1732 drm_dbg(&i915->drm, "RP1(Guar) GPU freq: %d MHz (%u)\n",
1733 intel_gpu_freq(rps, rps->rp1_freq), rps->rp1_freq);
1735 rps->min_freq = chv_rps_min_freq(rps);
1736 drm_dbg(&i915->drm, "min GPU freq: %d MHz (%u)\n",
1737 intel_gpu_freq(rps, rps->min_freq), rps->min_freq);
1739 vlv_iosf_sb_put(i915,
1740 BIT(VLV_IOSF_SB_PUNIT) |
1741 BIT(VLV_IOSF_SB_NC) |
1742 BIT(VLV_IOSF_SB_CCK));
1744 drm_WARN_ONCE(&i915->drm, (rps->max_freq | rps->efficient_freq |
1745 rps->rp1_freq | rps->min_freq) & 1,
1746 "Odd GPU freq values\n");
1749 static void vlv_c0_read(struct intel_uncore *uncore, struct intel_rps_ei *ei)
1751 ei->ktime = ktime_get_raw();
1752 ei->render_c0 = intel_uncore_read(uncore, VLV_RENDER_C0_COUNT);
1753 ei->media_c0 = intel_uncore_read(uncore, VLV_MEDIA_C0_COUNT);
1756 static u32 vlv_wa_c0_ei(struct intel_rps *rps, u32 pm_iir)
1758 struct intel_uncore *uncore = rps_to_uncore(rps);
1759 const struct intel_rps_ei *prev = &rps->ei;
1760 struct intel_rps_ei now;
1763 if ((pm_iir & GEN6_PM_RP_UP_EI_EXPIRED) == 0)
1766 vlv_c0_read(uncore, &now);
1772 time = ktime_us_delta(now.ktime, prev->ktime);
1774 time *= rps_to_i915(rps)->czclk_freq;
1776 /* Workload can be split between render + media,
1777 * e.g. SwapBuffers being blitted in X after being rendered in
1778 * mesa. To account for this we need to combine both engines
1779 * into our activity counter.
1781 render = now.render_c0 - prev->render_c0;
1782 media = now.media_c0 - prev->media_c0;
1783 c0 = max(render, media);
1784 c0 *= 1000 * 100 << 8; /* to usecs and scale to threshold% */
1786 if (c0 > time * rps->power.up_threshold)
1787 events = GEN6_PM_RP_UP_THRESHOLD;
1788 else if (c0 < time * rps->power.down_threshold)
1789 events = GEN6_PM_RP_DOWN_THRESHOLD;
1796 static void rps_work(struct work_struct *work)
1798 struct intel_rps *rps = container_of(work, typeof(*rps), work);
1799 struct intel_gt *gt = rps_to_gt(rps);
1800 struct drm_i915_private *i915 = rps_to_i915(rps);
1801 bool client_boost = false;
1802 int new_freq, adj, min, max;
1805 spin_lock_irq(gt->irq_lock);
1806 pm_iir = fetch_and_zero(&rps->pm_iir) & rps->pm_events;
1807 client_boost = atomic_read(&rps->num_waiters);
1808 spin_unlock_irq(gt->irq_lock);
1810 /* Make sure we didn't queue anything we're not going to process. */
1811 if (!pm_iir && !client_boost)
1814 mutex_lock(&rps->lock);
1815 if (!intel_rps_is_active(rps)) {
1816 mutex_unlock(&rps->lock);
1820 pm_iir |= vlv_wa_c0_ei(rps, pm_iir);
1822 adj = rps->last_adj;
1823 new_freq = rps->cur_freq;
1824 min = rps->min_freq_softlimit;
1825 max = rps->max_freq_softlimit;
1827 max = rps->max_freq;
1830 "pm_iir:%x, client_boost:%s, last:%d, cur:%x, min:%x, max:%x\n",
1831 pm_iir, str_yes_no(client_boost),
1832 adj, new_freq, min, max);
1834 if (client_boost && new_freq < rps->boost_freq) {
1835 new_freq = rps->boost_freq;
1837 } else if (pm_iir & GEN6_PM_RP_UP_THRESHOLD) {
1840 else /* CHV needs even encode values */
1841 adj = IS_CHERRYVIEW(gt->i915) ? 2 : 1;
1843 if (new_freq >= rps->max_freq_softlimit)
1845 } else if (client_boost) {
1847 } else if (pm_iir & GEN6_PM_RP_DOWN_TIMEOUT) {
1848 if (rps->cur_freq > rps->efficient_freq)
1849 new_freq = rps->efficient_freq;
1850 else if (rps->cur_freq > rps->min_freq_softlimit)
1851 new_freq = rps->min_freq_softlimit;
1853 } else if (pm_iir & GEN6_PM_RP_DOWN_THRESHOLD) {
1856 else /* CHV needs even encode values */
1857 adj = IS_CHERRYVIEW(gt->i915) ? -2 : -1;
1859 if (new_freq <= rps->min_freq_softlimit)
1861 } else { /* unknown event */
1866 * sysfs frequency limits may have snuck in while
1867 * servicing the interrupt
1870 new_freq = clamp_t(int, new_freq, min, max);
1872 if (intel_rps_set(rps, new_freq)) {
1873 drm_dbg(&i915->drm, "Failed to set new GPU frequency\n");
1876 rps->last_adj = adj;
1878 mutex_unlock(&rps->lock);
1881 spin_lock_irq(gt->irq_lock);
1882 gen6_gt_pm_unmask_irq(gt, rps->pm_events);
1883 spin_unlock_irq(gt->irq_lock);
1886 void gen11_rps_irq_handler(struct intel_rps *rps, u32 pm_iir)
1888 struct intel_gt *gt = rps_to_gt(rps);
1889 const u32 events = rps->pm_events & pm_iir;
1891 lockdep_assert_held(gt->irq_lock);
1893 if (unlikely(!events))
1896 GT_TRACE(gt, "irq events:%x\n", events);
1898 gen6_gt_pm_mask_irq(gt, events);
1900 rps->pm_iir |= events;
1901 schedule_work(&rps->work);
1904 void gen6_rps_irq_handler(struct intel_rps *rps, u32 pm_iir)
1906 struct intel_gt *gt = rps_to_gt(rps);
1909 events = pm_iir & rps->pm_events;
1911 spin_lock(gt->irq_lock);
1913 GT_TRACE(gt, "irq events:%x\n", events);
1915 gen6_gt_pm_mask_irq(gt, events);
1916 rps->pm_iir |= events;
1918 schedule_work(&rps->work);
1919 spin_unlock(gt->irq_lock);
1922 if (GRAPHICS_VER(gt->i915) >= 8)
1925 if (pm_iir & PM_VEBOX_USER_INTERRUPT)
1926 intel_engine_cs_irq(gt->engine[VECS0], pm_iir >> 10);
1928 if (pm_iir & PM_VEBOX_CS_ERROR_INTERRUPT)
1929 drm_dbg(&rps_to_i915(rps)->drm,
1930 "Command parser error, pm_iir 0x%08x\n", pm_iir);
1933 void gen5_rps_irq_handler(struct intel_rps *rps)
1935 struct intel_uncore *uncore = rps_to_uncore(rps);
1936 u32 busy_up, busy_down, max_avg, min_avg;
1939 spin_lock(&mchdev_lock);
1941 intel_uncore_write16(uncore,
1943 intel_uncore_read(uncore, MEMINTRSTS));
1945 intel_uncore_write16(uncore, MEMINTRSTS, MEMINT_EVAL_CHG);
1946 busy_up = intel_uncore_read(uncore, RCPREVBSYTUPAVG);
1947 busy_down = intel_uncore_read(uncore, RCPREVBSYTDNAVG);
1948 max_avg = intel_uncore_read(uncore, RCBMAXAVG);
1949 min_avg = intel_uncore_read(uncore, RCBMINAVG);
1951 /* Handle RCS change request from hw */
1952 new_freq = rps->cur_freq;
1953 if (busy_up > max_avg)
1955 else if (busy_down < min_avg)
1957 new_freq = clamp(new_freq,
1958 rps->min_freq_softlimit,
1959 rps->max_freq_softlimit);
1961 if (new_freq != rps->cur_freq && !__gen5_rps_set(rps, new_freq))
1962 rps->cur_freq = new_freq;
1964 spin_unlock(&mchdev_lock);
1967 void intel_rps_init_early(struct intel_rps *rps)
1969 mutex_init(&rps->lock);
1970 mutex_init(&rps->power.mutex);
1972 INIT_WORK(&rps->work, rps_work);
1973 timer_setup(&rps->timer, rps_timer, 0);
1975 atomic_set(&rps->num_waiters, 0);
1978 void intel_rps_init(struct intel_rps *rps)
1980 struct drm_i915_private *i915 = rps_to_i915(rps);
1982 if (rps_uses_slpc(rps))
1985 if (IS_CHERRYVIEW(i915))
1987 else if (IS_VALLEYVIEW(i915))
1989 else if (GRAPHICS_VER(i915) >= 6)
1991 else if (IS_IRONLAKE_M(i915))
1994 /* Derive initial user preferences/limits from the hardware limits */
1995 rps->max_freq_softlimit = rps->max_freq;
1996 rps_to_gt(rps)->defaults.max_freq = rps->max_freq_softlimit;
1997 rps->min_freq_softlimit = rps->min_freq;
1998 rps_to_gt(rps)->defaults.min_freq = rps->min_freq_softlimit;
2000 /* After setting max-softlimit, find the overclock max freq */
2001 if (GRAPHICS_VER(i915) == 6 || IS_IVYBRIDGE(i915) || IS_HASWELL(i915)) {
2004 snb_pcode_read(rps_to_gt(rps)->uncore, GEN6_READ_OC_PARAMS, ¶ms, NULL);
2005 if (params & BIT(31)) { /* OC supported */
2007 "Overclocking supported, max: %dMHz, overclock: %dMHz\n",
2008 (rps->max_freq & 0xff) * 50,
2009 (params & 0xff) * 50);
2010 rps->max_freq = params & 0xff;
2014 /* Finally allow us to boost to max by default */
2015 rps->boost_freq = rps->max_freq;
2016 rps->idle_freq = rps->min_freq;
2018 /* Start in the middle, from here we will autotune based on workload */
2019 rps->cur_freq = rps->efficient_freq;
2021 rps->pm_intrmsk_mbz = 0;
2024 * SNB,IVB,HSW can while VLV,CHV may hard hang on looping batchbuffer
2025 * if GEN6_PM_UP_EI_EXPIRED is masked.
2027 * TODO: verify if this can be reproduced on VLV,CHV.
2029 if (GRAPHICS_VER(i915) <= 7)
2030 rps->pm_intrmsk_mbz |= GEN6_PM_RP_UP_EI_EXPIRED;
2032 if (GRAPHICS_VER(i915) >= 8 && GRAPHICS_VER(i915) < 11)
2033 rps->pm_intrmsk_mbz |= GEN8_PMINTR_DISABLE_REDIRECT_TO_GUC;
2035 /* GuC needs ARAT expired interrupt unmasked */
2036 if (intel_uc_uses_guc_submission(&rps_to_gt(rps)->uc))
2037 rps->pm_intrmsk_mbz |= ARAT_EXPIRED_INTRMSK;
2040 void intel_rps_sanitize(struct intel_rps *rps)
2042 if (rps_uses_slpc(rps))
2045 if (GRAPHICS_VER(rps_to_i915(rps)) >= 6)
2046 rps_disable_interrupts(rps);
2049 u32 intel_rps_read_rpstat(struct intel_rps *rps)
2051 struct drm_i915_private *i915 = rps_to_i915(rps);
2054 rpstat = (GRAPHICS_VER(i915) >= 12) ? GEN12_RPSTAT1 : GEN6_RPSTAT1;
2056 return intel_uncore_read(rps_to_gt(rps)->uncore, rpstat);
2059 static u32 intel_rps_get_cagf(struct intel_rps *rps, u32 rpstat)
2061 struct drm_i915_private *i915 = rps_to_i915(rps);
2064 if (GRAPHICS_VER_FULL(i915) >= IP_VER(12, 70))
2065 cagf = REG_FIELD_GET(MTL_CAGF_MASK, rpstat);
2066 else if (GRAPHICS_VER(i915) >= 12)
2067 cagf = REG_FIELD_GET(GEN12_CAGF_MASK, rpstat);
2068 else if (IS_VALLEYVIEW(i915) || IS_CHERRYVIEW(i915))
2069 cagf = REG_FIELD_GET(RPE_MASK, rpstat);
2070 else if (GRAPHICS_VER(i915) >= 9)
2071 cagf = REG_FIELD_GET(GEN9_CAGF_MASK, rpstat);
2072 else if (IS_HASWELL(i915) || IS_BROADWELL(i915))
2073 cagf = REG_FIELD_GET(HSW_CAGF_MASK, rpstat);
2074 else if (GRAPHICS_VER(i915) >= 6)
2075 cagf = REG_FIELD_GET(GEN6_CAGF_MASK, rpstat);
2077 cagf = gen5_invert_freq(rps, REG_FIELD_GET(MEMSTAT_PSTATE_MASK, rpstat));
2082 static u32 __read_cagf(struct intel_rps *rps, bool take_fw)
2084 struct drm_i915_private *i915 = rps_to_i915(rps);
2085 struct intel_uncore *uncore = rps_to_uncore(rps);
2086 i915_reg_t r = INVALID_MMIO_REG;
2090 * For Gen12+ reading freq from HW does not need a forcewake and
2091 * registers will return 0 freq when GT is in RC6
2093 if (GRAPHICS_VER_FULL(i915) >= IP_VER(12, 70)) {
2094 r = MTL_MIRROR_TARGET_WP1;
2095 } else if (GRAPHICS_VER(i915) >= 12) {
2097 } else if (IS_VALLEYVIEW(i915) || IS_CHERRYVIEW(i915)) {
2098 vlv_punit_get(i915);
2099 freq = vlv_punit_read(i915, PUNIT_REG_GPU_FREQ_STS);
2100 vlv_punit_put(i915);
2101 } else if (GRAPHICS_VER(i915) >= 6) {
2107 if (i915_mmio_reg_valid(r))
2108 freq = take_fw ? intel_uncore_read(uncore, r) : intel_uncore_read_fw(uncore, r);
2110 return intel_rps_get_cagf(rps, freq);
2113 static u32 read_cagf(struct intel_rps *rps)
2115 return __read_cagf(rps, true);
2118 u32 intel_rps_read_actual_frequency(struct intel_rps *rps)
2120 struct intel_runtime_pm *rpm = rps_to_uncore(rps)->rpm;
2121 intel_wakeref_t wakeref;
2124 with_intel_runtime_pm_if_in_use(rpm, wakeref)
2125 freq = intel_gpu_freq(rps, read_cagf(rps));
2130 u32 intel_rps_read_actual_frequency_fw(struct intel_rps *rps)
2132 return intel_gpu_freq(rps, __read_cagf(rps, false));
2135 static u32 intel_rps_read_punit_req(struct intel_rps *rps)
2137 struct intel_uncore *uncore = rps_to_uncore(rps);
2138 struct intel_runtime_pm *rpm = rps_to_uncore(rps)->rpm;
2139 intel_wakeref_t wakeref;
2142 with_intel_runtime_pm_if_in_use(rpm, wakeref)
2143 freq = intel_uncore_read(uncore, GEN6_RPNSWREQ);
2148 static u32 intel_rps_get_req(u32 pureq)
2150 u32 req = pureq >> GEN9_SW_REQ_UNSLICE_RATIO_SHIFT;
2155 u32 intel_rps_read_punit_req_frequency(struct intel_rps *rps)
2157 u32 freq = intel_rps_get_req(intel_rps_read_punit_req(rps));
2159 return intel_gpu_freq(rps, freq);
2162 u32 intel_rps_get_requested_frequency(struct intel_rps *rps)
2164 if (rps_uses_slpc(rps))
2165 return intel_rps_read_punit_req_frequency(rps);
2167 return intel_gpu_freq(rps, rps->cur_freq);
2170 u32 intel_rps_get_max_frequency(struct intel_rps *rps)
2172 struct intel_guc_slpc *slpc = rps_to_slpc(rps);
2174 if (rps_uses_slpc(rps))
2175 return slpc->max_freq_softlimit;
2177 return intel_gpu_freq(rps, rps->max_freq_softlimit);
2181 * intel_rps_get_max_raw_freq - returns the max frequency in some raw format.
2182 * @rps: the intel_rps structure
2184 * Returns the max frequency in a raw format. In newer platforms raw is in
2187 u32 intel_rps_get_max_raw_freq(struct intel_rps *rps)
2189 struct intel_guc_slpc *slpc = rps_to_slpc(rps);
2192 if (rps_uses_slpc(rps)) {
2193 return DIV_ROUND_CLOSEST(slpc->rp0_freq,
2194 GT_FREQUENCY_MULTIPLIER);
2196 freq = rps->max_freq;
2197 if (GRAPHICS_VER(rps_to_i915(rps)) >= 9) {
2198 /* Convert GT frequency to 50 MHz units */
2199 freq /= GEN9_FREQ_SCALER;
2205 u32 intel_rps_get_rp0_frequency(struct intel_rps *rps)
2207 struct intel_guc_slpc *slpc = rps_to_slpc(rps);
2209 if (rps_uses_slpc(rps))
2210 return slpc->rp0_freq;
2212 return intel_gpu_freq(rps, rps->rp0_freq);
2215 u32 intel_rps_get_rp1_frequency(struct intel_rps *rps)
2217 struct intel_guc_slpc *slpc = rps_to_slpc(rps);
2219 if (rps_uses_slpc(rps))
2220 return slpc->rp1_freq;
2222 return intel_gpu_freq(rps, rps->rp1_freq);
2225 u32 intel_rps_get_rpn_frequency(struct intel_rps *rps)
2227 struct intel_guc_slpc *slpc = rps_to_slpc(rps);
2229 if (rps_uses_slpc(rps))
2230 return slpc->min_freq;
2232 return intel_gpu_freq(rps, rps->min_freq);
2235 static void rps_frequency_dump(struct intel_rps *rps, struct drm_printer *p)
2237 struct intel_gt *gt = rps_to_gt(rps);
2238 struct drm_i915_private *i915 = gt->i915;
2239 struct intel_uncore *uncore = gt->uncore;
2240 struct intel_rps_freq_caps caps;
2241 u32 rp_state_limits;
2243 u32 rpmodectl, rpinclimit, rpdeclimit;
2244 u32 rpstat, cagf, reqf;
2245 u32 rpcurupei, rpcurup, rpprevup;
2246 u32 rpcurdownei, rpcurdown, rpprevdown;
2247 u32 rpupei, rpupt, rpdownei, rpdownt;
2248 u32 pm_ier, pm_imr, pm_isr, pm_iir, pm_mask;
2250 rp_state_limits = intel_uncore_read(uncore, GEN6_RP_STATE_LIMITS);
2251 gen6_rps_get_freq_caps(rps, &caps);
2252 if (IS_GEN9_LP(i915))
2253 gt_perf_status = intel_uncore_read(uncore, BXT_GT_PERF_STATUS);
2255 gt_perf_status = intel_uncore_read(uncore, GEN6_GT_PERF_STATUS);
2257 /* RPSTAT1 is in the GT power well */
2258 intel_uncore_forcewake_get(uncore, FORCEWAKE_ALL);
2260 reqf = intel_uncore_read(uncore, GEN6_RPNSWREQ);
2261 if (GRAPHICS_VER(i915) >= 9) {
2264 reqf &= ~GEN6_TURBO_DISABLE;
2265 if (IS_HASWELL(i915) || IS_BROADWELL(i915))
2270 reqf = intel_gpu_freq(rps, reqf);
2272 rpmodectl = intel_uncore_read(uncore, GEN6_RP_CONTROL);
2273 rpinclimit = intel_uncore_read(uncore, GEN6_RP_UP_THRESHOLD);
2274 rpdeclimit = intel_uncore_read(uncore, GEN6_RP_DOWN_THRESHOLD);
2276 rpstat = intel_rps_read_rpstat(rps);
2277 rpcurupei = intel_uncore_read(uncore, GEN6_RP_CUR_UP_EI) & GEN6_CURICONT_MASK;
2278 rpcurup = intel_uncore_read(uncore, GEN6_RP_CUR_UP) & GEN6_CURBSYTAVG_MASK;
2279 rpprevup = intel_uncore_read(uncore, GEN6_RP_PREV_UP) & GEN6_CURBSYTAVG_MASK;
2280 rpcurdownei = intel_uncore_read(uncore, GEN6_RP_CUR_DOWN_EI) & GEN6_CURIAVG_MASK;
2281 rpcurdown = intel_uncore_read(uncore, GEN6_RP_CUR_DOWN) & GEN6_CURBSYTAVG_MASK;
2282 rpprevdown = intel_uncore_read(uncore, GEN6_RP_PREV_DOWN) & GEN6_CURBSYTAVG_MASK;
2284 rpupei = intel_uncore_read(uncore, GEN6_RP_UP_EI);
2285 rpupt = intel_uncore_read(uncore, GEN6_RP_UP_THRESHOLD);
2287 rpdownei = intel_uncore_read(uncore, GEN6_RP_DOWN_EI);
2288 rpdownt = intel_uncore_read(uncore, GEN6_RP_DOWN_THRESHOLD);
2290 cagf = intel_rps_read_actual_frequency(rps);
2292 intel_uncore_forcewake_put(uncore, FORCEWAKE_ALL);
2294 if (GRAPHICS_VER(i915) >= 11) {
2295 pm_ier = intel_uncore_read(uncore, GEN11_GPM_WGBOXPERF_INTR_ENABLE);
2296 pm_imr = intel_uncore_read(uncore, GEN11_GPM_WGBOXPERF_INTR_MASK);
2298 * The equivalent to the PM ISR & IIR cannot be read
2299 * without affecting the current state of the system
2303 } else if (GRAPHICS_VER(i915) >= 8) {
2304 pm_ier = intel_uncore_read(uncore, GEN8_GT_IER(2));
2305 pm_imr = intel_uncore_read(uncore, GEN8_GT_IMR(2));
2306 pm_isr = intel_uncore_read(uncore, GEN8_GT_ISR(2));
2307 pm_iir = intel_uncore_read(uncore, GEN8_GT_IIR(2));
2309 pm_ier = intel_uncore_read(uncore, GEN6_PMIER);
2310 pm_imr = intel_uncore_read(uncore, GEN6_PMIMR);
2311 pm_isr = intel_uncore_read(uncore, GEN6_PMISR);
2312 pm_iir = intel_uncore_read(uncore, GEN6_PMIIR);
2314 pm_mask = intel_uncore_read(uncore, GEN6_PMINTRMSK);
2316 drm_printf(p, "Video Turbo Mode: %s\n",
2317 str_yes_no(rpmodectl & GEN6_RP_MEDIA_TURBO));
2318 drm_printf(p, "HW control enabled: %s\n",
2319 str_yes_no(rpmodectl & GEN6_RP_ENABLE));
2320 drm_printf(p, "SW control enabled: %s\n",
2321 str_yes_no((rpmodectl & GEN6_RP_MEDIA_MODE_MASK) == GEN6_RP_MEDIA_SW_MODE));
2323 drm_printf(p, "PM IER=0x%08x IMR=0x%08x, MASK=0x%08x\n",
2324 pm_ier, pm_imr, pm_mask);
2325 if (GRAPHICS_VER(i915) <= 10)
2326 drm_printf(p, "PM ISR=0x%08x IIR=0x%08x\n",
2328 drm_printf(p, "pm_intrmsk_mbz: 0x%08x\n",
2329 rps->pm_intrmsk_mbz);
2330 drm_printf(p, "GT_PERF_STATUS: 0x%08x\n", gt_perf_status);
2331 drm_printf(p, "Render p-state ratio: %d\n",
2332 (gt_perf_status & (GRAPHICS_VER(i915) >= 9 ? 0x1ff00 : 0xff00)) >> 8);
2333 drm_printf(p, "Render p-state VID: %d\n",
2334 gt_perf_status & 0xff);
2335 drm_printf(p, "Render p-state limit: %d\n",
2336 rp_state_limits & 0xff);
2337 drm_printf(p, "RPSTAT1: 0x%08x\n", rpstat);
2338 drm_printf(p, "RPMODECTL: 0x%08x\n", rpmodectl);
2339 drm_printf(p, "RPINCLIMIT: 0x%08x\n", rpinclimit);
2340 drm_printf(p, "RPDECLIMIT: 0x%08x\n", rpdeclimit);
2341 drm_printf(p, "RPNSWREQ: %dMHz\n", reqf);
2342 drm_printf(p, "CAGF: %dMHz\n", cagf);
2343 drm_printf(p, "RP CUR UP EI: %d (%lldns)\n",
2345 intel_gt_pm_interval_to_ns(gt, rpcurupei));
2346 drm_printf(p, "RP CUR UP: %d (%lldns)\n",
2347 rpcurup, intel_gt_pm_interval_to_ns(gt, rpcurup));
2348 drm_printf(p, "RP PREV UP: %d (%lldns)\n",
2349 rpprevup, intel_gt_pm_interval_to_ns(gt, rpprevup));
2350 drm_printf(p, "Up threshold: %d%%\n",
2351 rps->power.up_threshold);
2352 drm_printf(p, "RP UP EI: %d (%lldns)\n",
2353 rpupei, intel_gt_pm_interval_to_ns(gt, rpupei));
2354 drm_printf(p, "RP UP THRESHOLD: %d (%lldns)\n",
2355 rpupt, intel_gt_pm_interval_to_ns(gt, rpupt));
2357 drm_printf(p, "RP CUR DOWN EI: %d (%lldns)\n",
2359 intel_gt_pm_interval_to_ns(gt, rpcurdownei));
2360 drm_printf(p, "RP CUR DOWN: %d (%lldns)\n",
2362 intel_gt_pm_interval_to_ns(gt, rpcurdown));
2363 drm_printf(p, "RP PREV DOWN: %d (%lldns)\n",
2365 intel_gt_pm_interval_to_ns(gt, rpprevdown));
2366 drm_printf(p, "Down threshold: %d%%\n",
2367 rps->power.down_threshold);
2368 drm_printf(p, "RP DOWN EI: %d (%lldns)\n",
2369 rpdownei, intel_gt_pm_interval_to_ns(gt, rpdownei));
2370 drm_printf(p, "RP DOWN THRESHOLD: %d (%lldns)\n",
2371 rpdownt, intel_gt_pm_interval_to_ns(gt, rpdownt));
2373 drm_printf(p, "Lowest (RPN) frequency: %dMHz\n",
2374 intel_gpu_freq(rps, caps.min_freq));
2375 drm_printf(p, "Nominal (RP1) frequency: %dMHz\n",
2376 intel_gpu_freq(rps, caps.rp1_freq));
2377 drm_printf(p, "Max non-overclocked (RP0) frequency: %dMHz\n",
2378 intel_gpu_freq(rps, caps.rp0_freq));
2379 drm_printf(p, "Max overclocked frequency: %dMHz\n",
2380 intel_gpu_freq(rps, rps->max_freq));
2382 drm_printf(p, "Current freq: %d MHz\n",
2383 intel_gpu_freq(rps, rps->cur_freq));
2384 drm_printf(p, "Actual freq: %d MHz\n", cagf);
2385 drm_printf(p, "Idle freq: %d MHz\n",
2386 intel_gpu_freq(rps, rps->idle_freq));
2387 drm_printf(p, "Min freq: %d MHz\n",
2388 intel_gpu_freq(rps, rps->min_freq));
2389 drm_printf(p, "Boost freq: %d MHz\n",
2390 intel_gpu_freq(rps, rps->boost_freq));
2391 drm_printf(p, "Max freq: %d MHz\n",
2392 intel_gpu_freq(rps, rps->max_freq));
2394 "efficient (RPe) frequency: %d MHz\n",
2395 intel_gpu_freq(rps, rps->efficient_freq));
2398 static void slpc_frequency_dump(struct intel_rps *rps, struct drm_printer *p)
2400 struct intel_gt *gt = rps_to_gt(rps);
2401 struct intel_uncore *uncore = gt->uncore;
2402 struct intel_rps_freq_caps caps;
2405 gen6_rps_get_freq_caps(rps, &caps);
2406 pm_mask = intel_uncore_read(uncore, GEN6_PMINTRMSK);
2408 drm_printf(p, "PM MASK=0x%08x\n", pm_mask);
2409 drm_printf(p, "pm_intrmsk_mbz: 0x%08x\n",
2410 rps->pm_intrmsk_mbz);
2411 drm_printf(p, "RPSTAT1: 0x%08x\n", intel_rps_read_rpstat(rps));
2412 drm_printf(p, "RPNSWREQ: %dMHz\n", intel_rps_get_requested_frequency(rps));
2413 drm_printf(p, "Lowest (RPN) frequency: %dMHz\n",
2414 intel_gpu_freq(rps, caps.min_freq));
2415 drm_printf(p, "Nominal (RP1) frequency: %dMHz\n",
2416 intel_gpu_freq(rps, caps.rp1_freq));
2417 drm_printf(p, "Max non-overclocked (RP0) frequency: %dMHz\n",
2418 intel_gpu_freq(rps, caps.rp0_freq));
2419 drm_printf(p, "Current freq: %d MHz\n",
2420 intel_rps_get_requested_frequency(rps));
2421 drm_printf(p, "Actual freq: %d MHz\n",
2422 intel_rps_read_actual_frequency(rps));
2423 drm_printf(p, "Min freq: %d MHz\n",
2424 intel_rps_get_min_frequency(rps));
2425 drm_printf(p, "Boost freq: %d MHz\n",
2426 intel_rps_get_boost_frequency(rps));
2427 drm_printf(p, "Max freq: %d MHz\n",
2428 intel_rps_get_max_frequency(rps));
2430 "efficient (RPe) frequency: %d MHz\n",
2431 intel_gpu_freq(rps, caps.rp1_freq));
2434 void gen6_rps_frequency_dump(struct intel_rps *rps, struct drm_printer *p)
2436 if (rps_uses_slpc(rps))
2437 return slpc_frequency_dump(rps, p);
2439 return rps_frequency_dump(rps, p);
2442 static int set_max_freq(struct intel_rps *rps, u32 val)
2444 struct drm_i915_private *i915 = rps_to_i915(rps);
2447 mutex_lock(&rps->lock);
2449 val = intel_freq_opcode(rps, val);
2450 if (val < rps->min_freq ||
2451 val > rps->max_freq ||
2452 val < rps->min_freq_softlimit) {
2457 if (val > rps->rp0_freq)
2458 drm_dbg(&i915->drm, "User requested overclocking to %d\n",
2459 intel_gpu_freq(rps, val));
2461 rps->max_freq_softlimit = val;
2463 val = clamp_t(int, rps->cur_freq,
2464 rps->min_freq_softlimit,
2465 rps->max_freq_softlimit);
2468 * We still need *_set_rps to process the new max_delay and
2469 * update the interrupt limits and PMINTRMSK even though
2470 * frequency request may be unchanged.
2472 intel_rps_set(rps, val);
2475 mutex_unlock(&rps->lock);
2480 int intel_rps_set_max_frequency(struct intel_rps *rps, u32 val)
2482 struct intel_guc_slpc *slpc = rps_to_slpc(rps);
2484 if (rps_uses_slpc(rps))
2485 return intel_guc_slpc_set_max_freq(slpc, val);
2487 return set_max_freq(rps, val);
2490 u32 intel_rps_get_min_frequency(struct intel_rps *rps)
2492 struct intel_guc_slpc *slpc = rps_to_slpc(rps);
2494 if (rps_uses_slpc(rps))
2495 return slpc->min_freq_softlimit;
2497 return intel_gpu_freq(rps, rps->min_freq_softlimit);
2501 * intel_rps_get_min_raw_freq - returns the min frequency in some raw format.
2502 * @rps: the intel_rps structure
2504 * Returns the min frequency in a raw format. In newer platforms raw is in
2507 u32 intel_rps_get_min_raw_freq(struct intel_rps *rps)
2509 struct intel_guc_slpc *slpc = rps_to_slpc(rps);
2512 if (rps_uses_slpc(rps)) {
2513 return DIV_ROUND_CLOSEST(slpc->min_freq,
2514 GT_FREQUENCY_MULTIPLIER);
2516 freq = rps->min_freq;
2517 if (GRAPHICS_VER(rps_to_i915(rps)) >= 9) {
2518 /* Convert GT frequency to 50 MHz units */
2519 freq /= GEN9_FREQ_SCALER;
2525 static int set_min_freq(struct intel_rps *rps, u32 val)
2529 mutex_lock(&rps->lock);
2531 val = intel_freq_opcode(rps, val);
2532 if (val < rps->min_freq ||
2533 val > rps->max_freq ||
2534 val > rps->max_freq_softlimit) {
2539 rps->min_freq_softlimit = val;
2541 val = clamp_t(int, rps->cur_freq,
2542 rps->min_freq_softlimit,
2543 rps->max_freq_softlimit);
2546 * We still need *_set_rps to process the new min_delay and
2547 * update the interrupt limits and PMINTRMSK even though
2548 * frequency request may be unchanged.
2550 intel_rps_set(rps, val);
2553 mutex_unlock(&rps->lock);
2558 int intel_rps_set_min_frequency(struct intel_rps *rps, u32 val)
2560 struct intel_guc_slpc *slpc = rps_to_slpc(rps);
2562 if (rps_uses_slpc(rps))
2563 return intel_guc_slpc_set_min_freq(slpc, val);
2565 return set_min_freq(rps, val);
2568 static void intel_rps_set_manual(struct intel_rps *rps, bool enable)
2570 struct intel_uncore *uncore = rps_to_uncore(rps);
2571 u32 state = enable ? GEN9_RPSWCTL_ENABLE : GEN9_RPSWCTL_DISABLE;
2573 /* Allow punit to process software requests */
2574 intel_uncore_write(uncore, GEN6_RP_CONTROL, state);
2577 void intel_rps_raise_unslice(struct intel_rps *rps)
2579 struct intel_uncore *uncore = rps_to_uncore(rps);
2581 mutex_lock(&rps->lock);
2583 if (rps_uses_slpc(rps)) {
2584 /* RP limits have not been initialized yet for SLPC path */
2585 struct intel_rps_freq_caps caps;
2587 gen6_rps_get_freq_caps(rps, &caps);
2589 intel_rps_set_manual(rps, true);
2590 intel_uncore_write(uncore, GEN6_RPNSWREQ,
2592 GEN9_SW_REQ_UNSLICE_RATIO_SHIFT) |
2593 GEN9_IGNORE_SLICE_RATIO));
2594 intel_rps_set_manual(rps, false);
2596 intel_rps_set(rps, rps->rp0_freq);
2599 mutex_unlock(&rps->lock);
2602 void intel_rps_lower_unslice(struct intel_rps *rps)
2604 struct intel_uncore *uncore = rps_to_uncore(rps);
2606 mutex_lock(&rps->lock);
2608 if (rps_uses_slpc(rps)) {
2609 /* RP limits have not been initialized yet for SLPC path */
2610 struct intel_rps_freq_caps caps;
2612 gen6_rps_get_freq_caps(rps, &caps);
2614 intel_rps_set_manual(rps, true);
2615 intel_uncore_write(uncore, GEN6_RPNSWREQ,
2617 GEN9_SW_REQ_UNSLICE_RATIO_SHIFT) |
2618 GEN9_IGNORE_SLICE_RATIO));
2619 intel_rps_set_manual(rps, false);
2621 intel_rps_set(rps, rps->min_freq);
2624 mutex_unlock(&rps->lock);
2627 static u32 rps_read_mmio(struct intel_rps *rps, i915_reg_t reg32)
2629 struct intel_gt *gt = rps_to_gt(rps);
2630 intel_wakeref_t wakeref;
2633 with_intel_runtime_pm(gt->uncore->rpm, wakeref)
2634 val = intel_uncore_read(gt->uncore, reg32);
2639 bool rps_read_mask_mmio(struct intel_rps *rps,
2640 i915_reg_t reg32, u32 mask)
2642 return rps_read_mmio(rps, reg32) & mask;
2645 /* External interface for intel_ips.ko */
2647 static struct drm_i915_private __rcu *ips_mchdev;
2650 * Tells the intel_ips driver that the i915 driver is now loaded, if
2651 * IPS got loaded first.
2653 * This awkward dance is so that neither module has to depend on the
2654 * other in order for IPS to do the appropriate communication of
2655 * GPU turbo limits to i915.
2658 ips_ping_for_i915_load(void)
2662 link = symbol_get(ips_link_to_i915_driver);
2665 symbol_put(ips_link_to_i915_driver);
2669 void intel_rps_driver_register(struct intel_rps *rps)
2671 struct intel_gt *gt = rps_to_gt(rps);
2674 * We only register the i915 ips part with intel-ips once everything is
2675 * set up, to avoid intel-ips sneaking in and reading bogus values.
2677 if (GRAPHICS_VER(gt->i915) == 5) {
2678 GEM_BUG_ON(ips_mchdev);
2679 rcu_assign_pointer(ips_mchdev, gt->i915);
2680 ips_ping_for_i915_load();
2684 void intel_rps_driver_unregister(struct intel_rps *rps)
2686 if (rcu_access_pointer(ips_mchdev) == rps_to_i915(rps))
2687 rcu_assign_pointer(ips_mchdev, NULL);
2690 static struct drm_i915_private *mchdev_get(void)
2692 struct drm_i915_private *i915;
2695 i915 = rcu_dereference(ips_mchdev);
2696 if (i915 && !kref_get_unless_zero(&i915->drm.ref))
2704 * i915_read_mch_val - return value for IPS use
2706 * Calculate and return a value for the IPS driver to use when deciding whether
2707 * we have thermal and power headroom to increase CPU or GPU power budget.
2709 unsigned long i915_read_mch_val(void)
2711 struct drm_i915_private *i915;
2712 unsigned long chipset_val = 0;
2713 unsigned long graphics_val = 0;
2714 intel_wakeref_t wakeref;
2716 i915 = mchdev_get();
2720 with_intel_runtime_pm(&i915->runtime_pm, wakeref) {
2721 struct intel_ips *ips = &to_gt(i915)->rps.ips;
2723 spin_lock_irq(&mchdev_lock);
2724 chipset_val = __ips_chipset_val(ips);
2725 graphics_val = __ips_gfx_val(ips);
2726 spin_unlock_irq(&mchdev_lock);
2729 drm_dev_put(&i915->drm);
2730 return chipset_val + graphics_val;
2732 EXPORT_SYMBOL_GPL(i915_read_mch_val);
2735 * i915_gpu_raise - raise GPU frequency limit
2737 * Raise the limit; IPS indicates we have thermal headroom.
2739 bool i915_gpu_raise(void)
2741 struct drm_i915_private *i915;
2742 struct intel_rps *rps;
2744 i915 = mchdev_get();
2748 rps = &to_gt(i915)->rps;
2750 spin_lock_irq(&mchdev_lock);
2751 if (rps->max_freq_softlimit < rps->max_freq)
2752 rps->max_freq_softlimit++;
2753 spin_unlock_irq(&mchdev_lock);
2755 drm_dev_put(&i915->drm);
2758 EXPORT_SYMBOL_GPL(i915_gpu_raise);
2761 * i915_gpu_lower - lower GPU frequency limit
2763 * IPS indicates we're close to a thermal limit, so throttle back the GPU
2764 * frequency maximum.
2766 bool i915_gpu_lower(void)
2768 struct drm_i915_private *i915;
2769 struct intel_rps *rps;
2771 i915 = mchdev_get();
2775 rps = &to_gt(i915)->rps;
2777 spin_lock_irq(&mchdev_lock);
2778 if (rps->max_freq_softlimit > rps->min_freq)
2779 rps->max_freq_softlimit--;
2780 spin_unlock_irq(&mchdev_lock);
2782 drm_dev_put(&i915->drm);
2785 EXPORT_SYMBOL_GPL(i915_gpu_lower);
2788 * i915_gpu_busy - indicate GPU business to IPS
2790 * Tell the IPS driver whether or not the GPU is busy.
2792 bool i915_gpu_busy(void)
2794 struct drm_i915_private *i915;
2797 i915 = mchdev_get();
2801 ret = to_gt(i915)->awake;
2803 drm_dev_put(&i915->drm);
2806 EXPORT_SYMBOL_GPL(i915_gpu_busy);
2809 * i915_gpu_turbo_disable - disable graphics turbo
2811 * Disable graphics turbo by resetting the max frequency and setting the
2812 * current frequency to the default.
2814 bool i915_gpu_turbo_disable(void)
2816 struct drm_i915_private *i915;
2817 struct intel_rps *rps;
2820 i915 = mchdev_get();
2824 rps = &to_gt(i915)->rps;
2826 spin_lock_irq(&mchdev_lock);
2827 rps->max_freq_softlimit = rps->min_freq;
2828 ret = !__gen5_rps_set(&to_gt(i915)->rps, rps->min_freq);
2829 spin_unlock_irq(&mchdev_lock);
2831 drm_dev_put(&i915->drm);
2834 EXPORT_SYMBOL_GPL(i915_gpu_turbo_disable);
2836 #if IS_ENABLED(CONFIG_DRM_I915_SELFTEST)
2837 #include "selftest_rps.c"
2838 #include "selftest_slpc.c"