2 * Copyright © 2012 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 * Eugeni Dodonov <eugeni.dodonov@intel.com>
28 #include <linux/cpufreq.h>
30 #include "intel_drv.h"
31 #include "../../../platform/x86/intel_ips.h"
32 #include <linux/module.h>
33 #include <linux/vgaarb.h>
34 #include <drm/i915_powerwell.h>
35 #include <linux/pm_runtime.h>
38 * RC6 is a special power stage which allows the GPU to enter an very
39 * low-voltage mode when idle, using down to 0V while at this stage. This
40 * stage is entered automatically when the GPU is idle when RC6 support is
41 * enabled, and as soon as new workload arises GPU wakes up automatically as well.
43 * There are different RC6 modes available in Intel GPU, which differentiate
44 * among each other with the latency required to enter and leave RC6 and
45 * voltage consumed by the GPU in different states.
47 * The combination of the following flags define which states GPU is allowed
48 * to enter, while RC6 is the normal RC6 state, RC6p is the deep RC6, and
49 * RC6pp is deepest RC6. Their support by hardware varies according to the
50 * GPU, BIOS, chipset and platform. RC6 is usually the safest one and the one
51 * which brings the most power savings; deeper states save more power, but
52 * require higher latency to switch to and wake up.
54 #define INTEL_RC6_ENABLE (1<<0)
55 #define INTEL_RC6p_ENABLE (1<<1)
56 #define INTEL_RC6pp_ENABLE (1<<2)
58 /* FBC, or Frame Buffer Compression, is a technique employed to compress the
59 * framebuffer contents in-memory, aiming at reducing the required bandwidth
60 * during in-memory transfers and, therefore, reduce the power packet.
62 * The benefits of FBC are mostly visible with solid backgrounds and
63 * variation-less patterns.
65 * FBC-related functionality can be enabled by the means of the
66 * i915.i915_enable_fbc parameter
69 static void i8xx_disable_fbc(struct drm_device
*dev
)
71 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
74 /* Disable compression */
75 fbc_ctl
= I915_READ(FBC_CONTROL
);
76 if ((fbc_ctl
& FBC_CTL_EN
) == 0)
79 fbc_ctl
&= ~FBC_CTL_EN
;
80 I915_WRITE(FBC_CONTROL
, fbc_ctl
);
82 /* Wait for compressing bit to clear */
83 if (wait_for((I915_READ(FBC_STATUS
) & FBC_STAT_COMPRESSING
) == 0, 10)) {
84 DRM_DEBUG_KMS("FBC idle timed out\n");
88 DRM_DEBUG_KMS("disabled FBC\n");
91 static void i8xx_enable_fbc(struct drm_crtc
*crtc
)
93 struct drm_device
*dev
= crtc
->dev
;
94 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
95 struct drm_framebuffer
*fb
= crtc
->primary
->fb
;
96 struct drm_i915_gem_object
*obj
= intel_fb_obj(fb
);
97 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
102 cfb_pitch
= dev_priv
->fbc
.size
/ FBC_LL_SIZE
;
103 if (fb
->pitches
[0] < cfb_pitch
)
104 cfb_pitch
= fb
->pitches
[0];
106 /* FBC_CTL wants 32B or 64B units */
108 cfb_pitch
= (cfb_pitch
/ 32) - 1;
110 cfb_pitch
= (cfb_pitch
/ 64) - 1;
113 for (i
= 0; i
< (FBC_LL_SIZE
/ 32) + 1; i
++)
114 I915_WRITE(FBC_TAG
+ (i
* 4), 0);
120 fbc_ctl2
= FBC_CTL_FENCE_DBL
| FBC_CTL_IDLE_IMM
| FBC_CTL_CPU_FENCE
;
121 fbc_ctl2
|= FBC_CTL_PLANE(intel_crtc
->plane
);
122 I915_WRITE(FBC_CONTROL2
, fbc_ctl2
);
123 I915_WRITE(FBC_FENCE_OFF
, crtc
->y
);
127 fbc_ctl
= I915_READ(FBC_CONTROL
);
128 fbc_ctl
&= 0x3fff << FBC_CTL_INTERVAL_SHIFT
;
129 fbc_ctl
|= FBC_CTL_EN
| FBC_CTL_PERIODIC
;
131 fbc_ctl
|= FBC_CTL_C3_IDLE
; /* 945 needs special SR handling */
132 fbc_ctl
|= (cfb_pitch
& 0xff) << FBC_CTL_STRIDE_SHIFT
;
133 fbc_ctl
|= obj
->fence_reg
;
134 I915_WRITE(FBC_CONTROL
, fbc_ctl
);
136 DRM_DEBUG_KMS("enabled FBC, pitch %d, yoff %d, plane %c\n",
137 cfb_pitch
, crtc
->y
, plane_name(intel_crtc
->plane
));
140 static bool i8xx_fbc_enabled(struct drm_device
*dev
)
142 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
144 return I915_READ(FBC_CONTROL
) & FBC_CTL_EN
;
147 static void g4x_enable_fbc(struct drm_crtc
*crtc
)
149 struct drm_device
*dev
= crtc
->dev
;
150 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
151 struct drm_framebuffer
*fb
= crtc
->primary
->fb
;
152 struct drm_i915_gem_object
*obj
= intel_fb_obj(fb
);
153 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
156 dpfc_ctl
= DPFC_CTL_PLANE(intel_crtc
->plane
) | DPFC_SR_EN
;
157 if (drm_format_plane_cpp(fb
->pixel_format
, 0) == 2)
158 dpfc_ctl
|= DPFC_CTL_LIMIT_2X
;
160 dpfc_ctl
|= DPFC_CTL_LIMIT_1X
;
161 dpfc_ctl
|= DPFC_CTL_FENCE_EN
| obj
->fence_reg
;
163 I915_WRITE(DPFC_FENCE_YOFF
, crtc
->y
);
166 I915_WRITE(DPFC_CONTROL
, dpfc_ctl
| DPFC_CTL_EN
);
168 DRM_DEBUG_KMS("enabled fbc on plane %c\n", plane_name(intel_crtc
->plane
));
171 static void g4x_disable_fbc(struct drm_device
*dev
)
173 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
176 /* Disable compression */
177 dpfc_ctl
= I915_READ(DPFC_CONTROL
);
178 if (dpfc_ctl
& DPFC_CTL_EN
) {
179 dpfc_ctl
&= ~DPFC_CTL_EN
;
180 I915_WRITE(DPFC_CONTROL
, dpfc_ctl
);
182 DRM_DEBUG_KMS("disabled FBC\n");
186 static bool g4x_fbc_enabled(struct drm_device
*dev
)
188 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
190 return I915_READ(DPFC_CONTROL
) & DPFC_CTL_EN
;
193 static void sandybridge_blit_fbc_update(struct drm_device
*dev
)
195 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
198 /* Make sure blitter notifies FBC of writes */
200 /* Blitter is part of Media powerwell on VLV. No impact of
201 * his param in other platforms for now */
202 gen6_gt_force_wake_get(dev_priv
, FORCEWAKE_MEDIA
);
204 blt_ecoskpd
= I915_READ(GEN6_BLITTER_ECOSKPD
);
205 blt_ecoskpd
|= GEN6_BLITTER_FBC_NOTIFY
<<
206 GEN6_BLITTER_LOCK_SHIFT
;
207 I915_WRITE(GEN6_BLITTER_ECOSKPD
, blt_ecoskpd
);
208 blt_ecoskpd
|= GEN6_BLITTER_FBC_NOTIFY
;
209 I915_WRITE(GEN6_BLITTER_ECOSKPD
, blt_ecoskpd
);
210 blt_ecoskpd
&= ~(GEN6_BLITTER_FBC_NOTIFY
<<
211 GEN6_BLITTER_LOCK_SHIFT
);
212 I915_WRITE(GEN6_BLITTER_ECOSKPD
, blt_ecoskpd
);
213 POSTING_READ(GEN6_BLITTER_ECOSKPD
);
215 gen6_gt_force_wake_put(dev_priv
, FORCEWAKE_MEDIA
);
218 static void ironlake_enable_fbc(struct drm_crtc
*crtc
)
220 struct drm_device
*dev
= crtc
->dev
;
221 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
222 struct drm_framebuffer
*fb
= crtc
->primary
->fb
;
223 struct drm_i915_gem_object
*obj
= intel_fb_obj(fb
);
224 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
227 dpfc_ctl
= DPFC_CTL_PLANE(intel_crtc
->plane
);
228 if (drm_format_plane_cpp(fb
->pixel_format
, 0) == 2)
229 dev_priv
->fbc
.threshold
++;
231 switch (dev_priv
->fbc
.threshold
) {
234 dpfc_ctl
|= DPFC_CTL_LIMIT_4X
;
237 dpfc_ctl
|= DPFC_CTL_LIMIT_2X
;
240 dpfc_ctl
|= DPFC_CTL_LIMIT_1X
;
243 dpfc_ctl
|= DPFC_CTL_FENCE_EN
;
245 dpfc_ctl
|= obj
->fence_reg
;
247 I915_WRITE(ILK_DPFC_FENCE_YOFF
, crtc
->y
);
248 I915_WRITE(ILK_FBC_RT_BASE
, i915_gem_obj_ggtt_offset(obj
) | ILK_FBC_RT_VALID
);
250 I915_WRITE(ILK_DPFC_CONTROL
, dpfc_ctl
| DPFC_CTL_EN
);
253 I915_WRITE(SNB_DPFC_CTL_SA
,
254 SNB_CPU_FENCE_ENABLE
| obj
->fence_reg
);
255 I915_WRITE(DPFC_CPU_FENCE_OFFSET
, crtc
->y
);
256 sandybridge_blit_fbc_update(dev
);
259 DRM_DEBUG_KMS("enabled fbc on plane %c\n", plane_name(intel_crtc
->plane
));
262 static void ironlake_disable_fbc(struct drm_device
*dev
)
264 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
267 /* Disable compression */
268 dpfc_ctl
= I915_READ(ILK_DPFC_CONTROL
);
269 if (dpfc_ctl
& DPFC_CTL_EN
) {
270 dpfc_ctl
&= ~DPFC_CTL_EN
;
271 I915_WRITE(ILK_DPFC_CONTROL
, dpfc_ctl
);
273 DRM_DEBUG_KMS("disabled FBC\n");
277 static bool ironlake_fbc_enabled(struct drm_device
*dev
)
279 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
281 return I915_READ(ILK_DPFC_CONTROL
) & DPFC_CTL_EN
;
284 static void gen7_enable_fbc(struct drm_crtc
*crtc
)
286 struct drm_device
*dev
= crtc
->dev
;
287 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
288 struct drm_framebuffer
*fb
= crtc
->primary
->fb
;
289 struct drm_i915_gem_object
*obj
= intel_fb_obj(fb
);
290 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
293 dpfc_ctl
= IVB_DPFC_CTL_PLANE(intel_crtc
->plane
);
294 if (drm_format_plane_cpp(fb
->pixel_format
, 0) == 2)
295 dev_priv
->fbc
.threshold
++;
297 switch (dev_priv
->fbc
.threshold
) {
300 dpfc_ctl
|= DPFC_CTL_LIMIT_4X
;
303 dpfc_ctl
|= DPFC_CTL_LIMIT_2X
;
306 dpfc_ctl
|= DPFC_CTL_LIMIT_1X
;
310 dpfc_ctl
|= IVB_DPFC_CTL_FENCE_EN
;
312 if (dev_priv
->fbc
.false_color
)
313 dpfc_ctl
|= FBC_CTL_FALSE_COLOR
;
315 I915_WRITE(ILK_DPFC_CONTROL
, dpfc_ctl
| DPFC_CTL_EN
);
317 if (IS_IVYBRIDGE(dev
)) {
318 /* WaFbcAsynchFlipDisableFbcQueue:ivb */
319 I915_WRITE(ILK_DISPLAY_CHICKEN1
,
320 I915_READ(ILK_DISPLAY_CHICKEN1
) |
323 /* WaFbcAsynchFlipDisableFbcQueue:hsw,bdw */
324 I915_WRITE(CHICKEN_PIPESL_1(intel_crtc
->pipe
),
325 I915_READ(CHICKEN_PIPESL_1(intel_crtc
->pipe
)) |
329 I915_WRITE(SNB_DPFC_CTL_SA
,
330 SNB_CPU_FENCE_ENABLE
| obj
->fence_reg
);
331 I915_WRITE(DPFC_CPU_FENCE_OFFSET
, crtc
->y
);
333 sandybridge_blit_fbc_update(dev
);
335 DRM_DEBUG_KMS("enabled fbc on plane %c\n", plane_name(intel_crtc
->plane
));
338 bool intel_fbc_enabled(struct drm_device
*dev
)
340 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
342 if (!dev_priv
->display
.fbc_enabled
)
345 return dev_priv
->display
.fbc_enabled(dev
);
348 static void intel_fbc_work_fn(struct work_struct
*__work
)
350 struct intel_fbc_work
*work
=
351 container_of(to_delayed_work(__work
),
352 struct intel_fbc_work
, work
);
353 struct drm_device
*dev
= work
->crtc
->dev
;
354 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
356 mutex_lock(&dev
->struct_mutex
);
357 if (work
== dev_priv
->fbc
.fbc_work
) {
358 /* Double check that we haven't switched fb without cancelling
361 if (work
->crtc
->primary
->fb
== work
->fb
) {
362 dev_priv
->display
.enable_fbc(work
->crtc
);
364 dev_priv
->fbc
.plane
= to_intel_crtc(work
->crtc
)->plane
;
365 dev_priv
->fbc
.fb_id
= work
->crtc
->primary
->fb
->base
.id
;
366 dev_priv
->fbc
.y
= work
->crtc
->y
;
369 dev_priv
->fbc
.fbc_work
= NULL
;
371 mutex_unlock(&dev
->struct_mutex
);
376 static void intel_cancel_fbc_work(struct drm_i915_private
*dev_priv
)
378 if (dev_priv
->fbc
.fbc_work
== NULL
)
381 DRM_DEBUG_KMS("cancelling pending FBC enable\n");
383 /* Synchronisation is provided by struct_mutex and checking of
384 * dev_priv->fbc.fbc_work, so we can perform the cancellation
385 * entirely asynchronously.
387 if (cancel_delayed_work(&dev_priv
->fbc
.fbc_work
->work
))
388 /* tasklet was killed before being run, clean up */
389 kfree(dev_priv
->fbc
.fbc_work
);
391 /* Mark the work as no longer wanted so that if it does
392 * wake-up (because the work was already running and waiting
393 * for our mutex), it will discover that is no longer
396 dev_priv
->fbc
.fbc_work
= NULL
;
399 static void intel_enable_fbc(struct drm_crtc
*crtc
)
401 struct intel_fbc_work
*work
;
402 struct drm_device
*dev
= crtc
->dev
;
403 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
405 if (!dev_priv
->display
.enable_fbc
)
408 intel_cancel_fbc_work(dev_priv
);
410 work
= kzalloc(sizeof(*work
), GFP_KERNEL
);
412 DRM_ERROR("Failed to allocate FBC work structure\n");
413 dev_priv
->display
.enable_fbc(crtc
);
418 work
->fb
= crtc
->primary
->fb
;
419 INIT_DELAYED_WORK(&work
->work
, intel_fbc_work_fn
);
421 dev_priv
->fbc
.fbc_work
= work
;
423 /* Delay the actual enabling to let pageflipping cease and the
424 * display to settle before starting the compression. Note that
425 * this delay also serves a second purpose: it allows for a
426 * vblank to pass after disabling the FBC before we attempt
427 * to modify the control registers.
429 * A more complicated solution would involve tracking vblanks
430 * following the termination of the page-flipping sequence
431 * and indeed performing the enable as a co-routine and not
432 * waiting synchronously upon the vblank.
434 * WaFbcWaitForVBlankBeforeEnable:ilk,snb
436 schedule_delayed_work(&work
->work
, msecs_to_jiffies(50));
439 void intel_disable_fbc(struct drm_device
*dev
)
441 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
443 intel_cancel_fbc_work(dev_priv
);
445 if (!dev_priv
->display
.disable_fbc
)
448 dev_priv
->display
.disable_fbc(dev
);
449 dev_priv
->fbc
.plane
= -1;
452 static bool set_no_fbc_reason(struct drm_i915_private
*dev_priv
,
453 enum no_fbc_reason reason
)
455 if (dev_priv
->fbc
.no_fbc_reason
== reason
)
458 dev_priv
->fbc
.no_fbc_reason
= reason
;
463 * intel_update_fbc - enable/disable FBC as needed
464 * @dev: the drm_device
466 * Set up the framebuffer compression hardware at mode set time. We
467 * enable it if possible:
468 * - plane A only (on pre-965)
469 * - no pixel mulitply/line duplication
470 * - no alpha buffer discard
472 * - framebuffer <= max_hdisplay in width, max_vdisplay in height
474 * We can't assume that any compression will take place (worst case),
475 * so the compressed buffer has to be the same size as the uncompressed
476 * one. It also must reside (along with the line length buffer) in
479 * We need to enable/disable FBC on a global basis.
481 void intel_update_fbc(struct drm_device
*dev
)
483 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
484 struct drm_crtc
*crtc
= NULL
, *tmp_crtc
;
485 struct intel_crtc
*intel_crtc
;
486 struct drm_framebuffer
*fb
;
487 struct drm_i915_gem_object
*obj
;
488 const struct drm_display_mode
*adjusted_mode
;
489 unsigned int max_width
, max_height
;
492 set_no_fbc_reason(dev_priv
, FBC_UNSUPPORTED
);
496 if (!i915
.powersave
) {
497 if (set_no_fbc_reason(dev_priv
, FBC_MODULE_PARAM
))
498 DRM_DEBUG_KMS("fbc disabled per module param\n");
503 * If FBC is already on, we just have to verify that we can
504 * keep it that way...
505 * Need to disable if:
506 * - more than one pipe is active
507 * - changing FBC params (stride, fence, mode)
508 * - new fb is too large to fit in compressed buffer
509 * - going to an unsupported config (interlace, pixel multiply, etc.)
511 for_each_crtc(dev
, tmp_crtc
) {
512 if (intel_crtc_active(tmp_crtc
) &&
513 to_intel_crtc(tmp_crtc
)->primary_enabled
) {
515 if (set_no_fbc_reason(dev_priv
, FBC_MULTIPLE_PIPES
))
516 DRM_DEBUG_KMS("more than one pipe active, disabling compression\n");
523 if (!crtc
|| crtc
->primary
->fb
== NULL
) {
524 if (set_no_fbc_reason(dev_priv
, FBC_NO_OUTPUT
))
525 DRM_DEBUG_KMS("no output, disabling\n");
529 intel_crtc
= to_intel_crtc(crtc
);
530 fb
= crtc
->primary
->fb
;
531 obj
= intel_fb_obj(fb
);
532 adjusted_mode
= &intel_crtc
->config
.adjusted_mode
;
534 if (i915
.enable_fbc
< 0) {
535 if (set_no_fbc_reason(dev_priv
, FBC_CHIP_DEFAULT
))
536 DRM_DEBUG_KMS("disabled per chip default\n");
539 if (!i915
.enable_fbc
) {
540 if (set_no_fbc_reason(dev_priv
, FBC_MODULE_PARAM
))
541 DRM_DEBUG_KMS("fbc disabled per module param\n");
544 if ((adjusted_mode
->flags
& DRM_MODE_FLAG_INTERLACE
) ||
545 (adjusted_mode
->flags
& DRM_MODE_FLAG_DBLSCAN
)) {
546 if (set_no_fbc_reason(dev_priv
, FBC_UNSUPPORTED_MODE
))
547 DRM_DEBUG_KMS("mode incompatible with compression, "
552 if (INTEL_INFO(dev
)->gen
>= 8 || IS_HASWELL(dev
)) {
555 } else if (IS_G4X(dev
) || INTEL_INFO(dev
)->gen
>= 5) {
562 if (intel_crtc
->config
.pipe_src_w
> max_width
||
563 intel_crtc
->config
.pipe_src_h
> max_height
) {
564 if (set_no_fbc_reason(dev_priv
, FBC_MODE_TOO_LARGE
))
565 DRM_DEBUG_KMS("mode too large for compression, disabling\n");
568 if ((INTEL_INFO(dev
)->gen
< 4 || HAS_DDI(dev
)) &&
569 intel_crtc
->plane
!= PLANE_A
) {
570 if (set_no_fbc_reason(dev_priv
, FBC_BAD_PLANE
))
571 DRM_DEBUG_KMS("plane not A, disabling compression\n");
575 /* The use of a CPU fence is mandatory in order to detect writes
576 * by the CPU to the scanout and trigger updates to the FBC.
578 if (obj
->tiling_mode
!= I915_TILING_X
||
579 obj
->fence_reg
== I915_FENCE_REG_NONE
) {
580 if (set_no_fbc_reason(dev_priv
, FBC_NOT_TILED
))
581 DRM_DEBUG_KMS("framebuffer not tiled or fenced, disabling compression\n");
584 if (INTEL_INFO(dev
)->gen
<= 4 && !IS_G4X(dev
) &&
585 to_intel_plane(crtc
->primary
)->rotation
!= BIT(DRM_ROTATE_0
)) {
586 if (set_no_fbc_reason(dev_priv
, FBC_UNSUPPORTED_MODE
))
587 DRM_DEBUG_KMS("Rotation unsupported, disabling\n");
591 /* If the kernel debugger is active, always disable compression */
595 if (i915_gem_stolen_setup_compression(dev
, obj
->base
.size
,
596 drm_format_plane_cpp(fb
->pixel_format
, 0))) {
597 if (set_no_fbc_reason(dev_priv
, FBC_STOLEN_TOO_SMALL
))
598 DRM_DEBUG_KMS("framebuffer too large, disabling compression\n");
602 /* If the scanout has not changed, don't modify the FBC settings.
603 * Note that we make the fundamental assumption that the fb->obj
604 * cannot be unpinned (and have its GTT offset and fence revoked)
605 * without first being decoupled from the scanout and FBC disabled.
607 if (dev_priv
->fbc
.plane
== intel_crtc
->plane
&&
608 dev_priv
->fbc
.fb_id
== fb
->base
.id
&&
609 dev_priv
->fbc
.y
== crtc
->y
)
612 if (intel_fbc_enabled(dev
)) {
613 /* We update FBC along two paths, after changing fb/crtc
614 * configuration (modeswitching) and after page-flipping
615 * finishes. For the latter, we know that not only did
616 * we disable the FBC at the start of the page-flip
617 * sequence, but also more than one vblank has passed.
619 * For the former case of modeswitching, it is possible
620 * to switch between two FBC valid configurations
621 * instantaneously so we do need to disable the FBC
622 * before we can modify its control registers. We also
623 * have to wait for the next vblank for that to take
624 * effect. However, since we delay enabling FBC we can
625 * assume that a vblank has passed since disabling and
626 * that we can safely alter the registers in the deferred
629 * In the scenario that we go from a valid to invalid
630 * and then back to valid FBC configuration we have
631 * no strict enforcement that a vblank occurred since
632 * disabling the FBC. However, along all current pipe
633 * disabling paths we do need to wait for a vblank at
634 * some point. And we wait before enabling FBC anyway.
636 DRM_DEBUG_KMS("disabling active FBC for update\n");
637 intel_disable_fbc(dev
);
640 intel_enable_fbc(crtc
);
641 dev_priv
->fbc
.no_fbc_reason
= FBC_OK
;
645 /* Multiple disables should be harmless */
646 if (intel_fbc_enabled(dev
)) {
647 DRM_DEBUG_KMS("unsupported config, disabling FBC\n");
648 intel_disable_fbc(dev
);
650 i915_gem_stolen_cleanup_compression(dev
);
653 static void i915_pineview_get_mem_freq(struct drm_device
*dev
)
655 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
658 tmp
= I915_READ(CLKCFG
);
660 switch (tmp
& CLKCFG_FSB_MASK
) {
662 dev_priv
->fsb_freq
= 533; /* 133*4 */
665 dev_priv
->fsb_freq
= 800; /* 200*4 */
668 dev_priv
->fsb_freq
= 667; /* 167*4 */
671 dev_priv
->fsb_freq
= 400; /* 100*4 */
675 switch (tmp
& CLKCFG_MEM_MASK
) {
677 dev_priv
->mem_freq
= 533;
680 dev_priv
->mem_freq
= 667;
683 dev_priv
->mem_freq
= 800;
687 /* detect pineview DDR3 setting */
688 tmp
= I915_READ(CSHRDDR3CTL
);
689 dev_priv
->is_ddr3
= (tmp
& CSHRDDR3CTL_DDR3
) ? 1 : 0;
692 static void i915_ironlake_get_mem_freq(struct drm_device
*dev
)
694 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
697 ddrpll
= I915_READ16(DDRMPLL1
);
698 csipll
= I915_READ16(CSIPLL0
);
700 switch (ddrpll
& 0xff) {
702 dev_priv
->mem_freq
= 800;
705 dev_priv
->mem_freq
= 1066;
708 dev_priv
->mem_freq
= 1333;
711 dev_priv
->mem_freq
= 1600;
714 DRM_DEBUG_DRIVER("unknown memory frequency 0x%02x\n",
716 dev_priv
->mem_freq
= 0;
720 dev_priv
->ips
.r_t
= dev_priv
->mem_freq
;
722 switch (csipll
& 0x3ff) {
724 dev_priv
->fsb_freq
= 3200;
727 dev_priv
->fsb_freq
= 3733;
730 dev_priv
->fsb_freq
= 4266;
733 dev_priv
->fsb_freq
= 4800;
736 dev_priv
->fsb_freq
= 5333;
739 dev_priv
->fsb_freq
= 5866;
742 dev_priv
->fsb_freq
= 6400;
745 DRM_DEBUG_DRIVER("unknown fsb frequency 0x%04x\n",
747 dev_priv
->fsb_freq
= 0;
751 if (dev_priv
->fsb_freq
== 3200) {
752 dev_priv
->ips
.c_m
= 0;
753 } else if (dev_priv
->fsb_freq
> 3200 && dev_priv
->fsb_freq
<= 4800) {
754 dev_priv
->ips
.c_m
= 1;
756 dev_priv
->ips
.c_m
= 2;
760 static const struct cxsr_latency cxsr_latency_table
[] = {
761 {1, 0, 800, 400, 3382, 33382, 3983, 33983}, /* DDR2-400 SC */
762 {1, 0, 800, 667, 3354, 33354, 3807, 33807}, /* DDR2-667 SC */
763 {1, 0, 800, 800, 3347, 33347, 3763, 33763}, /* DDR2-800 SC */
764 {1, 1, 800, 667, 6420, 36420, 6873, 36873}, /* DDR3-667 SC */
765 {1, 1, 800, 800, 5902, 35902, 6318, 36318}, /* DDR3-800 SC */
767 {1, 0, 667, 400, 3400, 33400, 4021, 34021}, /* DDR2-400 SC */
768 {1, 0, 667, 667, 3372, 33372, 3845, 33845}, /* DDR2-667 SC */
769 {1, 0, 667, 800, 3386, 33386, 3822, 33822}, /* DDR2-800 SC */
770 {1, 1, 667, 667, 6438, 36438, 6911, 36911}, /* DDR3-667 SC */
771 {1, 1, 667, 800, 5941, 35941, 6377, 36377}, /* DDR3-800 SC */
773 {1, 0, 400, 400, 3472, 33472, 4173, 34173}, /* DDR2-400 SC */
774 {1, 0, 400, 667, 3443, 33443, 3996, 33996}, /* DDR2-667 SC */
775 {1, 0, 400, 800, 3430, 33430, 3946, 33946}, /* DDR2-800 SC */
776 {1, 1, 400, 667, 6509, 36509, 7062, 37062}, /* DDR3-667 SC */
777 {1, 1, 400, 800, 5985, 35985, 6501, 36501}, /* DDR3-800 SC */
779 {0, 0, 800, 400, 3438, 33438, 4065, 34065}, /* DDR2-400 SC */
780 {0, 0, 800, 667, 3410, 33410, 3889, 33889}, /* DDR2-667 SC */
781 {0, 0, 800, 800, 3403, 33403, 3845, 33845}, /* DDR2-800 SC */
782 {0, 1, 800, 667, 6476, 36476, 6955, 36955}, /* DDR3-667 SC */
783 {0, 1, 800, 800, 5958, 35958, 6400, 36400}, /* DDR3-800 SC */
785 {0, 0, 667, 400, 3456, 33456, 4103, 34106}, /* DDR2-400 SC */
786 {0, 0, 667, 667, 3428, 33428, 3927, 33927}, /* DDR2-667 SC */
787 {0, 0, 667, 800, 3443, 33443, 3905, 33905}, /* DDR2-800 SC */
788 {0, 1, 667, 667, 6494, 36494, 6993, 36993}, /* DDR3-667 SC */
789 {0, 1, 667, 800, 5998, 35998, 6460, 36460}, /* DDR3-800 SC */
791 {0, 0, 400, 400, 3528, 33528, 4255, 34255}, /* DDR2-400 SC */
792 {0, 0, 400, 667, 3500, 33500, 4079, 34079}, /* DDR2-667 SC */
793 {0, 0, 400, 800, 3487, 33487, 4029, 34029}, /* DDR2-800 SC */
794 {0, 1, 400, 667, 6566, 36566, 7145, 37145}, /* DDR3-667 SC */
795 {0, 1, 400, 800, 6042, 36042, 6584, 36584}, /* DDR3-800 SC */
798 static const struct cxsr_latency
*intel_get_cxsr_latency(int is_desktop
,
803 const struct cxsr_latency
*latency
;
806 if (fsb
== 0 || mem
== 0)
809 for (i
= 0; i
< ARRAY_SIZE(cxsr_latency_table
); i
++) {
810 latency
= &cxsr_latency_table
[i
];
811 if (is_desktop
== latency
->is_desktop
&&
812 is_ddr3
== latency
->is_ddr3
&&
813 fsb
== latency
->fsb_freq
&& mem
== latency
->mem_freq
)
817 DRM_DEBUG_KMS("Unknown FSB/MEM found, disable CxSR\n");
822 void intel_set_memory_cxsr(struct drm_i915_private
*dev_priv
, bool enable
)
824 struct drm_device
*dev
= dev_priv
->dev
;
827 if (IS_VALLEYVIEW(dev
)) {
828 I915_WRITE(FW_BLC_SELF_VLV
, enable
? FW_CSPWRDWNEN
: 0);
829 } else if (IS_G4X(dev
) || IS_CRESTLINE(dev
)) {
830 I915_WRITE(FW_BLC_SELF
, enable
? FW_BLC_SELF_EN
: 0);
831 } else if (IS_PINEVIEW(dev
)) {
832 val
= I915_READ(DSPFW3
) & ~PINEVIEW_SELF_REFRESH_EN
;
833 val
|= enable
? PINEVIEW_SELF_REFRESH_EN
: 0;
834 I915_WRITE(DSPFW3
, val
);
835 } else if (IS_I945G(dev
) || IS_I945GM(dev
)) {
836 val
= enable
? _MASKED_BIT_ENABLE(FW_BLC_SELF_EN
) :
837 _MASKED_BIT_DISABLE(FW_BLC_SELF_EN
);
838 I915_WRITE(FW_BLC_SELF
, val
);
839 } else if (IS_I915GM(dev
)) {
840 val
= enable
? _MASKED_BIT_ENABLE(INSTPM_SELF_EN
) :
841 _MASKED_BIT_DISABLE(INSTPM_SELF_EN
);
842 I915_WRITE(INSTPM
, val
);
847 DRM_DEBUG_KMS("memory self-refresh is %s\n",
848 enable
? "enabled" : "disabled");
852 * Latency for FIFO fetches is dependent on several factors:
853 * - memory configuration (speed, channels)
855 * - current MCH state
856 * It can be fairly high in some situations, so here we assume a fairly
857 * pessimal value. It's a tradeoff between extra memory fetches (if we
858 * set this value too high, the FIFO will fetch frequently to stay full)
859 * and power consumption (set it too low to save power and we might see
860 * FIFO underruns and display "flicker").
862 * A value of 5us seems to be a good balance; safe for very low end
863 * platforms but not overly aggressive on lower latency configs.
865 static const int latency_ns
= 5000;
867 static int i9xx_get_fifo_size(struct drm_device
*dev
, int plane
)
869 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
870 uint32_t dsparb
= I915_READ(DSPARB
);
873 size
= dsparb
& 0x7f;
875 size
= ((dsparb
>> DSPARB_CSTART_SHIFT
) & 0x7f) - size
;
877 DRM_DEBUG_KMS("FIFO size - (0x%08x) %s: %d\n", dsparb
,
878 plane
? "B" : "A", size
);
883 static int i830_get_fifo_size(struct drm_device
*dev
, int plane
)
885 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
886 uint32_t dsparb
= I915_READ(DSPARB
);
889 size
= dsparb
& 0x1ff;
891 size
= ((dsparb
>> DSPARB_BEND_SHIFT
) & 0x1ff) - size
;
892 size
>>= 1; /* Convert to cachelines */
894 DRM_DEBUG_KMS("FIFO size - (0x%08x) %s: %d\n", dsparb
,
895 plane
? "B" : "A", size
);
900 static int i845_get_fifo_size(struct drm_device
*dev
, int plane
)
902 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
903 uint32_t dsparb
= I915_READ(DSPARB
);
906 size
= dsparb
& 0x7f;
907 size
>>= 2; /* Convert to cachelines */
909 DRM_DEBUG_KMS("FIFO size - (0x%08x) %s: %d\n", dsparb
,
916 /* Pineview has different values for various configs */
917 static const struct intel_watermark_params pineview_display_wm
= {
918 .fifo_size
= PINEVIEW_DISPLAY_FIFO
,
919 .max_wm
= PINEVIEW_MAX_WM
,
920 .default_wm
= PINEVIEW_DFT_WM
,
921 .guard_size
= PINEVIEW_GUARD_WM
,
922 .cacheline_size
= PINEVIEW_FIFO_LINE_SIZE
,
924 static const struct intel_watermark_params pineview_display_hplloff_wm
= {
925 .fifo_size
= PINEVIEW_DISPLAY_FIFO
,
926 .max_wm
= PINEVIEW_MAX_WM
,
927 .default_wm
= PINEVIEW_DFT_HPLLOFF_WM
,
928 .guard_size
= PINEVIEW_GUARD_WM
,
929 .cacheline_size
= PINEVIEW_FIFO_LINE_SIZE
,
931 static const struct intel_watermark_params pineview_cursor_wm
= {
932 .fifo_size
= PINEVIEW_CURSOR_FIFO
,
933 .max_wm
= PINEVIEW_CURSOR_MAX_WM
,
934 .default_wm
= PINEVIEW_CURSOR_DFT_WM
,
935 .guard_size
= PINEVIEW_CURSOR_GUARD_WM
,
936 .cacheline_size
= PINEVIEW_FIFO_LINE_SIZE
,
938 static const struct intel_watermark_params pineview_cursor_hplloff_wm
= {
939 .fifo_size
= PINEVIEW_CURSOR_FIFO
,
940 .max_wm
= PINEVIEW_CURSOR_MAX_WM
,
941 .default_wm
= PINEVIEW_CURSOR_DFT_WM
,
942 .guard_size
= PINEVIEW_CURSOR_GUARD_WM
,
943 .cacheline_size
= PINEVIEW_FIFO_LINE_SIZE
,
945 static const struct intel_watermark_params g4x_wm_info
= {
946 .fifo_size
= G4X_FIFO_SIZE
,
947 .max_wm
= G4X_MAX_WM
,
948 .default_wm
= G4X_MAX_WM
,
950 .cacheline_size
= G4X_FIFO_LINE_SIZE
,
952 static const struct intel_watermark_params g4x_cursor_wm_info
= {
953 .fifo_size
= I965_CURSOR_FIFO
,
954 .max_wm
= I965_CURSOR_MAX_WM
,
955 .default_wm
= I965_CURSOR_DFT_WM
,
957 .cacheline_size
= G4X_FIFO_LINE_SIZE
,
959 static const struct intel_watermark_params valleyview_wm_info
= {
960 .fifo_size
= VALLEYVIEW_FIFO_SIZE
,
961 .max_wm
= VALLEYVIEW_MAX_WM
,
962 .default_wm
= VALLEYVIEW_MAX_WM
,
964 .cacheline_size
= G4X_FIFO_LINE_SIZE
,
966 static const struct intel_watermark_params valleyview_cursor_wm_info
= {
967 .fifo_size
= I965_CURSOR_FIFO
,
968 .max_wm
= VALLEYVIEW_CURSOR_MAX_WM
,
969 .default_wm
= I965_CURSOR_DFT_WM
,
971 .cacheline_size
= G4X_FIFO_LINE_SIZE
,
973 static const struct intel_watermark_params i965_cursor_wm_info
= {
974 .fifo_size
= I965_CURSOR_FIFO
,
975 .max_wm
= I965_CURSOR_MAX_WM
,
976 .default_wm
= I965_CURSOR_DFT_WM
,
978 .cacheline_size
= I915_FIFO_LINE_SIZE
,
980 static const struct intel_watermark_params i945_wm_info
= {
981 .fifo_size
= I945_FIFO_SIZE
,
982 .max_wm
= I915_MAX_WM
,
985 .cacheline_size
= I915_FIFO_LINE_SIZE
,
987 static const struct intel_watermark_params i915_wm_info
= {
988 .fifo_size
= I915_FIFO_SIZE
,
989 .max_wm
= I915_MAX_WM
,
992 .cacheline_size
= I915_FIFO_LINE_SIZE
,
994 static const struct intel_watermark_params i830_wm_info
= {
995 .fifo_size
= I855GM_FIFO_SIZE
,
996 .max_wm
= I915_MAX_WM
,
999 .cacheline_size
= I830_FIFO_LINE_SIZE
,
1001 static const struct intel_watermark_params i845_wm_info
= {
1002 .fifo_size
= I830_FIFO_SIZE
,
1003 .max_wm
= I915_MAX_WM
,
1006 .cacheline_size
= I830_FIFO_LINE_SIZE
,
1010 * intel_calculate_wm - calculate watermark level
1011 * @clock_in_khz: pixel clock
1012 * @wm: chip FIFO params
1013 * @pixel_size: display pixel size
1014 * @latency_ns: memory latency for the platform
1016 * Calculate the watermark level (the level at which the display plane will
1017 * start fetching from memory again). Each chip has a different display
1018 * FIFO size and allocation, so the caller needs to figure that out and pass
1019 * in the correct intel_watermark_params structure.
1021 * As the pixel clock runs, the FIFO will be drained at a rate that depends
1022 * on the pixel size. When it reaches the watermark level, it'll start
1023 * fetching FIFO line sized based chunks from memory until the FIFO fills
1024 * past the watermark point. If the FIFO drains completely, a FIFO underrun
1025 * will occur, and a display engine hang could result.
1027 static unsigned long intel_calculate_wm(unsigned long clock_in_khz
,
1028 const struct intel_watermark_params
*wm
,
1031 unsigned long latency_ns
)
1033 long entries_required
, wm_size
;
1036 * Note: we need to make sure we don't overflow for various clock &
1038 * clocks go from a few thousand to several hundred thousand.
1039 * latency is usually a few thousand
1041 entries_required
= ((clock_in_khz
/ 1000) * pixel_size
* latency_ns
) /
1043 entries_required
= DIV_ROUND_UP(entries_required
, wm
->cacheline_size
);
1045 DRM_DEBUG_KMS("FIFO entries required for mode: %ld\n", entries_required
);
1047 wm_size
= fifo_size
- (entries_required
+ wm
->guard_size
);
1049 DRM_DEBUG_KMS("FIFO watermark level: %ld\n", wm_size
);
1051 /* Don't promote wm_size to unsigned... */
1052 if (wm_size
> (long)wm
->max_wm
)
1053 wm_size
= wm
->max_wm
;
1055 wm_size
= wm
->default_wm
;
1059 static struct drm_crtc
*single_enabled_crtc(struct drm_device
*dev
)
1061 struct drm_crtc
*crtc
, *enabled
= NULL
;
1063 for_each_crtc(dev
, crtc
) {
1064 if (intel_crtc_active(crtc
)) {
1074 static void pineview_update_wm(struct drm_crtc
*unused_crtc
)
1076 struct drm_device
*dev
= unused_crtc
->dev
;
1077 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1078 struct drm_crtc
*crtc
;
1079 const struct cxsr_latency
*latency
;
1083 latency
= intel_get_cxsr_latency(IS_PINEVIEW_G(dev
), dev_priv
->is_ddr3
,
1084 dev_priv
->fsb_freq
, dev_priv
->mem_freq
);
1086 DRM_DEBUG_KMS("Unknown FSB/MEM found, disable CxSR\n");
1087 intel_set_memory_cxsr(dev_priv
, false);
1091 crtc
= single_enabled_crtc(dev
);
1093 const struct drm_display_mode
*adjusted_mode
;
1094 int pixel_size
= crtc
->primary
->fb
->bits_per_pixel
/ 8;
1097 adjusted_mode
= &to_intel_crtc(crtc
)->config
.adjusted_mode
;
1098 clock
= adjusted_mode
->crtc_clock
;
1101 wm
= intel_calculate_wm(clock
, &pineview_display_wm
,
1102 pineview_display_wm
.fifo_size
,
1103 pixel_size
, latency
->display_sr
);
1104 reg
= I915_READ(DSPFW1
);
1105 reg
&= ~DSPFW_SR_MASK
;
1106 reg
|= wm
<< DSPFW_SR_SHIFT
;
1107 I915_WRITE(DSPFW1
, reg
);
1108 DRM_DEBUG_KMS("DSPFW1 register is %x\n", reg
);
1111 wm
= intel_calculate_wm(clock
, &pineview_cursor_wm
,
1112 pineview_display_wm
.fifo_size
,
1113 pixel_size
, latency
->cursor_sr
);
1114 reg
= I915_READ(DSPFW3
);
1115 reg
&= ~DSPFW_CURSOR_SR_MASK
;
1116 reg
|= (wm
& 0x3f) << DSPFW_CURSOR_SR_SHIFT
;
1117 I915_WRITE(DSPFW3
, reg
);
1119 /* Display HPLL off SR */
1120 wm
= intel_calculate_wm(clock
, &pineview_display_hplloff_wm
,
1121 pineview_display_hplloff_wm
.fifo_size
,
1122 pixel_size
, latency
->display_hpll_disable
);
1123 reg
= I915_READ(DSPFW3
);
1124 reg
&= ~DSPFW_HPLL_SR_MASK
;
1125 reg
|= wm
& DSPFW_HPLL_SR_MASK
;
1126 I915_WRITE(DSPFW3
, reg
);
1128 /* cursor HPLL off SR */
1129 wm
= intel_calculate_wm(clock
, &pineview_cursor_hplloff_wm
,
1130 pineview_display_hplloff_wm
.fifo_size
,
1131 pixel_size
, latency
->cursor_hpll_disable
);
1132 reg
= I915_READ(DSPFW3
);
1133 reg
&= ~DSPFW_HPLL_CURSOR_MASK
;
1134 reg
|= (wm
& 0x3f) << DSPFW_HPLL_CURSOR_SHIFT
;
1135 I915_WRITE(DSPFW3
, reg
);
1136 DRM_DEBUG_KMS("DSPFW3 register is %x\n", reg
);
1138 intel_set_memory_cxsr(dev_priv
, true);
1140 intel_set_memory_cxsr(dev_priv
, false);
1144 static bool g4x_compute_wm0(struct drm_device
*dev
,
1146 const struct intel_watermark_params
*display
,
1147 int display_latency_ns
,
1148 const struct intel_watermark_params
*cursor
,
1149 int cursor_latency_ns
,
1153 struct drm_crtc
*crtc
;
1154 const struct drm_display_mode
*adjusted_mode
;
1155 int htotal
, hdisplay
, clock
, pixel_size
;
1156 int line_time_us
, line_count
;
1157 int entries
, tlb_miss
;
1159 crtc
= intel_get_crtc_for_plane(dev
, plane
);
1160 if (!intel_crtc_active(crtc
)) {
1161 *cursor_wm
= cursor
->guard_size
;
1162 *plane_wm
= display
->guard_size
;
1166 adjusted_mode
= &to_intel_crtc(crtc
)->config
.adjusted_mode
;
1167 clock
= adjusted_mode
->crtc_clock
;
1168 htotal
= adjusted_mode
->crtc_htotal
;
1169 hdisplay
= to_intel_crtc(crtc
)->config
.pipe_src_w
;
1170 pixel_size
= crtc
->primary
->fb
->bits_per_pixel
/ 8;
1172 /* Use the small buffer method to calculate plane watermark */
1173 entries
= ((clock
* pixel_size
/ 1000) * display_latency_ns
) / 1000;
1174 tlb_miss
= display
->fifo_size
*display
->cacheline_size
- hdisplay
* 8;
1176 entries
+= tlb_miss
;
1177 entries
= DIV_ROUND_UP(entries
, display
->cacheline_size
);
1178 *plane_wm
= entries
+ display
->guard_size
;
1179 if (*plane_wm
> (int)display
->max_wm
)
1180 *plane_wm
= display
->max_wm
;
1182 /* Use the large buffer method to calculate cursor watermark */
1183 line_time_us
= max(htotal
* 1000 / clock
, 1);
1184 line_count
= (cursor_latency_ns
/ line_time_us
+ 1000) / 1000;
1185 entries
= line_count
* to_intel_crtc(crtc
)->cursor_width
* pixel_size
;
1186 tlb_miss
= cursor
->fifo_size
*cursor
->cacheline_size
- hdisplay
* 8;
1188 entries
+= tlb_miss
;
1189 entries
= DIV_ROUND_UP(entries
, cursor
->cacheline_size
);
1190 *cursor_wm
= entries
+ cursor
->guard_size
;
1191 if (*cursor_wm
> (int)cursor
->max_wm
)
1192 *cursor_wm
= (int)cursor
->max_wm
;
1198 * Check the wm result.
1200 * If any calculated watermark values is larger than the maximum value that
1201 * can be programmed into the associated watermark register, that watermark
1204 static bool g4x_check_srwm(struct drm_device
*dev
,
1205 int display_wm
, int cursor_wm
,
1206 const struct intel_watermark_params
*display
,
1207 const struct intel_watermark_params
*cursor
)
1209 DRM_DEBUG_KMS("SR watermark: display plane %d, cursor %d\n",
1210 display_wm
, cursor_wm
);
1212 if (display_wm
> display
->max_wm
) {
1213 DRM_DEBUG_KMS("display watermark is too large(%d/%ld), disabling\n",
1214 display_wm
, display
->max_wm
);
1218 if (cursor_wm
> cursor
->max_wm
) {
1219 DRM_DEBUG_KMS("cursor watermark is too large(%d/%ld), disabling\n",
1220 cursor_wm
, cursor
->max_wm
);
1224 if (!(display_wm
|| cursor_wm
)) {
1225 DRM_DEBUG_KMS("SR latency is 0, disabling\n");
1232 static bool g4x_compute_srwm(struct drm_device
*dev
,
1235 const struct intel_watermark_params
*display
,
1236 const struct intel_watermark_params
*cursor
,
1237 int *display_wm
, int *cursor_wm
)
1239 struct drm_crtc
*crtc
;
1240 const struct drm_display_mode
*adjusted_mode
;
1241 int hdisplay
, htotal
, pixel_size
, clock
;
1242 unsigned long line_time_us
;
1243 int line_count
, line_size
;
1248 *display_wm
= *cursor_wm
= 0;
1252 crtc
= intel_get_crtc_for_plane(dev
, plane
);
1253 adjusted_mode
= &to_intel_crtc(crtc
)->config
.adjusted_mode
;
1254 clock
= adjusted_mode
->crtc_clock
;
1255 htotal
= adjusted_mode
->crtc_htotal
;
1256 hdisplay
= to_intel_crtc(crtc
)->config
.pipe_src_w
;
1257 pixel_size
= crtc
->primary
->fb
->bits_per_pixel
/ 8;
1259 line_time_us
= max(htotal
* 1000 / clock
, 1);
1260 line_count
= (latency_ns
/ line_time_us
+ 1000) / 1000;
1261 line_size
= hdisplay
* pixel_size
;
1263 /* Use the minimum of the small and large buffer method for primary */
1264 small
= ((clock
* pixel_size
/ 1000) * latency_ns
) / 1000;
1265 large
= line_count
* line_size
;
1267 entries
= DIV_ROUND_UP(min(small
, large
), display
->cacheline_size
);
1268 *display_wm
= entries
+ display
->guard_size
;
1270 /* calculate the self-refresh watermark for display cursor */
1271 entries
= line_count
* pixel_size
* to_intel_crtc(crtc
)->cursor_width
;
1272 entries
= DIV_ROUND_UP(entries
, cursor
->cacheline_size
);
1273 *cursor_wm
= entries
+ cursor
->guard_size
;
1275 return g4x_check_srwm(dev
,
1276 *display_wm
, *cursor_wm
,
1280 static bool vlv_compute_drain_latency(struct drm_crtc
*crtc
,
1286 int clock
= to_intel_crtc(crtc
)->config
.adjusted_mode
.crtc_clock
;
1288 if (WARN(clock
== 0, "Pixel clock is zero!\n"))
1291 if (WARN(pixel_size
== 0, "Pixel size is zero!\n"))
1294 entries
= DIV_ROUND_UP(clock
, 1000) * pixel_size
;
1295 *prec_mult
= (entries
> 128) ? DRAIN_LATENCY_PRECISION_64
:
1296 DRAIN_LATENCY_PRECISION_32
;
1297 *drain_latency
= (64 * (*prec_mult
) * 4) / entries
;
1299 if (*drain_latency
> DRAIN_LATENCY_MASK
)
1300 *drain_latency
= DRAIN_LATENCY_MASK
;
1306 * Update drain latency registers of memory arbiter
1308 * Valleyview SoC has a new memory arbiter and needs drain latency registers
1309 * to be programmed. Each plane has a drain latency multiplier and a drain
1313 static void vlv_update_drain_latency(struct drm_crtc
*crtc
)
1315 struct drm_i915_private
*dev_priv
= crtc
->dev
->dev_private
;
1316 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
1319 enum pipe pipe
= intel_crtc
->pipe
;
1320 int plane_prec
, prec_mult
, plane_dl
;
1322 plane_dl
= I915_READ(VLV_DDL(pipe
)) & ~(DDL_PLANE_PRECISION_64
|
1323 DRAIN_LATENCY_MASK
| DDL_CURSOR_PRECISION_64
|
1324 (DRAIN_LATENCY_MASK
<< DDL_CURSOR_SHIFT
));
1326 if (!intel_crtc_active(crtc
)) {
1327 I915_WRITE(VLV_DDL(pipe
), plane_dl
);
1331 /* Primary plane Drain Latency */
1332 pixel_size
= crtc
->primary
->fb
->bits_per_pixel
/ 8; /* BPP */
1333 if (vlv_compute_drain_latency(crtc
, pixel_size
, &prec_mult
, &drain_latency
)) {
1334 plane_prec
= (prec_mult
== DRAIN_LATENCY_PRECISION_64
) ?
1335 DDL_PLANE_PRECISION_64
:
1336 DDL_PLANE_PRECISION_32
;
1337 plane_dl
|= plane_prec
| drain_latency
;
1340 /* Cursor Drain Latency
1341 * BPP is always 4 for cursor
1345 /* Program cursor DL only if it is enabled */
1346 if (intel_crtc
->cursor_base
&&
1347 vlv_compute_drain_latency(crtc
, pixel_size
, &prec_mult
, &drain_latency
)) {
1348 plane_prec
= (prec_mult
== DRAIN_LATENCY_PRECISION_64
) ?
1349 DDL_CURSOR_PRECISION_64
:
1350 DDL_CURSOR_PRECISION_32
;
1351 plane_dl
|= plane_prec
| (drain_latency
<< DDL_CURSOR_SHIFT
);
1354 I915_WRITE(VLV_DDL(pipe
), plane_dl
);
1357 #define single_plane_enabled(mask) is_power_of_2(mask)
1359 static void valleyview_update_wm(struct drm_crtc
*crtc
)
1361 struct drm_device
*dev
= crtc
->dev
;
1362 static const int sr_latency_ns
= 12000;
1363 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1364 int planea_wm
, planeb_wm
, cursora_wm
, cursorb_wm
;
1365 int plane_sr
, cursor_sr
;
1366 int ignore_plane_sr
, ignore_cursor_sr
;
1367 unsigned int enabled
= 0;
1370 vlv_update_drain_latency(crtc
);
1372 if (g4x_compute_wm0(dev
, PIPE_A
,
1373 &valleyview_wm_info
, latency_ns
,
1374 &valleyview_cursor_wm_info
, latency_ns
,
1375 &planea_wm
, &cursora_wm
))
1376 enabled
|= 1 << PIPE_A
;
1378 if (g4x_compute_wm0(dev
, PIPE_B
,
1379 &valleyview_wm_info
, latency_ns
,
1380 &valleyview_cursor_wm_info
, latency_ns
,
1381 &planeb_wm
, &cursorb_wm
))
1382 enabled
|= 1 << PIPE_B
;
1384 if (single_plane_enabled(enabled
) &&
1385 g4x_compute_srwm(dev
, ffs(enabled
) - 1,
1387 &valleyview_wm_info
,
1388 &valleyview_cursor_wm_info
,
1389 &plane_sr
, &ignore_cursor_sr
) &&
1390 g4x_compute_srwm(dev
, ffs(enabled
) - 1,
1392 &valleyview_wm_info
,
1393 &valleyview_cursor_wm_info
,
1394 &ignore_plane_sr
, &cursor_sr
)) {
1395 cxsr_enabled
= true;
1397 cxsr_enabled
= false;
1398 intel_set_memory_cxsr(dev_priv
, false);
1399 plane_sr
= cursor_sr
= 0;
1402 DRM_DEBUG_KMS("Setting FIFO watermarks - A: plane=%d, cursor=%d, "
1403 "B: plane=%d, cursor=%d, SR: plane=%d, cursor=%d\n",
1404 planea_wm
, cursora_wm
,
1405 planeb_wm
, cursorb_wm
,
1406 plane_sr
, cursor_sr
);
1409 (plane_sr
<< DSPFW_SR_SHIFT
) |
1410 (cursorb_wm
<< DSPFW_CURSORB_SHIFT
) |
1411 (planeb_wm
<< DSPFW_PLANEB_SHIFT
) |
1412 (planea_wm
<< DSPFW_PLANEA_SHIFT
));
1414 (I915_READ(DSPFW2
) & ~DSPFW_CURSORA_MASK
) |
1415 (cursora_wm
<< DSPFW_CURSORA_SHIFT
));
1417 (I915_READ(DSPFW3
) & ~DSPFW_CURSOR_SR_MASK
) |
1418 (cursor_sr
<< DSPFW_CURSOR_SR_SHIFT
));
1421 intel_set_memory_cxsr(dev_priv
, true);
1424 static void cherryview_update_wm(struct drm_crtc
*crtc
)
1426 struct drm_device
*dev
= crtc
->dev
;
1427 static const int sr_latency_ns
= 12000;
1428 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1429 int planea_wm
, planeb_wm
, planec_wm
;
1430 int cursora_wm
, cursorb_wm
, cursorc_wm
;
1431 int plane_sr
, cursor_sr
;
1432 int ignore_plane_sr
, ignore_cursor_sr
;
1433 unsigned int enabled
= 0;
1436 vlv_update_drain_latency(crtc
);
1438 if (g4x_compute_wm0(dev
, PIPE_A
,
1439 &valleyview_wm_info
, latency_ns
,
1440 &valleyview_cursor_wm_info
, latency_ns
,
1441 &planea_wm
, &cursora_wm
))
1442 enabled
|= 1 << PIPE_A
;
1444 if (g4x_compute_wm0(dev
, PIPE_B
,
1445 &valleyview_wm_info
, latency_ns
,
1446 &valleyview_cursor_wm_info
, latency_ns
,
1447 &planeb_wm
, &cursorb_wm
))
1448 enabled
|= 1 << PIPE_B
;
1450 if (g4x_compute_wm0(dev
, PIPE_C
,
1451 &valleyview_wm_info
, latency_ns
,
1452 &valleyview_cursor_wm_info
, latency_ns
,
1453 &planec_wm
, &cursorc_wm
))
1454 enabled
|= 1 << PIPE_C
;
1456 if (single_plane_enabled(enabled
) &&
1457 g4x_compute_srwm(dev
, ffs(enabled
) - 1,
1459 &valleyview_wm_info
,
1460 &valleyview_cursor_wm_info
,
1461 &plane_sr
, &ignore_cursor_sr
) &&
1462 g4x_compute_srwm(dev
, ffs(enabled
) - 1,
1464 &valleyview_wm_info
,
1465 &valleyview_cursor_wm_info
,
1466 &ignore_plane_sr
, &cursor_sr
)) {
1467 cxsr_enabled
= true;
1469 cxsr_enabled
= false;
1470 intel_set_memory_cxsr(dev_priv
, false);
1471 plane_sr
= cursor_sr
= 0;
1474 DRM_DEBUG_KMS("Setting FIFO watermarks - A: plane=%d, cursor=%d, "
1475 "B: plane=%d, cursor=%d, C: plane=%d, cursor=%d, "
1476 "SR: plane=%d, cursor=%d\n",
1477 planea_wm
, cursora_wm
,
1478 planeb_wm
, cursorb_wm
,
1479 planec_wm
, cursorc_wm
,
1480 plane_sr
, cursor_sr
);
1483 (plane_sr
<< DSPFW_SR_SHIFT
) |
1484 (cursorb_wm
<< DSPFW_CURSORB_SHIFT
) |
1485 (planeb_wm
<< DSPFW_PLANEB_SHIFT
) |
1486 (planea_wm
<< DSPFW_PLANEA_SHIFT
));
1488 (I915_READ(DSPFW2
) & ~DSPFW_CURSORA_MASK
) |
1489 (cursora_wm
<< DSPFW_CURSORA_SHIFT
));
1491 (I915_READ(DSPFW3
) & ~DSPFW_CURSOR_SR_MASK
) |
1492 (cursor_sr
<< DSPFW_CURSOR_SR_SHIFT
));
1493 I915_WRITE(DSPFW9_CHV
,
1494 (I915_READ(DSPFW9_CHV
) & ~(DSPFW_PLANEC_MASK
|
1495 DSPFW_CURSORC_MASK
)) |
1496 (planec_wm
<< DSPFW_PLANEC_SHIFT
) |
1497 (cursorc_wm
<< DSPFW_CURSORC_SHIFT
));
1500 intel_set_memory_cxsr(dev_priv
, true);
1503 static void valleyview_update_sprite_wm(struct drm_plane
*plane
,
1504 struct drm_crtc
*crtc
,
1505 uint32_t sprite_width
,
1506 uint32_t sprite_height
,
1508 bool enabled
, bool scaled
)
1510 struct drm_device
*dev
= crtc
->dev
;
1511 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1512 int pipe
= to_intel_plane(plane
)->pipe
;
1513 int sprite
= to_intel_plane(plane
)->plane
;
1519 sprite_dl
= I915_READ(VLV_DDL(pipe
)) & ~(DDL_SPRITE_PRECISION_64(sprite
) |
1520 (DRAIN_LATENCY_MASK
<< DDL_SPRITE_SHIFT(sprite
)));
1522 if (enabled
&& vlv_compute_drain_latency(crtc
, pixel_size
, &prec_mult
,
1524 plane_prec
= (prec_mult
== DRAIN_LATENCY_PRECISION_64
) ?
1525 DDL_SPRITE_PRECISION_64(sprite
) :
1526 DDL_SPRITE_PRECISION_32(sprite
);
1527 sprite_dl
|= plane_prec
|
1528 (drain_latency
<< DDL_SPRITE_SHIFT(sprite
));
1531 I915_WRITE(VLV_DDL(pipe
), sprite_dl
);
1534 static void g4x_update_wm(struct drm_crtc
*crtc
)
1536 struct drm_device
*dev
= crtc
->dev
;
1537 static const int sr_latency_ns
= 12000;
1538 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1539 int planea_wm
, planeb_wm
, cursora_wm
, cursorb_wm
;
1540 int plane_sr
, cursor_sr
;
1541 unsigned int enabled
= 0;
1544 if (g4x_compute_wm0(dev
, PIPE_A
,
1545 &g4x_wm_info
, latency_ns
,
1546 &g4x_cursor_wm_info
, latency_ns
,
1547 &planea_wm
, &cursora_wm
))
1548 enabled
|= 1 << PIPE_A
;
1550 if (g4x_compute_wm0(dev
, PIPE_B
,
1551 &g4x_wm_info
, latency_ns
,
1552 &g4x_cursor_wm_info
, latency_ns
,
1553 &planeb_wm
, &cursorb_wm
))
1554 enabled
|= 1 << PIPE_B
;
1556 if (single_plane_enabled(enabled
) &&
1557 g4x_compute_srwm(dev
, ffs(enabled
) - 1,
1560 &g4x_cursor_wm_info
,
1561 &plane_sr
, &cursor_sr
)) {
1562 cxsr_enabled
= true;
1564 cxsr_enabled
= false;
1565 intel_set_memory_cxsr(dev_priv
, false);
1566 plane_sr
= cursor_sr
= 0;
1569 DRM_DEBUG_KMS("Setting FIFO watermarks - A: plane=%d, cursor=%d, "
1570 "B: plane=%d, cursor=%d, SR: plane=%d, cursor=%d\n",
1571 planea_wm
, cursora_wm
,
1572 planeb_wm
, cursorb_wm
,
1573 plane_sr
, cursor_sr
);
1576 (plane_sr
<< DSPFW_SR_SHIFT
) |
1577 (cursorb_wm
<< DSPFW_CURSORB_SHIFT
) |
1578 (planeb_wm
<< DSPFW_PLANEB_SHIFT
) |
1579 (planea_wm
<< DSPFW_PLANEA_SHIFT
));
1581 (I915_READ(DSPFW2
) & ~DSPFW_CURSORA_MASK
) |
1582 (cursora_wm
<< DSPFW_CURSORA_SHIFT
));
1583 /* HPLL off in SR has some issues on G4x... disable it */
1585 (I915_READ(DSPFW3
) & ~(DSPFW_HPLL_SR_EN
| DSPFW_CURSOR_SR_MASK
)) |
1586 (cursor_sr
<< DSPFW_CURSOR_SR_SHIFT
));
1589 intel_set_memory_cxsr(dev_priv
, true);
1592 static void i965_update_wm(struct drm_crtc
*unused_crtc
)
1594 struct drm_device
*dev
= unused_crtc
->dev
;
1595 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1596 struct drm_crtc
*crtc
;
1601 /* Calc sr entries for one plane configs */
1602 crtc
= single_enabled_crtc(dev
);
1604 /* self-refresh has much higher latency */
1605 static const int sr_latency_ns
= 12000;
1606 const struct drm_display_mode
*adjusted_mode
=
1607 &to_intel_crtc(crtc
)->config
.adjusted_mode
;
1608 int clock
= adjusted_mode
->crtc_clock
;
1609 int htotal
= adjusted_mode
->crtc_htotal
;
1610 int hdisplay
= to_intel_crtc(crtc
)->config
.pipe_src_w
;
1611 int pixel_size
= crtc
->primary
->fb
->bits_per_pixel
/ 8;
1612 unsigned long line_time_us
;
1615 line_time_us
= max(htotal
* 1000 / clock
, 1);
1617 /* Use ns/us then divide to preserve precision */
1618 entries
= (((sr_latency_ns
/ line_time_us
) + 1000) / 1000) *
1619 pixel_size
* hdisplay
;
1620 entries
= DIV_ROUND_UP(entries
, I915_FIFO_LINE_SIZE
);
1621 srwm
= I965_FIFO_SIZE
- entries
;
1625 DRM_DEBUG_KMS("self-refresh entries: %d, wm: %d\n",
1628 entries
= (((sr_latency_ns
/ line_time_us
) + 1000) / 1000) *
1629 pixel_size
* to_intel_crtc(crtc
)->cursor_width
;
1630 entries
= DIV_ROUND_UP(entries
,
1631 i965_cursor_wm_info
.cacheline_size
);
1632 cursor_sr
= i965_cursor_wm_info
.fifo_size
-
1633 (entries
+ i965_cursor_wm_info
.guard_size
);
1635 if (cursor_sr
> i965_cursor_wm_info
.max_wm
)
1636 cursor_sr
= i965_cursor_wm_info
.max_wm
;
1638 DRM_DEBUG_KMS("self-refresh watermark: display plane %d "
1639 "cursor %d\n", srwm
, cursor_sr
);
1641 cxsr_enabled
= true;
1643 cxsr_enabled
= false;
1644 /* Turn off self refresh if both pipes are enabled */
1645 intel_set_memory_cxsr(dev_priv
, false);
1648 DRM_DEBUG_KMS("Setting FIFO watermarks - A: 8, B: 8, C: 8, SR %d\n",
1651 /* 965 has limitations... */
1652 I915_WRITE(DSPFW1
, (srwm
<< DSPFW_SR_SHIFT
) |
1653 (8 << DSPFW_CURSORB_SHIFT
) |
1654 (8 << DSPFW_PLANEB_SHIFT
) |
1655 (8 << DSPFW_PLANEA_SHIFT
));
1656 I915_WRITE(DSPFW2
, (8 << DSPFW_CURSORA_SHIFT
) |
1657 (8 << DSPFW_PLANEC_SHIFT_OLD
));
1658 /* update cursor SR watermark */
1659 I915_WRITE(DSPFW3
, (cursor_sr
<< DSPFW_CURSOR_SR_SHIFT
));
1662 intel_set_memory_cxsr(dev_priv
, true);
1665 static void i9xx_update_wm(struct drm_crtc
*unused_crtc
)
1667 struct drm_device
*dev
= unused_crtc
->dev
;
1668 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1669 const struct intel_watermark_params
*wm_info
;
1674 int planea_wm
, planeb_wm
;
1675 struct drm_crtc
*crtc
, *enabled
= NULL
;
1678 wm_info
= &i945_wm_info
;
1679 else if (!IS_GEN2(dev
))
1680 wm_info
= &i915_wm_info
;
1682 wm_info
= &i830_wm_info
;
1684 fifo_size
= dev_priv
->display
.get_fifo_size(dev
, 0);
1685 crtc
= intel_get_crtc_for_plane(dev
, 0);
1686 if (intel_crtc_active(crtc
)) {
1687 const struct drm_display_mode
*adjusted_mode
;
1688 int cpp
= crtc
->primary
->fb
->bits_per_pixel
/ 8;
1692 adjusted_mode
= &to_intel_crtc(crtc
)->config
.adjusted_mode
;
1693 planea_wm
= intel_calculate_wm(adjusted_mode
->crtc_clock
,
1694 wm_info
, fifo_size
, cpp
,
1698 planea_wm
= fifo_size
- wm_info
->guard_size
;
1700 fifo_size
= dev_priv
->display
.get_fifo_size(dev
, 1);
1701 crtc
= intel_get_crtc_for_plane(dev
, 1);
1702 if (intel_crtc_active(crtc
)) {
1703 const struct drm_display_mode
*adjusted_mode
;
1704 int cpp
= crtc
->primary
->fb
->bits_per_pixel
/ 8;
1708 adjusted_mode
= &to_intel_crtc(crtc
)->config
.adjusted_mode
;
1709 planeb_wm
= intel_calculate_wm(adjusted_mode
->crtc_clock
,
1710 wm_info
, fifo_size
, cpp
,
1712 if (enabled
== NULL
)
1717 planeb_wm
= fifo_size
- wm_info
->guard_size
;
1719 DRM_DEBUG_KMS("FIFO watermarks - A: %d, B: %d\n", planea_wm
, planeb_wm
);
1721 if (IS_I915GM(dev
) && enabled
) {
1722 struct drm_i915_gem_object
*obj
;
1724 obj
= intel_fb_obj(enabled
->primary
->fb
);
1726 /* self-refresh seems busted with untiled */
1727 if (obj
->tiling_mode
== I915_TILING_NONE
)
1732 * Overlay gets an aggressive default since video jitter is bad.
1736 /* Play safe and disable self-refresh before adjusting watermarks. */
1737 intel_set_memory_cxsr(dev_priv
, false);
1739 /* Calc sr entries for one plane configs */
1740 if (HAS_FW_BLC(dev
) && enabled
) {
1741 /* self-refresh has much higher latency */
1742 static const int sr_latency_ns
= 6000;
1743 const struct drm_display_mode
*adjusted_mode
=
1744 &to_intel_crtc(enabled
)->config
.adjusted_mode
;
1745 int clock
= adjusted_mode
->crtc_clock
;
1746 int htotal
= adjusted_mode
->crtc_htotal
;
1747 int hdisplay
= to_intel_crtc(enabled
)->config
.pipe_src_w
;
1748 int pixel_size
= enabled
->primary
->fb
->bits_per_pixel
/ 8;
1749 unsigned long line_time_us
;
1752 line_time_us
= max(htotal
* 1000 / clock
, 1);
1754 /* Use ns/us then divide to preserve precision */
1755 entries
= (((sr_latency_ns
/ line_time_us
) + 1000) / 1000) *
1756 pixel_size
* hdisplay
;
1757 entries
= DIV_ROUND_UP(entries
, wm_info
->cacheline_size
);
1758 DRM_DEBUG_KMS("self-refresh entries: %d\n", entries
);
1759 srwm
= wm_info
->fifo_size
- entries
;
1763 if (IS_I945G(dev
) || IS_I945GM(dev
))
1764 I915_WRITE(FW_BLC_SELF
,
1765 FW_BLC_SELF_FIFO_MASK
| (srwm
& 0xff));
1766 else if (IS_I915GM(dev
))
1767 I915_WRITE(FW_BLC_SELF
, srwm
& 0x3f);
1770 DRM_DEBUG_KMS("Setting FIFO watermarks - A: %d, B: %d, C: %d, SR %d\n",
1771 planea_wm
, planeb_wm
, cwm
, srwm
);
1773 fwater_lo
= ((planeb_wm
& 0x3f) << 16) | (planea_wm
& 0x3f);
1774 fwater_hi
= (cwm
& 0x1f);
1776 /* Set request length to 8 cachelines per fetch */
1777 fwater_lo
= fwater_lo
| (1 << 24) | (1 << 8);
1778 fwater_hi
= fwater_hi
| (1 << 8);
1780 I915_WRITE(FW_BLC
, fwater_lo
);
1781 I915_WRITE(FW_BLC2
, fwater_hi
);
1784 intel_set_memory_cxsr(dev_priv
, true);
1787 static void i845_update_wm(struct drm_crtc
*unused_crtc
)
1789 struct drm_device
*dev
= unused_crtc
->dev
;
1790 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1791 struct drm_crtc
*crtc
;
1792 const struct drm_display_mode
*adjusted_mode
;
1796 crtc
= single_enabled_crtc(dev
);
1800 adjusted_mode
= &to_intel_crtc(crtc
)->config
.adjusted_mode
;
1801 planea_wm
= intel_calculate_wm(adjusted_mode
->crtc_clock
,
1803 dev_priv
->display
.get_fifo_size(dev
, 0),
1805 fwater_lo
= I915_READ(FW_BLC
) & ~0xfff;
1806 fwater_lo
|= (3<<8) | planea_wm
;
1808 DRM_DEBUG_KMS("Setting FIFO watermarks - A: %d\n", planea_wm
);
1810 I915_WRITE(FW_BLC
, fwater_lo
);
1813 static uint32_t ilk_pipe_pixel_rate(struct drm_device
*dev
,
1814 struct drm_crtc
*crtc
)
1816 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
1817 uint32_t pixel_rate
;
1819 pixel_rate
= intel_crtc
->config
.adjusted_mode
.crtc_clock
;
1821 /* We only use IF-ID interlacing. If we ever use PF-ID we'll need to
1822 * adjust the pixel_rate here. */
1824 if (intel_crtc
->config
.pch_pfit
.enabled
) {
1825 uint64_t pipe_w
, pipe_h
, pfit_w
, pfit_h
;
1826 uint32_t pfit_size
= intel_crtc
->config
.pch_pfit
.size
;
1828 pipe_w
= intel_crtc
->config
.pipe_src_w
;
1829 pipe_h
= intel_crtc
->config
.pipe_src_h
;
1830 pfit_w
= (pfit_size
>> 16) & 0xFFFF;
1831 pfit_h
= pfit_size
& 0xFFFF;
1832 if (pipe_w
< pfit_w
)
1834 if (pipe_h
< pfit_h
)
1837 pixel_rate
= div_u64((uint64_t) pixel_rate
* pipe_w
* pipe_h
,
1844 /* latency must be in 0.1us units. */
1845 static uint32_t ilk_wm_method1(uint32_t pixel_rate
, uint8_t bytes_per_pixel
,
1850 if (WARN(latency
== 0, "Latency value missing\n"))
1853 ret
= (uint64_t) pixel_rate
* bytes_per_pixel
* latency
;
1854 ret
= DIV_ROUND_UP_ULL(ret
, 64 * 10000) + 2;
1859 /* latency must be in 0.1us units. */
1860 static uint32_t ilk_wm_method2(uint32_t pixel_rate
, uint32_t pipe_htotal
,
1861 uint32_t horiz_pixels
, uint8_t bytes_per_pixel
,
1866 if (WARN(latency
== 0, "Latency value missing\n"))
1869 ret
= (latency
* pixel_rate
) / (pipe_htotal
* 10000);
1870 ret
= (ret
+ 1) * horiz_pixels
* bytes_per_pixel
;
1871 ret
= DIV_ROUND_UP(ret
, 64) + 2;
1875 static uint32_t ilk_wm_fbc(uint32_t pri_val
, uint32_t horiz_pixels
,
1876 uint8_t bytes_per_pixel
)
1878 return DIV_ROUND_UP(pri_val
* 64, horiz_pixels
* bytes_per_pixel
) + 2;
1881 struct ilk_pipe_wm_parameters
{
1883 uint32_t pipe_htotal
;
1884 uint32_t pixel_rate
;
1885 struct intel_plane_wm_parameters pri
;
1886 struct intel_plane_wm_parameters spr
;
1887 struct intel_plane_wm_parameters cur
;
1890 struct ilk_wm_maximums
{
1897 /* used in computing the new watermarks state */
1898 struct intel_wm_config
{
1899 unsigned int num_pipes_active
;
1900 bool sprites_enabled
;
1901 bool sprites_scaled
;
1905 * For both WM_PIPE and WM_LP.
1906 * mem_value must be in 0.1us units.
1908 static uint32_t ilk_compute_pri_wm(const struct ilk_pipe_wm_parameters
*params
,
1912 uint32_t method1
, method2
;
1914 if (!params
->active
|| !params
->pri
.enabled
)
1917 method1
= ilk_wm_method1(params
->pixel_rate
,
1918 params
->pri
.bytes_per_pixel
,
1924 method2
= ilk_wm_method2(params
->pixel_rate
,
1925 params
->pipe_htotal
,
1926 params
->pri
.horiz_pixels
,
1927 params
->pri
.bytes_per_pixel
,
1930 return min(method1
, method2
);
1934 * For both WM_PIPE and WM_LP.
1935 * mem_value must be in 0.1us units.
1937 static uint32_t ilk_compute_spr_wm(const struct ilk_pipe_wm_parameters
*params
,
1940 uint32_t method1
, method2
;
1942 if (!params
->active
|| !params
->spr
.enabled
)
1945 method1
= ilk_wm_method1(params
->pixel_rate
,
1946 params
->spr
.bytes_per_pixel
,
1948 method2
= ilk_wm_method2(params
->pixel_rate
,
1949 params
->pipe_htotal
,
1950 params
->spr
.horiz_pixels
,
1951 params
->spr
.bytes_per_pixel
,
1953 return min(method1
, method2
);
1957 * For both WM_PIPE and WM_LP.
1958 * mem_value must be in 0.1us units.
1960 static uint32_t ilk_compute_cur_wm(const struct ilk_pipe_wm_parameters
*params
,
1963 if (!params
->active
|| !params
->cur
.enabled
)
1966 return ilk_wm_method2(params
->pixel_rate
,
1967 params
->pipe_htotal
,
1968 params
->cur
.horiz_pixels
,
1969 params
->cur
.bytes_per_pixel
,
1973 /* Only for WM_LP. */
1974 static uint32_t ilk_compute_fbc_wm(const struct ilk_pipe_wm_parameters
*params
,
1977 if (!params
->active
|| !params
->pri
.enabled
)
1980 return ilk_wm_fbc(pri_val
,
1981 params
->pri
.horiz_pixels
,
1982 params
->pri
.bytes_per_pixel
);
1985 static unsigned int ilk_display_fifo_size(const struct drm_device
*dev
)
1987 if (INTEL_INFO(dev
)->gen
>= 8)
1989 else if (INTEL_INFO(dev
)->gen
>= 7)
1995 static unsigned int ilk_plane_wm_reg_max(const struct drm_device
*dev
,
1996 int level
, bool is_sprite
)
1998 if (INTEL_INFO(dev
)->gen
>= 8)
1999 /* BDW primary/sprite plane watermarks */
2000 return level
== 0 ? 255 : 2047;
2001 else if (INTEL_INFO(dev
)->gen
>= 7)
2002 /* IVB/HSW primary/sprite plane watermarks */
2003 return level
== 0 ? 127 : 1023;
2004 else if (!is_sprite
)
2005 /* ILK/SNB primary plane watermarks */
2006 return level
== 0 ? 127 : 511;
2008 /* ILK/SNB sprite plane watermarks */
2009 return level
== 0 ? 63 : 255;
2012 static unsigned int ilk_cursor_wm_reg_max(const struct drm_device
*dev
,
2015 if (INTEL_INFO(dev
)->gen
>= 7)
2016 return level
== 0 ? 63 : 255;
2018 return level
== 0 ? 31 : 63;
2021 static unsigned int ilk_fbc_wm_reg_max(const struct drm_device
*dev
)
2023 if (INTEL_INFO(dev
)->gen
>= 8)
2029 /* Calculate the maximum primary/sprite plane watermark */
2030 static unsigned int ilk_plane_wm_max(const struct drm_device
*dev
,
2032 const struct intel_wm_config
*config
,
2033 enum intel_ddb_partitioning ddb_partitioning
,
2036 unsigned int fifo_size
= ilk_display_fifo_size(dev
);
2038 /* if sprites aren't enabled, sprites get nothing */
2039 if (is_sprite
&& !config
->sprites_enabled
)
2042 /* HSW allows LP1+ watermarks even with multiple pipes */
2043 if (level
== 0 || config
->num_pipes_active
> 1) {
2044 fifo_size
/= INTEL_INFO(dev
)->num_pipes
;
2047 * For some reason the non self refresh
2048 * FIFO size is only half of the self
2049 * refresh FIFO size on ILK/SNB.
2051 if (INTEL_INFO(dev
)->gen
<= 6)
2055 if (config
->sprites_enabled
) {
2056 /* level 0 is always calculated with 1:1 split */
2057 if (level
> 0 && ddb_partitioning
== INTEL_DDB_PART_5_6
) {
2066 /* clamp to max that the registers can hold */
2067 return min(fifo_size
, ilk_plane_wm_reg_max(dev
, level
, is_sprite
));
2070 /* Calculate the maximum cursor plane watermark */
2071 static unsigned int ilk_cursor_wm_max(const struct drm_device
*dev
,
2073 const struct intel_wm_config
*config
)
2075 /* HSW LP1+ watermarks w/ multiple pipes */
2076 if (level
> 0 && config
->num_pipes_active
> 1)
2079 /* otherwise just report max that registers can hold */
2080 return ilk_cursor_wm_reg_max(dev
, level
);
2083 static void ilk_compute_wm_maximums(const struct drm_device
*dev
,
2085 const struct intel_wm_config
*config
,
2086 enum intel_ddb_partitioning ddb_partitioning
,
2087 struct ilk_wm_maximums
*max
)
2089 max
->pri
= ilk_plane_wm_max(dev
, level
, config
, ddb_partitioning
, false);
2090 max
->spr
= ilk_plane_wm_max(dev
, level
, config
, ddb_partitioning
, true);
2091 max
->cur
= ilk_cursor_wm_max(dev
, level
, config
);
2092 max
->fbc
= ilk_fbc_wm_reg_max(dev
);
2095 static void ilk_compute_wm_reg_maximums(struct drm_device
*dev
,
2097 struct ilk_wm_maximums
*max
)
2099 max
->pri
= ilk_plane_wm_reg_max(dev
, level
, false);
2100 max
->spr
= ilk_plane_wm_reg_max(dev
, level
, true);
2101 max
->cur
= ilk_cursor_wm_reg_max(dev
, level
);
2102 max
->fbc
= ilk_fbc_wm_reg_max(dev
);
2105 static bool ilk_validate_wm_level(int level
,
2106 const struct ilk_wm_maximums
*max
,
2107 struct intel_wm_level
*result
)
2111 /* already determined to be invalid? */
2112 if (!result
->enable
)
2115 result
->enable
= result
->pri_val
<= max
->pri
&&
2116 result
->spr_val
<= max
->spr
&&
2117 result
->cur_val
<= max
->cur
;
2119 ret
= result
->enable
;
2122 * HACK until we can pre-compute everything,
2123 * and thus fail gracefully if LP0 watermarks
2126 if (level
== 0 && !result
->enable
) {
2127 if (result
->pri_val
> max
->pri
)
2128 DRM_DEBUG_KMS("Primary WM%d too large %u (max %u)\n",
2129 level
, result
->pri_val
, max
->pri
);
2130 if (result
->spr_val
> max
->spr
)
2131 DRM_DEBUG_KMS("Sprite WM%d too large %u (max %u)\n",
2132 level
, result
->spr_val
, max
->spr
);
2133 if (result
->cur_val
> max
->cur
)
2134 DRM_DEBUG_KMS("Cursor WM%d too large %u (max %u)\n",
2135 level
, result
->cur_val
, max
->cur
);
2137 result
->pri_val
= min_t(uint32_t, result
->pri_val
, max
->pri
);
2138 result
->spr_val
= min_t(uint32_t, result
->spr_val
, max
->spr
);
2139 result
->cur_val
= min_t(uint32_t, result
->cur_val
, max
->cur
);
2140 result
->enable
= true;
2146 static void ilk_compute_wm_level(const struct drm_i915_private
*dev_priv
,
2148 const struct ilk_pipe_wm_parameters
*p
,
2149 struct intel_wm_level
*result
)
2151 uint16_t pri_latency
= dev_priv
->wm
.pri_latency
[level
];
2152 uint16_t spr_latency
= dev_priv
->wm
.spr_latency
[level
];
2153 uint16_t cur_latency
= dev_priv
->wm
.cur_latency
[level
];
2155 /* WM1+ latency values stored in 0.5us units */
2162 result
->pri_val
= ilk_compute_pri_wm(p
, pri_latency
, level
);
2163 result
->spr_val
= ilk_compute_spr_wm(p
, spr_latency
);
2164 result
->cur_val
= ilk_compute_cur_wm(p
, cur_latency
);
2165 result
->fbc_val
= ilk_compute_fbc_wm(p
, result
->pri_val
);
2166 result
->enable
= true;
2170 hsw_compute_linetime_wm(struct drm_device
*dev
, struct drm_crtc
*crtc
)
2172 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2173 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2174 struct drm_display_mode
*mode
= &intel_crtc
->config
.adjusted_mode
;
2175 u32 linetime
, ips_linetime
;
2177 if (!intel_crtc_active(crtc
))
2180 /* The WM are computed with base on how long it takes to fill a single
2181 * row at the given clock rate, multiplied by 8.
2183 linetime
= DIV_ROUND_CLOSEST(mode
->crtc_htotal
* 1000 * 8,
2185 ips_linetime
= DIV_ROUND_CLOSEST(mode
->crtc_htotal
* 1000 * 8,
2186 intel_ddi_get_cdclk_freq(dev_priv
));
2188 return PIPE_WM_LINETIME_IPS_LINETIME(ips_linetime
) |
2189 PIPE_WM_LINETIME_TIME(linetime
);
2192 static void intel_read_wm_latency(struct drm_device
*dev
, uint16_t wm
[5])
2194 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2196 if (IS_HASWELL(dev
) || IS_BROADWELL(dev
)) {
2197 uint64_t sskpd
= I915_READ64(MCH_SSKPD
);
2199 wm
[0] = (sskpd
>> 56) & 0xFF;
2201 wm
[0] = sskpd
& 0xF;
2202 wm
[1] = (sskpd
>> 4) & 0xFF;
2203 wm
[2] = (sskpd
>> 12) & 0xFF;
2204 wm
[3] = (sskpd
>> 20) & 0x1FF;
2205 wm
[4] = (sskpd
>> 32) & 0x1FF;
2206 } else if (INTEL_INFO(dev
)->gen
>= 6) {
2207 uint32_t sskpd
= I915_READ(MCH_SSKPD
);
2209 wm
[0] = (sskpd
>> SSKPD_WM0_SHIFT
) & SSKPD_WM_MASK
;
2210 wm
[1] = (sskpd
>> SSKPD_WM1_SHIFT
) & SSKPD_WM_MASK
;
2211 wm
[2] = (sskpd
>> SSKPD_WM2_SHIFT
) & SSKPD_WM_MASK
;
2212 wm
[3] = (sskpd
>> SSKPD_WM3_SHIFT
) & SSKPD_WM_MASK
;
2213 } else if (INTEL_INFO(dev
)->gen
>= 5) {
2214 uint32_t mltr
= I915_READ(MLTR_ILK
);
2216 /* ILK primary LP0 latency is 700 ns */
2218 wm
[1] = (mltr
>> MLTR_WM1_SHIFT
) & ILK_SRLT_MASK
;
2219 wm
[2] = (mltr
>> MLTR_WM2_SHIFT
) & ILK_SRLT_MASK
;
2223 static void intel_fixup_spr_wm_latency(struct drm_device
*dev
, uint16_t wm
[5])
2225 /* ILK sprite LP0 latency is 1300 ns */
2226 if (INTEL_INFO(dev
)->gen
== 5)
2230 static void intel_fixup_cur_wm_latency(struct drm_device
*dev
, uint16_t wm
[5])
2232 /* ILK cursor LP0 latency is 1300 ns */
2233 if (INTEL_INFO(dev
)->gen
== 5)
2236 /* WaDoubleCursorLP3Latency:ivb */
2237 if (IS_IVYBRIDGE(dev
))
2241 int ilk_wm_max_level(const struct drm_device
*dev
)
2243 /* how many WM levels are we expecting */
2244 if (IS_HASWELL(dev
) || IS_BROADWELL(dev
))
2246 else if (INTEL_INFO(dev
)->gen
>= 6)
2252 static void intel_print_wm_latency(struct drm_device
*dev
,
2254 const uint16_t wm
[5])
2256 int level
, max_level
= ilk_wm_max_level(dev
);
2258 for (level
= 0; level
<= max_level
; level
++) {
2259 unsigned int latency
= wm
[level
];
2262 DRM_ERROR("%s WM%d latency not provided\n",
2267 /* WM1+ latency values in 0.5us units */
2271 DRM_DEBUG_KMS("%s WM%d latency %u (%u.%u usec)\n",
2272 name
, level
, wm
[level
],
2273 latency
/ 10, latency
% 10);
2277 static bool ilk_increase_wm_latency(struct drm_i915_private
*dev_priv
,
2278 uint16_t wm
[5], uint16_t min
)
2280 int level
, max_level
= ilk_wm_max_level(dev_priv
->dev
);
2285 wm
[0] = max(wm
[0], min
);
2286 for (level
= 1; level
<= max_level
; level
++)
2287 wm
[level
] = max_t(uint16_t, wm
[level
], DIV_ROUND_UP(min
, 5));
2292 static void snb_wm_latency_quirk(struct drm_device
*dev
)
2294 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2298 * The BIOS provided WM memory latency values are often
2299 * inadequate for high resolution displays. Adjust them.
2301 changed
= ilk_increase_wm_latency(dev_priv
, dev_priv
->wm
.pri_latency
, 12) |
2302 ilk_increase_wm_latency(dev_priv
, dev_priv
->wm
.spr_latency
, 12) |
2303 ilk_increase_wm_latency(dev_priv
, dev_priv
->wm
.cur_latency
, 12);
2308 DRM_DEBUG_KMS("WM latency values increased to avoid potential underruns\n");
2309 intel_print_wm_latency(dev
, "Primary", dev_priv
->wm
.pri_latency
);
2310 intel_print_wm_latency(dev
, "Sprite", dev_priv
->wm
.spr_latency
);
2311 intel_print_wm_latency(dev
, "Cursor", dev_priv
->wm
.cur_latency
);
2314 static void ilk_setup_wm_latency(struct drm_device
*dev
)
2316 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2318 intel_read_wm_latency(dev
, dev_priv
->wm
.pri_latency
);
2320 memcpy(dev_priv
->wm
.spr_latency
, dev_priv
->wm
.pri_latency
,
2321 sizeof(dev_priv
->wm
.pri_latency
));
2322 memcpy(dev_priv
->wm
.cur_latency
, dev_priv
->wm
.pri_latency
,
2323 sizeof(dev_priv
->wm
.pri_latency
));
2325 intel_fixup_spr_wm_latency(dev
, dev_priv
->wm
.spr_latency
);
2326 intel_fixup_cur_wm_latency(dev
, dev_priv
->wm
.cur_latency
);
2328 intel_print_wm_latency(dev
, "Primary", dev_priv
->wm
.pri_latency
);
2329 intel_print_wm_latency(dev
, "Sprite", dev_priv
->wm
.spr_latency
);
2330 intel_print_wm_latency(dev
, "Cursor", dev_priv
->wm
.cur_latency
);
2333 snb_wm_latency_quirk(dev
);
2336 static void ilk_compute_wm_parameters(struct drm_crtc
*crtc
,
2337 struct ilk_pipe_wm_parameters
*p
)
2339 struct drm_device
*dev
= crtc
->dev
;
2340 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2341 enum pipe pipe
= intel_crtc
->pipe
;
2342 struct drm_plane
*plane
;
2344 if (!intel_crtc_active(crtc
))
2348 p
->pipe_htotal
= intel_crtc
->config
.adjusted_mode
.crtc_htotal
;
2349 p
->pixel_rate
= ilk_pipe_pixel_rate(dev
, crtc
);
2350 p
->pri
.bytes_per_pixel
= crtc
->primary
->fb
->bits_per_pixel
/ 8;
2351 p
->cur
.bytes_per_pixel
= 4;
2352 p
->pri
.horiz_pixels
= intel_crtc
->config
.pipe_src_w
;
2353 p
->cur
.horiz_pixels
= intel_crtc
->cursor_width
;
2354 /* TODO: for now, assume primary and cursor planes are always enabled. */
2355 p
->pri
.enabled
= true;
2356 p
->cur
.enabled
= true;
2358 drm_for_each_legacy_plane(plane
, &dev
->mode_config
.plane_list
) {
2359 struct intel_plane
*intel_plane
= to_intel_plane(plane
);
2361 if (intel_plane
->pipe
== pipe
) {
2362 p
->spr
= intel_plane
->wm
;
2368 static void ilk_compute_wm_config(struct drm_device
*dev
,
2369 struct intel_wm_config
*config
)
2371 struct intel_crtc
*intel_crtc
;
2373 /* Compute the currently _active_ config */
2374 for_each_intel_crtc(dev
, intel_crtc
) {
2375 const struct intel_pipe_wm
*wm
= &intel_crtc
->wm
.active
;
2377 if (!wm
->pipe_enabled
)
2380 config
->sprites_enabled
|= wm
->sprites_enabled
;
2381 config
->sprites_scaled
|= wm
->sprites_scaled
;
2382 config
->num_pipes_active
++;
2386 /* Compute new watermarks for the pipe */
2387 static bool intel_compute_pipe_wm(struct drm_crtc
*crtc
,
2388 const struct ilk_pipe_wm_parameters
*params
,
2389 struct intel_pipe_wm
*pipe_wm
)
2391 struct drm_device
*dev
= crtc
->dev
;
2392 const struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2393 int level
, max_level
= ilk_wm_max_level(dev
);
2394 /* LP0 watermark maximums depend on this pipe alone */
2395 struct intel_wm_config config
= {
2396 .num_pipes_active
= 1,
2397 .sprites_enabled
= params
->spr
.enabled
,
2398 .sprites_scaled
= params
->spr
.scaled
,
2400 struct ilk_wm_maximums max
;
2402 pipe_wm
->pipe_enabled
= params
->active
;
2403 pipe_wm
->sprites_enabled
= params
->spr
.enabled
;
2404 pipe_wm
->sprites_scaled
= params
->spr
.scaled
;
2406 /* ILK/SNB: LP2+ watermarks only w/o sprites */
2407 if (INTEL_INFO(dev
)->gen
<= 6 && params
->spr
.enabled
)
2410 /* ILK/SNB/IVB: LP1+ watermarks only w/o scaling */
2411 if (params
->spr
.scaled
)
2414 ilk_compute_wm_level(dev_priv
, 0, params
, &pipe_wm
->wm
[0]);
2416 if (IS_HASWELL(dev
) || IS_BROADWELL(dev
))
2417 pipe_wm
->linetime
= hsw_compute_linetime_wm(dev
, crtc
);
2419 /* LP0 watermarks always use 1/2 DDB partitioning */
2420 ilk_compute_wm_maximums(dev
, 0, &config
, INTEL_DDB_PART_1_2
, &max
);
2422 /* At least LP0 must be valid */
2423 if (!ilk_validate_wm_level(0, &max
, &pipe_wm
->wm
[0]))
2426 ilk_compute_wm_reg_maximums(dev
, 1, &max
);
2428 for (level
= 1; level
<= max_level
; level
++) {
2429 struct intel_wm_level wm
= {};
2431 ilk_compute_wm_level(dev_priv
, level
, params
, &wm
);
2434 * Disable any watermark level that exceeds the
2435 * register maximums since such watermarks are
2438 if (!ilk_validate_wm_level(level
, &max
, &wm
))
2441 pipe_wm
->wm
[level
] = wm
;
2448 * Merge the watermarks from all active pipes for a specific level.
2450 static void ilk_merge_wm_level(struct drm_device
*dev
,
2452 struct intel_wm_level
*ret_wm
)
2454 const struct intel_crtc
*intel_crtc
;
2456 ret_wm
->enable
= true;
2458 for_each_intel_crtc(dev
, intel_crtc
) {
2459 const struct intel_pipe_wm
*active
= &intel_crtc
->wm
.active
;
2460 const struct intel_wm_level
*wm
= &active
->wm
[level
];
2462 if (!active
->pipe_enabled
)
2466 * The watermark values may have been used in the past,
2467 * so we must maintain them in the registers for some
2468 * time even if the level is now disabled.
2471 ret_wm
->enable
= false;
2473 ret_wm
->pri_val
= max(ret_wm
->pri_val
, wm
->pri_val
);
2474 ret_wm
->spr_val
= max(ret_wm
->spr_val
, wm
->spr_val
);
2475 ret_wm
->cur_val
= max(ret_wm
->cur_val
, wm
->cur_val
);
2476 ret_wm
->fbc_val
= max(ret_wm
->fbc_val
, wm
->fbc_val
);
2481 * Merge all low power watermarks for all active pipes.
2483 static void ilk_wm_merge(struct drm_device
*dev
,
2484 const struct intel_wm_config
*config
,
2485 const struct ilk_wm_maximums
*max
,
2486 struct intel_pipe_wm
*merged
)
2488 int level
, max_level
= ilk_wm_max_level(dev
);
2489 int last_enabled_level
= max_level
;
2491 /* ILK/SNB/IVB: LP1+ watermarks only w/ single pipe */
2492 if ((INTEL_INFO(dev
)->gen
<= 6 || IS_IVYBRIDGE(dev
)) &&
2493 config
->num_pipes_active
> 1)
2496 /* ILK: FBC WM must be disabled always */
2497 merged
->fbc_wm_enabled
= INTEL_INFO(dev
)->gen
>= 6;
2499 /* merge each WM1+ level */
2500 for (level
= 1; level
<= max_level
; level
++) {
2501 struct intel_wm_level
*wm
= &merged
->wm
[level
];
2503 ilk_merge_wm_level(dev
, level
, wm
);
2505 if (level
> last_enabled_level
)
2507 else if (!ilk_validate_wm_level(level
, max
, wm
))
2508 /* make sure all following levels get disabled */
2509 last_enabled_level
= level
- 1;
2512 * The spec says it is preferred to disable
2513 * FBC WMs instead of disabling a WM level.
2515 if (wm
->fbc_val
> max
->fbc
) {
2517 merged
->fbc_wm_enabled
= false;
2522 /* ILK: LP2+ must be disabled when FBC WM is disabled but FBC enabled */
2524 * FIXME this is racy. FBC might get enabled later.
2525 * What we should check here is whether FBC can be
2526 * enabled sometime later.
2528 if (IS_GEN5(dev
) && !merged
->fbc_wm_enabled
&& intel_fbc_enabled(dev
)) {
2529 for (level
= 2; level
<= max_level
; level
++) {
2530 struct intel_wm_level
*wm
= &merged
->wm
[level
];
2537 static int ilk_wm_lp_to_level(int wm_lp
, const struct intel_pipe_wm
*pipe_wm
)
2539 /* LP1,LP2,LP3 levels are either 1,2,3 or 1,3,4 */
2540 return wm_lp
+ (wm_lp
>= 2 && pipe_wm
->wm
[4].enable
);
2543 /* The value we need to program into the WM_LPx latency field */
2544 static unsigned int ilk_wm_lp_latency(struct drm_device
*dev
, int level
)
2546 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2548 if (IS_HASWELL(dev
) || IS_BROADWELL(dev
))
2551 return dev_priv
->wm
.pri_latency
[level
];
2554 static void ilk_compute_wm_results(struct drm_device
*dev
,
2555 const struct intel_pipe_wm
*merged
,
2556 enum intel_ddb_partitioning partitioning
,
2557 struct ilk_wm_values
*results
)
2559 struct intel_crtc
*intel_crtc
;
2562 results
->enable_fbc_wm
= merged
->fbc_wm_enabled
;
2563 results
->partitioning
= partitioning
;
2565 /* LP1+ register values */
2566 for (wm_lp
= 1; wm_lp
<= 3; wm_lp
++) {
2567 const struct intel_wm_level
*r
;
2569 level
= ilk_wm_lp_to_level(wm_lp
, merged
);
2571 r
= &merged
->wm
[level
];
2574 * Maintain the watermark values even if the level is
2575 * disabled. Doing otherwise could cause underruns.
2577 results
->wm_lp
[wm_lp
- 1] =
2578 (ilk_wm_lp_latency(dev
, level
) << WM1_LP_LATENCY_SHIFT
) |
2579 (r
->pri_val
<< WM1_LP_SR_SHIFT
) |
2583 results
->wm_lp
[wm_lp
- 1] |= WM1_LP_SR_EN
;
2585 if (INTEL_INFO(dev
)->gen
>= 8)
2586 results
->wm_lp
[wm_lp
- 1] |=
2587 r
->fbc_val
<< WM1_LP_FBC_SHIFT_BDW
;
2589 results
->wm_lp
[wm_lp
- 1] |=
2590 r
->fbc_val
<< WM1_LP_FBC_SHIFT
;
2593 * Always set WM1S_LP_EN when spr_val != 0, even if the
2594 * level is disabled. Doing otherwise could cause underruns.
2596 if (INTEL_INFO(dev
)->gen
<= 6 && r
->spr_val
) {
2597 WARN_ON(wm_lp
!= 1);
2598 results
->wm_lp_spr
[wm_lp
- 1] = WM1S_LP_EN
| r
->spr_val
;
2600 results
->wm_lp_spr
[wm_lp
- 1] = r
->spr_val
;
2603 /* LP0 register values */
2604 for_each_intel_crtc(dev
, intel_crtc
) {
2605 enum pipe pipe
= intel_crtc
->pipe
;
2606 const struct intel_wm_level
*r
=
2607 &intel_crtc
->wm
.active
.wm
[0];
2609 if (WARN_ON(!r
->enable
))
2612 results
->wm_linetime
[pipe
] = intel_crtc
->wm
.active
.linetime
;
2614 results
->wm_pipe
[pipe
] =
2615 (r
->pri_val
<< WM0_PIPE_PLANE_SHIFT
) |
2616 (r
->spr_val
<< WM0_PIPE_SPRITE_SHIFT
) |
2621 /* Find the result with the highest level enabled. Check for enable_fbc_wm in
2622 * case both are at the same level. Prefer r1 in case they're the same. */
2623 static struct intel_pipe_wm
*ilk_find_best_result(struct drm_device
*dev
,
2624 struct intel_pipe_wm
*r1
,
2625 struct intel_pipe_wm
*r2
)
2627 int level
, max_level
= ilk_wm_max_level(dev
);
2628 int level1
= 0, level2
= 0;
2630 for (level
= 1; level
<= max_level
; level
++) {
2631 if (r1
->wm
[level
].enable
)
2633 if (r2
->wm
[level
].enable
)
2637 if (level1
== level2
) {
2638 if (r2
->fbc_wm_enabled
&& !r1
->fbc_wm_enabled
)
2642 } else if (level1
> level2
) {
2649 /* dirty bits used to track which watermarks need changes */
2650 #define WM_DIRTY_PIPE(pipe) (1 << (pipe))
2651 #define WM_DIRTY_LINETIME(pipe) (1 << (8 + (pipe)))
2652 #define WM_DIRTY_LP(wm_lp) (1 << (15 + (wm_lp)))
2653 #define WM_DIRTY_LP_ALL (WM_DIRTY_LP(1) | WM_DIRTY_LP(2) | WM_DIRTY_LP(3))
2654 #define WM_DIRTY_FBC (1 << 24)
2655 #define WM_DIRTY_DDB (1 << 25)
2657 static unsigned int ilk_compute_wm_dirty(struct drm_i915_private
*dev_priv
,
2658 const struct ilk_wm_values
*old
,
2659 const struct ilk_wm_values
*new)
2661 unsigned int dirty
= 0;
2665 for_each_pipe(dev_priv
, pipe
) {
2666 if (old
->wm_linetime
[pipe
] != new->wm_linetime
[pipe
]) {
2667 dirty
|= WM_DIRTY_LINETIME(pipe
);
2668 /* Must disable LP1+ watermarks too */
2669 dirty
|= WM_DIRTY_LP_ALL
;
2672 if (old
->wm_pipe
[pipe
] != new->wm_pipe
[pipe
]) {
2673 dirty
|= WM_DIRTY_PIPE(pipe
);
2674 /* Must disable LP1+ watermarks too */
2675 dirty
|= WM_DIRTY_LP_ALL
;
2679 if (old
->enable_fbc_wm
!= new->enable_fbc_wm
) {
2680 dirty
|= WM_DIRTY_FBC
;
2681 /* Must disable LP1+ watermarks too */
2682 dirty
|= WM_DIRTY_LP_ALL
;
2685 if (old
->partitioning
!= new->partitioning
) {
2686 dirty
|= WM_DIRTY_DDB
;
2687 /* Must disable LP1+ watermarks too */
2688 dirty
|= WM_DIRTY_LP_ALL
;
2691 /* LP1+ watermarks already deemed dirty, no need to continue */
2692 if (dirty
& WM_DIRTY_LP_ALL
)
2695 /* Find the lowest numbered LP1+ watermark in need of an update... */
2696 for (wm_lp
= 1; wm_lp
<= 3; wm_lp
++) {
2697 if (old
->wm_lp
[wm_lp
- 1] != new->wm_lp
[wm_lp
- 1] ||
2698 old
->wm_lp_spr
[wm_lp
- 1] != new->wm_lp_spr
[wm_lp
- 1])
2702 /* ...and mark it and all higher numbered LP1+ watermarks as dirty */
2703 for (; wm_lp
<= 3; wm_lp
++)
2704 dirty
|= WM_DIRTY_LP(wm_lp
);
2709 static bool _ilk_disable_lp_wm(struct drm_i915_private
*dev_priv
,
2712 struct ilk_wm_values
*previous
= &dev_priv
->wm
.hw
;
2713 bool changed
= false;
2715 if (dirty
& WM_DIRTY_LP(3) && previous
->wm_lp
[2] & WM1_LP_SR_EN
) {
2716 previous
->wm_lp
[2] &= ~WM1_LP_SR_EN
;
2717 I915_WRITE(WM3_LP_ILK
, previous
->wm_lp
[2]);
2720 if (dirty
& WM_DIRTY_LP(2) && previous
->wm_lp
[1] & WM1_LP_SR_EN
) {
2721 previous
->wm_lp
[1] &= ~WM1_LP_SR_EN
;
2722 I915_WRITE(WM2_LP_ILK
, previous
->wm_lp
[1]);
2725 if (dirty
& WM_DIRTY_LP(1) && previous
->wm_lp
[0] & WM1_LP_SR_EN
) {
2726 previous
->wm_lp
[0] &= ~WM1_LP_SR_EN
;
2727 I915_WRITE(WM1_LP_ILK
, previous
->wm_lp
[0]);
2732 * Don't touch WM1S_LP_EN here.
2733 * Doing so could cause underruns.
2740 * The spec says we shouldn't write when we don't need, because every write
2741 * causes WMs to be re-evaluated, expending some power.
2743 static void ilk_write_wm_values(struct drm_i915_private
*dev_priv
,
2744 struct ilk_wm_values
*results
)
2746 struct drm_device
*dev
= dev_priv
->dev
;
2747 struct ilk_wm_values
*previous
= &dev_priv
->wm
.hw
;
2751 dirty
= ilk_compute_wm_dirty(dev_priv
, previous
, results
);
2755 _ilk_disable_lp_wm(dev_priv
, dirty
);
2757 if (dirty
& WM_DIRTY_PIPE(PIPE_A
))
2758 I915_WRITE(WM0_PIPEA_ILK
, results
->wm_pipe
[0]);
2759 if (dirty
& WM_DIRTY_PIPE(PIPE_B
))
2760 I915_WRITE(WM0_PIPEB_ILK
, results
->wm_pipe
[1]);
2761 if (dirty
& WM_DIRTY_PIPE(PIPE_C
))
2762 I915_WRITE(WM0_PIPEC_IVB
, results
->wm_pipe
[2]);
2764 if (dirty
& WM_DIRTY_LINETIME(PIPE_A
))
2765 I915_WRITE(PIPE_WM_LINETIME(PIPE_A
), results
->wm_linetime
[0]);
2766 if (dirty
& WM_DIRTY_LINETIME(PIPE_B
))
2767 I915_WRITE(PIPE_WM_LINETIME(PIPE_B
), results
->wm_linetime
[1]);
2768 if (dirty
& WM_DIRTY_LINETIME(PIPE_C
))
2769 I915_WRITE(PIPE_WM_LINETIME(PIPE_C
), results
->wm_linetime
[2]);
2771 if (dirty
& WM_DIRTY_DDB
) {
2772 if (IS_HASWELL(dev
) || IS_BROADWELL(dev
)) {
2773 val
= I915_READ(WM_MISC
);
2774 if (results
->partitioning
== INTEL_DDB_PART_1_2
)
2775 val
&= ~WM_MISC_DATA_PARTITION_5_6
;
2777 val
|= WM_MISC_DATA_PARTITION_5_6
;
2778 I915_WRITE(WM_MISC
, val
);
2780 val
= I915_READ(DISP_ARB_CTL2
);
2781 if (results
->partitioning
== INTEL_DDB_PART_1_2
)
2782 val
&= ~DISP_DATA_PARTITION_5_6
;
2784 val
|= DISP_DATA_PARTITION_5_6
;
2785 I915_WRITE(DISP_ARB_CTL2
, val
);
2789 if (dirty
& WM_DIRTY_FBC
) {
2790 val
= I915_READ(DISP_ARB_CTL
);
2791 if (results
->enable_fbc_wm
)
2792 val
&= ~DISP_FBC_WM_DIS
;
2794 val
|= DISP_FBC_WM_DIS
;
2795 I915_WRITE(DISP_ARB_CTL
, val
);
2798 if (dirty
& WM_DIRTY_LP(1) &&
2799 previous
->wm_lp_spr
[0] != results
->wm_lp_spr
[0])
2800 I915_WRITE(WM1S_LP_ILK
, results
->wm_lp_spr
[0]);
2802 if (INTEL_INFO(dev
)->gen
>= 7) {
2803 if (dirty
& WM_DIRTY_LP(2) && previous
->wm_lp_spr
[1] != results
->wm_lp_spr
[1])
2804 I915_WRITE(WM2S_LP_IVB
, results
->wm_lp_spr
[1]);
2805 if (dirty
& WM_DIRTY_LP(3) && previous
->wm_lp_spr
[2] != results
->wm_lp_spr
[2])
2806 I915_WRITE(WM3S_LP_IVB
, results
->wm_lp_spr
[2]);
2809 if (dirty
& WM_DIRTY_LP(1) && previous
->wm_lp
[0] != results
->wm_lp
[0])
2810 I915_WRITE(WM1_LP_ILK
, results
->wm_lp
[0]);
2811 if (dirty
& WM_DIRTY_LP(2) && previous
->wm_lp
[1] != results
->wm_lp
[1])
2812 I915_WRITE(WM2_LP_ILK
, results
->wm_lp
[1]);
2813 if (dirty
& WM_DIRTY_LP(3) && previous
->wm_lp
[2] != results
->wm_lp
[2])
2814 I915_WRITE(WM3_LP_ILK
, results
->wm_lp
[2]);
2816 dev_priv
->wm
.hw
= *results
;
2819 static bool ilk_disable_lp_wm(struct drm_device
*dev
)
2821 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2823 return _ilk_disable_lp_wm(dev_priv
, WM_DIRTY_LP_ALL
);
2826 static void ilk_update_wm(struct drm_crtc
*crtc
)
2828 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2829 struct drm_device
*dev
= crtc
->dev
;
2830 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2831 struct ilk_wm_maximums max
;
2832 struct ilk_pipe_wm_parameters params
= {};
2833 struct ilk_wm_values results
= {};
2834 enum intel_ddb_partitioning partitioning
;
2835 struct intel_pipe_wm pipe_wm
= {};
2836 struct intel_pipe_wm lp_wm_1_2
= {}, lp_wm_5_6
= {}, *best_lp_wm
;
2837 struct intel_wm_config config
= {};
2839 ilk_compute_wm_parameters(crtc
, ¶ms
);
2841 intel_compute_pipe_wm(crtc
, ¶ms
, &pipe_wm
);
2843 if (!memcmp(&intel_crtc
->wm
.active
, &pipe_wm
, sizeof(pipe_wm
)))
2846 intel_crtc
->wm
.active
= pipe_wm
;
2848 ilk_compute_wm_config(dev
, &config
);
2850 ilk_compute_wm_maximums(dev
, 1, &config
, INTEL_DDB_PART_1_2
, &max
);
2851 ilk_wm_merge(dev
, &config
, &max
, &lp_wm_1_2
);
2853 /* 5/6 split only in single pipe config on IVB+ */
2854 if (INTEL_INFO(dev
)->gen
>= 7 &&
2855 config
.num_pipes_active
== 1 && config
.sprites_enabled
) {
2856 ilk_compute_wm_maximums(dev
, 1, &config
, INTEL_DDB_PART_5_6
, &max
);
2857 ilk_wm_merge(dev
, &config
, &max
, &lp_wm_5_6
);
2859 best_lp_wm
= ilk_find_best_result(dev
, &lp_wm_1_2
, &lp_wm_5_6
);
2861 best_lp_wm
= &lp_wm_1_2
;
2864 partitioning
= (best_lp_wm
== &lp_wm_1_2
) ?
2865 INTEL_DDB_PART_1_2
: INTEL_DDB_PART_5_6
;
2867 ilk_compute_wm_results(dev
, best_lp_wm
, partitioning
, &results
);
2869 ilk_write_wm_values(dev_priv
, &results
);
2873 ilk_update_sprite_wm(struct drm_plane
*plane
,
2874 struct drm_crtc
*crtc
,
2875 uint32_t sprite_width
, uint32_t sprite_height
,
2876 int pixel_size
, bool enabled
, bool scaled
)
2878 struct drm_device
*dev
= plane
->dev
;
2879 struct intel_plane
*intel_plane
= to_intel_plane(plane
);
2881 intel_plane
->wm
.enabled
= enabled
;
2882 intel_plane
->wm
.scaled
= scaled
;
2883 intel_plane
->wm
.horiz_pixels
= sprite_width
;
2884 intel_plane
->wm
.vert_pixels
= sprite_width
;
2885 intel_plane
->wm
.bytes_per_pixel
= pixel_size
;
2888 * IVB workaround: must disable low power watermarks for at least
2889 * one frame before enabling scaling. LP watermarks can be re-enabled
2890 * when scaling is disabled.
2892 * WaCxSRDisabledForSpriteScaling:ivb
2894 if (IS_IVYBRIDGE(dev
) && scaled
&& ilk_disable_lp_wm(dev
))
2895 intel_wait_for_vblank(dev
, intel_plane
->pipe
);
2897 ilk_update_wm(crtc
);
2900 static void ilk_pipe_wm_get_hw_state(struct drm_crtc
*crtc
)
2902 struct drm_device
*dev
= crtc
->dev
;
2903 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2904 struct ilk_wm_values
*hw
= &dev_priv
->wm
.hw
;
2905 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2906 struct intel_pipe_wm
*active
= &intel_crtc
->wm
.active
;
2907 enum pipe pipe
= intel_crtc
->pipe
;
2908 static const unsigned int wm0_pipe_reg
[] = {
2909 [PIPE_A
] = WM0_PIPEA_ILK
,
2910 [PIPE_B
] = WM0_PIPEB_ILK
,
2911 [PIPE_C
] = WM0_PIPEC_IVB
,
2914 hw
->wm_pipe
[pipe
] = I915_READ(wm0_pipe_reg
[pipe
]);
2915 if (IS_HASWELL(dev
) || IS_BROADWELL(dev
))
2916 hw
->wm_linetime
[pipe
] = I915_READ(PIPE_WM_LINETIME(pipe
));
2918 active
->pipe_enabled
= intel_crtc_active(crtc
);
2920 if (active
->pipe_enabled
) {
2921 u32 tmp
= hw
->wm_pipe
[pipe
];
2924 * For active pipes LP0 watermark is marked as
2925 * enabled, and LP1+ watermaks as disabled since
2926 * we can't really reverse compute them in case
2927 * multiple pipes are active.
2929 active
->wm
[0].enable
= true;
2930 active
->wm
[0].pri_val
= (tmp
& WM0_PIPE_PLANE_MASK
) >> WM0_PIPE_PLANE_SHIFT
;
2931 active
->wm
[0].spr_val
= (tmp
& WM0_PIPE_SPRITE_MASK
) >> WM0_PIPE_SPRITE_SHIFT
;
2932 active
->wm
[0].cur_val
= tmp
& WM0_PIPE_CURSOR_MASK
;
2933 active
->linetime
= hw
->wm_linetime
[pipe
];
2935 int level
, max_level
= ilk_wm_max_level(dev
);
2938 * For inactive pipes, all watermark levels
2939 * should be marked as enabled but zeroed,
2940 * which is what we'd compute them to.
2942 for (level
= 0; level
<= max_level
; level
++)
2943 active
->wm
[level
].enable
= true;
2947 void ilk_wm_get_hw_state(struct drm_device
*dev
)
2949 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2950 struct ilk_wm_values
*hw
= &dev_priv
->wm
.hw
;
2951 struct drm_crtc
*crtc
;
2953 for_each_crtc(dev
, crtc
)
2954 ilk_pipe_wm_get_hw_state(crtc
);
2956 hw
->wm_lp
[0] = I915_READ(WM1_LP_ILK
);
2957 hw
->wm_lp
[1] = I915_READ(WM2_LP_ILK
);
2958 hw
->wm_lp
[2] = I915_READ(WM3_LP_ILK
);
2960 hw
->wm_lp_spr
[0] = I915_READ(WM1S_LP_ILK
);
2961 if (INTEL_INFO(dev
)->gen
>= 7) {
2962 hw
->wm_lp_spr
[1] = I915_READ(WM2S_LP_IVB
);
2963 hw
->wm_lp_spr
[2] = I915_READ(WM3S_LP_IVB
);
2966 if (IS_HASWELL(dev
) || IS_BROADWELL(dev
))
2967 hw
->partitioning
= (I915_READ(WM_MISC
) & WM_MISC_DATA_PARTITION_5_6
) ?
2968 INTEL_DDB_PART_5_6
: INTEL_DDB_PART_1_2
;
2969 else if (IS_IVYBRIDGE(dev
))
2970 hw
->partitioning
= (I915_READ(DISP_ARB_CTL2
) & DISP_DATA_PARTITION_5_6
) ?
2971 INTEL_DDB_PART_5_6
: INTEL_DDB_PART_1_2
;
2974 !(I915_READ(DISP_ARB_CTL
) & DISP_FBC_WM_DIS
);
2978 * intel_update_watermarks - update FIFO watermark values based on current modes
2980 * Calculate watermark values for the various WM regs based on current mode
2981 * and plane configuration.
2983 * There are several cases to deal with here:
2984 * - normal (i.e. non-self-refresh)
2985 * - self-refresh (SR) mode
2986 * - lines are large relative to FIFO size (buffer can hold up to 2)
2987 * - lines are small relative to FIFO size (buffer can hold more than 2
2988 * lines), so need to account for TLB latency
2990 * The normal calculation is:
2991 * watermark = dotclock * bytes per pixel * latency
2992 * where latency is platform & configuration dependent (we assume pessimal
2995 * The SR calculation is:
2996 * watermark = (trunc(latency/line time)+1) * surface width *
2999 * line time = htotal / dotclock
3000 * surface width = hdisplay for normal plane and 64 for cursor
3001 * and latency is assumed to be high, as above.
3003 * The final value programmed to the register should always be rounded up,
3004 * and include an extra 2 entries to account for clock crossings.
3006 * We don't use the sprite, so we can ignore that. And on Crestline we have
3007 * to set the non-SR watermarks to 8.
3009 void intel_update_watermarks(struct drm_crtc
*crtc
)
3011 struct drm_i915_private
*dev_priv
= crtc
->dev
->dev_private
;
3013 if (dev_priv
->display
.update_wm
)
3014 dev_priv
->display
.update_wm(crtc
);
3017 void intel_update_sprite_watermarks(struct drm_plane
*plane
,
3018 struct drm_crtc
*crtc
,
3019 uint32_t sprite_width
,
3020 uint32_t sprite_height
,
3022 bool enabled
, bool scaled
)
3024 struct drm_i915_private
*dev_priv
= plane
->dev
->dev_private
;
3026 if (dev_priv
->display
.update_sprite_wm
)
3027 dev_priv
->display
.update_sprite_wm(plane
, crtc
,
3028 sprite_width
, sprite_height
,
3029 pixel_size
, enabled
, scaled
);
3032 static struct drm_i915_gem_object
*
3033 intel_alloc_context_page(struct drm_device
*dev
)
3035 struct drm_i915_gem_object
*ctx
;
3038 WARN_ON(!mutex_is_locked(&dev
->struct_mutex
));
3040 ctx
= i915_gem_alloc_object(dev
, 4096);
3042 DRM_DEBUG("failed to alloc power context, RC6 disabled\n");
3046 ret
= i915_gem_obj_ggtt_pin(ctx
, 4096, 0);
3048 DRM_ERROR("failed to pin power context: %d\n", ret
);
3052 ret
= i915_gem_object_set_to_gtt_domain(ctx
, 1);
3054 DRM_ERROR("failed to set-domain on power context: %d\n", ret
);
3061 i915_gem_object_ggtt_unpin(ctx
);
3063 drm_gem_object_unreference(&ctx
->base
);
3068 * Lock protecting IPS related data structures
3070 DEFINE_SPINLOCK(mchdev_lock
);
3072 /* Global for IPS driver to get at the current i915 device. Protected by
3074 static struct drm_i915_private
*i915_mch_dev
;
3076 bool ironlake_set_drps(struct drm_device
*dev
, u8 val
)
3078 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3081 assert_spin_locked(&mchdev_lock
);
3083 rgvswctl
= I915_READ16(MEMSWCTL
);
3084 if (rgvswctl
& MEMCTL_CMD_STS
) {
3085 DRM_DEBUG("gpu busy, RCS change rejected\n");
3086 return false; /* still busy with another command */
3089 rgvswctl
= (MEMCTL_CMD_CHFREQ
<< MEMCTL_CMD_SHIFT
) |
3090 (val
<< MEMCTL_FREQ_SHIFT
) | MEMCTL_SFCAVM
;
3091 I915_WRITE16(MEMSWCTL
, rgvswctl
);
3092 POSTING_READ16(MEMSWCTL
);
3094 rgvswctl
|= MEMCTL_CMD_STS
;
3095 I915_WRITE16(MEMSWCTL
, rgvswctl
);
3100 static void ironlake_enable_drps(struct drm_device
*dev
)
3102 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3103 u32 rgvmodectl
= I915_READ(MEMMODECTL
);
3104 u8 fmax
, fmin
, fstart
, vstart
;
3106 spin_lock_irq(&mchdev_lock
);
3108 /* Enable temp reporting */
3109 I915_WRITE16(PMMISC
, I915_READ(PMMISC
) | MCPPCE_EN
);
3110 I915_WRITE16(TSC1
, I915_READ(TSC1
) | TSE
);
3112 /* 100ms RC evaluation intervals */
3113 I915_WRITE(RCUPEI
, 100000);
3114 I915_WRITE(RCDNEI
, 100000);
3116 /* Set max/min thresholds to 90ms and 80ms respectively */
3117 I915_WRITE(RCBMAXAVG
, 90000);
3118 I915_WRITE(RCBMINAVG
, 80000);
3120 I915_WRITE(MEMIHYST
, 1);
3122 /* Set up min, max, and cur for interrupt handling */
3123 fmax
= (rgvmodectl
& MEMMODE_FMAX_MASK
) >> MEMMODE_FMAX_SHIFT
;
3124 fmin
= (rgvmodectl
& MEMMODE_FMIN_MASK
);
3125 fstart
= (rgvmodectl
& MEMMODE_FSTART_MASK
) >>
3126 MEMMODE_FSTART_SHIFT
;
3128 vstart
= (I915_READ(PXVFREQ_BASE
+ (fstart
* 4)) & PXVFREQ_PX_MASK
) >>
3131 dev_priv
->ips
.fmax
= fmax
; /* IPS callback will increase this */
3132 dev_priv
->ips
.fstart
= fstart
;
3134 dev_priv
->ips
.max_delay
= fstart
;
3135 dev_priv
->ips
.min_delay
= fmin
;
3136 dev_priv
->ips
.cur_delay
= fstart
;
3138 DRM_DEBUG_DRIVER("fmax: %d, fmin: %d, fstart: %d\n",
3139 fmax
, fmin
, fstart
);
3141 I915_WRITE(MEMINTREN
, MEMINT_CX_SUPR_EN
| MEMINT_EVAL_CHG_EN
);
3144 * Interrupts will be enabled in ironlake_irq_postinstall
3147 I915_WRITE(VIDSTART
, vstart
);
3148 POSTING_READ(VIDSTART
);
3150 rgvmodectl
|= MEMMODE_SWMODE_EN
;
3151 I915_WRITE(MEMMODECTL
, rgvmodectl
);
3153 if (wait_for_atomic((I915_READ(MEMSWCTL
) & MEMCTL_CMD_STS
) == 0, 10))
3154 DRM_ERROR("stuck trying to change perf mode\n");
3157 ironlake_set_drps(dev
, fstart
);
3159 dev_priv
->ips
.last_count1
= I915_READ(0x112e4) + I915_READ(0x112e8) +
3161 dev_priv
->ips
.last_time1
= jiffies_to_msecs(jiffies
);
3162 dev_priv
->ips
.last_count2
= I915_READ(0x112f4);
3163 dev_priv
->ips
.last_time2
= ktime_get_raw_ns();
3165 spin_unlock_irq(&mchdev_lock
);
3168 static void ironlake_disable_drps(struct drm_device
*dev
)
3170 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3173 spin_lock_irq(&mchdev_lock
);
3175 rgvswctl
= I915_READ16(MEMSWCTL
);
3177 /* Ack interrupts, disable EFC interrupt */
3178 I915_WRITE(MEMINTREN
, I915_READ(MEMINTREN
) & ~MEMINT_EVAL_CHG_EN
);
3179 I915_WRITE(MEMINTRSTS
, MEMINT_EVAL_CHG
);
3180 I915_WRITE(DEIER
, I915_READ(DEIER
) & ~DE_PCU_EVENT
);
3181 I915_WRITE(DEIIR
, DE_PCU_EVENT
);
3182 I915_WRITE(DEIMR
, I915_READ(DEIMR
) | DE_PCU_EVENT
);
3184 /* Go back to the starting frequency */
3185 ironlake_set_drps(dev
, dev_priv
->ips
.fstart
);
3187 rgvswctl
|= MEMCTL_CMD_STS
;
3188 I915_WRITE(MEMSWCTL
, rgvswctl
);
3191 spin_unlock_irq(&mchdev_lock
);
3194 /* There's a funny hw issue where the hw returns all 0 when reading from
3195 * GEN6_RP_INTERRUPT_LIMITS. Hence we always need to compute the desired value
3196 * ourselves, instead of doing a rmw cycle (which might result in us clearing
3197 * all limits and the gpu stuck at whatever frequency it is at atm).
3199 static u32
gen6_rps_limits(struct drm_i915_private
*dev_priv
, u8 val
)
3203 /* Only set the down limit when we've reached the lowest level to avoid
3204 * getting more interrupts, otherwise leave this clear. This prevents a
3205 * race in the hw when coming out of rc6: There's a tiny window where
3206 * the hw runs at the minimal clock before selecting the desired
3207 * frequency, if the down threshold expires in that window we will not
3208 * receive a down interrupt. */
3209 limits
= dev_priv
->rps
.max_freq_softlimit
<< 24;
3210 if (val
<= dev_priv
->rps
.min_freq_softlimit
)
3211 limits
|= dev_priv
->rps
.min_freq_softlimit
<< 16;
3216 static void gen6_set_rps_thresholds(struct drm_i915_private
*dev_priv
, u8 val
)
3220 new_power
= dev_priv
->rps
.power
;
3221 switch (dev_priv
->rps
.power
) {
3223 if (val
> dev_priv
->rps
.efficient_freq
+ 1 && val
> dev_priv
->rps
.cur_freq
)
3224 new_power
= BETWEEN
;
3228 if (val
<= dev_priv
->rps
.efficient_freq
&& val
< dev_priv
->rps
.cur_freq
)
3229 new_power
= LOW_POWER
;
3230 else if (val
>= dev_priv
->rps
.rp0_freq
&& val
> dev_priv
->rps
.cur_freq
)
3231 new_power
= HIGH_POWER
;
3235 if (val
< (dev_priv
->rps
.rp1_freq
+ dev_priv
->rps
.rp0_freq
) >> 1 && val
< dev_priv
->rps
.cur_freq
)
3236 new_power
= BETWEEN
;
3239 /* Max/min bins are special */
3240 if (val
== dev_priv
->rps
.min_freq_softlimit
)
3241 new_power
= LOW_POWER
;
3242 if (val
== dev_priv
->rps
.max_freq_softlimit
)
3243 new_power
= HIGH_POWER
;
3244 if (new_power
== dev_priv
->rps
.power
)
3247 /* Note the units here are not exactly 1us, but 1280ns. */
3248 switch (new_power
) {
3250 /* Upclock if more than 95% busy over 16ms */
3251 I915_WRITE(GEN6_RP_UP_EI
, 12500);
3252 I915_WRITE(GEN6_RP_UP_THRESHOLD
, 11800);
3254 /* Downclock if less than 85% busy over 32ms */
3255 I915_WRITE(GEN6_RP_DOWN_EI
, 25000);
3256 I915_WRITE(GEN6_RP_DOWN_THRESHOLD
, 21250);
3258 I915_WRITE(GEN6_RP_CONTROL
,
3259 GEN6_RP_MEDIA_TURBO
|
3260 GEN6_RP_MEDIA_HW_NORMAL_MODE
|
3261 GEN6_RP_MEDIA_IS_GFX
|
3263 GEN6_RP_UP_BUSY_AVG
|
3264 GEN6_RP_DOWN_IDLE_AVG
);
3268 /* Upclock if more than 90% busy over 13ms */
3269 I915_WRITE(GEN6_RP_UP_EI
, 10250);
3270 I915_WRITE(GEN6_RP_UP_THRESHOLD
, 9225);
3272 /* Downclock if less than 75% busy over 32ms */
3273 I915_WRITE(GEN6_RP_DOWN_EI
, 25000);
3274 I915_WRITE(GEN6_RP_DOWN_THRESHOLD
, 18750);
3276 I915_WRITE(GEN6_RP_CONTROL
,
3277 GEN6_RP_MEDIA_TURBO
|
3278 GEN6_RP_MEDIA_HW_NORMAL_MODE
|
3279 GEN6_RP_MEDIA_IS_GFX
|
3281 GEN6_RP_UP_BUSY_AVG
|
3282 GEN6_RP_DOWN_IDLE_AVG
);
3286 /* Upclock if more than 85% busy over 10ms */
3287 I915_WRITE(GEN6_RP_UP_EI
, 8000);
3288 I915_WRITE(GEN6_RP_UP_THRESHOLD
, 6800);
3290 /* Downclock if less than 60% busy over 32ms */
3291 I915_WRITE(GEN6_RP_DOWN_EI
, 25000);
3292 I915_WRITE(GEN6_RP_DOWN_THRESHOLD
, 15000);
3294 I915_WRITE(GEN6_RP_CONTROL
,
3295 GEN6_RP_MEDIA_TURBO
|
3296 GEN6_RP_MEDIA_HW_NORMAL_MODE
|
3297 GEN6_RP_MEDIA_IS_GFX
|
3299 GEN6_RP_UP_BUSY_AVG
|
3300 GEN6_RP_DOWN_IDLE_AVG
);
3304 dev_priv
->rps
.power
= new_power
;
3305 dev_priv
->rps
.last_adj
= 0;
3308 static u32
gen6_rps_pm_mask(struct drm_i915_private
*dev_priv
, u8 val
)
3312 if (val
> dev_priv
->rps
.min_freq_softlimit
)
3313 mask
|= GEN6_PM_RP_DOWN_THRESHOLD
| GEN6_PM_RP_DOWN_TIMEOUT
;
3314 if (val
< dev_priv
->rps
.max_freq_softlimit
)
3315 mask
|= GEN6_PM_RP_UP_THRESHOLD
;
3317 mask
|= dev_priv
->pm_rps_events
& (GEN6_PM_RP_DOWN_EI_EXPIRED
| GEN6_PM_RP_UP_EI_EXPIRED
);
3318 mask
&= dev_priv
->pm_rps_events
;
3320 /* IVB and SNB hard hangs on looping batchbuffer
3321 * if GEN6_PM_UP_EI_EXPIRED is masked.
3323 if (INTEL_INFO(dev_priv
->dev
)->gen
<= 7 && !IS_HASWELL(dev_priv
->dev
))
3324 mask
|= GEN6_PM_RP_UP_EI_EXPIRED
;
3326 if (IS_GEN8(dev_priv
->dev
))
3327 mask
|= GEN8_PMINTR_REDIRECT_TO_NON_DISP
;
3332 /* gen6_set_rps is called to update the frequency request, but should also be
3333 * called when the range (min_delay and max_delay) is modified so that we can
3334 * update the GEN6_RP_INTERRUPT_LIMITS register accordingly. */
3335 void gen6_set_rps(struct drm_device
*dev
, u8 val
)
3337 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3339 WARN_ON(!mutex_is_locked(&dev_priv
->rps
.hw_lock
));
3340 WARN_ON(val
> dev_priv
->rps
.max_freq_softlimit
);
3341 WARN_ON(val
< dev_priv
->rps
.min_freq_softlimit
);
3343 /* min/max delay may still have been modified so be sure to
3344 * write the limits value.
3346 if (val
!= dev_priv
->rps
.cur_freq
) {
3347 gen6_set_rps_thresholds(dev_priv
, val
);
3349 if (IS_HASWELL(dev
) || IS_BROADWELL(dev
))
3350 I915_WRITE(GEN6_RPNSWREQ
,
3351 HSW_FREQUENCY(val
));
3353 I915_WRITE(GEN6_RPNSWREQ
,
3354 GEN6_FREQUENCY(val
) |
3356 GEN6_AGGRESSIVE_TURBO
);
3359 /* Make sure we continue to get interrupts
3360 * until we hit the minimum or maximum frequencies.
3362 I915_WRITE(GEN6_RP_INTERRUPT_LIMITS
, gen6_rps_limits(dev_priv
, val
));
3363 I915_WRITE(GEN6_PMINTRMSK
, gen6_rps_pm_mask(dev_priv
, val
));
3365 POSTING_READ(GEN6_RPNSWREQ
);
3367 dev_priv
->rps
.cur_freq
= val
;
3368 trace_intel_gpu_freq_change(val
* 50);
3371 /* vlv_set_rps_idle: Set the frequency to Rpn if Gfx clocks are down
3373 * * If Gfx is Idle, then
3374 * 1. Mask Turbo interrupts
3375 * 2. Bring up Gfx clock
3376 * 3. Change the freq to Rpn and wait till P-Unit updates freq
3377 * 4. Clear the Force GFX CLK ON bit so that Gfx can down
3378 * 5. Unmask Turbo interrupts
3380 static void vlv_set_rps_idle(struct drm_i915_private
*dev_priv
)
3382 struct drm_device
*dev
= dev_priv
->dev
;
3384 /* Latest VLV doesn't need to force the gfx clock */
3385 if (dev
->pdev
->revision
>= 0xd) {
3386 valleyview_set_rps(dev_priv
->dev
, dev_priv
->rps
.min_freq_softlimit
);
3391 * When we are idle. Drop to min voltage state.
3394 if (dev_priv
->rps
.cur_freq
<= dev_priv
->rps
.min_freq_softlimit
)
3397 /* Mask turbo interrupt so that they will not come in between */
3398 I915_WRITE(GEN6_PMINTRMSK
, 0xffffffff);
3400 vlv_force_gfx_clock(dev_priv
, true);
3402 dev_priv
->rps
.cur_freq
= dev_priv
->rps
.min_freq_softlimit
;
3404 vlv_punit_write(dev_priv
, PUNIT_REG_GPU_FREQ_REQ
,
3405 dev_priv
->rps
.min_freq_softlimit
);
3407 if (wait_for(((vlv_punit_read(dev_priv
, PUNIT_REG_GPU_FREQ_STS
))
3408 & GENFREQSTATUS
) == 0, 5))
3409 DRM_ERROR("timed out waiting for Punit\n");
3411 vlv_force_gfx_clock(dev_priv
, false);
3413 I915_WRITE(GEN6_PMINTRMSK
,
3414 gen6_rps_pm_mask(dev_priv
, dev_priv
->rps
.cur_freq
));
3417 void gen6_rps_idle(struct drm_i915_private
*dev_priv
)
3419 struct drm_device
*dev
= dev_priv
->dev
;
3421 mutex_lock(&dev_priv
->rps
.hw_lock
);
3422 if (dev_priv
->rps
.enabled
) {
3423 if (IS_CHERRYVIEW(dev
))
3424 valleyview_set_rps(dev_priv
->dev
, dev_priv
->rps
.min_freq_softlimit
);
3425 else if (IS_VALLEYVIEW(dev
))
3426 vlv_set_rps_idle(dev_priv
);
3428 gen6_set_rps(dev_priv
->dev
, dev_priv
->rps
.min_freq_softlimit
);
3429 dev_priv
->rps
.last_adj
= 0;
3431 mutex_unlock(&dev_priv
->rps
.hw_lock
);
3434 void gen6_rps_boost(struct drm_i915_private
*dev_priv
)
3436 struct drm_device
*dev
= dev_priv
->dev
;
3438 mutex_lock(&dev_priv
->rps
.hw_lock
);
3439 if (dev_priv
->rps
.enabled
) {
3440 if (IS_VALLEYVIEW(dev
))
3441 valleyview_set_rps(dev_priv
->dev
, dev_priv
->rps
.max_freq_softlimit
);
3443 gen6_set_rps(dev_priv
->dev
, dev_priv
->rps
.max_freq_softlimit
);
3444 dev_priv
->rps
.last_adj
= 0;
3446 mutex_unlock(&dev_priv
->rps
.hw_lock
);
3449 void valleyview_set_rps(struct drm_device
*dev
, u8 val
)
3451 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3453 WARN_ON(!mutex_is_locked(&dev_priv
->rps
.hw_lock
));
3454 WARN_ON(val
> dev_priv
->rps
.max_freq_softlimit
);
3455 WARN_ON(val
< dev_priv
->rps
.min_freq_softlimit
);
3457 DRM_DEBUG_DRIVER("GPU freq request from %d MHz (%u) to %d MHz (%u)\n",
3458 vlv_gpu_freq(dev_priv
, dev_priv
->rps
.cur_freq
),
3459 dev_priv
->rps
.cur_freq
,
3460 vlv_gpu_freq(dev_priv
, val
), val
);
3462 if (val
!= dev_priv
->rps
.cur_freq
)
3463 vlv_punit_write(dev_priv
, PUNIT_REG_GPU_FREQ_REQ
, val
);
3465 I915_WRITE(GEN6_PMINTRMSK
, gen6_rps_pm_mask(dev_priv
, val
));
3467 dev_priv
->rps
.cur_freq
= val
;
3468 trace_intel_gpu_freq_change(vlv_gpu_freq(dev_priv
, val
));
3471 static void gen8_disable_rps_interrupts(struct drm_device
*dev
)
3473 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3475 I915_WRITE(GEN6_PMINTRMSK
, ~GEN8_PMINTR_REDIRECT_TO_NON_DISP
);
3476 I915_WRITE(GEN8_GT_IER(2), I915_READ(GEN8_GT_IER(2)) &
3477 ~dev_priv
->pm_rps_events
);
3478 /* Complete PM interrupt masking here doesn't race with the rps work
3479 * item again unmasking PM interrupts because that is using a different
3480 * register (GEN8_GT_IMR(2)) to mask PM interrupts. The only risk is in
3481 * leaving stale bits in GEN8_GT_IIR(2) and GEN8_GT_IMR(2) which
3482 * gen8_enable_rps will clean up. */
3484 spin_lock_irq(&dev_priv
->irq_lock
);
3485 dev_priv
->rps
.pm_iir
= 0;
3486 spin_unlock_irq(&dev_priv
->irq_lock
);
3488 I915_WRITE(GEN8_GT_IIR(2), dev_priv
->pm_rps_events
);
3491 static void gen6_disable_rps_interrupts(struct drm_device
*dev
)
3493 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3495 I915_WRITE(GEN6_PMINTRMSK
, 0xffffffff);
3496 I915_WRITE(GEN6_PMIER
, I915_READ(GEN6_PMIER
) &
3497 ~dev_priv
->pm_rps_events
);
3498 /* Complete PM interrupt masking here doesn't race with the rps work
3499 * item again unmasking PM interrupts because that is using a different
3500 * register (PMIMR) to mask PM interrupts. The only risk is in leaving
3501 * stale bits in PMIIR and PMIMR which gen6_enable_rps will clean up. */
3503 spin_lock_irq(&dev_priv
->irq_lock
);
3504 dev_priv
->rps
.pm_iir
= 0;
3505 spin_unlock_irq(&dev_priv
->irq_lock
);
3507 I915_WRITE(GEN6_PMIIR
, dev_priv
->pm_rps_events
);
3510 static void gen6_disable_rps(struct drm_device
*dev
)
3512 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3514 I915_WRITE(GEN6_RC_CONTROL
, 0);
3515 I915_WRITE(GEN6_RPNSWREQ
, 1 << 31);
3517 if (IS_BROADWELL(dev
))
3518 gen8_disable_rps_interrupts(dev
);
3520 gen6_disable_rps_interrupts(dev
);
3523 static void cherryview_disable_rps(struct drm_device
*dev
)
3525 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3527 I915_WRITE(GEN6_RC_CONTROL
, 0);
3529 gen8_disable_rps_interrupts(dev
);
3532 static void valleyview_disable_rps(struct drm_device
*dev
)
3534 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3536 /* we're doing forcewake before Disabling RC6,
3537 * This what the BIOS expects when going into suspend */
3538 gen6_gt_force_wake_get(dev_priv
, FORCEWAKE_ALL
);
3540 I915_WRITE(GEN6_RC_CONTROL
, 0);
3542 gen6_gt_force_wake_put(dev_priv
, FORCEWAKE_ALL
);
3544 gen6_disable_rps_interrupts(dev
);
3547 static void intel_print_rc6_info(struct drm_device
*dev
, u32 mode
)
3549 if (IS_VALLEYVIEW(dev
)) {
3550 if (mode
& (GEN7_RC_CTL_TO_MODE
| GEN6_RC_CTL_EI_MODE(1)))
3551 mode
= GEN6_RC_CTL_RC6_ENABLE
;
3555 DRM_DEBUG_KMS("Enabling RC6 states: RC6 %s, RC6p %s, RC6pp %s\n",
3556 (mode
& GEN6_RC_CTL_RC6_ENABLE
) ? "on" : "off",
3557 (mode
& GEN6_RC_CTL_RC6p_ENABLE
) ? "on" : "off",
3558 (mode
& GEN6_RC_CTL_RC6pp_ENABLE
) ? "on" : "off");
3561 static int sanitize_rc6_option(const struct drm_device
*dev
, int enable_rc6
)
3563 /* No RC6 before Ironlake */
3564 if (INTEL_INFO(dev
)->gen
< 5)
3567 /* RC6 is only on Ironlake mobile not on desktop */
3568 if (INTEL_INFO(dev
)->gen
== 5 && !IS_IRONLAKE_M(dev
))
3571 /* Respect the kernel parameter if it is set */
3572 if (enable_rc6
>= 0) {
3575 if (INTEL_INFO(dev
)->gen
== 6 || IS_IVYBRIDGE(dev
))
3576 mask
= INTEL_RC6_ENABLE
| INTEL_RC6p_ENABLE
|
3579 mask
= INTEL_RC6_ENABLE
;
3581 if ((enable_rc6
& mask
) != enable_rc6
)
3582 DRM_DEBUG_KMS("Adjusting RC6 mask to %d (requested %d, valid %d)\n",
3583 enable_rc6
& mask
, enable_rc6
, mask
);
3585 return enable_rc6
& mask
;
3588 /* Disable RC6 on Ironlake */
3589 if (INTEL_INFO(dev
)->gen
== 5)
3592 if (IS_IVYBRIDGE(dev
))
3593 return (INTEL_RC6_ENABLE
| INTEL_RC6p_ENABLE
);
3595 return INTEL_RC6_ENABLE
;
3598 int intel_enable_rc6(const struct drm_device
*dev
)
3600 return i915
.enable_rc6
;
3603 static void gen8_enable_rps_interrupts(struct drm_device
*dev
)
3605 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3607 spin_lock_irq(&dev_priv
->irq_lock
);
3608 WARN_ON(dev_priv
->rps
.pm_iir
);
3609 gen8_enable_pm_irq(dev_priv
, dev_priv
->pm_rps_events
);
3610 I915_WRITE(GEN8_GT_IIR(2), dev_priv
->pm_rps_events
);
3611 spin_unlock_irq(&dev_priv
->irq_lock
);
3614 static void gen6_enable_rps_interrupts(struct drm_device
*dev
)
3616 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3618 spin_lock_irq(&dev_priv
->irq_lock
);
3619 WARN_ON(dev_priv
->rps
.pm_iir
);
3620 gen6_enable_pm_irq(dev_priv
, dev_priv
->pm_rps_events
);
3621 I915_WRITE(GEN6_PMIIR
, dev_priv
->pm_rps_events
);
3622 spin_unlock_irq(&dev_priv
->irq_lock
);
3625 static void parse_rp_state_cap(struct drm_i915_private
*dev_priv
, u32 rp_state_cap
)
3627 /* All of these values are in units of 50MHz */
3628 dev_priv
->rps
.cur_freq
= 0;
3629 /* static values from HW: RP0 < RPe < RP1 < RPn (min_freq) */
3630 dev_priv
->rps
.rp1_freq
= (rp_state_cap
>> 8) & 0xff;
3631 dev_priv
->rps
.rp0_freq
= (rp_state_cap
>> 0) & 0xff;
3632 dev_priv
->rps
.min_freq
= (rp_state_cap
>> 16) & 0xff;
3633 /* XXX: only BYT has a special efficient freq */
3634 dev_priv
->rps
.efficient_freq
= dev_priv
->rps
.rp1_freq
;
3635 /* hw_max = RP0 until we check for overclocking */
3636 dev_priv
->rps
.max_freq
= dev_priv
->rps
.rp0_freq
;
3638 /* Preserve min/max settings in case of re-init */
3639 if (dev_priv
->rps
.max_freq_softlimit
== 0)
3640 dev_priv
->rps
.max_freq_softlimit
= dev_priv
->rps
.max_freq
;
3642 if (dev_priv
->rps
.min_freq_softlimit
== 0)
3643 dev_priv
->rps
.min_freq_softlimit
= dev_priv
->rps
.min_freq
;
3646 static void gen8_enable_rps(struct drm_device
*dev
)
3648 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3649 struct intel_engine_cs
*ring
;
3650 uint32_t rc6_mask
= 0, rp_state_cap
;
3653 /* 1a: Software RC state - RC0 */
3654 I915_WRITE(GEN6_RC_STATE
, 0);
3656 /* 1c & 1d: Get forcewake during program sequence. Although the driver
3657 * hasn't enabled a state yet where we need forcewake, BIOS may have.*/
3658 gen6_gt_force_wake_get(dev_priv
, FORCEWAKE_ALL
);
3660 /* 2a: Disable RC states. */
3661 I915_WRITE(GEN6_RC_CONTROL
, 0);
3663 rp_state_cap
= I915_READ(GEN6_RP_STATE_CAP
);
3664 parse_rp_state_cap(dev_priv
, rp_state_cap
);
3666 /* 2b: Program RC6 thresholds.*/
3667 I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT
, 40 << 16);
3668 I915_WRITE(GEN6_RC_EVALUATION_INTERVAL
, 125000); /* 12500 * 1280ns */
3669 I915_WRITE(GEN6_RC_IDLE_HYSTERSIS
, 25); /* 25 * 1280ns */
3670 for_each_ring(ring
, dev_priv
, unused
)
3671 I915_WRITE(RING_MAX_IDLE(ring
->mmio_base
), 10);
3672 I915_WRITE(GEN6_RC_SLEEP
, 0);
3673 if (IS_BROADWELL(dev
))
3674 I915_WRITE(GEN6_RC6_THRESHOLD
, 625); /* 800us/1.28 for TO */
3676 I915_WRITE(GEN6_RC6_THRESHOLD
, 50000); /* 50/125ms per EI */
3679 if (intel_enable_rc6(dev
) & INTEL_RC6_ENABLE
)
3680 rc6_mask
= GEN6_RC_CTL_RC6_ENABLE
;
3681 intel_print_rc6_info(dev
, rc6_mask
);
3682 if (IS_BROADWELL(dev
))
3683 I915_WRITE(GEN6_RC_CONTROL
, GEN6_RC_CTL_HW_ENABLE
|
3684 GEN7_RC_CTL_TO_MODE
|
3687 I915_WRITE(GEN6_RC_CONTROL
, GEN6_RC_CTL_HW_ENABLE
|
3688 GEN6_RC_CTL_EI_MODE(1) |
3691 /* 4 Program defaults and thresholds for RPS*/
3692 I915_WRITE(GEN6_RPNSWREQ
,
3693 HSW_FREQUENCY(dev_priv
->rps
.rp1_freq
));
3694 I915_WRITE(GEN6_RC_VIDEO_FREQ
,
3695 HSW_FREQUENCY(dev_priv
->rps
.rp1_freq
));
3696 /* NB: Docs say 1s, and 1000000 - which aren't equivalent */
3697 I915_WRITE(GEN6_RP_DOWN_TIMEOUT
, 100000000 / 128); /* 1 second timeout */
3699 /* Docs recommend 900MHz, and 300 MHz respectively */
3700 I915_WRITE(GEN6_RP_INTERRUPT_LIMITS
,
3701 dev_priv
->rps
.max_freq_softlimit
<< 24 |
3702 dev_priv
->rps
.min_freq_softlimit
<< 16);
3704 I915_WRITE(GEN6_RP_UP_THRESHOLD
, 7600000 / 128); /* 76ms busyness per EI, 90% */
3705 I915_WRITE(GEN6_RP_DOWN_THRESHOLD
, 31300000 / 128); /* 313ms busyness per EI, 70%*/
3706 I915_WRITE(GEN6_RP_UP_EI
, 66000); /* 84.48ms, XXX: random? */
3707 I915_WRITE(GEN6_RP_DOWN_EI
, 350000); /* 448ms, XXX: random? */
3709 I915_WRITE(GEN6_RP_IDLE_HYSTERSIS
, 10);
3712 I915_WRITE(GEN6_RP_CONTROL
,
3713 GEN6_RP_MEDIA_TURBO
|
3714 GEN6_RP_MEDIA_HW_NORMAL_MODE
|
3715 GEN6_RP_MEDIA_IS_GFX
|
3717 GEN6_RP_UP_BUSY_AVG
|
3718 GEN6_RP_DOWN_IDLE_AVG
);
3720 /* 6: Ring frequency + overclocking (our driver does this later */
3722 gen6_set_rps(dev
, (I915_READ(GEN6_GT_PERF_STATUS
) & 0xff00) >> 8);
3724 gen8_enable_rps_interrupts(dev
);
3726 gen6_gt_force_wake_put(dev_priv
, FORCEWAKE_ALL
);
3729 static void gen6_enable_rps(struct drm_device
*dev
)
3731 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3732 struct intel_engine_cs
*ring
;
3734 u32 rc6vids
, pcu_mbox
= 0, rc6_mask
= 0;
3739 WARN_ON(!mutex_is_locked(&dev_priv
->rps
.hw_lock
));
3741 /* Here begins a magic sequence of register writes to enable
3742 * auto-downclocking.
3744 * Perhaps there might be some value in exposing these to
3747 I915_WRITE(GEN6_RC_STATE
, 0);
3749 /* Clear the DBG now so we don't confuse earlier errors */
3750 if ((gtfifodbg
= I915_READ(GTFIFODBG
))) {
3751 DRM_ERROR("GT fifo had a previous error %x\n", gtfifodbg
);
3752 I915_WRITE(GTFIFODBG
, gtfifodbg
);
3755 gen6_gt_force_wake_get(dev_priv
, FORCEWAKE_ALL
);
3757 rp_state_cap
= I915_READ(GEN6_RP_STATE_CAP
);
3759 parse_rp_state_cap(dev_priv
, rp_state_cap
);
3761 /* disable the counters and set deterministic thresholds */
3762 I915_WRITE(GEN6_RC_CONTROL
, 0);
3764 I915_WRITE(GEN6_RC1_WAKE_RATE_LIMIT
, 1000 << 16);
3765 I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT
, 40 << 16 | 30);
3766 I915_WRITE(GEN6_RC6pp_WAKE_RATE_LIMIT
, 30);
3767 I915_WRITE(GEN6_RC_EVALUATION_INTERVAL
, 125000);
3768 I915_WRITE(GEN6_RC_IDLE_HYSTERSIS
, 25);
3770 for_each_ring(ring
, dev_priv
, i
)
3771 I915_WRITE(RING_MAX_IDLE(ring
->mmio_base
), 10);
3773 I915_WRITE(GEN6_RC_SLEEP
, 0);
3774 I915_WRITE(GEN6_RC1e_THRESHOLD
, 1000);
3775 if (IS_IVYBRIDGE(dev
))
3776 I915_WRITE(GEN6_RC6_THRESHOLD
, 125000);
3778 I915_WRITE(GEN6_RC6_THRESHOLD
, 50000);
3779 I915_WRITE(GEN6_RC6p_THRESHOLD
, 150000);
3780 I915_WRITE(GEN6_RC6pp_THRESHOLD
, 64000); /* unused */
3782 /* Check if we are enabling RC6 */
3783 rc6_mode
= intel_enable_rc6(dev_priv
->dev
);
3784 if (rc6_mode
& INTEL_RC6_ENABLE
)
3785 rc6_mask
|= GEN6_RC_CTL_RC6_ENABLE
;
3787 /* We don't use those on Haswell */
3788 if (!IS_HASWELL(dev
)) {
3789 if (rc6_mode
& INTEL_RC6p_ENABLE
)
3790 rc6_mask
|= GEN6_RC_CTL_RC6p_ENABLE
;
3792 if (rc6_mode
& INTEL_RC6pp_ENABLE
)
3793 rc6_mask
|= GEN6_RC_CTL_RC6pp_ENABLE
;
3796 intel_print_rc6_info(dev
, rc6_mask
);
3798 I915_WRITE(GEN6_RC_CONTROL
,
3800 GEN6_RC_CTL_EI_MODE(1) |
3801 GEN6_RC_CTL_HW_ENABLE
);
3803 /* Power down if completely idle for over 50ms */
3804 I915_WRITE(GEN6_RP_DOWN_TIMEOUT
, 50000);
3805 I915_WRITE(GEN6_RP_IDLE_HYSTERSIS
, 10);
3807 ret
= sandybridge_pcode_write(dev_priv
, GEN6_PCODE_WRITE_MIN_FREQ_TABLE
, 0);
3809 DRM_DEBUG_DRIVER("Failed to set the min frequency\n");
3811 ret
= sandybridge_pcode_read(dev_priv
, GEN6_READ_OC_PARAMS
, &pcu_mbox
);
3812 if (!ret
&& (pcu_mbox
& (1<<31))) { /* OC supported */
3813 DRM_DEBUG_DRIVER("Overclocking supported. Max: %dMHz, Overclock max: %dMHz\n",
3814 (dev_priv
->rps
.max_freq_softlimit
& 0xff) * 50,
3815 (pcu_mbox
& 0xff) * 50);
3816 dev_priv
->rps
.max_freq
= pcu_mbox
& 0xff;
3819 dev_priv
->rps
.power
= HIGH_POWER
; /* force a reset */
3820 gen6_set_rps(dev_priv
->dev
, dev_priv
->rps
.min_freq_softlimit
);
3822 gen6_enable_rps_interrupts(dev
);
3825 ret
= sandybridge_pcode_read(dev_priv
, GEN6_PCODE_READ_RC6VIDS
, &rc6vids
);
3826 if (IS_GEN6(dev
) && ret
) {
3827 DRM_DEBUG_DRIVER("Couldn't check for BIOS workaround\n");
3828 } else if (IS_GEN6(dev
) && (GEN6_DECODE_RC6_VID(rc6vids
& 0xff) < 450)) {
3829 DRM_DEBUG_DRIVER("You should update your BIOS. Correcting minimum rc6 voltage (%dmV->%dmV)\n",
3830 GEN6_DECODE_RC6_VID(rc6vids
& 0xff), 450);
3831 rc6vids
&= 0xffff00;
3832 rc6vids
|= GEN6_ENCODE_RC6_VID(450);
3833 ret
= sandybridge_pcode_write(dev_priv
, GEN6_PCODE_WRITE_RC6VIDS
, rc6vids
);
3835 DRM_ERROR("Couldn't fix incorrect rc6 voltage\n");
3838 gen6_gt_force_wake_put(dev_priv
, FORCEWAKE_ALL
);
3841 static void __gen6_update_ring_freq(struct drm_device
*dev
)
3843 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3845 unsigned int gpu_freq
;
3846 unsigned int max_ia_freq
, min_ring_freq
;
3847 int scaling_factor
= 180;
3848 struct cpufreq_policy
*policy
;
3850 WARN_ON(!mutex_is_locked(&dev_priv
->rps
.hw_lock
));
3852 policy
= cpufreq_cpu_get(0);
3854 max_ia_freq
= policy
->cpuinfo
.max_freq
;
3855 cpufreq_cpu_put(policy
);
3858 * Default to measured freq if none found, PCU will ensure we
3861 max_ia_freq
= tsc_khz
;
3864 /* Convert from kHz to MHz */
3865 max_ia_freq
/= 1000;
3867 min_ring_freq
= I915_READ(DCLK
) & 0xf;
3868 /* convert DDR frequency from units of 266.6MHz to bandwidth */
3869 min_ring_freq
= mult_frac(min_ring_freq
, 8, 3);
3872 * For each potential GPU frequency, load a ring frequency we'd like
3873 * to use for memory access. We do this by specifying the IA frequency
3874 * the PCU should use as a reference to determine the ring frequency.
3876 for (gpu_freq
= dev_priv
->rps
.max_freq_softlimit
; gpu_freq
>= dev_priv
->rps
.min_freq_softlimit
;
3878 int diff
= dev_priv
->rps
.max_freq_softlimit
- gpu_freq
;
3879 unsigned int ia_freq
= 0, ring_freq
= 0;
3881 if (INTEL_INFO(dev
)->gen
>= 8) {
3882 /* max(2 * GT, DDR). NB: GT is 50MHz units */
3883 ring_freq
= max(min_ring_freq
, gpu_freq
);
3884 } else if (IS_HASWELL(dev
)) {
3885 ring_freq
= mult_frac(gpu_freq
, 5, 4);
3886 ring_freq
= max(min_ring_freq
, ring_freq
);
3887 /* leave ia_freq as the default, chosen by cpufreq */
3889 /* On older processors, there is no separate ring
3890 * clock domain, so in order to boost the bandwidth
3891 * of the ring, we need to upclock the CPU (ia_freq).
3893 * For GPU frequencies less than 750MHz,
3894 * just use the lowest ring freq.
3896 if (gpu_freq
< min_freq
)
3899 ia_freq
= max_ia_freq
- ((diff
* scaling_factor
) / 2);
3900 ia_freq
= DIV_ROUND_CLOSEST(ia_freq
, 100);
3903 sandybridge_pcode_write(dev_priv
,
3904 GEN6_PCODE_WRITE_MIN_FREQ_TABLE
,
3905 ia_freq
<< GEN6_PCODE_FREQ_IA_RATIO_SHIFT
|
3906 ring_freq
<< GEN6_PCODE_FREQ_RING_RATIO_SHIFT
|
3911 void gen6_update_ring_freq(struct drm_device
*dev
)
3913 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3915 if (INTEL_INFO(dev
)->gen
< 6 || IS_VALLEYVIEW(dev
))
3918 mutex_lock(&dev_priv
->rps
.hw_lock
);
3919 __gen6_update_ring_freq(dev
);
3920 mutex_unlock(&dev_priv
->rps
.hw_lock
);
3923 static int cherryview_rps_max_freq(struct drm_i915_private
*dev_priv
)
3927 val
= vlv_punit_read(dev_priv
, PUNIT_GPU_STATUS_REG
);
3928 rp0
= (val
>> PUNIT_GPU_STATUS_MAX_FREQ_SHIFT
) & PUNIT_GPU_STATUS_MAX_FREQ_MASK
;
3933 static int cherryview_rps_rpe_freq(struct drm_i915_private
*dev_priv
)
3937 val
= vlv_punit_read(dev_priv
, PUNIT_GPU_DUTYCYCLE_REG
);
3938 rpe
= (val
>> PUNIT_GPU_DUTYCYCLE_RPE_FREQ_SHIFT
) & PUNIT_GPU_DUTYCYCLE_RPE_FREQ_MASK
;
3943 static int cherryview_rps_guar_freq(struct drm_i915_private
*dev_priv
)
3947 val
= vlv_punit_read(dev_priv
, PUNIT_REG_GPU_FREQ_STS
);
3948 rp1
= (val
>> PUNIT_GPU_STATUS_MAX_FREQ_SHIFT
) & PUNIT_GPU_STATUS_MAX_FREQ_MASK
;
3953 static int cherryview_rps_min_freq(struct drm_i915_private
*dev_priv
)
3957 val
= vlv_punit_read(dev_priv
, PUNIT_GPU_STATUS_REG
);
3958 rpn
= (val
>> PUNIT_GPU_STATIS_GFX_MIN_FREQ_SHIFT
) & PUNIT_GPU_STATUS_GFX_MIN_FREQ_MASK
;
3962 static int valleyview_rps_guar_freq(struct drm_i915_private
*dev_priv
)
3966 val
= vlv_nc_read(dev_priv
, IOSF_NC_FB_GFX_FREQ_FUSE
);
3968 rp1
= (val
& FB_GFX_FGUARANTEED_FREQ_FUSE_MASK
) >> FB_GFX_FGUARANTEED_FREQ_FUSE_SHIFT
;
3973 static int valleyview_rps_max_freq(struct drm_i915_private
*dev_priv
)
3977 val
= vlv_nc_read(dev_priv
, IOSF_NC_FB_GFX_FREQ_FUSE
);
3979 rp0
= (val
& FB_GFX_MAX_FREQ_FUSE_MASK
) >> FB_GFX_MAX_FREQ_FUSE_SHIFT
;
3981 rp0
= min_t(u32
, rp0
, 0xea);
3986 static int valleyview_rps_rpe_freq(struct drm_i915_private
*dev_priv
)
3990 val
= vlv_nc_read(dev_priv
, IOSF_NC_FB_GFX_FMAX_FUSE_LO
);
3991 rpe
= (val
& FB_FMAX_VMIN_FREQ_LO_MASK
) >> FB_FMAX_VMIN_FREQ_LO_SHIFT
;
3992 val
= vlv_nc_read(dev_priv
, IOSF_NC_FB_GFX_FMAX_FUSE_HI
);
3993 rpe
|= (val
& FB_FMAX_VMIN_FREQ_HI_MASK
) << 5;
3998 static int valleyview_rps_min_freq(struct drm_i915_private
*dev_priv
)
4000 return vlv_punit_read(dev_priv
, PUNIT_REG_GPU_LFM
) & 0xff;
4003 /* Check that the pctx buffer wasn't move under us. */
4004 static void valleyview_check_pctx(struct drm_i915_private
*dev_priv
)
4006 unsigned long pctx_addr
= I915_READ(VLV_PCBR
) & ~4095;
4008 WARN_ON(pctx_addr
!= dev_priv
->mm
.stolen_base
+
4009 dev_priv
->vlv_pctx
->stolen
->start
);
4013 /* Check that the pcbr address is not empty. */
4014 static void cherryview_check_pctx(struct drm_i915_private
*dev_priv
)
4016 unsigned long pctx_addr
= I915_READ(VLV_PCBR
) & ~4095;
4018 WARN_ON((pctx_addr
>> VLV_PCBR_ADDR_SHIFT
) == 0);
4021 static void cherryview_setup_pctx(struct drm_device
*dev
)
4023 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4024 unsigned long pctx_paddr
, paddr
;
4025 struct i915_gtt
*gtt
= &dev_priv
->gtt
;
4027 int pctx_size
= 32*1024;
4029 WARN_ON(!mutex_is_locked(&dev
->struct_mutex
));
4031 pcbr
= I915_READ(VLV_PCBR
);
4032 if ((pcbr
>> VLV_PCBR_ADDR_SHIFT
) == 0) {
4033 paddr
= (dev_priv
->mm
.stolen_base
+
4034 (gtt
->stolen_size
- pctx_size
));
4036 pctx_paddr
= (paddr
& (~4095));
4037 I915_WRITE(VLV_PCBR
, pctx_paddr
);
4041 static void valleyview_setup_pctx(struct drm_device
*dev
)
4043 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4044 struct drm_i915_gem_object
*pctx
;
4045 unsigned long pctx_paddr
;
4047 int pctx_size
= 24*1024;
4049 WARN_ON(!mutex_is_locked(&dev
->struct_mutex
));
4051 pcbr
= I915_READ(VLV_PCBR
);
4053 /* BIOS set it up already, grab the pre-alloc'd space */
4056 pcbr_offset
= (pcbr
& (~4095)) - dev_priv
->mm
.stolen_base
;
4057 pctx
= i915_gem_object_create_stolen_for_preallocated(dev_priv
->dev
,
4059 I915_GTT_OFFSET_NONE
,
4065 * From the Gunit register HAS:
4066 * The Gfx driver is expected to program this register and ensure
4067 * proper allocation within Gfx stolen memory. For example, this
4068 * register should be programmed such than the PCBR range does not
4069 * overlap with other ranges, such as the frame buffer, protected
4070 * memory, or any other relevant ranges.
4072 pctx
= i915_gem_object_create_stolen(dev
, pctx_size
);
4074 DRM_DEBUG("not enough stolen space for PCTX, disabling\n");
4078 pctx_paddr
= dev_priv
->mm
.stolen_base
+ pctx
->stolen
->start
;
4079 I915_WRITE(VLV_PCBR
, pctx_paddr
);
4082 dev_priv
->vlv_pctx
= pctx
;
4085 static void valleyview_cleanup_pctx(struct drm_device
*dev
)
4087 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4089 if (WARN_ON(!dev_priv
->vlv_pctx
))
4092 drm_gem_object_unreference(&dev_priv
->vlv_pctx
->base
);
4093 dev_priv
->vlv_pctx
= NULL
;
4096 static void valleyview_init_gt_powersave(struct drm_device
*dev
)
4098 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4100 valleyview_setup_pctx(dev
);
4102 mutex_lock(&dev_priv
->rps
.hw_lock
);
4104 dev_priv
->rps
.max_freq
= valleyview_rps_max_freq(dev_priv
);
4105 dev_priv
->rps
.rp0_freq
= dev_priv
->rps
.max_freq
;
4106 DRM_DEBUG_DRIVER("max GPU freq: %d MHz (%u)\n",
4107 vlv_gpu_freq(dev_priv
, dev_priv
->rps
.max_freq
),
4108 dev_priv
->rps
.max_freq
);
4110 dev_priv
->rps
.efficient_freq
= valleyview_rps_rpe_freq(dev_priv
);
4111 DRM_DEBUG_DRIVER("RPe GPU freq: %d MHz (%u)\n",
4112 vlv_gpu_freq(dev_priv
, dev_priv
->rps
.efficient_freq
),
4113 dev_priv
->rps
.efficient_freq
);
4115 dev_priv
->rps
.rp1_freq
= valleyview_rps_guar_freq(dev_priv
);
4116 DRM_DEBUG_DRIVER("RP1(Guar Freq) GPU freq: %d MHz (%u)\n",
4117 vlv_gpu_freq(dev_priv
, dev_priv
->rps
.rp1_freq
),
4118 dev_priv
->rps
.rp1_freq
);
4120 dev_priv
->rps
.min_freq
= valleyview_rps_min_freq(dev_priv
);
4121 DRM_DEBUG_DRIVER("min GPU freq: %d MHz (%u)\n",
4122 vlv_gpu_freq(dev_priv
, dev_priv
->rps
.min_freq
),
4123 dev_priv
->rps
.min_freq
);
4125 /* Preserve min/max settings in case of re-init */
4126 if (dev_priv
->rps
.max_freq_softlimit
== 0)
4127 dev_priv
->rps
.max_freq_softlimit
= dev_priv
->rps
.max_freq
;
4129 if (dev_priv
->rps
.min_freq_softlimit
== 0)
4130 dev_priv
->rps
.min_freq_softlimit
= dev_priv
->rps
.min_freq
;
4132 mutex_unlock(&dev_priv
->rps
.hw_lock
);
4135 static void cherryview_init_gt_powersave(struct drm_device
*dev
)
4137 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4139 cherryview_setup_pctx(dev
);
4141 mutex_lock(&dev_priv
->rps
.hw_lock
);
4143 dev_priv
->rps
.max_freq
= cherryview_rps_max_freq(dev_priv
);
4144 dev_priv
->rps
.rp0_freq
= dev_priv
->rps
.max_freq
;
4145 DRM_DEBUG_DRIVER("max GPU freq: %d MHz (%u)\n",
4146 vlv_gpu_freq(dev_priv
, dev_priv
->rps
.max_freq
),
4147 dev_priv
->rps
.max_freq
);
4149 dev_priv
->rps
.efficient_freq
= cherryview_rps_rpe_freq(dev_priv
);
4150 DRM_DEBUG_DRIVER("RPe GPU freq: %d MHz (%u)\n",
4151 vlv_gpu_freq(dev_priv
, dev_priv
->rps
.efficient_freq
),
4152 dev_priv
->rps
.efficient_freq
);
4154 dev_priv
->rps
.rp1_freq
= cherryview_rps_guar_freq(dev_priv
);
4155 DRM_DEBUG_DRIVER("RP1(Guar) GPU freq: %d MHz (%u)\n",
4156 vlv_gpu_freq(dev_priv
, dev_priv
->rps
.rp1_freq
),
4157 dev_priv
->rps
.rp1_freq
);
4159 dev_priv
->rps
.min_freq
= cherryview_rps_min_freq(dev_priv
);
4160 DRM_DEBUG_DRIVER("min GPU freq: %d MHz (%u)\n",
4161 vlv_gpu_freq(dev_priv
, dev_priv
->rps
.min_freq
),
4162 dev_priv
->rps
.min_freq
);
4164 /* Preserve min/max settings in case of re-init */
4165 if (dev_priv
->rps
.max_freq_softlimit
== 0)
4166 dev_priv
->rps
.max_freq_softlimit
= dev_priv
->rps
.max_freq
;
4168 if (dev_priv
->rps
.min_freq_softlimit
== 0)
4169 dev_priv
->rps
.min_freq_softlimit
= dev_priv
->rps
.min_freq
;
4171 mutex_unlock(&dev_priv
->rps
.hw_lock
);
4174 static void valleyview_cleanup_gt_powersave(struct drm_device
*dev
)
4176 valleyview_cleanup_pctx(dev
);
4179 static void cherryview_enable_rps(struct drm_device
*dev
)
4181 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4182 struct intel_engine_cs
*ring
;
4183 u32 gtfifodbg
, val
, rc6_mode
= 0, pcbr
;
4186 WARN_ON(!mutex_is_locked(&dev_priv
->rps
.hw_lock
));
4188 gtfifodbg
= I915_READ(GTFIFODBG
);
4190 DRM_DEBUG_DRIVER("GT fifo had a previous error %x\n",
4192 I915_WRITE(GTFIFODBG
, gtfifodbg
);
4195 cherryview_check_pctx(dev_priv
);
4197 /* 1a & 1b: Get forcewake during program sequence. Although the driver
4198 * hasn't enabled a state yet where we need forcewake, BIOS may have.*/
4199 gen6_gt_force_wake_get(dev_priv
, FORCEWAKE_ALL
);
4201 /* 2a: Program RC6 thresholds.*/
4202 I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT
, 40 << 16);
4203 I915_WRITE(GEN6_RC_EVALUATION_INTERVAL
, 125000); /* 12500 * 1280ns */
4204 I915_WRITE(GEN6_RC_IDLE_HYSTERSIS
, 25); /* 25 * 1280ns */
4206 for_each_ring(ring
, dev_priv
, i
)
4207 I915_WRITE(RING_MAX_IDLE(ring
->mmio_base
), 10);
4208 I915_WRITE(GEN6_RC_SLEEP
, 0);
4210 I915_WRITE(GEN6_RC6_THRESHOLD
, 50000); /* 50/125ms per EI */
4212 /* allows RC6 residency counter to work */
4213 I915_WRITE(VLV_COUNTER_CONTROL
,
4214 _MASKED_BIT_ENABLE(VLV_COUNT_RANGE_HIGH
|
4215 VLV_MEDIA_RC6_COUNT_EN
|
4216 VLV_RENDER_RC6_COUNT_EN
));
4218 /* For now we assume BIOS is allocating and populating the PCBR */
4219 pcbr
= I915_READ(VLV_PCBR
);
4221 DRM_DEBUG_DRIVER("PCBR offset : 0x%x\n", pcbr
);
4224 if ((intel_enable_rc6(dev
) & INTEL_RC6_ENABLE
) &&
4225 (pcbr
>> VLV_PCBR_ADDR_SHIFT
))
4226 rc6_mode
= GEN6_RC_CTL_EI_MODE(1);
4228 I915_WRITE(GEN6_RC_CONTROL
, rc6_mode
);
4230 /* 4 Program defaults and thresholds for RPS*/
4231 I915_WRITE(GEN6_RP_UP_THRESHOLD
, 59400);
4232 I915_WRITE(GEN6_RP_DOWN_THRESHOLD
, 245000);
4233 I915_WRITE(GEN6_RP_UP_EI
, 66000);
4234 I915_WRITE(GEN6_RP_DOWN_EI
, 350000);
4236 I915_WRITE(GEN6_RP_IDLE_HYSTERSIS
, 10);
4238 /* WaDisablePwrmtrEvent:chv (pre-production hw) */
4239 I915_WRITE(0xA80C, I915_READ(0xA80C) & 0x00ffffff);
4240 I915_WRITE(0xA810, I915_READ(0xA810) & 0xffffff00);
4243 I915_WRITE(GEN6_RP_CONTROL
,
4244 GEN6_RP_MEDIA_HW_NORMAL_MODE
|
4245 GEN6_RP_MEDIA_IS_GFX
| /* WaSetMaskForGfxBusyness:chv (pre-production hw ?) */
4247 GEN6_RP_UP_BUSY_AVG
|
4248 GEN6_RP_DOWN_IDLE_AVG
);
4250 val
= vlv_punit_read(dev_priv
, PUNIT_REG_GPU_FREQ_STS
);
4252 DRM_DEBUG_DRIVER("GPLL enabled? %s\n", val
& 0x10 ? "yes" : "no");
4253 DRM_DEBUG_DRIVER("GPU status: 0x%08x\n", val
);
4255 dev_priv
->rps
.cur_freq
= (val
>> 8) & 0xff;
4256 DRM_DEBUG_DRIVER("current GPU freq: %d MHz (%u)\n",
4257 vlv_gpu_freq(dev_priv
, dev_priv
->rps
.cur_freq
),
4258 dev_priv
->rps
.cur_freq
);
4260 DRM_DEBUG_DRIVER("setting GPU freq to %d MHz (%u)\n",
4261 vlv_gpu_freq(dev_priv
, dev_priv
->rps
.efficient_freq
),
4262 dev_priv
->rps
.efficient_freq
);
4264 valleyview_set_rps(dev_priv
->dev
, dev_priv
->rps
.efficient_freq
);
4266 gen8_enable_rps_interrupts(dev
);
4268 gen6_gt_force_wake_put(dev_priv
, FORCEWAKE_ALL
);
4271 static void valleyview_enable_rps(struct drm_device
*dev
)
4273 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4274 struct intel_engine_cs
*ring
;
4275 u32 gtfifodbg
, val
, rc6_mode
= 0;
4278 WARN_ON(!mutex_is_locked(&dev_priv
->rps
.hw_lock
));
4280 valleyview_check_pctx(dev_priv
);
4282 if ((gtfifodbg
= I915_READ(GTFIFODBG
))) {
4283 DRM_DEBUG_DRIVER("GT fifo had a previous error %x\n",
4285 I915_WRITE(GTFIFODBG
, gtfifodbg
);
4288 /* If VLV, Forcewake all wells, else re-direct to regular path */
4289 gen6_gt_force_wake_get(dev_priv
, FORCEWAKE_ALL
);
4291 I915_WRITE(GEN6_RP_UP_THRESHOLD
, 59400);
4292 I915_WRITE(GEN6_RP_DOWN_THRESHOLD
, 245000);
4293 I915_WRITE(GEN6_RP_UP_EI
, 66000);
4294 I915_WRITE(GEN6_RP_DOWN_EI
, 350000);
4296 I915_WRITE(GEN6_RP_IDLE_HYSTERSIS
, 10);
4297 I915_WRITE(GEN6_RP_DOWN_TIMEOUT
, 0xf4240);
4299 I915_WRITE(GEN6_RP_CONTROL
,
4300 GEN6_RP_MEDIA_TURBO
|
4301 GEN6_RP_MEDIA_HW_NORMAL_MODE
|
4302 GEN6_RP_MEDIA_IS_GFX
|
4304 GEN6_RP_UP_BUSY_AVG
|
4305 GEN6_RP_DOWN_IDLE_CONT
);
4307 I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT
, 0x00280000);
4308 I915_WRITE(GEN6_RC_EVALUATION_INTERVAL
, 125000);
4309 I915_WRITE(GEN6_RC_IDLE_HYSTERSIS
, 25);
4311 for_each_ring(ring
, dev_priv
, i
)
4312 I915_WRITE(RING_MAX_IDLE(ring
->mmio_base
), 10);
4314 I915_WRITE(GEN6_RC6_THRESHOLD
, 0x557);
4316 /* allows RC6 residency counter to work */
4317 I915_WRITE(VLV_COUNTER_CONTROL
,
4318 _MASKED_BIT_ENABLE(VLV_MEDIA_RC0_COUNT_EN
|
4319 VLV_RENDER_RC0_COUNT_EN
|
4320 VLV_MEDIA_RC6_COUNT_EN
|
4321 VLV_RENDER_RC6_COUNT_EN
));
4323 if (intel_enable_rc6(dev
) & INTEL_RC6_ENABLE
)
4324 rc6_mode
= GEN7_RC_CTL_TO_MODE
| VLV_RC_CTL_CTX_RST_PARALLEL
;
4326 intel_print_rc6_info(dev
, rc6_mode
);
4328 I915_WRITE(GEN6_RC_CONTROL
, rc6_mode
);
4330 val
= vlv_punit_read(dev_priv
, PUNIT_REG_GPU_FREQ_STS
);
4332 DRM_DEBUG_DRIVER("GPLL enabled? %s\n", val
& 0x10 ? "yes" : "no");
4333 DRM_DEBUG_DRIVER("GPU status: 0x%08x\n", val
);
4335 dev_priv
->rps
.cur_freq
= (val
>> 8) & 0xff;
4336 DRM_DEBUG_DRIVER("current GPU freq: %d MHz (%u)\n",
4337 vlv_gpu_freq(dev_priv
, dev_priv
->rps
.cur_freq
),
4338 dev_priv
->rps
.cur_freq
);
4340 DRM_DEBUG_DRIVER("setting GPU freq to %d MHz (%u)\n",
4341 vlv_gpu_freq(dev_priv
, dev_priv
->rps
.efficient_freq
),
4342 dev_priv
->rps
.efficient_freq
);
4344 valleyview_set_rps(dev_priv
->dev
, dev_priv
->rps
.efficient_freq
);
4346 gen6_enable_rps_interrupts(dev
);
4348 gen6_gt_force_wake_put(dev_priv
, FORCEWAKE_ALL
);
4351 void ironlake_teardown_rc6(struct drm_device
*dev
)
4353 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4355 if (dev_priv
->ips
.renderctx
) {
4356 i915_gem_object_ggtt_unpin(dev_priv
->ips
.renderctx
);
4357 drm_gem_object_unreference(&dev_priv
->ips
.renderctx
->base
);
4358 dev_priv
->ips
.renderctx
= NULL
;
4361 if (dev_priv
->ips
.pwrctx
) {
4362 i915_gem_object_ggtt_unpin(dev_priv
->ips
.pwrctx
);
4363 drm_gem_object_unreference(&dev_priv
->ips
.pwrctx
->base
);
4364 dev_priv
->ips
.pwrctx
= NULL
;
4368 static void ironlake_disable_rc6(struct drm_device
*dev
)
4370 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4372 if (I915_READ(PWRCTXA
)) {
4373 /* Wake the GPU, prevent RC6, then restore RSTDBYCTL */
4374 I915_WRITE(RSTDBYCTL
, I915_READ(RSTDBYCTL
) | RCX_SW_EXIT
);
4375 wait_for(((I915_READ(RSTDBYCTL
) & RSX_STATUS_MASK
) == RSX_STATUS_ON
),
4378 I915_WRITE(PWRCTXA
, 0);
4379 POSTING_READ(PWRCTXA
);
4381 I915_WRITE(RSTDBYCTL
, I915_READ(RSTDBYCTL
) & ~RCX_SW_EXIT
);
4382 POSTING_READ(RSTDBYCTL
);
4386 static int ironlake_setup_rc6(struct drm_device
*dev
)
4388 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4390 if (dev_priv
->ips
.renderctx
== NULL
)
4391 dev_priv
->ips
.renderctx
= intel_alloc_context_page(dev
);
4392 if (!dev_priv
->ips
.renderctx
)
4395 if (dev_priv
->ips
.pwrctx
== NULL
)
4396 dev_priv
->ips
.pwrctx
= intel_alloc_context_page(dev
);
4397 if (!dev_priv
->ips
.pwrctx
) {
4398 ironlake_teardown_rc6(dev
);
4405 static void ironlake_enable_rc6(struct drm_device
*dev
)
4407 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4408 struct intel_engine_cs
*ring
= &dev_priv
->ring
[RCS
];
4409 bool was_interruptible
;
4412 /* rc6 disabled by default due to repeated reports of hanging during
4415 if (!intel_enable_rc6(dev
))
4418 WARN_ON(!mutex_is_locked(&dev
->struct_mutex
));
4420 ret
= ironlake_setup_rc6(dev
);
4424 was_interruptible
= dev_priv
->mm
.interruptible
;
4425 dev_priv
->mm
.interruptible
= false;
4428 * GPU can automatically power down the render unit if given a page
4431 ret
= intel_ring_begin(ring
, 6);
4433 ironlake_teardown_rc6(dev
);
4434 dev_priv
->mm
.interruptible
= was_interruptible
;
4438 intel_ring_emit(ring
, MI_SUSPEND_FLUSH
| MI_SUSPEND_FLUSH_EN
);
4439 intel_ring_emit(ring
, MI_SET_CONTEXT
);
4440 intel_ring_emit(ring
, i915_gem_obj_ggtt_offset(dev_priv
->ips
.renderctx
) |
4442 MI_SAVE_EXT_STATE_EN
|
4443 MI_RESTORE_EXT_STATE_EN
|
4444 MI_RESTORE_INHIBIT
);
4445 intel_ring_emit(ring
, MI_SUSPEND_FLUSH
);
4446 intel_ring_emit(ring
, MI_NOOP
);
4447 intel_ring_emit(ring
, MI_FLUSH
);
4448 intel_ring_advance(ring
);
4451 * Wait for the command parser to advance past MI_SET_CONTEXT. The HW
4452 * does an implicit flush, combined with MI_FLUSH above, it should be
4453 * safe to assume that renderctx is valid
4455 ret
= intel_ring_idle(ring
);
4456 dev_priv
->mm
.interruptible
= was_interruptible
;
4458 DRM_ERROR("failed to enable ironlake power savings\n");
4459 ironlake_teardown_rc6(dev
);
4463 I915_WRITE(PWRCTXA
, i915_gem_obj_ggtt_offset(dev_priv
->ips
.pwrctx
) | PWRCTX_EN
);
4464 I915_WRITE(RSTDBYCTL
, I915_READ(RSTDBYCTL
) & ~RCX_SW_EXIT
);
4466 intel_print_rc6_info(dev
, GEN6_RC_CTL_RC6_ENABLE
);
4469 static unsigned long intel_pxfreq(u32 vidfreq
)
4472 int div
= (vidfreq
& 0x3f0000) >> 16;
4473 int post
= (vidfreq
& 0x3000) >> 12;
4474 int pre
= (vidfreq
& 0x7);
4479 freq
= ((div
* 133333) / ((1<<post
) * pre
));
4484 static const struct cparams
{
4490 { 1, 1333, 301, 28664 },
4491 { 1, 1066, 294, 24460 },
4492 { 1, 800, 294, 25192 },
4493 { 0, 1333, 276, 27605 },
4494 { 0, 1066, 276, 27605 },
4495 { 0, 800, 231, 23784 },
4498 static unsigned long __i915_chipset_val(struct drm_i915_private
*dev_priv
)
4500 u64 total_count
, diff
, ret
;
4501 u32 count1
, count2
, count3
, m
= 0, c
= 0;
4502 unsigned long now
= jiffies_to_msecs(jiffies
), diff1
;
4505 assert_spin_locked(&mchdev_lock
);
4507 diff1
= now
- dev_priv
->ips
.last_time1
;
4509 /* Prevent division-by-zero if we are asking too fast.
4510 * Also, we don't get interesting results if we are polling
4511 * faster than once in 10ms, so just return the saved value
4515 return dev_priv
->ips
.chipset_power
;
4517 count1
= I915_READ(DMIEC
);
4518 count2
= I915_READ(DDREC
);
4519 count3
= I915_READ(CSIEC
);
4521 total_count
= count1
+ count2
+ count3
;
4523 /* FIXME: handle per-counter overflow */
4524 if (total_count
< dev_priv
->ips
.last_count1
) {
4525 diff
= ~0UL - dev_priv
->ips
.last_count1
;
4526 diff
+= total_count
;
4528 diff
= total_count
- dev_priv
->ips
.last_count1
;
4531 for (i
= 0; i
< ARRAY_SIZE(cparams
); i
++) {
4532 if (cparams
[i
].i
== dev_priv
->ips
.c_m
&&
4533 cparams
[i
].t
== dev_priv
->ips
.r_t
) {
4540 diff
= div_u64(diff
, diff1
);
4541 ret
= ((m
* diff
) + c
);
4542 ret
= div_u64(ret
, 10);
4544 dev_priv
->ips
.last_count1
= total_count
;
4545 dev_priv
->ips
.last_time1
= now
;
4547 dev_priv
->ips
.chipset_power
= ret
;
4552 unsigned long i915_chipset_val(struct drm_i915_private
*dev_priv
)
4554 struct drm_device
*dev
= dev_priv
->dev
;
4557 if (INTEL_INFO(dev
)->gen
!= 5)
4560 spin_lock_irq(&mchdev_lock
);
4562 val
= __i915_chipset_val(dev_priv
);
4564 spin_unlock_irq(&mchdev_lock
);
4569 unsigned long i915_mch_val(struct drm_i915_private
*dev_priv
)
4571 unsigned long m
, x
, b
;
4574 tsfs
= I915_READ(TSFS
);
4576 m
= ((tsfs
& TSFS_SLOPE_MASK
) >> TSFS_SLOPE_SHIFT
);
4577 x
= I915_READ8(TR1
);
4579 b
= tsfs
& TSFS_INTR_MASK
;
4581 return ((m
* x
) / 127) - b
;
4584 static u16
pvid_to_extvid(struct drm_i915_private
*dev_priv
, u8 pxvid
)
4586 struct drm_device
*dev
= dev_priv
->dev
;
4587 static const struct v_table
{
4588 u16 vd
; /* in .1 mil */
4589 u16 vm
; /* in .1 mil */
4720 if (INTEL_INFO(dev
)->is_mobile
)
4721 return v_table
[pxvid
].vm
;
4723 return v_table
[pxvid
].vd
;
4726 static void __i915_update_gfx_val(struct drm_i915_private
*dev_priv
)
4728 u64 now
, diff
, diffms
;
4731 assert_spin_locked(&mchdev_lock
);
4733 now
= ktime_get_raw_ns();
4734 diffms
= now
- dev_priv
->ips
.last_time2
;
4735 do_div(diffms
, NSEC_PER_MSEC
);
4737 /* Don't divide by 0 */
4741 count
= I915_READ(GFXEC
);
4743 if (count
< dev_priv
->ips
.last_count2
) {
4744 diff
= ~0UL - dev_priv
->ips
.last_count2
;
4747 diff
= count
- dev_priv
->ips
.last_count2
;
4750 dev_priv
->ips
.last_count2
= count
;
4751 dev_priv
->ips
.last_time2
= now
;
4753 /* More magic constants... */
4755 diff
= div_u64(diff
, diffms
* 10);
4756 dev_priv
->ips
.gfx_power
= diff
;
4759 void i915_update_gfx_val(struct drm_i915_private
*dev_priv
)
4761 struct drm_device
*dev
= dev_priv
->dev
;
4763 if (INTEL_INFO(dev
)->gen
!= 5)
4766 spin_lock_irq(&mchdev_lock
);
4768 __i915_update_gfx_val(dev_priv
);
4770 spin_unlock_irq(&mchdev_lock
);
4773 static unsigned long __i915_gfx_val(struct drm_i915_private
*dev_priv
)
4775 unsigned long t
, corr
, state1
, corr2
, state2
;
4778 assert_spin_locked(&mchdev_lock
);
4780 pxvid
= I915_READ(PXVFREQ_BASE
+ (dev_priv
->rps
.cur_freq
* 4));
4781 pxvid
= (pxvid
>> 24) & 0x7f;
4782 ext_v
= pvid_to_extvid(dev_priv
, pxvid
);
4786 t
= i915_mch_val(dev_priv
);
4788 /* Revel in the empirically derived constants */
4790 /* Correction factor in 1/100000 units */
4792 corr
= ((t
* 2349) + 135940);
4794 corr
= ((t
* 964) + 29317);
4796 corr
= ((t
* 301) + 1004);
4798 corr
= corr
* ((150142 * state1
) / 10000 - 78642);
4800 corr2
= (corr
* dev_priv
->ips
.corr
);
4802 state2
= (corr2
* state1
) / 10000;
4803 state2
/= 100; /* convert to mW */
4805 __i915_update_gfx_val(dev_priv
);
4807 return dev_priv
->ips
.gfx_power
+ state2
;
4810 unsigned long i915_gfx_val(struct drm_i915_private
*dev_priv
)
4812 struct drm_device
*dev
= dev_priv
->dev
;
4815 if (INTEL_INFO(dev
)->gen
!= 5)
4818 spin_lock_irq(&mchdev_lock
);
4820 val
= __i915_gfx_val(dev_priv
);
4822 spin_unlock_irq(&mchdev_lock
);
4828 * i915_read_mch_val - return value for IPS use
4830 * Calculate and return a value for the IPS driver to use when deciding whether
4831 * we have thermal and power headroom to increase CPU or GPU power budget.
4833 unsigned long i915_read_mch_val(void)
4835 struct drm_i915_private
*dev_priv
;
4836 unsigned long chipset_val
, graphics_val
, ret
= 0;
4838 spin_lock_irq(&mchdev_lock
);
4841 dev_priv
= i915_mch_dev
;
4843 chipset_val
= __i915_chipset_val(dev_priv
);
4844 graphics_val
= __i915_gfx_val(dev_priv
);
4846 ret
= chipset_val
+ graphics_val
;
4849 spin_unlock_irq(&mchdev_lock
);
4853 EXPORT_SYMBOL_GPL(i915_read_mch_val
);
4856 * i915_gpu_raise - raise GPU frequency limit
4858 * Raise the limit; IPS indicates we have thermal headroom.
4860 bool i915_gpu_raise(void)
4862 struct drm_i915_private
*dev_priv
;
4865 spin_lock_irq(&mchdev_lock
);
4866 if (!i915_mch_dev
) {
4870 dev_priv
= i915_mch_dev
;
4872 if (dev_priv
->ips
.max_delay
> dev_priv
->ips
.fmax
)
4873 dev_priv
->ips
.max_delay
--;
4876 spin_unlock_irq(&mchdev_lock
);
4880 EXPORT_SYMBOL_GPL(i915_gpu_raise
);
4883 * i915_gpu_lower - lower GPU frequency limit
4885 * IPS indicates we're close to a thermal limit, so throttle back the GPU
4886 * frequency maximum.
4888 bool i915_gpu_lower(void)
4890 struct drm_i915_private
*dev_priv
;
4893 spin_lock_irq(&mchdev_lock
);
4894 if (!i915_mch_dev
) {
4898 dev_priv
= i915_mch_dev
;
4900 if (dev_priv
->ips
.max_delay
< dev_priv
->ips
.min_delay
)
4901 dev_priv
->ips
.max_delay
++;
4904 spin_unlock_irq(&mchdev_lock
);
4908 EXPORT_SYMBOL_GPL(i915_gpu_lower
);
4911 * i915_gpu_busy - indicate GPU business to IPS
4913 * Tell the IPS driver whether or not the GPU is busy.
4915 bool i915_gpu_busy(void)
4917 struct drm_i915_private
*dev_priv
;
4918 struct intel_engine_cs
*ring
;
4922 spin_lock_irq(&mchdev_lock
);
4925 dev_priv
= i915_mch_dev
;
4927 for_each_ring(ring
, dev_priv
, i
)
4928 ret
|= !list_empty(&ring
->request_list
);
4931 spin_unlock_irq(&mchdev_lock
);
4935 EXPORT_SYMBOL_GPL(i915_gpu_busy
);
4938 * i915_gpu_turbo_disable - disable graphics turbo
4940 * Disable graphics turbo by resetting the max frequency and setting the
4941 * current frequency to the default.
4943 bool i915_gpu_turbo_disable(void)
4945 struct drm_i915_private
*dev_priv
;
4948 spin_lock_irq(&mchdev_lock
);
4949 if (!i915_mch_dev
) {
4953 dev_priv
= i915_mch_dev
;
4955 dev_priv
->ips
.max_delay
= dev_priv
->ips
.fstart
;
4957 if (!ironlake_set_drps(dev_priv
->dev
, dev_priv
->ips
.fstart
))
4961 spin_unlock_irq(&mchdev_lock
);
4965 EXPORT_SYMBOL_GPL(i915_gpu_turbo_disable
);
4968 * Tells the intel_ips driver that the i915 driver is now loaded, if
4969 * IPS got loaded first.
4971 * This awkward dance is so that neither module has to depend on the
4972 * other in order for IPS to do the appropriate communication of
4973 * GPU turbo limits to i915.
4976 ips_ping_for_i915_load(void)
4980 link
= symbol_get(ips_link_to_i915_driver
);
4983 symbol_put(ips_link_to_i915_driver
);
4987 void intel_gpu_ips_init(struct drm_i915_private
*dev_priv
)
4989 /* We only register the i915 ips part with intel-ips once everything is
4990 * set up, to avoid intel-ips sneaking in and reading bogus values. */
4991 spin_lock_irq(&mchdev_lock
);
4992 i915_mch_dev
= dev_priv
;
4993 spin_unlock_irq(&mchdev_lock
);
4995 ips_ping_for_i915_load();
4998 void intel_gpu_ips_teardown(void)
5000 spin_lock_irq(&mchdev_lock
);
5001 i915_mch_dev
= NULL
;
5002 spin_unlock_irq(&mchdev_lock
);
5005 static void intel_init_emon(struct drm_device
*dev
)
5007 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5012 /* Disable to program */
5016 /* Program energy weights for various events */
5017 I915_WRITE(SDEW
, 0x15040d00);
5018 I915_WRITE(CSIEW0
, 0x007f0000);
5019 I915_WRITE(CSIEW1
, 0x1e220004);
5020 I915_WRITE(CSIEW2
, 0x04000004);
5022 for (i
= 0; i
< 5; i
++)
5023 I915_WRITE(PEW
+ (i
* 4), 0);
5024 for (i
= 0; i
< 3; i
++)
5025 I915_WRITE(DEW
+ (i
* 4), 0);
5027 /* Program P-state weights to account for frequency power adjustment */
5028 for (i
= 0; i
< 16; i
++) {
5029 u32 pxvidfreq
= I915_READ(PXVFREQ_BASE
+ (i
* 4));
5030 unsigned long freq
= intel_pxfreq(pxvidfreq
);
5031 unsigned long vid
= (pxvidfreq
& PXVFREQ_PX_MASK
) >>
5036 val
*= (freq
/ 1000);
5038 val
/= (127*127*900);
5040 DRM_ERROR("bad pxval: %ld\n", val
);
5043 /* Render standby states get 0 weight */
5047 for (i
= 0; i
< 4; i
++) {
5048 u32 val
= (pxw
[i
*4] << 24) | (pxw
[(i
*4)+1] << 16) |
5049 (pxw
[(i
*4)+2] << 8) | (pxw
[(i
*4)+3]);
5050 I915_WRITE(PXW
+ (i
* 4), val
);
5053 /* Adjust magic regs to magic values (more experimental results) */
5054 I915_WRITE(OGW0
, 0);
5055 I915_WRITE(OGW1
, 0);
5056 I915_WRITE(EG0
, 0x00007f00);
5057 I915_WRITE(EG1
, 0x0000000e);
5058 I915_WRITE(EG2
, 0x000e0000);
5059 I915_WRITE(EG3
, 0x68000300);
5060 I915_WRITE(EG4
, 0x42000000);
5061 I915_WRITE(EG5
, 0x00140031);
5065 for (i
= 0; i
< 8; i
++)
5066 I915_WRITE(PXWL
+ (i
* 4), 0);
5068 /* Enable PMON + select events */
5069 I915_WRITE(ECR
, 0x80000019);
5071 lcfuse
= I915_READ(LCFUSE02
);
5073 dev_priv
->ips
.corr
= (lcfuse
& LCFUSE_HIV_MASK
);
5076 void intel_init_gt_powersave(struct drm_device
*dev
)
5078 i915
.enable_rc6
= sanitize_rc6_option(dev
, i915
.enable_rc6
);
5080 if (IS_CHERRYVIEW(dev
))
5081 cherryview_init_gt_powersave(dev
);
5082 else if (IS_VALLEYVIEW(dev
))
5083 valleyview_init_gt_powersave(dev
);
5086 void intel_cleanup_gt_powersave(struct drm_device
*dev
)
5088 if (IS_CHERRYVIEW(dev
))
5090 else if (IS_VALLEYVIEW(dev
))
5091 valleyview_cleanup_gt_powersave(dev
);
5095 * intel_suspend_gt_powersave - suspend PM work and helper threads
5098 * We don't want to disable RC6 or other features here, we just want
5099 * to make sure any work we've queued has finished and won't bother
5100 * us while we're suspended.
5102 void intel_suspend_gt_powersave(struct drm_device
*dev
)
5104 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5106 /* Interrupts should be disabled already to avoid re-arming. */
5107 WARN_ON(intel_irqs_enabled(dev_priv
));
5109 flush_delayed_work(&dev_priv
->rps
.delayed_resume_work
);
5111 cancel_work_sync(&dev_priv
->rps
.work
);
5113 /* Force GPU to min freq during suspend */
5114 gen6_rps_idle(dev_priv
);
5117 void intel_disable_gt_powersave(struct drm_device
*dev
)
5119 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5121 /* Interrupts should be disabled already to avoid re-arming. */
5122 WARN_ON(intel_irqs_enabled(dev_priv
));
5124 if (IS_IRONLAKE_M(dev
)) {
5125 ironlake_disable_drps(dev
);
5126 ironlake_disable_rc6(dev
);
5127 } else if (INTEL_INFO(dev
)->gen
>= 6) {
5128 intel_suspend_gt_powersave(dev
);
5130 mutex_lock(&dev_priv
->rps
.hw_lock
);
5131 if (IS_CHERRYVIEW(dev
))
5132 cherryview_disable_rps(dev
);
5133 else if (IS_VALLEYVIEW(dev
))
5134 valleyview_disable_rps(dev
);
5136 gen6_disable_rps(dev
);
5137 dev_priv
->rps
.enabled
= false;
5138 mutex_unlock(&dev_priv
->rps
.hw_lock
);
5142 static void intel_gen6_powersave_work(struct work_struct
*work
)
5144 struct drm_i915_private
*dev_priv
=
5145 container_of(work
, struct drm_i915_private
,
5146 rps
.delayed_resume_work
.work
);
5147 struct drm_device
*dev
= dev_priv
->dev
;
5149 mutex_lock(&dev_priv
->rps
.hw_lock
);
5151 if (IS_CHERRYVIEW(dev
)) {
5152 cherryview_enable_rps(dev
);
5153 } else if (IS_VALLEYVIEW(dev
)) {
5154 valleyview_enable_rps(dev
);
5155 } else if (IS_BROADWELL(dev
)) {
5156 gen8_enable_rps(dev
);
5157 __gen6_update_ring_freq(dev
);
5159 gen6_enable_rps(dev
);
5160 __gen6_update_ring_freq(dev
);
5162 dev_priv
->rps
.enabled
= true;
5163 mutex_unlock(&dev_priv
->rps
.hw_lock
);
5165 intel_runtime_pm_put(dev_priv
);
5168 void intel_enable_gt_powersave(struct drm_device
*dev
)
5170 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5172 if (IS_IRONLAKE_M(dev
)) {
5173 mutex_lock(&dev
->struct_mutex
);
5174 ironlake_enable_drps(dev
);
5175 ironlake_enable_rc6(dev
);
5176 intel_init_emon(dev
);
5177 mutex_unlock(&dev
->struct_mutex
);
5178 } else if (INTEL_INFO(dev
)->gen
>= 6) {
5180 * PCU communication is slow and this doesn't need to be
5181 * done at any specific time, so do this out of our fast path
5182 * to make resume and init faster.
5184 * We depend on the HW RC6 power context save/restore
5185 * mechanism when entering D3 through runtime PM suspend. So
5186 * disable RPM until RPS/RC6 is properly setup. We can only
5187 * get here via the driver load/system resume/runtime resume
5188 * paths, so the _noresume version is enough (and in case of
5189 * runtime resume it's necessary).
5191 if (schedule_delayed_work(&dev_priv
->rps
.delayed_resume_work
,
5192 round_jiffies_up_relative(HZ
)))
5193 intel_runtime_pm_get_noresume(dev_priv
);
5197 void intel_reset_gt_powersave(struct drm_device
*dev
)
5199 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5201 dev_priv
->rps
.enabled
= false;
5202 intel_enable_gt_powersave(dev
);
5205 static void ibx_init_clock_gating(struct drm_device
*dev
)
5207 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5210 * On Ibex Peak and Cougar Point, we need to disable clock
5211 * gating for the panel power sequencer or it will fail to
5212 * start up when no ports are active.
5214 I915_WRITE(SOUTH_DSPCLK_GATE_D
, PCH_DPLSUNIT_CLOCK_GATE_DISABLE
);
5217 static void g4x_disable_trickle_feed(struct drm_device
*dev
)
5219 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5222 for_each_pipe(dev_priv
, pipe
) {
5223 I915_WRITE(DSPCNTR(pipe
),
5224 I915_READ(DSPCNTR(pipe
)) |
5225 DISPPLANE_TRICKLE_FEED_DISABLE
);
5226 intel_flush_primary_plane(dev_priv
, pipe
);
5230 static void ilk_init_lp_watermarks(struct drm_device
*dev
)
5232 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5234 I915_WRITE(WM3_LP_ILK
, I915_READ(WM3_LP_ILK
) & ~WM1_LP_SR_EN
);
5235 I915_WRITE(WM2_LP_ILK
, I915_READ(WM2_LP_ILK
) & ~WM1_LP_SR_EN
);
5236 I915_WRITE(WM1_LP_ILK
, I915_READ(WM1_LP_ILK
) & ~WM1_LP_SR_EN
);
5239 * Don't touch WM1S_LP_EN here.
5240 * Doing so could cause underruns.
5244 static void ironlake_init_clock_gating(struct drm_device
*dev
)
5246 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5247 uint32_t dspclk_gate
= ILK_VRHUNIT_CLOCK_GATE_DISABLE
;
5251 * WaFbcDisableDpfcClockGating:ilk
5253 dspclk_gate
|= ILK_DPFCRUNIT_CLOCK_GATE_DISABLE
|
5254 ILK_DPFCUNIT_CLOCK_GATE_DISABLE
|
5255 ILK_DPFDUNIT_CLOCK_GATE_ENABLE
;
5257 I915_WRITE(PCH_3DCGDIS0
,
5258 MARIUNIT_CLOCK_GATE_DISABLE
|
5259 SVSMUNIT_CLOCK_GATE_DISABLE
);
5260 I915_WRITE(PCH_3DCGDIS1
,
5261 VFMUNIT_CLOCK_GATE_DISABLE
);
5264 * According to the spec the following bits should be set in
5265 * order to enable memory self-refresh
5266 * The bit 22/21 of 0x42004
5267 * The bit 5 of 0x42020
5268 * The bit 15 of 0x45000
5270 I915_WRITE(ILK_DISPLAY_CHICKEN2
,
5271 (I915_READ(ILK_DISPLAY_CHICKEN2
) |
5272 ILK_DPARB_GATE
| ILK_VSDPFD_FULL
));
5273 dspclk_gate
|= ILK_DPARBUNIT_CLOCK_GATE_ENABLE
;
5274 I915_WRITE(DISP_ARB_CTL
,
5275 (I915_READ(DISP_ARB_CTL
) |
5278 ilk_init_lp_watermarks(dev
);
5281 * Based on the document from hardware guys the following bits
5282 * should be set unconditionally in order to enable FBC.
5283 * The bit 22 of 0x42000
5284 * The bit 22 of 0x42004
5285 * The bit 7,8,9 of 0x42020.
5287 if (IS_IRONLAKE_M(dev
)) {
5288 /* WaFbcAsynchFlipDisableFbcQueue:ilk */
5289 I915_WRITE(ILK_DISPLAY_CHICKEN1
,
5290 I915_READ(ILK_DISPLAY_CHICKEN1
) |
5292 I915_WRITE(ILK_DISPLAY_CHICKEN2
,
5293 I915_READ(ILK_DISPLAY_CHICKEN2
) |
5297 I915_WRITE(ILK_DSPCLK_GATE_D
, dspclk_gate
);
5299 I915_WRITE(ILK_DISPLAY_CHICKEN2
,
5300 I915_READ(ILK_DISPLAY_CHICKEN2
) |
5301 ILK_ELPIN_409_SELECT
);
5302 I915_WRITE(_3D_CHICKEN2
,
5303 _3D_CHICKEN2_WM_READ_PIPELINED
<< 16 |
5304 _3D_CHICKEN2_WM_READ_PIPELINED
);
5306 /* WaDisableRenderCachePipelinedFlush:ilk */
5307 I915_WRITE(CACHE_MODE_0
,
5308 _MASKED_BIT_ENABLE(CM0_PIPELINED_RENDER_FLUSH_DISABLE
));
5310 /* WaDisable_RenderCache_OperationalFlush:ilk */
5311 I915_WRITE(CACHE_MODE_0
, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE
));
5313 g4x_disable_trickle_feed(dev
);
5315 ibx_init_clock_gating(dev
);
5318 static void cpt_init_clock_gating(struct drm_device
*dev
)
5320 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5325 * On Ibex Peak and Cougar Point, we need to disable clock
5326 * gating for the panel power sequencer or it will fail to
5327 * start up when no ports are active.
5329 I915_WRITE(SOUTH_DSPCLK_GATE_D
, PCH_DPLSUNIT_CLOCK_GATE_DISABLE
|
5330 PCH_DPLUNIT_CLOCK_GATE_DISABLE
|
5331 PCH_CPUNIT_CLOCK_GATE_DISABLE
);
5332 I915_WRITE(SOUTH_CHICKEN2
, I915_READ(SOUTH_CHICKEN2
) |
5333 DPLS_EDP_PPS_FIX_DIS
);
5334 /* The below fixes the weird display corruption, a few pixels shifted
5335 * downward, on (only) LVDS of some HP laptops with IVY.
5337 for_each_pipe(dev_priv
, pipe
) {
5338 val
= I915_READ(TRANS_CHICKEN2(pipe
));
5339 val
|= TRANS_CHICKEN2_TIMING_OVERRIDE
;
5340 val
&= ~TRANS_CHICKEN2_FDI_POLARITY_REVERSED
;
5341 if (dev_priv
->vbt
.fdi_rx_polarity_inverted
)
5342 val
|= TRANS_CHICKEN2_FDI_POLARITY_REVERSED
;
5343 val
&= ~TRANS_CHICKEN2_FRAME_START_DELAY_MASK
;
5344 val
&= ~TRANS_CHICKEN2_DISABLE_DEEP_COLOR_COUNTER
;
5345 val
&= ~TRANS_CHICKEN2_DISABLE_DEEP_COLOR_MODESWITCH
;
5346 I915_WRITE(TRANS_CHICKEN2(pipe
), val
);
5348 /* WADP0ClockGatingDisable */
5349 for_each_pipe(dev_priv
, pipe
) {
5350 I915_WRITE(TRANS_CHICKEN1(pipe
),
5351 TRANS_CHICKEN1_DP0UNIT_GC_DISABLE
);
5355 static void gen6_check_mch_setup(struct drm_device
*dev
)
5357 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5360 tmp
= I915_READ(MCH_SSKPD
);
5361 if ((tmp
& MCH_SSKPD_WM0_MASK
) != MCH_SSKPD_WM0_VAL
)
5362 DRM_DEBUG_KMS("Wrong MCH_SSKPD value: 0x%08x This can cause underruns.\n",
5366 static void gen6_init_clock_gating(struct drm_device
*dev
)
5368 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5369 uint32_t dspclk_gate
= ILK_VRHUNIT_CLOCK_GATE_DISABLE
;
5371 I915_WRITE(ILK_DSPCLK_GATE_D
, dspclk_gate
);
5373 I915_WRITE(ILK_DISPLAY_CHICKEN2
,
5374 I915_READ(ILK_DISPLAY_CHICKEN2
) |
5375 ILK_ELPIN_409_SELECT
);
5377 /* WaDisableHiZPlanesWhenMSAAEnabled:snb */
5378 I915_WRITE(_3D_CHICKEN
,
5379 _MASKED_BIT_ENABLE(_3D_CHICKEN_HIZ_PLANE_DISABLE_MSAA_4X_SNB
));
5381 /* WaSetupGtModeTdRowDispatch:snb */
5382 if (IS_SNB_GT1(dev
))
5383 I915_WRITE(GEN6_GT_MODE
,
5384 _MASKED_BIT_ENABLE(GEN6_TD_FOUR_ROW_DISPATCH_DISABLE
));
5386 /* WaDisable_RenderCache_OperationalFlush:snb */
5387 I915_WRITE(CACHE_MODE_0
, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE
));
5390 * BSpec recoomends 8x4 when MSAA is used,
5391 * however in practice 16x4 seems fastest.
5393 * Note that PS/WM thread counts depend on the WIZ hashing
5394 * disable bit, which we don't touch here, but it's good
5395 * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM).
5397 I915_WRITE(GEN6_GT_MODE
,
5398 GEN6_WIZ_HASHING_MASK
| GEN6_WIZ_HASHING_16x4
);
5400 ilk_init_lp_watermarks(dev
);
5402 I915_WRITE(CACHE_MODE_0
,
5403 _MASKED_BIT_DISABLE(CM0_STC_EVICT_DISABLE_LRA_SNB
));
5405 I915_WRITE(GEN6_UCGCTL1
,
5406 I915_READ(GEN6_UCGCTL1
) |
5407 GEN6_BLBUNIT_CLOCK_GATE_DISABLE
|
5408 GEN6_CSUNIT_CLOCK_GATE_DISABLE
);
5410 /* According to the BSpec vol1g, bit 12 (RCPBUNIT) clock
5411 * gating disable must be set. Failure to set it results in
5412 * flickering pixels due to Z write ordering failures after
5413 * some amount of runtime in the Mesa "fire" demo, and Unigine
5414 * Sanctuary and Tropics, and apparently anything else with
5415 * alpha test or pixel discard.
5417 * According to the spec, bit 11 (RCCUNIT) must also be set,
5418 * but we didn't debug actual testcases to find it out.
5420 * WaDisableRCCUnitClockGating:snb
5421 * WaDisableRCPBUnitClockGating:snb
5423 I915_WRITE(GEN6_UCGCTL2
,
5424 GEN6_RCPBUNIT_CLOCK_GATE_DISABLE
|
5425 GEN6_RCCUNIT_CLOCK_GATE_DISABLE
);
5427 /* WaStripsFansDisableFastClipPerformanceFix:snb */
5428 I915_WRITE(_3D_CHICKEN3
,
5429 _MASKED_BIT_ENABLE(_3D_CHICKEN3_SF_DISABLE_FASTCLIP_CULL
));
5433 * "This bit must be set if 3DSTATE_CLIP clip mode is set to normal and
5434 * 3DSTATE_SF number of SF output attributes is more than 16."
5436 I915_WRITE(_3D_CHICKEN3
,
5437 _MASKED_BIT_ENABLE(_3D_CHICKEN3_SF_DISABLE_PIPELINED_ATTR_FETCH
));
5440 * According to the spec the following bits should be
5441 * set in order to enable memory self-refresh and fbc:
5442 * The bit21 and bit22 of 0x42000
5443 * The bit21 and bit22 of 0x42004
5444 * The bit5 and bit7 of 0x42020
5445 * The bit14 of 0x70180
5446 * The bit14 of 0x71180
5448 * WaFbcAsynchFlipDisableFbcQueue:snb
5450 I915_WRITE(ILK_DISPLAY_CHICKEN1
,
5451 I915_READ(ILK_DISPLAY_CHICKEN1
) |
5452 ILK_FBCQ_DIS
| ILK_PABSTRETCH_DIS
);
5453 I915_WRITE(ILK_DISPLAY_CHICKEN2
,
5454 I915_READ(ILK_DISPLAY_CHICKEN2
) |
5455 ILK_DPARB_GATE
| ILK_VSDPFD_FULL
);
5456 I915_WRITE(ILK_DSPCLK_GATE_D
,
5457 I915_READ(ILK_DSPCLK_GATE_D
) |
5458 ILK_DPARBUNIT_CLOCK_GATE_ENABLE
|
5459 ILK_DPFDUNIT_CLOCK_GATE_ENABLE
);
5461 g4x_disable_trickle_feed(dev
);
5463 cpt_init_clock_gating(dev
);
5465 gen6_check_mch_setup(dev
);
5468 static void gen7_setup_fixed_func_scheduler(struct drm_i915_private
*dev_priv
)
5470 uint32_t reg
= I915_READ(GEN7_FF_THREAD_MODE
);
5473 * WaVSThreadDispatchOverride:ivb,vlv
5475 * This actually overrides the dispatch
5476 * mode for all thread types.
5478 reg
&= ~GEN7_FF_SCHED_MASK
;
5479 reg
|= GEN7_FF_TS_SCHED_HW
;
5480 reg
|= GEN7_FF_VS_SCHED_HW
;
5481 reg
|= GEN7_FF_DS_SCHED_HW
;
5483 I915_WRITE(GEN7_FF_THREAD_MODE
, reg
);
5486 static void lpt_init_clock_gating(struct drm_device
*dev
)
5488 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5491 * TODO: this bit should only be enabled when really needed, then
5492 * disabled when not needed anymore in order to save power.
5494 if (dev_priv
->pch_id
== INTEL_PCH_LPT_LP_DEVICE_ID_TYPE
)
5495 I915_WRITE(SOUTH_DSPCLK_GATE_D
,
5496 I915_READ(SOUTH_DSPCLK_GATE_D
) |
5497 PCH_LP_PARTITION_LEVEL_DISABLE
);
5499 /* WADPOClockGatingDisable:hsw */
5500 I915_WRITE(_TRANSA_CHICKEN1
,
5501 I915_READ(_TRANSA_CHICKEN1
) |
5502 TRANS_CHICKEN1_DP0UNIT_GC_DISABLE
);
5505 static void lpt_suspend_hw(struct drm_device
*dev
)
5507 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5509 if (dev_priv
->pch_id
== INTEL_PCH_LPT_LP_DEVICE_ID_TYPE
) {
5510 uint32_t val
= I915_READ(SOUTH_DSPCLK_GATE_D
);
5512 val
&= ~PCH_LP_PARTITION_LEVEL_DISABLE
;
5513 I915_WRITE(SOUTH_DSPCLK_GATE_D
, val
);
5517 static void gen8_init_clock_gating(struct drm_device
*dev
)
5519 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5522 I915_WRITE(WM3_LP_ILK
, 0);
5523 I915_WRITE(WM2_LP_ILK
, 0);
5524 I915_WRITE(WM1_LP_ILK
, 0);
5526 /* FIXME(BDW): Check all the w/a, some might only apply to
5527 * pre-production hw. */
5529 /* WaDisablePartialInstShootdown:bdw */
5530 I915_WRITE(GEN8_ROW_CHICKEN
,
5531 _MASKED_BIT_ENABLE(PARTIAL_INSTRUCTION_SHOOTDOWN_DISABLE
));
5533 /* WaDisableThreadStallDopClockGating:bdw */
5534 /* FIXME: Unclear whether we really need this on production bdw. */
5535 I915_WRITE(GEN8_ROW_CHICKEN
,
5536 _MASKED_BIT_ENABLE(STALL_DOP_GATING_DISABLE
));
5539 * This GEN8_CENTROID_PIXEL_OPT_DIS W/A is only needed for
5540 * pre-production hardware
5542 I915_WRITE(HALF_SLICE_CHICKEN3
,
5543 _MASKED_BIT_ENABLE(GEN8_CENTROID_PIXEL_OPT_DIS
));
5544 I915_WRITE(HALF_SLICE_CHICKEN3
,
5545 _MASKED_BIT_ENABLE(GEN8_SAMPLER_POWER_BYPASS_DIS
));
5546 I915_WRITE(GAMTARBMODE
, _MASKED_BIT_ENABLE(ARB_MODE_BWGTLB_DISABLE
));
5548 I915_WRITE(_3D_CHICKEN3
,
5549 _MASKED_BIT_ENABLE(_3D_CHICKEN_SDE_LIMIT_FIFO_POLY_DEPTH(2)));
5551 I915_WRITE(COMMON_SLICE_CHICKEN2
,
5552 _MASKED_BIT_ENABLE(GEN8_CSC2_SBE_VUE_CACHE_CONSERVATIVE
));
5554 I915_WRITE(GEN7_HALF_SLICE_CHICKEN1
,
5555 _MASKED_BIT_ENABLE(GEN7_SINGLE_SUBSCAN_DISPATCH_ENABLE
));
5557 /* WaDisableDopClockGating:bdw May not be needed for production */
5558 I915_WRITE(GEN7_ROW_CHICKEN2
,
5559 _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE
));
5561 /* WaSwitchSolVfFArbitrationPriority:bdw */
5562 I915_WRITE(GAM_ECOCHK
, I915_READ(GAM_ECOCHK
) | HSW_ECOCHK_ARB_PRIO_SOL
);
5564 /* WaPsrDPAMaskVBlankInSRD:bdw */
5565 I915_WRITE(CHICKEN_PAR1_1
,
5566 I915_READ(CHICKEN_PAR1_1
) | DPA_MASK_VBLANK_SRD
);
5568 /* WaPsrDPRSUnmaskVBlankInSRD:bdw */
5569 for_each_pipe(dev_priv
, pipe
) {
5570 I915_WRITE(CHICKEN_PIPESL_1(pipe
),
5571 I915_READ(CHICKEN_PIPESL_1(pipe
)) |
5572 BDW_DPRS_MASK_VBLANK_SRD
);
5575 /* Use Force Non-Coherent whenever executing a 3D context. This is a
5576 * workaround for for a possible hang in the unlikely event a TLB
5577 * invalidation occurs during a PSD flush.
5579 I915_WRITE(HDC_CHICKEN0
,
5580 I915_READ(HDC_CHICKEN0
) |
5581 _MASKED_BIT_ENABLE(HDC_FORCE_NON_COHERENT
));
5583 /* WaVSRefCountFullforceMissDisable:bdw */
5584 /* WaDSRefCountFullforceMissDisable:bdw */
5585 I915_WRITE(GEN7_FF_THREAD_MODE
,
5586 I915_READ(GEN7_FF_THREAD_MODE
) &
5587 ~(GEN8_FF_DS_REF_CNT_FFME
| GEN7_FF_VS_REF_CNT_FFME
));
5590 * BSpec recommends 8x4 when MSAA is used,
5591 * however in practice 16x4 seems fastest.
5593 * Note that PS/WM thread counts depend on the WIZ hashing
5594 * disable bit, which we don't touch here, but it's good
5595 * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM).
5597 I915_WRITE(GEN7_GT_MODE
,
5598 GEN6_WIZ_HASHING_MASK
| GEN6_WIZ_HASHING_16x4
);
5600 I915_WRITE(GEN6_RC_SLEEP_PSMI_CONTROL
,
5601 _MASKED_BIT_ENABLE(GEN8_RC_SEMA_IDLE_MSG_DISABLE
));
5603 /* WaDisableSDEUnitClockGating:bdw */
5604 I915_WRITE(GEN8_UCGCTL6
, I915_READ(GEN8_UCGCTL6
) |
5605 GEN8_SDEUNIT_CLOCK_GATE_DISABLE
);
5607 /* Wa4x4STCOptimizationDisable:bdw */
5608 I915_WRITE(CACHE_MODE_1
,
5609 _MASKED_BIT_ENABLE(GEN8_4x4_STC_OPTIMIZATION_DISABLE
));
5612 static void haswell_init_clock_gating(struct drm_device
*dev
)
5614 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5616 ilk_init_lp_watermarks(dev
);
5618 /* L3 caching of data atomics doesn't work -- disable it. */
5619 I915_WRITE(HSW_SCRATCH1
, HSW_SCRATCH1_L3_DATA_ATOMICS_DISABLE
);
5620 I915_WRITE(HSW_ROW_CHICKEN3
,
5621 _MASKED_BIT_ENABLE(HSW_ROW_CHICKEN3_L3_GLOBAL_ATOMICS_DISABLE
));
5623 /* This is required by WaCatErrorRejectionIssue:hsw */
5624 I915_WRITE(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG
,
5625 I915_READ(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG
) |
5626 GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB
);
5628 /* WaVSRefCountFullforceMissDisable:hsw */
5629 I915_WRITE(GEN7_FF_THREAD_MODE
,
5630 I915_READ(GEN7_FF_THREAD_MODE
) & ~GEN7_FF_VS_REF_CNT_FFME
);
5632 /* WaDisable_RenderCache_OperationalFlush:hsw */
5633 I915_WRITE(CACHE_MODE_0_GEN7
, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE
));
5635 /* enable HiZ Raw Stall Optimization */
5636 I915_WRITE(CACHE_MODE_0_GEN7
,
5637 _MASKED_BIT_DISABLE(HIZ_RAW_STALL_OPT_DISABLE
));
5639 /* WaDisable4x2SubspanOptimization:hsw */
5640 I915_WRITE(CACHE_MODE_1
,
5641 _MASKED_BIT_ENABLE(PIXEL_SUBSPAN_COLLECT_OPT_DISABLE
));
5644 * BSpec recommends 8x4 when MSAA is used,
5645 * however in practice 16x4 seems fastest.
5647 * Note that PS/WM thread counts depend on the WIZ hashing
5648 * disable bit, which we don't touch here, but it's good
5649 * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM).
5651 I915_WRITE(GEN7_GT_MODE
,
5652 GEN6_WIZ_HASHING_MASK
| GEN6_WIZ_HASHING_16x4
);
5654 /* WaSwitchSolVfFArbitrationPriority:hsw */
5655 I915_WRITE(GAM_ECOCHK
, I915_READ(GAM_ECOCHK
) | HSW_ECOCHK_ARB_PRIO_SOL
);
5657 /* WaRsPkgCStateDisplayPMReq:hsw */
5658 I915_WRITE(CHICKEN_PAR1_1
,
5659 I915_READ(CHICKEN_PAR1_1
) | FORCE_ARB_IDLE_PLANES
);
5661 lpt_init_clock_gating(dev
);
5664 static void ivybridge_init_clock_gating(struct drm_device
*dev
)
5666 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5669 ilk_init_lp_watermarks(dev
);
5671 I915_WRITE(ILK_DSPCLK_GATE_D
, ILK_VRHUNIT_CLOCK_GATE_DISABLE
);
5673 /* WaDisableEarlyCull:ivb */
5674 I915_WRITE(_3D_CHICKEN3
,
5675 _MASKED_BIT_ENABLE(_3D_CHICKEN_SF_DISABLE_OBJEND_CULL
));
5677 /* WaDisableBackToBackFlipFix:ivb */
5678 I915_WRITE(IVB_CHICKEN3
,
5679 CHICKEN3_DGMG_REQ_OUT_FIX_DISABLE
|
5680 CHICKEN3_DGMG_DONE_FIX_DISABLE
);
5682 /* WaDisablePSDDualDispatchEnable:ivb */
5683 if (IS_IVB_GT1(dev
))
5684 I915_WRITE(GEN7_HALF_SLICE_CHICKEN1
,
5685 _MASKED_BIT_ENABLE(GEN7_PSD_SINGLE_PORT_DISPATCH_ENABLE
));
5687 /* WaDisable_RenderCache_OperationalFlush:ivb */
5688 I915_WRITE(CACHE_MODE_0_GEN7
, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE
));
5690 /* Apply the WaDisableRHWOOptimizationForRenderHang:ivb workaround. */
5691 I915_WRITE(GEN7_COMMON_SLICE_CHICKEN1
,
5692 GEN7_CSC1_RHWO_OPT_DISABLE_IN_RCC
);
5694 /* WaApplyL3ControlAndL3ChickenMode:ivb */
5695 I915_WRITE(GEN7_L3CNTLREG1
,
5696 GEN7_WA_FOR_GEN7_L3_CONTROL
);
5697 I915_WRITE(GEN7_L3_CHICKEN_MODE_REGISTER
,
5698 GEN7_WA_L3_CHICKEN_MODE
);
5699 if (IS_IVB_GT1(dev
))
5700 I915_WRITE(GEN7_ROW_CHICKEN2
,
5701 _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE
));
5703 /* must write both registers */
5704 I915_WRITE(GEN7_ROW_CHICKEN2
,
5705 _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE
));
5706 I915_WRITE(GEN7_ROW_CHICKEN2_GT2
,
5707 _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE
));
5710 /* WaForceL3Serialization:ivb */
5711 I915_WRITE(GEN7_L3SQCREG4
, I915_READ(GEN7_L3SQCREG4
) &
5712 ~L3SQ_URB_READ_CAM_MATCH_DISABLE
);
5715 * According to the spec, bit 13 (RCZUNIT) must be set on IVB.
5716 * This implements the WaDisableRCZUnitClockGating:ivb workaround.
5718 I915_WRITE(GEN6_UCGCTL2
,
5719 GEN6_RCZUNIT_CLOCK_GATE_DISABLE
);
5721 /* This is required by WaCatErrorRejectionIssue:ivb */
5722 I915_WRITE(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG
,
5723 I915_READ(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG
) |
5724 GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB
);
5726 g4x_disable_trickle_feed(dev
);
5728 gen7_setup_fixed_func_scheduler(dev_priv
);
5730 if (0) { /* causes HiZ corruption on ivb:gt1 */
5731 /* enable HiZ Raw Stall Optimization */
5732 I915_WRITE(CACHE_MODE_0_GEN7
,
5733 _MASKED_BIT_DISABLE(HIZ_RAW_STALL_OPT_DISABLE
));
5736 /* WaDisable4x2SubspanOptimization:ivb */
5737 I915_WRITE(CACHE_MODE_1
,
5738 _MASKED_BIT_ENABLE(PIXEL_SUBSPAN_COLLECT_OPT_DISABLE
));
5741 * BSpec recommends 8x4 when MSAA is used,
5742 * however in practice 16x4 seems fastest.
5744 * Note that PS/WM thread counts depend on the WIZ hashing
5745 * disable bit, which we don't touch here, but it's good
5746 * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM).
5748 I915_WRITE(GEN7_GT_MODE
,
5749 GEN6_WIZ_HASHING_MASK
| GEN6_WIZ_HASHING_16x4
);
5751 snpcr
= I915_READ(GEN6_MBCUNIT_SNPCR
);
5752 snpcr
&= ~GEN6_MBC_SNPCR_MASK
;
5753 snpcr
|= GEN6_MBC_SNPCR_MED
;
5754 I915_WRITE(GEN6_MBCUNIT_SNPCR
, snpcr
);
5756 if (!HAS_PCH_NOP(dev
))
5757 cpt_init_clock_gating(dev
);
5759 gen6_check_mch_setup(dev
);
5762 static void valleyview_init_clock_gating(struct drm_device
*dev
)
5764 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5767 mutex_lock(&dev_priv
->rps
.hw_lock
);
5768 val
= vlv_punit_read(dev_priv
, PUNIT_REG_GPU_FREQ_STS
);
5769 mutex_unlock(&dev_priv
->rps
.hw_lock
);
5770 switch ((val
>> 6) & 3) {
5773 dev_priv
->mem_freq
= 800;
5776 dev_priv
->mem_freq
= 1066;
5779 dev_priv
->mem_freq
= 1333;
5782 DRM_DEBUG_DRIVER("DDR speed: %d MHz", dev_priv
->mem_freq
);
5784 I915_WRITE(DSPCLK_GATE_D
, VRHUNIT_CLOCK_GATE_DISABLE
);
5786 /* WaDisableEarlyCull:vlv */
5787 I915_WRITE(_3D_CHICKEN3
,
5788 _MASKED_BIT_ENABLE(_3D_CHICKEN_SF_DISABLE_OBJEND_CULL
));
5790 /* WaDisableBackToBackFlipFix:vlv */
5791 I915_WRITE(IVB_CHICKEN3
,
5792 CHICKEN3_DGMG_REQ_OUT_FIX_DISABLE
|
5793 CHICKEN3_DGMG_DONE_FIX_DISABLE
);
5795 /* WaPsdDispatchEnable:vlv */
5796 /* WaDisablePSDDualDispatchEnable:vlv */
5797 I915_WRITE(GEN7_HALF_SLICE_CHICKEN1
,
5798 _MASKED_BIT_ENABLE(GEN7_MAX_PS_THREAD_DEP
|
5799 GEN7_PSD_SINGLE_PORT_DISPATCH_ENABLE
));
5801 /* WaDisable_RenderCache_OperationalFlush:vlv */
5802 I915_WRITE(CACHE_MODE_0_GEN7
, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE
));
5804 /* WaForceL3Serialization:vlv */
5805 I915_WRITE(GEN7_L3SQCREG4
, I915_READ(GEN7_L3SQCREG4
) &
5806 ~L3SQ_URB_READ_CAM_MATCH_DISABLE
);
5808 /* WaDisableDopClockGating:vlv */
5809 I915_WRITE(GEN7_ROW_CHICKEN2
,
5810 _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE
));
5812 /* This is required by WaCatErrorRejectionIssue:vlv */
5813 I915_WRITE(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG
,
5814 I915_READ(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG
) |
5815 GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB
);
5817 gen7_setup_fixed_func_scheduler(dev_priv
);
5820 * According to the spec, bit 13 (RCZUNIT) must be set on IVB.
5821 * This implements the WaDisableRCZUnitClockGating:vlv workaround.
5823 I915_WRITE(GEN6_UCGCTL2
,
5824 GEN6_RCZUNIT_CLOCK_GATE_DISABLE
);
5826 /* WaDisableL3Bank2xClockGate:vlv
5827 * Disabling L3 clock gating- MMIO 940c[25] = 1
5828 * Set bit 25, to disable L3_BANK_2x_CLK_GATING */
5829 I915_WRITE(GEN7_UCGCTL4
,
5830 I915_READ(GEN7_UCGCTL4
) | GEN7_L3BANK2X_CLOCK_GATE_DISABLE
);
5832 I915_WRITE(MI_ARB_VLV
, MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE
);
5835 * BSpec says this must be set, even though
5836 * WaDisable4x2SubspanOptimization isn't listed for VLV.
5838 I915_WRITE(CACHE_MODE_1
,
5839 _MASKED_BIT_ENABLE(PIXEL_SUBSPAN_COLLECT_OPT_DISABLE
));
5842 * WaIncreaseL3CreditsForVLVB0:vlv
5843 * This is the hardware default actually.
5845 I915_WRITE(GEN7_L3SQCREG1
, VLV_B0_WA_L3SQCREG1_VALUE
);
5848 * WaDisableVLVClockGating_VBIIssue:vlv
5849 * Disable clock gating on th GCFG unit to prevent a delay
5850 * in the reporting of vblank events.
5852 I915_WRITE(VLV_GUNIT_CLOCK_GATE
, GCFG_DIS
);
5855 static void cherryview_init_clock_gating(struct drm_device
*dev
)
5857 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5860 mutex_lock(&dev_priv
->rps
.hw_lock
);
5861 val
= vlv_punit_read(dev_priv
, CCK_FUSE_REG
);
5862 mutex_unlock(&dev_priv
->rps
.hw_lock
);
5863 switch ((val
>> 2) & 0x7) {
5866 dev_priv
->rps
.cz_freq
= CHV_CZ_CLOCK_FREQ_MODE_200
;
5867 dev_priv
->mem_freq
= 1600;
5870 dev_priv
->rps
.cz_freq
= CHV_CZ_CLOCK_FREQ_MODE_267
;
5871 dev_priv
->mem_freq
= 1600;
5874 dev_priv
->rps
.cz_freq
= CHV_CZ_CLOCK_FREQ_MODE_333
;
5875 dev_priv
->mem_freq
= 2000;
5878 dev_priv
->rps
.cz_freq
= CHV_CZ_CLOCK_FREQ_MODE_320
;
5879 dev_priv
->mem_freq
= 1600;
5882 dev_priv
->rps
.cz_freq
= CHV_CZ_CLOCK_FREQ_MODE_400
;
5883 dev_priv
->mem_freq
= 1600;
5886 DRM_DEBUG_DRIVER("DDR speed: %d MHz", dev_priv
->mem_freq
);
5888 I915_WRITE(DSPCLK_GATE_D
, VRHUNIT_CLOCK_GATE_DISABLE
);
5890 I915_WRITE(MI_ARB_VLV
, MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE
);
5892 /* WaDisablePartialInstShootdown:chv */
5893 I915_WRITE(GEN8_ROW_CHICKEN
,
5894 _MASKED_BIT_ENABLE(PARTIAL_INSTRUCTION_SHOOTDOWN_DISABLE
));
5896 /* WaDisableThreadStallDopClockGating:chv */
5897 I915_WRITE(GEN8_ROW_CHICKEN
,
5898 _MASKED_BIT_ENABLE(STALL_DOP_GATING_DISABLE
));
5900 /* WaVSRefCountFullforceMissDisable:chv */
5901 /* WaDSRefCountFullforceMissDisable:chv */
5902 I915_WRITE(GEN7_FF_THREAD_MODE
,
5903 I915_READ(GEN7_FF_THREAD_MODE
) &
5904 ~(GEN8_FF_DS_REF_CNT_FFME
| GEN7_FF_VS_REF_CNT_FFME
));
5906 /* WaDisableSemaphoreAndSyncFlipWait:chv */
5907 I915_WRITE(GEN6_RC_SLEEP_PSMI_CONTROL
,
5908 _MASKED_BIT_ENABLE(GEN8_RC_SEMA_IDLE_MSG_DISABLE
));
5910 /* WaDisableCSUnitClockGating:chv */
5911 I915_WRITE(GEN6_UCGCTL1
, I915_READ(GEN6_UCGCTL1
) |
5912 GEN6_CSUNIT_CLOCK_GATE_DISABLE
);
5914 /* WaDisableSDEUnitClockGating:chv */
5915 I915_WRITE(GEN8_UCGCTL6
, I915_READ(GEN8_UCGCTL6
) |
5916 GEN8_SDEUNIT_CLOCK_GATE_DISABLE
);
5918 /* WaDisableSamplerPowerBypass:chv (pre-production hw) */
5919 I915_WRITE(HALF_SLICE_CHICKEN3
,
5920 _MASKED_BIT_ENABLE(GEN8_SAMPLER_POWER_BYPASS_DIS
));
5922 /* WaDisableGunitClockGating:chv (pre-production hw) */
5923 I915_WRITE(VLV_GUNIT_CLOCK_GATE
, I915_READ(VLV_GUNIT_CLOCK_GATE
) |
5926 /* WaDisableFfDopClockGating:chv (pre-production hw) */
5927 I915_WRITE(GEN6_RC_SLEEP_PSMI_CONTROL
,
5928 _MASKED_BIT_ENABLE(GEN8_FF_DOP_CLOCK_GATE_DISABLE
));
5930 /* WaDisableDopClockGating:chv (pre-production hw) */
5931 I915_WRITE(GEN7_ROW_CHICKEN2
,
5932 _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE
));
5933 I915_WRITE(GEN6_UCGCTL1
, I915_READ(GEN6_UCGCTL1
) |
5934 GEN6_EU_TCUNIT_CLOCK_GATE_DISABLE
);
5937 static void g4x_init_clock_gating(struct drm_device
*dev
)
5939 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5940 uint32_t dspclk_gate
;
5942 I915_WRITE(RENCLK_GATE_D1
, 0);
5943 I915_WRITE(RENCLK_GATE_D2
, VF_UNIT_CLOCK_GATE_DISABLE
|
5944 GS_UNIT_CLOCK_GATE_DISABLE
|
5945 CL_UNIT_CLOCK_GATE_DISABLE
);
5946 I915_WRITE(RAMCLK_GATE_D
, 0);
5947 dspclk_gate
= VRHUNIT_CLOCK_GATE_DISABLE
|
5948 OVRUNIT_CLOCK_GATE_DISABLE
|
5949 OVCUNIT_CLOCK_GATE_DISABLE
;
5951 dspclk_gate
|= DSSUNIT_CLOCK_GATE_DISABLE
;
5952 I915_WRITE(DSPCLK_GATE_D
, dspclk_gate
);
5954 /* WaDisableRenderCachePipelinedFlush */
5955 I915_WRITE(CACHE_MODE_0
,
5956 _MASKED_BIT_ENABLE(CM0_PIPELINED_RENDER_FLUSH_DISABLE
));
5958 /* WaDisable_RenderCache_OperationalFlush:g4x */
5959 I915_WRITE(CACHE_MODE_0
, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE
));
5961 g4x_disable_trickle_feed(dev
);
5964 static void crestline_init_clock_gating(struct drm_device
*dev
)
5966 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5968 I915_WRITE(RENCLK_GATE_D1
, I965_RCC_CLOCK_GATE_DISABLE
);
5969 I915_WRITE(RENCLK_GATE_D2
, 0);
5970 I915_WRITE(DSPCLK_GATE_D
, 0);
5971 I915_WRITE(RAMCLK_GATE_D
, 0);
5972 I915_WRITE16(DEUC
, 0);
5973 I915_WRITE(MI_ARB_STATE
,
5974 _MASKED_BIT_ENABLE(MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE
));
5976 /* WaDisable_RenderCache_OperationalFlush:gen4 */
5977 I915_WRITE(CACHE_MODE_0
, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE
));
5980 static void broadwater_init_clock_gating(struct drm_device
*dev
)
5982 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5984 I915_WRITE(RENCLK_GATE_D1
, I965_RCZ_CLOCK_GATE_DISABLE
|
5985 I965_RCC_CLOCK_GATE_DISABLE
|
5986 I965_RCPB_CLOCK_GATE_DISABLE
|
5987 I965_ISC_CLOCK_GATE_DISABLE
|
5988 I965_FBC_CLOCK_GATE_DISABLE
);
5989 I915_WRITE(RENCLK_GATE_D2
, 0);
5990 I915_WRITE(MI_ARB_STATE
,
5991 _MASKED_BIT_ENABLE(MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE
));
5993 /* WaDisable_RenderCache_OperationalFlush:gen4 */
5994 I915_WRITE(CACHE_MODE_0
, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE
));
5997 static void gen3_init_clock_gating(struct drm_device
*dev
)
5999 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6000 u32 dstate
= I915_READ(D_STATE
);
6002 dstate
|= DSTATE_PLL_D3_OFF
| DSTATE_GFX_CLOCK_GATING
|
6003 DSTATE_DOT_CLOCK_GATING
;
6004 I915_WRITE(D_STATE
, dstate
);
6006 if (IS_PINEVIEW(dev
))
6007 I915_WRITE(ECOSKPD
, _MASKED_BIT_ENABLE(ECO_GATING_CX_ONLY
));
6009 /* IIR "flip pending" means done if this bit is set */
6010 I915_WRITE(ECOSKPD
, _MASKED_BIT_DISABLE(ECO_FLIP_DONE
));
6012 /* interrupts should cause a wake up from C3 */
6013 I915_WRITE(INSTPM
, _MASKED_BIT_ENABLE(INSTPM_AGPBUSY_INT_EN
));
6015 /* On GEN3 we really need to make sure the ARB C3 LP bit is set */
6016 I915_WRITE(MI_ARB_STATE
, _MASKED_BIT_ENABLE(MI_ARB_C3_LP_WRITE_ENABLE
));
6019 static void i85x_init_clock_gating(struct drm_device
*dev
)
6021 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6023 I915_WRITE(RENCLK_GATE_D1
, SV_CLOCK_GATE_DISABLE
);
6025 /* interrupts should cause a wake up from C3 */
6026 I915_WRITE(MI_STATE
, _MASKED_BIT_ENABLE(MI_AGPBUSY_INT_EN
) |
6027 _MASKED_BIT_DISABLE(MI_AGPBUSY_830_MODE
));
6030 static void i830_init_clock_gating(struct drm_device
*dev
)
6032 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6034 I915_WRITE(DSPCLK_GATE_D
, OVRUNIT_CLOCK_GATE_DISABLE
);
6037 void intel_init_clock_gating(struct drm_device
*dev
)
6039 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6041 dev_priv
->display
.init_clock_gating(dev
);
6044 void intel_suspend_hw(struct drm_device
*dev
)
6046 if (HAS_PCH_LPT(dev
))
6047 lpt_suspend_hw(dev
);
6050 #define for_each_power_well(i, power_well, domain_mask, power_domains) \
6052 i < (power_domains)->power_well_count && \
6053 ((power_well) = &(power_domains)->power_wells[i]); \
6055 if ((power_well)->domains & (domain_mask))
6057 #define for_each_power_well_rev(i, power_well, domain_mask, power_domains) \
6058 for (i = (power_domains)->power_well_count - 1; \
6059 i >= 0 && ((power_well) = &(power_domains)->power_wells[i]);\
6061 if ((power_well)->domains & (domain_mask))
6064 * We should only use the power well if we explicitly asked the hardware to
6065 * enable it, so check if it's enabled and also check if we've requested it to
6068 static bool hsw_power_well_enabled(struct drm_i915_private
*dev_priv
,
6069 struct i915_power_well
*power_well
)
6071 return I915_READ(HSW_PWR_WELL_DRIVER
) ==
6072 (HSW_PWR_WELL_ENABLE_REQUEST
| HSW_PWR_WELL_STATE_ENABLED
);
6075 bool intel_display_power_enabled_unlocked(struct drm_i915_private
*dev_priv
,
6076 enum intel_display_power_domain domain
)
6078 struct i915_power_domains
*power_domains
;
6079 struct i915_power_well
*power_well
;
6083 if (dev_priv
->pm
.suspended
)
6086 power_domains
= &dev_priv
->power_domains
;
6090 for_each_power_well_rev(i
, power_well
, BIT(domain
), power_domains
) {
6091 if (power_well
->always_on
)
6094 if (!power_well
->hw_enabled
) {
6103 bool intel_display_power_enabled(struct drm_i915_private
*dev_priv
,
6104 enum intel_display_power_domain domain
)
6106 struct i915_power_domains
*power_domains
;
6109 power_domains
= &dev_priv
->power_domains
;
6111 mutex_lock(&power_domains
->lock
);
6112 ret
= intel_display_power_enabled_unlocked(dev_priv
, domain
);
6113 mutex_unlock(&power_domains
->lock
);
6119 * Starting with Haswell, we have a "Power Down Well" that can be turned off
6120 * when not needed anymore. We have 4 registers that can request the power well
6121 * to be enabled, and it will only be disabled if none of the registers is
6122 * requesting it to be enabled.
6124 static void hsw_power_well_post_enable(struct drm_i915_private
*dev_priv
)
6126 struct drm_device
*dev
= dev_priv
->dev
;
6129 * After we re-enable the power well, if we touch VGA register 0x3d5
6130 * we'll get unclaimed register interrupts. This stops after we write
6131 * anything to the VGA MSR register. The vgacon module uses this
6132 * register all the time, so if we unbind our driver and, as a
6133 * consequence, bind vgacon, we'll get stuck in an infinite loop at
6134 * console_unlock(). So make here we touch the VGA MSR register, making
6135 * sure vgacon can keep working normally without triggering interrupts
6136 * and error messages.
6138 vga_get_uninterruptible(dev
->pdev
, VGA_RSRC_LEGACY_IO
);
6139 outb(inb(VGA_MSR_READ
), VGA_MSR_WRITE
);
6140 vga_put(dev
->pdev
, VGA_RSRC_LEGACY_IO
);
6142 if (IS_BROADWELL(dev
))
6143 gen8_irq_power_well_post_enable(dev_priv
);
6146 static void hsw_set_power_well(struct drm_i915_private
*dev_priv
,
6147 struct i915_power_well
*power_well
, bool enable
)
6149 bool is_enabled
, enable_requested
;
6152 tmp
= I915_READ(HSW_PWR_WELL_DRIVER
);
6153 is_enabled
= tmp
& HSW_PWR_WELL_STATE_ENABLED
;
6154 enable_requested
= tmp
& HSW_PWR_WELL_ENABLE_REQUEST
;
6157 if (!enable_requested
)
6158 I915_WRITE(HSW_PWR_WELL_DRIVER
,
6159 HSW_PWR_WELL_ENABLE_REQUEST
);
6162 DRM_DEBUG_KMS("Enabling power well\n");
6163 if (wait_for((I915_READ(HSW_PWR_WELL_DRIVER
) &
6164 HSW_PWR_WELL_STATE_ENABLED
), 20))
6165 DRM_ERROR("Timeout enabling power well\n");
6168 hsw_power_well_post_enable(dev_priv
);
6170 if (enable_requested
) {
6171 I915_WRITE(HSW_PWR_WELL_DRIVER
, 0);
6172 POSTING_READ(HSW_PWR_WELL_DRIVER
);
6173 DRM_DEBUG_KMS("Requesting to disable the power well\n");
6178 static void hsw_power_well_sync_hw(struct drm_i915_private
*dev_priv
,
6179 struct i915_power_well
*power_well
)
6181 hsw_set_power_well(dev_priv
, power_well
, power_well
->count
> 0);
6184 * We're taking over the BIOS, so clear any requests made by it since
6185 * the driver is in charge now.
6187 if (I915_READ(HSW_PWR_WELL_BIOS
) & HSW_PWR_WELL_ENABLE_REQUEST
)
6188 I915_WRITE(HSW_PWR_WELL_BIOS
, 0);
6191 static void hsw_power_well_enable(struct drm_i915_private
*dev_priv
,
6192 struct i915_power_well
*power_well
)
6194 hsw_set_power_well(dev_priv
, power_well
, true);
6197 static void hsw_power_well_disable(struct drm_i915_private
*dev_priv
,
6198 struct i915_power_well
*power_well
)
6200 hsw_set_power_well(dev_priv
, power_well
, false);
6203 static void i9xx_always_on_power_well_noop(struct drm_i915_private
*dev_priv
,
6204 struct i915_power_well
*power_well
)
6208 static bool i9xx_always_on_power_well_enabled(struct drm_i915_private
*dev_priv
,
6209 struct i915_power_well
*power_well
)
6214 static void vlv_set_power_well(struct drm_i915_private
*dev_priv
,
6215 struct i915_power_well
*power_well
, bool enable
)
6217 enum punit_power_well power_well_id
= power_well
->data
;
6222 mask
= PUNIT_PWRGT_MASK(power_well_id
);
6223 state
= enable
? PUNIT_PWRGT_PWR_ON(power_well_id
) :
6224 PUNIT_PWRGT_PWR_GATE(power_well_id
);
6226 mutex_lock(&dev_priv
->rps
.hw_lock
);
6229 ((vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_STATUS) & mask) == state)
6234 ctrl
= vlv_punit_read(dev_priv
, PUNIT_REG_PWRGT_CTRL
);
6237 vlv_punit_write(dev_priv
, PUNIT_REG_PWRGT_CTRL
, ctrl
);
6239 if (wait_for(COND
, 100))
6240 DRM_ERROR("timout setting power well state %08x (%08x)\n",
6242 vlv_punit_read(dev_priv
, PUNIT_REG_PWRGT_CTRL
));
6247 mutex_unlock(&dev_priv
->rps
.hw_lock
);
6250 static void vlv_power_well_sync_hw(struct drm_i915_private
*dev_priv
,
6251 struct i915_power_well
*power_well
)
6253 vlv_set_power_well(dev_priv
, power_well
, power_well
->count
> 0);
6256 static void vlv_power_well_enable(struct drm_i915_private
*dev_priv
,
6257 struct i915_power_well
*power_well
)
6259 vlv_set_power_well(dev_priv
, power_well
, true);
6262 static void vlv_power_well_disable(struct drm_i915_private
*dev_priv
,
6263 struct i915_power_well
*power_well
)
6265 vlv_set_power_well(dev_priv
, power_well
, false);
6268 static bool vlv_power_well_enabled(struct drm_i915_private
*dev_priv
,
6269 struct i915_power_well
*power_well
)
6271 int power_well_id
= power_well
->data
;
6272 bool enabled
= false;
6277 mask
= PUNIT_PWRGT_MASK(power_well_id
);
6278 ctrl
= PUNIT_PWRGT_PWR_ON(power_well_id
);
6280 mutex_lock(&dev_priv
->rps
.hw_lock
);
6282 state
= vlv_punit_read(dev_priv
, PUNIT_REG_PWRGT_STATUS
) & mask
;
6284 * We only ever set the power-on and power-gate states, anything
6285 * else is unexpected.
6287 WARN_ON(state
!= PUNIT_PWRGT_PWR_ON(power_well_id
) &&
6288 state
!= PUNIT_PWRGT_PWR_GATE(power_well_id
));
6293 * A transient state at this point would mean some unexpected party
6294 * is poking at the power controls too.
6296 ctrl
= vlv_punit_read(dev_priv
, PUNIT_REG_PWRGT_CTRL
) & mask
;
6297 WARN_ON(ctrl
!= state
);
6299 mutex_unlock(&dev_priv
->rps
.hw_lock
);
6304 static void vlv_display_power_well_enable(struct drm_i915_private
*dev_priv
,
6305 struct i915_power_well
*power_well
)
6307 WARN_ON_ONCE(power_well
->data
!= PUNIT_POWER_WELL_DISP2D
);
6309 vlv_set_power_well(dev_priv
, power_well
, true);
6311 spin_lock_irq(&dev_priv
->irq_lock
);
6312 valleyview_enable_display_irqs(dev_priv
);
6313 spin_unlock_irq(&dev_priv
->irq_lock
);
6316 * During driver initialization/resume we can avoid restoring the
6317 * part of the HW/SW state that will be inited anyway explicitly.
6319 if (dev_priv
->power_domains
.initializing
)
6322 intel_hpd_init(dev_priv
->dev
);
6324 i915_redisable_vga_power_on(dev_priv
->dev
);
6327 static void vlv_display_power_well_disable(struct drm_i915_private
*dev_priv
,
6328 struct i915_power_well
*power_well
)
6330 WARN_ON_ONCE(power_well
->data
!= PUNIT_POWER_WELL_DISP2D
);
6332 spin_lock_irq(&dev_priv
->irq_lock
);
6333 valleyview_disable_display_irqs(dev_priv
);
6334 spin_unlock_irq(&dev_priv
->irq_lock
);
6336 vlv_set_power_well(dev_priv
, power_well
, false);
6339 static void vlv_dpio_cmn_power_well_enable(struct drm_i915_private
*dev_priv
,
6340 struct i915_power_well
*power_well
)
6342 WARN_ON_ONCE(power_well
->data
!= PUNIT_POWER_WELL_DPIO_CMN_BC
);
6345 * Enable the CRI clock source so we can get at the
6346 * display and the reference clock for VGA
6347 * hotplug / manual detection.
6349 I915_WRITE(DPLL(PIPE_B
), I915_READ(DPLL(PIPE_B
)) |
6350 DPLL_REFA_CLK_ENABLE_VLV
| DPLL_INTEGRATED_CRI_CLK_VLV
);
6351 udelay(1); /* >10ns for cmnreset, >0ns for sidereset */
6353 vlv_set_power_well(dev_priv
, power_well
, true);
6356 * From VLV2A0_DP_eDP_DPIO_driver_vbios_notes_10.docx -
6357 * 6. De-assert cmn_reset/side_reset. Same as VLV X0.
6358 * a. GUnit 0x2110 bit[0] set to 1 (def 0)
6359 * b. The other bits such as sfr settings / modesel may all
6362 * This should only be done on init and resume from S3 with
6363 * both PLLs disabled, or we risk losing DPIO and PLL
6366 I915_WRITE(DPIO_CTL
, I915_READ(DPIO_CTL
) | DPIO_CMNRST
);
6369 static void vlv_dpio_cmn_power_well_disable(struct drm_i915_private
*dev_priv
,
6370 struct i915_power_well
*power_well
)
6374 WARN_ON_ONCE(power_well
->data
!= PUNIT_POWER_WELL_DPIO_CMN_BC
);
6376 for_each_pipe(dev_priv
, pipe
)
6377 assert_pll_disabled(dev_priv
, pipe
);
6379 /* Assert common reset */
6380 I915_WRITE(DPIO_CTL
, I915_READ(DPIO_CTL
) & ~DPIO_CMNRST
);
6382 vlv_set_power_well(dev_priv
, power_well
, false);
6385 static void chv_dpio_cmn_power_well_enable(struct drm_i915_private
*dev_priv
,
6386 struct i915_power_well
*power_well
)
6390 WARN_ON_ONCE(power_well
->data
!= PUNIT_POWER_WELL_DPIO_CMN_BC
&&
6391 power_well
->data
!= PUNIT_POWER_WELL_DPIO_CMN_D
);
6394 * Enable the CRI clock source so we can get at the
6395 * display and the reference clock for VGA
6396 * hotplug / manual detection.
6398 if (power_well
->data
== PUNIT_POWER_WELL_DPIO_CMN_BC
) {
6400 I915_WRITE(DPLL(PIPE_B
), I915_READ(DPLL(PIPE_B
)) |
6401 DPLL_REFA_CLK_ENABLE_VLV
);
6402 I915_WRITE(DPLL(PIPE_B
), I915_READ(DPLL(PIPE_B
)) |
6403 DPLL_REFA_CLK_ENABLE_VLV
| DPLL_INTEGRATED_CRI_CLK_VLV
);
6406 I915_WRITE(DPLL(PIPE_C
), I915_READ(DPLL(PIPE_C
)) |
6407 DPLL_REFA_CLK_ENABLE_VLV
| DPLL_INTEGRATED_CRI_CLK_VLV
);
6409 udelay(1); /* >10ns for cmnreset, >0ns for sidereset */
6410 vlv_set_power_well(dev_priv
, power_well
, true);
6412 /* Poll for phypwrgood signal */
6413 if (wait_for(I915_READ(DISPLAY_PHY_STATUS
) & PHY_POWERGOOD(phy
), 1))
6414 DRM_ERROR("Display PHY %d is not power up\n", phy
);
6416 I915_WRITE(DISPLAY_PHY_CONTROL
, I915_READ(DISPLAY_PHY_CONTROL
) |
6417 PHY_COM_LANE_RESET_DEASSERT(phy
));
6420 static void chv_dpio_cmn_power_well_disable(struct drm_i915_private
*dev_priv
,
6421 struct i915_power_well
*power_well
)
6425 WARN_ON_ONCE(power_well
->data
!= PUNIT_POWER_WELL_DPIO_CMN_BC
&&
6426 power_well
->data
!= PUNIT_POWER_WELL_DPIO_CMN_D
);
6428 if (power_well
->data
== PUNIT_POWER_WELL_DPIO_CMN_BC
) {
6430 assert_pll_disabled(dev_priv
, PIPE_A
);
6431 assert_pll_disabled(dev_priv
, PIPE_B
);
6434 assert_pll_disabled(dev_priv
, PIPE_C
);
6437 I915_WRITE(DISPLAY_PHY_CONTROL
, I915_READ(DISPLAY_PHY_CONTROL
) &
6438 ~PHY_COM_LANE_RESET_DEASSERT(phy
));
6440 vlv_set_power_well(dev_priv
, power_well
, false);
6443 static bool chv_pipe_power_well_enabled(struct drm_i915_private
*dev_priv
,
6444 struct i915_power_well
*power_well
)
6446 enum pipe pipe
= power_well
->data
;
6450 mutex_lock(&dev_priv
->rps
.hw_lock
);
6452 state
= vlv_punit_read(dev_priv
, PUNIT_REG_DSPFREQ
) & DP_SSS_MASK(pipe
);
6454 * We only ever set the power-on and power-gate states, anything
6455 * else is unexpected.
6457 WARN_ON(state
!= DP_SSS_PWR_ON(pipe
) && state
!= DP_SSS_PWR_GATE(pipe
));
6458 enabled
= state
== DP_SSS_PWR_ON(pipe
);
6461 * A transient state at this point would mean some unexpected party
6462 * is poking at the power controls too.
6464 ctrl
= vlv_punit_read(dev_priv
, PUNIT_REG_DSPFREQ
) & DP_SSC_MASK(pipe
);
6465 WARN_ON(ctrl
<< 16 != state
);
6467 mutex_unlock(&dev_priv
->rps
.hw_lock
);
6472 static void chv_set_pipe_power_well(struct drm_i915_private
*dev_priv
,
6473 struct i915_power_well
*power_well
,
6476 enum pipe pipe
= power_well
->data
;
6480 state
= enable
? DP_SSS_PWR_ON(pipe
) : DP_SSS_PWR_GATE(pipe
);
6482 mutex_lock(&dev_priv
->rps
.hw_lock
);
6485 ((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSS_MASK(pipe)) == state)
6490 ctrl
= vlv_punit_read(dev_priv
, PUNIT_REG_DSPFREQ
);
6491 ctrl
&= ~DP_SSC_MASK(pipe
);
6492 ctrl
|= enable
? DP_SSC_PWR_ON(pipe
) : DP_SSC_PWR_GATE(pipe
);
6493 vlv_punit_write(dev_priv
, PUNIT_REG_DSPFREQ
, ctrl
);
6495 if (wait_for(COND
, 100))
6496 DRM_ERROR("timout setting power well state %08x (%08x)\n",
6498 vlv_punit_read(dev_priv
, PUNIT_REG_DSPFREQ
));
6503 mutex_unlock(&dev_priv
->rps
.hw_lock
);
6506 static void chv_pipe_power_well_sync_hw(struct drm_i915_private
*dev_priv
,
6507 struct i915_power_well
*power_well
)
6509 chv_set_pipe_power_well(dev_priv
, power_well
, power_well
->count
> 0);
6512 static void chv_pipe_power_well_enable(struct drm_i915_private
*dev_priv
,
6513 struct i915_power_well
*power_well
)
6515 WARN_ON_ONCE(power_well
->data
!= PIPE_A
&&
6516 power_well
->data
!= PIPE_B
&&
6517 power_well
->data
!= PIPE_C
);
6519 chv_set_pipe_power_well(dev_priv
, power_well
, true);
6522 static void chv_pipe_power_well_disable(struct drm_i915_private
*dev_priv
,
6523 struct i915_power_well
*power_well
)
6525 WARN_ON_ONCE(power_well
->data
!= PIPE_A
&&
6526 power_well
->data
!= PIPE_B
&&
6527 power_well
->data
!= PIPE_C
);
6529 chv_set_pipe_power_well(dev_priv
, power_well
, false);
6532 static void check_power_well_state(struct drm_i915_private
*dev_priv
,
6533 struct i915_power_well
*power_well
)
6535 bool enabled
= power_well
->ops
->is_enabled(dev_priv
, power_well
);
6537 if (power_well
->always_on
|| !i915
.disable_power_well
) {
6544 if (enabled
!= (power_well
->count
> 0))
6550 WARN(1, "state mismatch for '%s' (always_on %d hw state %d use-count %d disable_power_well %d\n",
6551 power_well
->name
, power_well
->always_on
, enabled
,
6552 power_well
->count
, i915
.disable_power_well
);
6555 void intel_display_power_get(struct drm_i915_private
*dev_priv
,
6556 enum intel_display_power_domain domain
)
6558 struct i915_power_domains
*power_domains
;
6559 struct i915_power_well
*power_well
;
6562 intel_runtime_pm_get(dev_priv
);
6564 power_domains
= &dev_priv
->power_domains
;
6566 mutex_lock(&power_domains
->lock
);
6568 for_each_power_well(i
, power_well
, BIT(domain
), power_domains
) {
6569 if (!power_well
->count
++) {
6570 DRM_DEBUG_KMS("enabling %s\n", power_well
->name
);
6571 power_well
->ops
->enable(dev_priv
, power_well
);
6572 power_well
->hw_enabled
= true;
6575 check_power_well_state(dev_priv
, power_well
);
6578 power_domains
->domain_use_count
[domain
]++;
6580 mutex_unlock(&power_domains
->lock
);
6583 void intel_display_power_put(struct drm_i915_private
*dev_priv
,
6584 enum intel_display_power_domain domain
)
6586 struct i915_power_domains
*power_domains
;
6587 struct i915_power_well
*power_well
;
6590 power_domains
= &dev_priv
->power_domains
;
6592 mutex_lock(&power_domains
->lock
);
6594 WARN_ON(!power_domains
->domain_use_count
[domain
]);
6595 power_domains
->domain_use_count
[domain
]--;
6597 for_each_power_well_rev(i
, power_well
, BIT(domain
), power_domains
) {
6598 WARN_ON(!power_well
->count
);
6600 if (!--power_well
->count
&& i915
.disable_power_well
) {
6601 DRM_DEBUG_KMS("disabling %s\n", power_well
->name
);
6602 power_well
->hw_enabled
= false;
6603 power_well
->ops
->disable(dev_priv
, power_well
);
6606 check_power_well_state(dev_priv
, power_well
);
6609 mutex_unlock(&power_domains
->lock
);
6611 intel_runtime_pm_put(dev_priv
);
6614 static struct i915_power_domains
*hsw_pwr
;
6616 /* Display audio driver power well request */
6617 int i915_request_power_well(void)
6619 struct drm_i915_private
*dev_priv
;
6624 dev_priv
= container_of(hsw_pwr
, struct drm_i915_private
,
6626 intel_display_power_get(dev_priv
, POWER_DOMAIN_AUDIO
);
6629 EXPORT_SYMBOL_GPL(i915_request_power_well
);
6631 /* Display audio driver power well release */
6632 int i915_release_power_well(void)
6634 struct drm_i915_private
*dev_priv
;
6639 dev_priv
= container_of(hsw_pwr
, struct drm_i915_private
,
6641 intel_display_power_put(dev_priv
, POWER_DOMAIN_AUDIO
);
6644 EXPORT_SYMBOL_GPL(i915_release_power_well
);
6647 * Private interface for the audio driver to get CDCLK in kHz.
6649 * Caller must request power well using i915_request_power_well() prior to
6652 int i915_get_cdclk_freq(void)
6654 struct drm_i915_private
*dev_priv
;
6659 dev_priv
= container_of(hsw_pwr
, struct drm_i915_private
,
6662 return intel_ddi_get_cdclk_freq(dev_priv
);
6664 EXPORT_SYMBOL_GPL(i915_get_cdclk_freq
);
6667 #define POWER_DOMAIN_MASK (BIT(POWER_DOMAIN_NUM) - 1)
6669 #define HSW_ALWAYS_ON_POWER_DOMAINS ( \
6670 BIT(POWER_DOMAIN_PIPE_A) | \
6671 BIT(POWER_DOMAIN_TRANSCODER_EDP) | \
6672 BIT(POWER_DOMAIN_PORT_DDI_A_2_LANES) | \
6673 BIT(POWER_DOMAIN_PORT_DDI_A_4_LANES) | \
6674 BIT(POWER_DOMAIN_PORT_DDI_B_2_LANES) | \
6675 BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \
6676 BIT(POWER_DOMAIN_PORT_DDI_C_2_LANES) | \
6677 BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \
6678 BIT(POWER_DOMAIN_PORT_DDI_D_2_LANES) | \
6679 BIT(POWER_DOMAIN_PORT_DDI_D_4_LANES) | \
6680 BIT(POWER_DOMAIN_PORT_CRT) | \
6681 BIT(POWER_DOMAIN_PLLS) | \
6682 BIT(POWER_DOMAIN_INIT))
6683 #define HSW_DISPLAY_POWER_DOMAINS ( \
6684 (POWER_DOMAIN_MASK & ~HSW_ALWAYS_ON_POWER_DOMAINS) | \
6685 BIT(POWER_DOMAIN_INIT))
6687 #define BDW_ALWAYS_ON_POWER_DOMAINS ( \
6688 HSW_ALWAYS_ON_POWER_DOMAINS | \
6689 BIT(POWER_DOMAIN_PIPE_A_PANEL_FITTER))
6690 #define BDW_DISPLAY_POWER_DOMAINS ( \
6691 (POWER_DOMAIN_MASK & ~BDW_ALWAYS_ON_POWER_DOMAINS) | \
6692 BIT(POWER_DOMAIN_INIT))
6694 #define VLV_ALWAYS_ON_POWER_DOMAINS BIT(POWER_DOMAIN_INIT)
6695 #define VLV_DISPLAY_POWER_DOMAINS POWER_DOMAIN_MASK
6697 #define VLV_DPIO_CMN_BC_POWER_DOMAINS ( \
6698 BIT(POWER_DOMAIN_PORT_DDI_B_2_LANES) | \
6699 BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \
6700 BIT(POWER_DOMAIN_PORT_DDI_C_2_LANES) | \
6701 BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \
6702 BIT(POWER_DOMAIN_PORT_CRT) | \
6703 BIT(POWER_DOMAIN_INIT))
6705 #define VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS ( \
6706 BIT(POWER_DOMAIN_PORT_DDI_B_2_LANES) | \
6707 BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \
6708 BIT(POWER_DOMAIN_INIT))
6710 #define VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS ( \
6711 BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \
6712 BIT(POWER_DOMAIN_INIT))
6714 #define VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS ( \
6715 BIT(POWER_DOMAIN_PORT_DDI_C_2_LANES) | \
6716 BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \
6717 BIT(POWER_DOMAIN_INIT))
6719 #define VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS ( \
6720 BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \
6721 BIT(POWER_DOMAIN_INIT))
6723 #define CHV_PIPE_A_POWER_DOMAINS ( \
6724 BIT(POWER_DOMAIN_PIPE_A) | \
6725 BIT(POWER_DOMAIN_INIT))
6727 #define CHV_PIPE_B_POWER_DOMAINS ( \
6728 BIT(POWER_DOMAIN_PIPE_B) | \
6729 BIT(POWER_DOMAIN_INIT))
6731 #define CHV_PIPE_C_POWER_DOMAINS ( \
6732 BIT(POWER_DOMAIN_PIPE_C) | \
6733 BIT(POWER_DOMAIN_INIT))
6735 #define CHV_DPIO_CMN_BC_POWER_DOMAINS ( \
6736 BIT(POWER_DOMAIN_PORT_DDI_B_2_LANES) | \
6737 BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \
6738 BIT(POWER_DOMAIN_PORT_DDI_C_2_LANES) | \
6739 BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \
6740 BIT(POWER_DOMAIN_INIT))
6742 #define CHV_DPIO_CMN_D_POWER_DOMAINS ( \
6743 BIT(POWER_DOMAIN_PORT_DDI_D_2_LANES) | \
6744 BIT(POWER_DOMAIN_PORT_DDI_D_4_LANES) | \
6745 BIT(POWER_DOMAIN_INIT))
6747 #define CHV_DPIO_TX_D_LANES_01_POWER_DOMAINS ( \
6748 BIT(POWER_DOMAIN_PORT_DDI_D_2_LANES) | \
6749 BIT(POWER_DOMAIN_PORT_DDI_D_4_LANES) | \
6750 BIT(POWER_DOMAIN_INIT))
6752 #define CHV_DPIO_TX_D_LANES_23_POWER_DOMAINS ( \
6753 BIT(POWER_DOMAIN_PORT_DDI_D_4_LANES) | \
6754 BIT(POWER_DOMAIN_INIT))
6756 static const struct i915_power_well_ops i9xx_always_on_power_well_ops
= {
6757 .sync_hw
= i9xx_always_on_power_well_noop
,
6758 .enable
= i9xx_always_on_power_well_noop
,
6759 .disable
= i9xx_always_on_power_well_noop
,
6760 .is_enabled
= i9xx_always_on_power_well_enabled
,
6763 static const struct i915_power_well_ops chv_pipe_power_well_ops
= {
6764 .sync_hw
= chv_pipe_power_well_sync_hw
,
6765 .enable
= chv_pipe_power_well_enable
,
6766 .disable
= chv_pipe_power_well_disable
,
6767 .is_enabled
= chv_pipe_power_well_enabled
,
6770 static const struct i915_power_well_ops chv_dpio_cmn_power_well_ops
= {
6771 .sync_hw
= vlv_power_well_sync_hw
,
6772 .enable
= chv_dpio_cmn_power_well_enable
,
6773 .disable
= chv_dpio_cmn_power_well_disable
,
6774 .is_enabled
= vlv_power_well_enabled
,
6777 static struct i915_power_well i9xx_always_on_power_well
[] = {
6779 .name
= "always-on",
6781 .domains
= POWER_DOMAIN_MASK
,
6782 .ops
= &i9xx_always_on_power_well_ops
,
6786 static const struct i915_power_well_ops hsw_power_well_ops
= {
6787 .sync_hw
= hsw_power_well_sync_hw
,
6788 .enable
= hsw_power_well_enable
,
6789 .disable
= hsw_power_well_disable
,
6790 .is_enabled
= hsw_power_well_enabled
,
6793 static struct i915_power_well hsw_power_wells
[] = {
6795 .name
= "always-on",
6797 .domains
= HSW_ALWAYS_ON_POWER_DOMAINS
,
6798 .ops
= &i9xx_always_on_power_well_ops
,
6802 .domains
= HSW_DISPLAY_POWER_DOMAINS
,
6803 .ops
= &hsw_power_well_ops
,
6807 static struct i915_power_well bdw_power_wells
[] = {
6809 .name
= "always-on",
6811 .domains
= BDW_ALWAYS_ON_POWER_DOMAINS
,
6812 .ops
= &i9xx_always_on_power_well_ops
,
6816 .domains
= BDW_DISPLAY_POWER_DOMAINS
,
6817 .ops
= &hsw_power_well_ops
,
6821 static const struct i915_power_well_ops vlv_display_power_well_ops
= {
6822 .sync_hw
= vlv_power_well_sync_hw
,
6823 .enable
= vlv_display_power_well_enable
,
6824 .disable
= vlv_display_power_well_disable
,
6825 .is_enabled
= vlv_power_well_enabled
,
6828 static const struct i915_power_well_ops vlv_dpio_cmn_power_well_ops
= {
6829 .sync_hw
= vlv_power_well_sync_hw
,
6830 .enable
= vlv_dpio_cmn_power_well_enable
,
6831 .disable
= vlv_dpio_cmn_power_well_disable
,
6832 .is_enabled
= vlv_power_well_enabled
,
6835 static const struct i915_power_well_ops vlv_dpio_power_well_ops
= {
6836 .sync_hw
= vlv_power_well_sync_hw
,
6837 .enable
= vlv_power_well_enable
,
6838 .disable
= vlv_power_well_disable
,
6839 .is_enabled
= vlv_power_well_enabled
,
6842 static struct i915_power_well vlv_power_wells
[] = {
6844 .name
= "always-on",
6846 .domains
= VLV_ALWAYS_ON_POWER_DOMAINS
,
6847 .ops
= &i9xx_always_on_power_well_ops
,
6851 .domains
= VLV_DISPLAY_POWER_DOMAINS
,
6852 .data
= PUNIT_POWER_WELL_DISP2D
,
6853 .ops
= &vlv_display_power_well_ops
,
6856 .name
= "dpio-tx-b-01",
6857 .domains
= VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS
|
6858 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS
|
6859 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS
|
6860 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS
,
6861 .ops
= &vlv_dpio_power_well_ops
,
6862 .data
= PUNIT_POWER_WELL_DPIO_TX_B_LANES_01
,
6865 .name
= "dpio-tx-b-23",
6866 .domains
= VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS
|
6867 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS
|
6868 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS
|
6869 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS
,
6870 .ops
= &vlv_dpio_power_well_ops
,
6871 .data
= PUNIT_POWER_WELL_DPIO_TX_B_LANES_23
,
6874 .name
= "dpio-tx-c-01",
6875 .domains
= VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS
|
6876 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS
|
6877 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS
|
6878 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS
,
6879 .ops
= &vlv_dpio_power_well_ops
,
6880 .data
= PUNIT_POWER_WELL_DPIO_TX_C_LANES_01
,
6883 .name
= "dpio-tx-c-23",
6884 .domains
= VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS
|
6885 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS
|
6886 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS
|
6887 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS
,
6888 .ops
= &vlv_dpio_power_well_ops
,
6889 .data
= PUNIT_POWER_WELL_DPIO_TX_C_LANES_23
,
6892 .name
= "dpio-common",
6893 .domains
= VLV_DPIO_CMN_BC_POWER_DOMAINS
,
6894 .data
= PUNIT_POWER_WELL_DPIO_CMN_BC
,
6895 .ops
= &vlv_dpio_cmn_power_well_ops
,
6899 static struct i915_power_well chv_power_wells
[] = {
6901 .name
= "always-on",
6903 .domains
= VLV_ALWAYS_ON_POWER_DOMAINS
,
6904 .ops
= &i9xx_always_on_power_well_ops
,
6909 .domains
= VLV_DISPLAY_POWER_DOMAINS
,
6910 .data
= PUNIT_POWER_WELL_DISP2D
,
6911 .ops
= &vlv_display_power_well_ops
,
6915 .domains
= CHV_PIPE_A_POWER_DOMAINS
,
6917 .ops
= &chv_pipe_power_well_ops
,
6921 .domains
= CHV_PIPE_B_POWER_DOMAINS
,
6923 .ops
= &chv_pipe_power_well_ops
,
6927 .domains
= CHV_PIPE_C_POWER_DOMAINS
,
6929 .ops
= &chv_pipe_power_well_ops
,
6933 .name
= "dpio-common-bc",
6935 * XXX: cmnreset for one PHY seems to disturb the other.
6936 * As a workaround keep both powered on at the same
6939 .domains
= CHV_DPIO_CMN_BC_POWER_DOMAINS
| CHV_DPIO_CMN_D_POWER_DOMAINS
,
6940 .data
= PUNIT_POWER_WELL_DPIO_CMN_BC
,
6941 .ops
= &chv_dpio_cmn_power_well_ops
,
6944 .name
= "dpio-common-d",
6946 * XXX: cmnreset for one PHY seems to disturb the other.
6947 * As a workaround keep both powered on at the same
6950 .domains
= CHV_DPIO_CMN_BC_POWER_DOMAINS
| CHV_DPIO_CMN_D_POWER_DOMAINS
,
6951 .data
= PUNIT_POWER_WELL_DPIO_CMN_D
,
6952 .ops
= &chv_dpio_cmn_power_well_ops
,
6956 .name
= "dpio-tx-b-01",
6957 .domains
= VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS
|
6958 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS
,
6959 .ops
= &vlv_dpio_power_well_ops
,
6960 .data
= PUNIT_POWER_WELL_DPIO_TX_B_LANES_01
,
6963 .name
= "dpio-tx-b-23",
6964 .domains
= VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS
|
6965 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS
,
6966 .ops
= &vlv_dpio_power_well_ops
,
6967 .data
= PUNIT_POWER_WELL_DPIO_TX_B_LANES_23
,
6970 .name
= "dpio-tx-c-01",
6971 .domains
= VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS
|
6972 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS
,
6973 .ops
= &vlv_dpio_power_well_ops
,
6974 .data
= PUNIT_POWER_WELL_DPIO_TX_C_LANES_01
,
6977 .name
= "dpio-tx-c-23",
6978 .domains
= VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS
|
6979 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS
,
6980 .ops
= &vlv_dpio_power_well_ops
,
6981 .data
= PUNIT_POWER_WELL_DPIO_TX_C_LANES_23
,
6984 .name
= "dpio-tx-d-01",
6985 .domains
= CHV_DPIO_TX_D_LANES_01_POWER_DOMAINS
|
6986 CHV_DPIO_TX_D_LANES_23_POWER_DOMAINS
,
6987 .ops
= &vlv_dpio_power_well_ops
,
6988 .data
= PUNIT_POWER_WELL_DPIO_TX_D_LANES_01
,
6991 .name
= "dpio-tx-d-23",
6992 .domains
= CHV_DPIO_TX_D_LANES_01_POWER_DOMAINS
|
6993 CHV_DPIO_TX_D_LANES_23_POWER_DOMAINS
,
6994 .ops
= &vlv_dpio_power_well_ops
,
6995 .data
= PUNIT_POWER_WELL_DPIO_TX_D_LANES_23
,
7000 static struct i915_power_well
*lookup_power_well(struct drm_i915_private
*dev_priv
,
7001 enum punit_power_well power_well_id
)
7003 struct i915_power_domains
*power_domains
= &dev_priv
->power_domains
;
7004 struct i915_power_well
*power_well
;
7007 for_each_power_well(i
, power_well
, POWER_DOMAIN_MASK
, power_domains
) {
7008 if (power_well
->data
== power_well_id
)
7015 #define set_power_wells(power_domains, __power_wells) ({ \
7016 (power_domains)->power_wells = (__power_wells); \
7017 (power_domains)->power_well_count = ARRAY_SIZE(__power_wells); \
7020 int intel_power_domains_init(struct drm_i915_private
*dev_priv
)
7022 struct i915_power_domains
*power_domains
= &dev_priv
->power_domains
;
7024 mutex_init(&power_domains
->lock
);
7027 * The enabling order will be from lower to higher indexed wells,
7028 * the disabling order is reversed.
7030 if (IS_HASWELL(dev_priv
->dev
)) {
7031 set_power_wells(power_domains
, hsw_power_wells
);
7032 hsw_pwr
= power_domains
;
7033 } else if (IS_BROADWELL(dev_priv
->dev
)) {
7034 set_power_wells(power_domains
, bdw_power_wells
);
7035 hsw_pwr
= power_domains
;
7036 } else if (IS_CHERRYVIEW(dev_priv
->dev
)) {
7037 set_power_wells(power_domains
, chv_power_wells
);
7038 } else if (IS_VALLEYVIEW(dev_priv
->dev
)) {
7039 set_power_wells(power_domains
, vlv_power_wells
);
7041 set_power_wells(power_domains
, i9xx_always_on_power_well
);
7047 void intel_power_domains_remove(struct drm_i915_private
*dev_priv
)
7052 static void intel_power_domains_resume(struct drm_i915_private
*dev_priv
)
7054 struct i915_power_domains
*power_domains
= &dev_priv
->power_domains
;
7055 struct i915_power_well
*power_well
;
7058 mutex_lock(&power_domains
->lock
);
7059 for_each_power_well(i
, power_well
, POWER_DOMAIN_MASK
, power_domains
) {
7060 power_well
->ops
->sync_hw(dev_priv
, power_well
);
7061 power_well
->hw_enabled
= power_well
->ops
->is_enabled(dev_priv
,
7064 mutex_unlock(&power_domains
->lock
);
7067 static void vlv_cmnlane_wa(struct drm_i915_private
*dev_priv
)
7069 struct i915_power_well
*cmn
=
7070 lookup_power_well(dev_priv
, PUNIT_POWER_WELL_DPIO_CMN_BC
);
7071 struct i915_power_well
*disp2d
=
7072 lookup_power_well(dev_priv
, PUNIT_POWER_WELL_DISP2D
);
7074 /* nothing to do if common lane is already off */
7075 if (!cmn
->ops
->is_enabled(dev_priv
, cmn
))
7078 /* If the display might be already active skip this */
7079 if (disp2d
->ops
->is_enabled(dev_priv
, disp2d
) &&
7080 I915_READ(DPIO_CTL
) & DPIO_CMNRST
)
7083 DRM_DEBUG_KMS("toggling display PHY side reset\n");
7085 /* cmnlane needs DPLL registers */
7086 disp2d
->ops
->enable(dev_priv
, disp2d
);
7089 * From VLV2A0_DP_eDP_HDMI_DPIO_driver_vbios_notes_11.docx:
7090 * Need to assert and de-assert PHY SB reset by gating the
7091 * common lane power, then un-gating it.
7092 * Simply ungating isn't enough to reset the PHY enough to get
7093 * ports and lanes running.
7095 cmn
->ops
->disable(dev_priv
, cmn
);
7098 void intel_power_domains_init_hw(struct drm_i915_private
*dev_priv
)
7100 struct drm_device
*dev
= dev_priv
->dev
;
7101 struct i915_power_domains
*power_domains
= &dev_priv
->power_domains
;
7103 power_domains
->initializing
= true;
7105 if (IS_VALLEYVIEW(dev
) && !IS_CHERRYVIEW(dev
)) {
7106 mutex_lock(&power_domains
->lock
);
7107 vlv_cmnlane_wa(dev_priv
);
7108 mutex_unlock(&power_domains
->lock
);
7111 /* For now, we need the power well to be always enabled. */
7112 intel_display_set_init_power(dev_priv
, true);
7113 intel_power_domains_resume(dev_priv
);
7114 power_domains
->initializing
= false;
7117 void intel_aux_display_runtime_get(struct drm_i915_private
*dev_priv
)
7119 intel_runtime_pm_get(dev_priv
);
7122 void intel_aux_display_runtime_put(struct drm_i915_private
*dev_priv
)
7124 intel_runtime_pm_put(dev_priv
);
7127 void intel_runtime_pm_get(struct drm_i915_private
*dev_priv
)
7129 struct drm_device
*dev
= dev_priv
->dev
;
7130 struct device
*device
= &dev
->pdev
->dev
;
7132 if (!HAS_RUNTIME_PM(dev
))
7135 pm_runtime_get_sync(device
);
7136 WARN(dev_priv
->pm
.suspended
, "Device still suspended.\n");
7139 void intel_runtime_pm_get_noresume(struct drm_i915_private
*dev_priv
)
7141 struct drm_device
*dev
= dev_priv
->dev
;
7142 struct device
*device
= &dev
->pdev
->dev
;
7144 if (!HAS_RUNTIME_PM(dev
))
7147 WARN(dev_priv
->pm
.suspended
, "Getting nosync-ref while suspended.\n");
7148 pm_runtime_get_noresume(device
);
7151 void intel_runtime_pm_put(struct drm_i915_private
*dev_priv
)
7153 struct drm_device
*dev
= dev_priv
->dev
;
7154 struct device
*device
= &dev
->pdev
->dev
;
7156 if (!HAS_RUNTIME_PM(dev
))
7159 pm_runtime_mark_last_busy(device
);
7160 pm_runtime_put_autosuspend(device
);
7163 void intel_init_runtime_pm(struct drm_i915_private
*dev_priv
)
7165 struct drm_device
*dev
= dev_priv
->dev
;
7166 struct device
*device
= &dev
->pdev
->dev
;
7168 if (!HAS_RUNTIME_PM(dev
))
7171 pm_runtime_set_active(device
);
7174 * RPM depends on RC6 to save restore the GT HW context, so make RC6 a
7177 if (!intel_enable_rc6(dev
)) {
7178 DRM_INFO("RC6 disabled, disabling runtime PM support\n");
7182 pm_runtime_set_autosuspend_delay(device
, 10000); /* 10s */
7183 pm_runtime_mark_last_busy(device
);
7184 pm_runtime_use_autosuspend(device
);
7186 pm_runtime_put_autosuspend(device
);
7189 void intel_fini_runtime_pm(struct drm_i915_private
*dev_priv
)
7191 struct drm_device
*dev
= dev_priv
->dev
;
7192 struct device
*device
= &dev
->pdev
->dev
;
7194 if (!HAS_RUNTIME_PM(dev
))
7197 if (!intel_enable_rc6(dev
))
7200 /* Make sure we're not suspended first. */
7201 pm_runtime_get_sync(device
);
7202 pm_runtime_disable(device
);
7205 /* Set up chip specific power management-related functions */
7206 void intel_init_pm(struct drm_device
*dev
)
7208 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7211 if (INTEL_INFO(dev
)->gen
>= 7) {
7212 dev_priv
->display
.fbc_enabled
= ironlake_fbc_enabled
;
7213 dev_priv
->display
.enable_fbc
= gen7_enable_fbc
;
7214 dev_priv
->display
.disable_fbc
= ironlake_disable_fbc
;
7215 } else if (INTEL_INFO(dev
)->gen
>= 5) {
7216 dev_priv
->display
.fbc_enabled
= ironlake_fbc_enabled
;
7217 dev_priv
->display
.enable_fbc
= ironlake_enable_fbc
;
7218 dev_priv
->display
.disable_fbc
= ironlake_disable_fbc
;
7219 } else if (IS_GM45(dev
)) {
7220 dev_priv
->display
.fbc_enabled
= g4x_fbc_enabled
;
7221 dev_priv
->display
.enable_fbc
= g4x_enable_fbc
;
7222 dev_priv
->display
.disable_fbc
= g4x_disable_fbc
;
7224 dev_priv
->display
.fbc_enabled
= i8xx_fbc_enabled
;
7225 dev_priv
->display
.enable_fbc
= i8xx_enable_fbc
;
7226 dev_priv
->display
.disable_fbc
= i8xx_disable_fbc
;
7228 /* This value was pulled out of someone's hat */
7229 I915_WRITE(FBC_CONTROL
, 500 << FBC_CTL_INTERVAL_SHIFT
);
7234 if (IS_PINEVIEW(dev
))
7235 i915_pineview_get_mem_freq(dev
);
7236 else if (IS_GEN5(dev
))
7237 i915_ironlake_get_mem_freq(dev
);
7239 /* For FIFO watermark updates */
7240 if (HAS_PCH_SPLIT(dev
)) {
7241 ilk_setup_wm_latency(dev
);
7243 if ((IS_GEN5(dev
) && dev_priv
->wm
.pri_latency
[1] &&
7244 dev_priv
->wm
.spr_latency
[1] && dev_priv
->wm
.cur_latency
[1]) ||
7245 (!IS_GEN5(dev
) && dev_priv
->wm
.pri_latency
[0] &&
7246 dev_priv
->wm
.spr_latency
[0] && dev_priv
->wm
.cur_latency
[0])) {
7247 dev_priv
->display
.update_wm
= ilk_update_wm
;
7248 dev_priv
->display
.update_sprite_wm
= ilk_update_sprite_wm
;
7250 DRM_DEBUG_KMS("Failed to read display plane latency. "
7255 dev_priv
->display
.init_clock_gating
= ironlake_init_clock_gating
;
7256 else if (IS_GEN6(dev
))
7257 dev_priv
->display
.init_clock_gating
= gen6_init_clock_gating
;
7258 else if (IS_IVYBRIDGE(dev
))
7259 dev_priv
->display
.init_clock_gating
= ivybridge_init_clock_gating
;
7260 else if (IS_HASWELL(dev
))
7261 dev_priv
->display
.init_clock_gating
= haswell_init_clock_gating
;
7262 else if (INTEL_INFO(dev
)->gen
== 8)
7263 dev_priv
->display
.init_clock_gating
= gen8_init_clock_gating
;
7264 } else if (IS_CHERRYVIEW(dev
)) {
7265 dev_priv
->display
.update_wm
= cherryview_update_wm
;
7266 dev_priv
->display
.update_sprite_wm
= valleyview_update_sprite_wm
;
7267 dev_priv
->display
.init_clock_gating
=
7268 cherryview_init_clock_gating
;
7269 } else if (IS_VALLEYVIEW(dev
)) {
7270 dev_priv
->display
.update_wm
= valleyview_update_wm
;
7271 dev_priv
->display
.update_sprite_wm
= valleyview_update_sprite_wm
;
7272 dev_priv
->display
.init_clock_gating
=
7273 valleyview_init_clock_gating
;
7274 } else if (IS_PINEVIEW(dev
)) {
7275 if (!intel_get_cxsr_latency(IS_PINEVIEW_G(dev
),
7278 dev_priv
->mem_freq
)) {
7279 DRM_INFO("failed to find known CxSR latency "
7280 "(found ddr%s fsb freq %d, mem freq %d), "
7282 (dev_priv
->is_ddr3
== 1) ? "3" : "2",
7283 dev_priv
->fsb_freq
, dev_priv
->mem_freq
);
7284 /* Disable CxSR and never update its watermark again */
7285 intel_set_memory_cxsr(dev_priv
, false);
7286 dev_priv
->display
.update_wm
= NULL
;
7288 dev_priv
->display
.update_wm
= pineview_update_wm
;
7289 dev_priv
->display
.init_clock_gating
= gen3_init_clock_gating
;
7290 } else if (IS_G4X(dev
)) {
7291 dev_priv
->display
.update_wm
= g4x_update_wm
;
7292 dev_priv
->display
.init_clock_gating
= g4x_init_clock_gating
;
7293 } else if (IS_GEN4(dev
)) {
7294 dev_priv
->display
.update_wm
= i965_update_wm
;
7295 if (IS_CRESTLINE(dev
))
7296 dev_priv
->display
.init_clock_gating
= crestline_init_clock_gating
;
7297 else if (IS_BROADWATER(dev
))
7298 dev_priv
->display
.init_clock_gating
= broadwater_init_clock_gating
;
7299 } else if (IS_GEN3(dev
)) {
7300 dev_priv
->display
.update_wm
= i9xx_update_wm
;
7301 dev_priv
->display
.get_fifo_size
= i9xx_get_fifo_size
;
7302 dev_priv
->display
.init_clock_gating
= gen3_init_clock_gating
;
7303 } else if (IS_GEN2(dev
)) {
7304 if (INTEL_INFO(dev
)->num_pipes
== 1) {
7305 dev_priv
->display
.update_wm
= i845_update_wm
;
7306 dev_priv
->display
.get_fifo_size
= i845_get_fifo_size
;
7308 dev_priv
->display
.update_wm
= i9xx_update_wm
;
7309 dev_priv
->display
.get_fifo_size
= i830_get_fifo_size
;
7312 if (IS_I85X(dev
) || IS_I865G(dev
))
7313 dev_priv
->display
.init_clock_gating
= i85x_init_clock_gating
;
7315 dev_priv
->display
.init_clock_gating
= i830_init_clock_gating
;
7317 DRM_ERROR("unexpected fall-through in intel_init_pm\n");
7321 int sandybridge_pcode_read(struct drm_i915_private
*dev_priv
, u8 mbox
, u32
*val
)
7323 WARN_ON(!mutex_is_locked(&dev_priv
->rps
.hw_lock
));
7325 if (I915_READ(GEN6_PCODE_MAILBOX
) & GEN6_PCODE_READY
) {
7326 DRM_DEBUG_DRIVER("warning: pcode (read) mailbox access failed\n");
7330 I915_WRITE(GEN6_PCODE_DATA
, *val
);
7331 I915_WRITE(GEN6_PCODE_MAILBOX
, GEN6_PCODE_READY
| mbox
);
7333 if (wait_for((I915_READ(GEN6_PCODE_MAILBOX
) & GEN6_PCODE_READY
) == 0,
7335 DRM_ERROR("timeout waiting for pcode read (%d) to finish\n", mbox
);
7339 *val
= I915_READ(GEN6_PCODE_DATA
);
7340 I915_WRITE(GEN6_PCODE_DATA
, 0);
7345 int sandybridge_pcode_write(struct drm_i915_private
*dev_priv
, u8 mbox
, u32 val
)
7347 WARN_ON(!mutex_is_locked(&dev_priv
->rps
.hw_lock
));
7349 if (I915_READ(GEN6_PCODE_MAILBOX
) & GEN6_PCODE_READY
) {
7350 DRM_DEBUG_DRIVER("warning: pcode (write) mailbox access failed\n");
7354 I915_WRITE(GEN6_PCODE_DATA
, val
);
7355 I915_WRITE(GEN6_PCODE_MAILBOX
, GEN6_PCODE_READY
| mbox
);
7357 if (wait_for((I915_READ(GEN6_PCODE_MAILBOX
) & GEN6_PCODE_READY
) == 0,
7359 DRM_ERROR("timeout waiting for pcode write (%d) to finish\n", mbox
);
7363 I915_WRITE(GEN6_PCODE_DATA
, 0);
7368 static int byt_gpu_freq(struct drm_i915_private
*dev_priv
, int val
)
7373 switch (dev_priv
->mem_freq
) {
7387 return DIV_ROUND_CLOSEST(dev_priv
->mem_freq
* (val
+ 6 - 0xbd), 4 * div
);
7390 static int byt_freq_opcode(struct drm_i915_private
*dev_priv
, int val
)
7395 switch (dev_priv
->mem_freq
) {
7409 return DIV_ROUND_CLOSEST(4 * mul
* val
, dev_priv
->mem_freq
) + 0xbd - 6;
7412 static int chv_gpu_freq(struct drm_i915_private
*dev_priv
, int val
)
7416 switch (dev_priv
->rps
.cz_freq
) {
7432 freq
= (DIV_ROUND_CLOSEST((dev_priv
->rps
.cz_freq
* val
), 2 * div
) / 2);
7437 static int chv_freq_opcode(struct drm_i915_private
*dev_priv
, int val
)
7441 switch (dev_priv
->rps
.cz_freq
) {
7457 opcode
= (DIV_ROUND_CLOSEST((val
* 2 * mul
), dev_priv
->rps
.cz_freq
) * 2);
7462 int vlv_gpu_freq(struct drm_i915_private
*dev_priv
, int val
)
7466 if (IS_CHERRYVIEW(dev_priv
->dev
))
7467 ret
= chv_gpu_freq(dev_priv
, val
);
7468 else if (IS_VALLEYVIEW(dev_priv
->dev
))
7469 ret
= byt_gpu_freq(dev_priv
, val
);
7474 int vlv_freq_opcode(struct drm_i915_private
*dev_priv
, int val
)
7478 if (IS_CHERRYVIEW(dev_priv
->dev
))
7479 ret
= chv_freq_opcode(dev_priv
, val
);
7480 else if (IS_VALLEYVIEW(dev_priv
->dev
))
7481 ret
= byt_freq_opcode(dev_priv
, val
);
7486 void intel_pm_setup(struct drm_device
*dev
)
7488 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7490 mutex_init(&dev_priv
->rps
.hw_lock
);
7492 INIT_DELAYED_WORK(&dev_priv
->rps
.delayed_resume_work
,
7493 intel_gen6_powersave_work
);
7495 dev_priv
->pm
.suspended
= false;
7496 dev_priv
->pm
._irqs_disabled
= false;