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 void gen8_fbc_sw_flush(struct drm_device
*dev
, u32 value
)
350 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
355 I915_WRITE(MSG_FBC_REND_STATE
, value
);
358 static void intel_fbc_work_fn(struct work_struct
*__work
)
360 struct intel_fbc_work
*work
=
361 container_of(to_delayed_work(__work
),
362 struct intel_fbc_work
, work
);
363 struct drm_device
*dev
= work
->crtc
->dev
;
364 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
366 mutex_lock(&dev
->struct_mutex
);
367 if (work
== dev_priv
->fbc
.fbc_work
) {
368 /* Double check that we haven't switched fb without cancelling
371 if (work
->crtc
->primary
->fb
== work
->fb
) {
372 dev_priv
->display
.enable_fbc(work
->crtc
);
374 dev_priv
->fbc
.plane
= to_intel_crtc(work
->crtc
)->plane
;
375 dev_priv
->fbc
.fb_id
= work
->crtc
->primary
->fb
->base
.id
;
376 dev_priv
->fbc
.y
= work
->crtc
->y
;
379 dev_priv
->fbc
.fbc_work
= NULL
;
381 mutex_unlock(&dev
->struct_mutex
);
386 static void intel_cancel_fbc_work(struct drm_i915_private
*dev_priv
)
388 if (dev_priv
->fbc
.fbc_work
== NULL
)
391 DRM_DEBUG_KMS("cancelling pending FBC enable\n");
393 /* Synchronisation is provided by struct_mutex and checking of
394 * dev_priv->fbc.fbc_work, so we can perform the cancellation
395 * entirely asynchronously.
397 if (cancel_delayed_work(&dev_priv
->fbc
.fbc_work
->work
))
398 /* tasklet was killed before being run, clean up */
399 kfree(dev_priv
->fbc
.fbc_work
);
401 /* Mark the work as no longer wanted so that if it does
402 * wake-up (because the work was already running and waiting
403 * for our mutex), it will discover that is no longer
406 dev_priv
->fbc
.fbc_work
= NULL
;
409 static void intel_enable_fbc(struct drm_crtc
*crtc
)
411 struct intel_fbc_work
*work
;
412 struct drm_device
*dev
= crtc
->dev
;
413 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
415 if (!dev_priv
->display
.enable_fbc
)
418 intel_cancel_fbc_work(dev_priv
);
420 work
= kzalloc(sizeof(*work
), GFP_KERNEL
);
422 DRM_ERROR("Failed to allocate FBC work structure\n");
423 dev_priv
->display
.enable_fbc(crtc
);
428 work
->fb
= crtc
->primary
->fb
;
429 INIT_DELAYED_WORK(&work
->work
, intel_fbc_work_fn
);
431 dev_priv
->fbc
.fbc_work
= work
;
433 /* Delay the actual enabling to let pageflipping cease and the
434 * display to settle before starting the compression. Note that
435 * this delay also serves a second purpose: it allows for a
436 * vblank to pass after disabling the FBC before we attempt
437 * to modify the control registers.
439 * A more complicated solution would involve tracking vblanks
440 * following the termination of the page-flipping sequence
441 * and indeed performing the enable as a co-routine and not
442 * waiting synchronously upon the vblank.
444 * WaFbcWaitForVBlankBeforeEnable:ilk,snb
446 schedule_delayed_work(&work
->work
, msecs_to_jiffies(50));
449 void intel_disable_fbc(struct drm_device
*dev
)
451 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
453 intel_cancel_fbc_work(dev_priv
);
455 if (!dev_priv
->display
.disable_fbc
)
458 dev_priv
->display
.disable_fbc(dev
);
459 dev_priv
->fbc
.plane
= -1;
462 static bool set_no_fbc_reason(struct drm_i915_private
*dev_priv
,
463 enum no_fbc_reason reason
)
465 if (dev_priv
->fbc
.no_fbc_reason
== reason
)
468 dev_priv
->fbc
.no_fbc_reason
= reason
;
473 * intel_update_fbc - enable/disable FBC as needed
474 * @dev: the drm_device
476 * Set up the framebuffer compression hardware at mode set time. We
477 * enable it if possible:
478 * - plane A only (on pre-965)
479 * - no pixel mulitply/line duplication
480 * - no alpha buffer discard
482 * - framebuffer <= max_hdisplay in width, max_vdisplay in height
484 * We can't assume that any compression will take place (worst case),
485 * so the compressed buffer has to be the same size as the uncompressed
486 * one. It also must reside (along with the line length buffer) in
489 * We need to enable/disable FBC on a global basis.
491 void intel_update_fbc(struct drm_device
*dev
)
493 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
494 struct drm_crtc
*crtc
= NULL
, *tmp_crtc
;
495 struct intel_crtc
*intel_crtc
;
496 struct drm_framebuffer
*fb
;
497 struct drm_i915_gem_object
*obj
;
498 const struct drm_display_mode
*adjusted_mode
;
499 unsigned int max_width
, max_height
;
502 set_no_fbc_reason(dev_priv
, FBC_UNSUPPORTED
);
506 if (!i915
.powersave
) {
507 if (set_no_fbc_reason(dev_priv
, FBC_MODULE_PARAM
))
508 DRM_DEBUG_KMS("fbc disabled per module param\n");
513 * If FBC is already on, we just have to verify that we can
514 * keep it that way...
515 * Need to disable if:
516 * - more than one pipe is active
517 * - changing FBC params (stride, fence, mode)
518 * - new fb is too large to fit in compressed buffer
519 * - going to an unsupported config (interlace, pixel multiply, etc.)
521 for_each_crtc(dev
, tmp_crtc
) {
522 if (intel_crtc_active(tmp_crtc
) &&
523 to_intel_crtc(tmp_crtc
)->primary_enabled
) {
525 if (set_no_fbc_reason(dev_priv
, FBC_MULTIPLE_PIPES
))
526 DRM_DEBUG_KMS("more than one pipe active, disabling compression\n");
533 if (!crtc
|| crtc
->primary
->fb
== NULL
) {
534 if (set_no_fbc_reason(dev_priv
, FBC_NO_OUTPUT
))
535 DRM_DEBUG_KMS("no output, disabling\n");
539 intel_crtc
= to_intel_crtc(crtc
);
540 fb
= crtc
->primary
->fb
;
541 obj
= intel_fb_obj(fb
);
542 adjusted_mode
= &intel_crtc
->config
.adjusted_mode
;
544 if (i915
.enable_fbc
< 0) {
545 if (set_no_fbc_reason(dev_priv
, FBC_CHIP_DEFAULT
))
546 DRM_DEBUG_KMS("disabled per chip default\n");
549 if (!i915
.enable_fbc
) {
550 if (set_no_fbc_reason(dev_priv
, FBC_MODULE_PARAM
))
551 DRM_DEBUG_KMS("fbc disabled per module param\n");
554 if ((adjusted_mode
->flags
& DRM_MODE_FLAG_INTERLACE
) ||
555 (adjusted_mode
->flags
& DRM_MODE_FLAG_DBLSCAN
)) {
556 if (set_no_fbc_reason(dev_priv
, FBC_UNSUPPORTED_MODE
))
557 DRM_DEBUG_KMS("mode incompatible with compression, "
562 if (INTEL_INFO(dev
)->gen
>= 8 || IS_HASWELL(dev
)) {
565 } else if (IS_G4X(dev
) || INTEL_INFO(dev
)->gen
>= 5) {
572 if (intel_crtc
->config
.pipe_src_w
> max_width
||
573 intel_crtc
->config
.pipe_src_h
> max_height
) {
574 if (set_no_fbc_reason(dev_priv
, FBC_MODE_TOO_LARGE
))
575 DRM_DEBUG_KMS("mode too large for compression, disabling\n");
578 if ((INTEL_INFO(dev
)->gen
< 4 || HAS_DDI(dev
)) &&
579 intel_crtc
->plane
!= PLANE_A
) {
580 if (set_no_fbc_reason(dev_priv
, FBC_BAD_PLANE
))
581 DRM_DEBUG_KMS("plane not A, disabling compression\n");
585 /* The use of a CPU fence is mandatory in order to detect writes
586 * by the CPU to the scanout and trigger updates to the FBC.
588 if (obj
->tiling_mode
!= I915_TILING_X
||
589 obj
->fence_reg
== I915_FENCE_REG_NONE
) {
590 if (set_no_fbc_reason(dev_priv
, FBC_NOT_TILED
))
591 DRM_DEBUG_KMS("framebuffer not tiled or fenced, disabling compression\n");
594 if (INTEL_INFO(dev
)->gen
<= 4 && !IS_G4X(dev
) &&
595 to_intel_plane(crtc
->primary
)->rotation
!= BIT(DRM_ROTATE_0
)) {
596 if (set_no_fbc_reason(dev_priv
, FBC_UNSUPPORTED_MODE
))
597 DRM_DEBUG_KMS("Rotation unsupported, disabling\n");
601 /* If the kernel debugger is active, always disable compression */
605 if (i915_gem_stolen_setup_compression(dev
, obj
->base
.size
,
606 drm_format_plane_cpp(fb
->pixel_format
, 0))) {
607 if (set_no_fbc_reason(dev_priv
, FBC_STOLEN_TOO_SMALL
))
608 DRM_DEBUG_KMS("framebuffer too large, disabling compression\n");
612 /* If the scanout has not changed, don't modify the FBC settings.
613 * Note that we make the fundamental assumption that the fb->obj
614 * cannot be unpinned (and have its GTT offset and fence revoked)
615 * without first being decoupled from the scanout and FBC disabled.
617 if (dev_priv
->fbc
.plane
== intel_crtc
->plane
&&
618 dev_priv
->fbc
.fb_id
== fb
->base
.id
&&
619 dev_priv
->fbc
.y
== crtc
->y
)
622 if (intel_fbc_enabled(dev
)) {
623 /* We update FBC along two paths, after changing fb/crtc
624 * configuration (modeswitching) and after page-flipping
625 * finishes. For the latter, we know that not only did
626 * we disable the FBC at the start of the page-flip
627 * sequence, but also more than one vblank has passed.
629 * For the former case of modeswitching, it is possible
630 * to switch between two FBC valid configurations
631 * instantaneously so we do need to disable the FBC
632 * before we can modify its control registers. We also
633 * have to wait for the next vblank for that to take
634 * effect. However, since we delay enabling FBC we can
635 * assume that a vblank has passed since disabling and
636 * that we can safely alter the registers in the deferred
639 * In the scenario that we go from a valid to invalid
640 * and then back to valid FBC configuration we have
641 * no strict enforcement that a vblank occurred since
642 * disabling the FBC. However, along all current pipe
643 * disabling paths we do need to wait for a vblank at
644 * some point. And we wait before enabling FBC anyway.
646 DRM_DEBUG_KMS("disabling active FBC for update\n");
647 intel_disable_fbc(dev
);
650 intel_enable_fbc(crtc
);
651 dev_priv
->fbc
.no_fbc_reason
= FBC_OK
;
655 /* Multiple disables should be harmless */
656 if (intel_fbc_enabled(dev
)) {
657 DRM_DEBUG_KMS("unsupported config, disabling FBC\n");
658 intel_disable_fbc(dev
);
660 i915_gem_stolen_cleanup_compression(dev
);
663 static void i915_pineview_get_mem_freq(struct drm_device
*dev
)
665 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
668 tmp
= I915_READ(CLKCFG
);
670 switch (tmp
& CLKCFG_FSB_MASK
) {
672 dev_priv
->fsb_freq
= 533; /* 133*4 */
675 dev_priv
->fsb_freq
= 800; /* 200*4 */
678 dev_priv
->fsb_freq
= 667; /* 167*4 */
681 dev_priv
->fsb_freq
= 400; /* 100*4 */
685 switch (tmp
& CLKCFG_MEM_MASK
) {
687 dev_priv
->mem_freq
= 533;
690 dev_priv
->mem_freq
= 667;
693 dev_priv
->mem_freq
= 800;
697 /* detect pineview DDR3 setting */
698 tmp
= I915_READ(CSHRDDR3CTL
);
699 dev_priv
->is_ddr3
= (tmp
& CSHRDDR3CTL_DDR3
) ? 1 : 0;
702 static void i915_ironlake_get_mem_freq(struct drm_device
*dev
)
704 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
707 ddrpll
= I915_READ16(DDRMPLL1
);
708 csipll
= I915_READ16(CSIPLL0
);
710 switch (ddrpll
& 0xff) {
712 dev_priv
->mem_freq
= 800;
715 dev_priv
->mem_freq
= 1066;
718 dev_priv
->mem_freq
= 1333;
721 dev_priv
->mem_freq
= 1600;
724 DRM_DEBUG_DRIVER("unknown memory frequency 0x%02x\n",
726 dev_priv
->mem_freq
= 0;
730 dev_priv
->ips
.r_t
= dev_priv
->mem_freq
;
732 switch (csipll
& 0x3ff) {
734 dev_priv
->fsb_freq
= 3200;
737 dev_priv
->fsb_freq
= 3733;
740 dev_priv
->fsb_freq
= 4266;
743 dev_priv
->fsb_freq
= 4800;
746 dev_priv
->fsb_freq
= 5333;
749 dev_priv
->fsb_freq
= 5866;
752 dev_priv
->fsb_freq
= 6400;
755 DRM_DEBUG_DRIVER("unknown fsb frequency 0x%04x\n",
757 dev_priv
->fsb_freq
= 0;
761 if (dev_priv
->fsb_freq
== 3200) {
762 dev_priv
->ips
.c_m
= 0;
763 } else if (dev_priv
->fsb_freq
> 3200 && dev_priv
->fsb_freq
<= 4800) {
764 dev_priv
->ips
.c_m
= 1;
766 dev_priv
->ips
.c_m
= 2;
770 static const struct cxsr_latency cxsr_latency_table
[] = {
771 {1, 0, 800, 400, 3382, 33382, 3983, 33983}, /* DDR2-400 SC */
772 {1, 0, 800, 667, 3354, 33354, 3807, 33807}, /* DDR2-667 SC */
773 {1, 0, 800, 800, 3347, 33347, 3763, 33763}, /* DDR2-800 SC */
774 {1, 1, 800, 667, 6420, 36420, 6873, 36873}, /* DDR3-667 SC */
775 {1, 1, 800, 800, 5902, 35902, 6318, 36318}, /* DDR3-800 SC */
777 {1, 0, 667, 400, 3400, 33400, 4021, 34021}, /* DDR2-400 SC */
778 {1, 0, 667, 667, 3372, 33372, 3845, 33845}, /* DDR2-667 SC */
779 {1, 0, 667, 800, 3386, 33386, 3822, 33822}, /* DDR2-800 SC */
780 {1, 1, 667, 667, 6438, 36438, 6911, 36911}, /* DDR3-667 SC */
781 {1, 1, 667, 800, 5941, 35941, 6377, 36377}, /* DDR3-800 SC */
783 {1, 0, 400, 400, 3472, 33472, 4173, 34173}, /* DDR2-400 SC */
784 {1, 0, 400, 667, 3443, 33443, 3996, 33996}, /* DDR2-667 SC */
785 {1, 0, 400, 800, 3430, 33430, 3946, 33946}, /* DDR2-800 SC */
786 {1, 1, 400, 667, 6509, 36509, 7062, 37062}, /* DDR3-667 SC */
787 {1, 1, 400, 800, 5985, 35985, 6501, 36501}, /* DDR3-800 SC */
789 {0, 0, 800, 400, 3438, 33438, 4065, 34065}, /* DDR2-400 SC */
790 {0, 0, 800, 667, 3410, 33410, 3889, 33889}, /* DDR2-667 SC */
791 {0, 0, 800, 800, 3403, 33403, 3845, 33845}, /* DDR2-800 SC */
792 {0, 1, 800, 667, 6476, 36476, 6955, 36955}, /* DDR3-667 SC */
793 {0, 1, 800, 800, 5958, 35958, 6400, 36400}, /* DDR3-800 SC */
795 {0, 0, 667, 400, 3456, 33456, 4103, 34106}, /* DDR2-400 SC */
796 {0, 0, 667, 667, 3428, 33428, 3927, 33927}, /* DDR2-667 SC */
797 {0, 0, 667, 800, 3443, 33443, 3905, 33905}, /* DDR2-800 SC */
798 {0, 1, 667, 667, 6494, 36494, 6993, 36993}, /* DDR3-667 SC */
799 {0, 1, 667, 800, 5998, 35998, 6460, 36460}, /* DDR3-800 SC */
801 {0, 0, 400, 400, 3528, 33528, 4255, 34255}, /* DDR2-400 SC */
802 {0, 0, 400, 667, 3500, 33500, 4079, 34079}, /* DDR2-667 SC */
803 {0, 0, 400, 800, 3487, 33487, 4029, 34029}, /* DDR2-800 SC */
804 {0, 1, 400, 667, 6566, 36566, 7145, 37145}, /* DDR3-667 SC */
805 {0, 1, 400, 800, 6042, 36042, 6584, 36584}, /* DDR3-800 SC */
808 static const struct cxsr_latency
*intel_get_cxsr_latency(int is_desktop
,
813 const struct cxsr_latency
*latency
;
816 if (fsb
== 0 || mem
== 0)
819 for (i
= 0; i
< ARRAY_SIZE(cxsr_latency_table
); i
++) {
820 latency
= &cxsr_latency_table
[i
];
821 if (is_desktop
== latency
->is_desktop
&&
822 is_ddr3
== latency
->is_ddr3
&&
823 fsb
== latency
->fsb_freq
&& mem
== latency
->mem_freq
)
827 DRM_DEBUG_KMS("Unknown FSB/MEM found, disable CxSR\n");
832 void intel_set_memory_cxsr(struct drm_i915_private
*dev_priv
, bool enable
)
834 struct drm_device
*dev
= dev_priv
->dev
;
837 if (IS_VALLEYVIEW(dev
)) {
838 I915_WRITE(FW_BLC_SELF_VLV
, enable
? FW_CSPWRDWNEN
: 0);
839 } else if (IS_G4X(dev
) || IS_CRESTLINE(dev
)) {
840 I915_WRITE(FW_BLC_SELF
, enable
? FW_BLC_SELF_EN
: 0);
841 } else if (IS_PINEVIEW(dev
)) {
842 val
= I915_READ(DSPFW3
) & ~PINEVIEW_SELF_REFRESH_EN
;
843 val
|= enable
? PINEVIEW_SELF_REFRESH_EN
: 0;
844 I915_WRITE(DSPFW3
, val
);
845 } else if (IS_I945G(dev
) || IS_I945GM(dev
)) {
846 val
= enable
? _MASKED_BIT_ENABLE(FW_BLC_SELF_EN
) :
847 _MASKED_BIT_DISABLE(FW_BLC_SELF_EN
);
848 I915_WRITE(FW_BLC_SELF
, val
);
849 } else if (IS_I915GM(dev
)) {
850 val
= enable
? _MASKED_BIT_ENABLE(INSTPM_SELF_EN
) :
851 _MASKED_BIT_DISABLE(INSTPM_SELF_EN
);
852 I915_WRITE(INSTPM
, val
);
857 DRM_DEBUG_KMS("memory self-refresh is %s\n",
858 enable
? "enabled" : "disabled");
862 * Latency for FIFO fetches is dependent on several factors:
863 * - memory configuration (speed, channels)
865 * - current MCH state
866 * It can be fairly high in some situations, so here we assume a fairly
867 * pessimal value. It's a tradeoff between extra memory fetches (if we
868 * set this value too high, the FIFO will fetch frequently to stay full)
869 * and power consumption (set it too low to save power and we might see
870 * FIFO underruns and display "flicker").
872 * A value of 5us seems to be a good balance; safe for very low end
873 * platforms but not overly aggressive on lower latency configs.
875 static const int latency_ns
= 5000;
877 static int i9xx_get_fifo_size(struct drm_device
*dev
, int plane
)
879 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
880 uint32_t dsparb
= I915_READ(DSPARB
);
883 size
= dsparb
& 0x7f;
885 size
= ((dsparb
>> DSPARB_CSTART_SHIFT
) & 0x7f) - size
;
887 DRM_DEBUG_KMS("FIFO size - (0x%08x) %s: %d\n", dsparb
,
888 plane
? "B" : "A", size
);
893 static int i830_get_fifo_size(struct drm_device
*dev
, int plane
)
895 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
896 uint32_t dsparb
= I915_READ(DSPARB
);
899 size
= dsparb
& 0x1ff;
901 size
= ((dsparb
>> DSPARB_BEND_SHIFT
) & 0x1ff) - size
;
902 size
>>= 1; /* Convert to cachelines */
904 DRM_DEBUG_KMS("FIFO size - (0x%08x) %s: %d\n", dsparb
,
905 plane
? "B" : "A", size
);
910 static int i845_get_fifo_size(struct drm_device
*dev
, int plane
)
912 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
913 uint32_t dsparb
= I915_READ(DSPARB
);
916 size
= dsparb
& 0x7f;
917 size
>>= 2; /* Convert to cachelines */
919 DRM_DEBUG_KMS("FIFO size - (0x%08x) %s: %d\n", dsparb
,
926 /* Pineview has different values for various configs */
927 static const struct intel_watermark_params pineview_display_wm
= {
928 .fifo_size
= PINEVIEW_DISPLAY_FIFO
,
929 .max_wm
= PINEVIEW_MAX_WM
,
930 .default_wm
= PINEVIEW_DFT_WM
,
931 .guard_size
= PINEVIEW_GUARD_WM
,
932 .cacheline_size
= PINEVIEW_FIFO_LINE_SIZE
,
934 static const struct intel_watermark_params pineview_display_hplloff_wm
= {
935 .fifo_size
= PINEVIEW_DISPLAY_FIFO
,
936 .max_wm
= PINEVIEW_MAX_WM
,
937 .default_wm
= PINEVIEW_DFT_HPLLOFF_WM
,
938 .guard_size
= PINEVIEW_GUARD_WM
,
939 .cacheline_size
= PINEVIEW_FIFO_LINE_SIZE
,
941 static const struct intel_watermark_params pineview_cursor_wm
= {
942 .fifo_size
= PINEVIEW_CURSOR_FIFO
,
943 .max_wm
= PINEVIEW_CURSOR_MAX_WM
,
944 .default_wm
= PINEVIEW_CURSOR_DFT_WM
,
945 .guard_size
= PINEVIEW_CURSOR_GUARD_WM
,
946 .cacheline_size
= PINEVIEW_FIFO_LINE_SIZE
,
948 static const struct intel_watermark_params pineview_cursor_hplloff_wm
= {
949 .fifo_size
= PINEVIEW_CURSOR_FIFO
,
950 .max_wm
= PINEVIEW_CURSOR_MAX_WM
,
951 .default_wm
= PINEVIEW_CURSOR_DFT_WM
,
952 .guard_size
= PINEVIEW_CURSOR_GUARD_WM
,
953 .cacheline_size
= PINEVIEW_FIFO_LINE_SIZE
,
955 static const struct intel_watermark_params g4x_wm_info
= {
956 .fifo_size
= G4X_FIFO_SIZE
,
957 .max_wm
= G4X_MAX_WM
,
958 .default_wm
= G4X_MAX_WM
,
960 .cacheline_size
= G4X_FIFO_LINE_SIZE
,
962 static const struct intel_watermark_params g4x_cursor_wm_info
= {
963 .fifo_size
= I965_CURSOR_FIFO
,
964 .max_wm
= I965_CURSOR_MAX_WM
,
965 .default_wm
= I965_CURSOR_DFT_WM
,
967 .cacheline_size
= G4X_FIFO_LINE_SIZE
,
969 static const struct intel_watermark_params valleyview_wm_info
= {
970 .fifo_size
= VALLEYVIEW_FIFO_SIZE
,
971 .max_wm
= VALLEYVIEW_MAX_WM
,
972 .default_wm
= VALLEYVIEW_MAX_WM
,
974 .cacheline_size
= G4X_FIFO_LINE_SIZE
,
976 static const struct intel_watermark_params valleyview_cursor_wm_info
= {
977 .fifo_size
= I965_CURSOR_FIFO
,
978 .max_wm
= VALLEYVIEW_CURSOR_MAX_WM
,
979 .default_wm
= I965_CURSOR_DFT_WM
,
981 .cacheline_size
= G4X_FIFO_LINE_SIZE
,
983 static const struct intel_watermark_params i965_cursor_wm_info
= {
984 .fifo_size
= I965_CURSOR_FIFO
,
985 .max_wm
= I965_CURSOR_MAX_WM
,
986 .default_wm
= I965_CURSOR_DFT_WM
,
988 .cacheline_size
= I915_FIFO_LINE_SIZE
,
990 static const struct intel_watermark_params i945_wm_info
= {
991 .fifo_size
= I945_FIFO_SIZE
,
992 .max_wm
= I915_MAX_WM
,
995 .cacheline_size
= I915_FIFO_LINE_SIZE
,
997 static const struct intel_watermark_params i915_wm_info
= {
998 .fifo_size
= I915_FIFO_SIZE
,
999 .max_wm
= I915_MAX_WM
,
1002 .cacheline_size
= I915_FIFO_LINE_SIZE
,
1004 static const struct intel_watermark_params i830_wm_info
= {
1005 .fifo_size
= I855GM_FIFO_SIZE
,
1006 .max_wm
= I915_MAX_WM
,
1009 .cacheline_size
= I830_FIFO_LINE_SIZE
,
1011 static const struct intel_watermark_params i845_wm_info
= {
1012 .fifo_size
= I830_FIFO_SIZE
,
1013 .max_wm
= I915_MAX_WM
,
1016 .cacheline_size
= I830_FIFO_LINE_SIZE
,
1020 * intel_calculate_wm - calculate watermark level
1021 * @clock_in_khz: pixel clock
1022 * @wm: chip FIFO params
1023 * @pixel_size: display pixel size
1024 * @latency_ns: memory latency for the platform
1026 * Calculate the watermark level (the level at which the display plane will
1027 * start fetching from memory again). Each chip has a different display
1028 * FIFO size and allocation, so the caller needs to figure that out and pass
1029 * in the correct intel_watermark_params structure.
1031 * As the pixel clock runs, the FIFO will be drained at a rate that depends
1032 * on the pixel size. When it reaches the watermark level, it'll start
1033 * fetching FIFO line sized based chunks from memory until the FIFO fills
1034 * past the watermark point. If the FIFO drains completely, a FIFO underrun
1035 * will occur, and a display engine hang could result.
1037 static unsigned long intel_calculate_wm(unsigned long clock_in_khz
,
1038 const struct intel_watermark_params
*wm
,
1041 unsigned long latency_ns
)
1043 long entries_required
, wm_size
;
1046 * Note: we need to make sure we don't overflow for various clock &
1048 * clocks go from a few thousand to several hundred thousand.
1049 * latency is usually a few thousand
1051 entries_required
= ((clock_in_khz
/ 1000) * pixel_size
* latency_ns
) /
1053 entries_required
= DIV_ROUND_UP(entries_required
, wm
->cacheline_size
);
1055 DRM_DEBUG_KMS("FIFO entries required for mode: %ld\n", entries_required
);
1057 wm_size
= fifo_size
- (entries_required
+ wm
->guard_size
);
1059 DRM_DEBUG_KMS("FIFO watermark level: %ld\n", wm_size
);
1061 /* Don't promote wm_size to unsigned... */
1062 if (wm_size
> (long)wm
->max_wm
)
1063 wm_size
= wm
->max_wm
;
1065 wm_size
= wm
->default_wm
;
1069 static struct drm_crtc
*single_enabled_crtc(struct drm_device
*dev
)
1071 struct drm_crtc
*crtc
, *enabled
= NULL
;
1073 for_each_crtc(dev
, crtc
) {
1074 if (intel_crtc_active(crtc
)) {
1084 static void pineview_update_wm(struct drm_crtc
*unused_crtc
)
1086 struct drm_device
*dev
= unused_crtc
->dev
;
1087 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1088 struct drm_crtc
*crtc
;
1089 const struct cxsr_latency
*latency
;
1093 latency
= intel_get_cxsr_latency(IS_PINEVIEW_G(dev
), dev_priv
->is_ddr3
,
1094 dev_priv
->fsb_freq
, dev_priv
->mem_freq
);
1096 DRM_DEBUG_KMS("Unknown FSB/MEM found, disable CxSR\n");
1097 intel_set_memory_cxsr(dev_priv
, false);
1101 crtc
= single_enabled_crtc(dev
);
1103 const struct drm_display_mode
*adjusted_mode
;
1104 int pixel_size
= crtc
->primary
->fb
->bits_per_pixel
/ 8;
1107 adjusted_mode
= &to_intel_crtc(crtc
)->config
.adjusted_mode
;
1108 clock
= adjusted_mode
->crtc_clock
;
1111 wm
= intel_calculate_wm(clock
, &pineview_display_wm
,
1112 pineview_display_wm
.fifo_size
,
1113 pixel_size
, latency
->display_sr
);
1114 reg
= I915_READ(DSPFW1
);
1115 reg
&= ~DSPFW_SR_MASK
;
1116 reg
|= wm
<< DSPFW_SR_SHIFT
;
1117 I915_WRITE(DSPFW1
, reg
);
1118 DRM_DEBUG_KMS("DSPFW1 register is %x\n", reg
);
1121 wm
= intel_calculate_wm(clock
, &pineview_cursor_wm
,
1122 pineview_display_wm
.fifo_size
,
1123 pixel_size
, latency
->cursor_sr
);
1124 reg
= I915_READ(DSPFW3
);
1125 reg
&= ~DSPFW_CURSOR_SR_MASK
;
1126 reg
|= (wm
& 0x3f) << DSPFW_CURSOR_SR_SHIFT
;
1127 I915_WRITE(DSPFW3
, reg
);
1129 /* Display HPLL off SR */
1130 wm
= intel_calculate_wm(clock
, &pineview_display_hplloff_wm
,
1131 pineview_display_hplloff_wm
.fifo_size
,
1132 pixel_size
, latency
->display_hpll_disable
);
1133 reg
= I915_READ(DSPFW3
);
1134 reg
&= ~DSPFW_HPLL_SR_MASK
;
1135 reg
|= wm
& DSPFW_HPLL_SR_MASK
;
1136 I915_WRITE(DSPFW3
, reg
);
1138 /* cursor HPLL off SR */
1139 wm
= intel_calculate_wm(clock
, &pineview_cursor_hplloff_wm
,
1140 pineview_display_hplloff_wm
.fifo_size
,
1141 pixel_size
, latency
->cursor_hpll_disable
);
1142 reg
= I915_READ(DSPFW3
);
1143 reg
&= ~DSPFW_HPLL_CURSOR_MASK
;
1144 reg
|= (wm
& 0x3f) << DSPFW_HPLL_CURSOR_SHIFT
;
1145 I915_WRITE(DSPFW3
, reg
);
1146 DRM_DEBUG_KMS("DSPFW3 register is %x\n", reg
);
1148 intel_set_memory_cxsr(dev_priv
, true);
1150 intel_set_memory_cxsr(dev_priv
, false);
1154 static bool g4x_compute_wm0(struct drm_device
*dev
,
1156 const struct intel_watermark_params
*display
,
1157 int display_latency_ns
,
1158 const struct intel_watermark_params
*cursor
,
1159 int cursor_latency_ns
,
1163 struct drm_crtc
*crtc
;
1164 const struct drm_display_mode
*adjusted_mode
;
1165 int htotal
, hdisplay
, clock
, pixel_size
;
1166 int line_time_us
, line_count
;
1167 int entries
, tlb_miss
;
1169 crtc
= intel_get_crtc_for_plane(dev
, plane
);
1170 if (!intel_crtc_active(crtc
)) {
1171 *cursor_wm
= cursor
->guard_size
;
1172 *plane_wm
= display
->guard_size
;
1176 adjusted_mode
= &to_intel_crtc(crtc
)->config
.adjusted_mode
;
1177 clock
= adjusted_mode
->crtc_clock
;
1178 htotal
= adjusted_mode
->crtc_htotal
;
1179 hdisplay
= to_intel_crtc(crtc
)->config
.pipe_src_w
;
1180 pixel_size
= crtc
->primary
->fb
->bits_per_pixel
/ 8;
1182 /* Use the small buffer method to calculate plane watermark */
1183 entries
= ((clock
* pixel_size
/ 1000) * display_latency_ns
) / 1000;
1184 tlb_miss
= display
->fifo_size
*display
->cacheline_size
- hdisplay
* 8;
1186 entries
+= tlb_miss
;
1187 entries
= DIV_ROUND_UP(entries
, display
->cacheline_size
);
1188 *plane_wm
= entries
+ display
->guard_size
;
1189 if (*plane_wm
> (int)display
->max_wm
)
1190 *plane_wm
= display
->max_wm
;
1192 /* Use the large buffer method to calculate cursor watermark */
1193 line_time_us
= max(htotal
* 1000 / clock
, 1);
1194 line_count
= (cursor_latency_ns
/ line_time_us
+ 1000) / 1000;
1195 entries
= line_count
* to_intel_crtc(crtc
)->cursor_width
* pixel_size
;
1196 tlb_miss
= cursor
->fifo_size
*cursor
->cacheline_size
- hdisplay
* 8;
1198 entries
+= tlb_miss
;
1199 entries
= DIV_ROUND_UP(entries
, cursor
->cacheline_size
);
1200 *cursor_wm
= entries
+ cursor
->guard_size
;
1201 if (*cursor_wm
> (int)cursor
->max_wm
)
1202 *cursor_wm
= (int)cursor
->max_wm
;
1208 * Check the wm result.
1210 * If any calculated watermark values is larger than the maximum value that
1211 * can be programmed into the associated watermark register, that watermark
1214 static bool g4x_check_srwm(struct drm_device
*dev
,
1215 int display_wm
, int cursor_wm
,
1216 const struct intel_watermark_params
*display
,
1217 const struct intel_watermark_params
*cursor
)
1219 DRM_DEBUG_KMS("SR watermark: display plane %d, cursor %d\n",
1220 display_wm
, cursor_wm
);
1222 if (display_wm
> display
->max_wm
) {
1223 DRM_DEBUG_KMS("display watermark is too large(%d/%ld), disabling\n",
1224 display_wm
, display
->max_wm
);
1228 if (cursor_wm
> cursor
->max_wm
) {
1229 DRM_DEBUG_KMS("cursor watermark is too large(%d/%ld), disabling\n",
1230 cursor_wm
, cursor
->max_wm
);
1234 if (!(display_wm
|| cursor_wm
)) {
1235 DRM_DEBUG_KMS("SR latency is 0, disabling\n");
1242 static bool g4x_compute_srwm(struct drm_device
*dev
,
1245 const struct intel_watermark_params
*display
,
1246 const struct intel_watermark_params
*cursor
,
1247 int *display_wm
, int *cursor_wm
)
1249 struct drm_crtc
*crtc
;
1250 const struct drm_display_mode
*adjusted_mode
;
1251 int hdisplay
, htotal
, pixel_size
, clock
;
1252 unsigned long line_time_us
;
1253 int line_count
, line_size
;
1258 *display_wm
= *cursor_wm
= 0;
1262 crtc
= intel_get_crtc_for_plane(dev
, plane
);
1263 adjusted_mode
= &to_intel_crtc(crtc
)->config
.adjusted_mode
;
1264 clock
= adjusted_mode
->crtc_clock
;
1265 htotal
= adjusted_mode
->crtc_htotal
;
1266 hdisplay
= to_intel_crtc(crtc
)->config
.pipe_src_w
;
1267 pixel_size
= crtc
->primary
->fb
->bits_per_pixel
/ 8;
1269 line_time_us
= max(htotal
* 1000 / clock
, 1);
1270 line_count
= (latency_ns
/ line_time_us
+ 1000) / 1000;
1271 line_size
= hdisplay
* pixel_size
;
1273 /* Use the minimum of the small and large buffer method for primary */
1274 small
= ((clock
* pixel_size
/ 1000) * latency_ns
) / 1000;
1275 large
= line_count
* line_size
;
1277 entries
= DIV_ROUND_UP(min(small
, large
), display
->cacheline_size
);
1278 *display_wm
= entries
+ display
->guard_size
;
1280 /* calculate the self-refresh watermark for display cursor */
1281 entries
= line_count
* pixel_size
* to_intel_crtc(crtc
)->cursor_width
;
1282 entries
= DIV_ROUND_UP(entries
, cursor
->cacheline_size
);
1283 *cursor_wm
= entries
+ cursor
->guard_size
;
1285 return g4x_check_srwm(dev
,
1286 *display_wm
, *cursor_wm
,
1290 static bool vlv_compute_drain_latency(struct drm_crtc
*crtc
,
1296 int clock
= to_intel_crtc(crtc
)->config
.adjusted_mode
.crtc_clock
;
1298 if (WARN(clock
== 0, "Pixel clock is zero!\n"))
1301 if (WARN(pixel_size
== 0, "Pixel size is zero!\n"))
1304 entries
= DIV_ROUND_UP(clock
, 1000) * pixel_size
;
1305 *prec_mult
= (entries
> 128) ? DRAIN_LATENCY_PRECISION_64
:
1306 DRAIN_LATENCY_PRECISION_32
;
1307 *drain_latency
= (64 * (*prec_mult
) * 4) / entries
;
1309 if (*drain_latency
> DRAIN_LATENCY_MASK
)
1310 *drain_latency
= DRAIN_LATENCY_MASK
;
1316 * Update drain latency registers of memory arbiter
1318 * Valleyview SoC has a new memory arbiter and needs drain latency registers
1319 * to be programmed. Each plane has a drain latency multiplier and a drain
1323 static void vlv_update_drain_latency(struct drm_crtc
*crtc
)
1325 struct drm_i915_private
*dev_priv
= crtc
->dev
->dev_private
;
1326 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
1329 enum pipe pipe
= intel_crtc
->pipe
;
1330 int plane_prec
, prec_mult
, plane_dl
;
1332 plane_dl
= I915_READ(VLV_DDL(pipe
)) & ~(DDL_PLANE_PRECISION_64
|
1333 DRAIN_LATENCY_MASK
| DDL_CURSOR_PRECISION_64
|
1334 (DRAIN_LATENCY_MASK
<< DDL_CURSOR_SHIFT
));
1336 if (!intel_crtc_active(crtc
)) {
1337 I915_WRITE(VLV_DDL(pipe
), plane_dl
);
1341 /* Primary plane Drain Latency */
1342 pixel_size
= crtc
->primary
->fb
->bits_per_pixel
/ 8; /* BPP */
1343 if (vlv_compute_drain_latency(crtc
, pixel_size
, &prec_mult
, &drain_latency
)) {
1344 plane_prec
= (prec_mult
== DRAIN_LATENCY_PRECISION_64
) ?
1345 DDL_PLANE_PRECISION_64
:
1346 DDL_PLANE_PRECISION_32
;
1347 plane_dl
|= plane_prec
| drain_latency
;
1350 /* Cursor Drain Latency
1351 * BPP is always 4 for cursor
1355 /* Program cursor DL only if it is enabled */
1356 if (intel_crtc
->cursor_base
&&
1357 vlv_compute_drain_latency(crtc
, pixel_size
, &prec_mult
, &drain_latency
)) {
1358 plane_prec
= (prec_mult
== DRAIN_LATENCY_PRECISION_64
) ?
1359 DDL_CURSOR_PRECISION_64
:
1360 DDL_CURSOR_PRECISION_32
;
1361 plane_dl
|= plane_prec
| (drain_latency
<< DDL_CURSOR_SHIFT
);
1364 I915_WRITE(VLV_DDL(pipe
), plane_dl
);
1367 #define single_plane_enabled(mask) is_power_of_2(mask)
1369 static void valleyview_update_wm(struct drm_crtc
*crtc
)
1371 struct drm_device
*dev
= crtc
->dev
;
1372 static const int sr_latency_ns
= 12000;
1373 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1374 int planea_wm
, planeb_wm
, cursora_wm
, cursorb_wm
;
1375 int plane_sr
, cursor_sr
;
1376 int ignore_plane_sr
, ignore_cursor_sr
;
1377 unsigned int enabled
= 0;
1380 vlv_update_drain_latency(crtc
);
1382 if (g4x_compute_wm0(dev
, PIPE_A
,
1383 &valleyview_wm_info
, latency_ns
,
1384 &valleyview_cursor_wm_info
, latency_ns
,
1385 &planea_wm
, &cursora_wm
))
1386 enabled
|= 1 << PIPE_A
;
1388 if (g4x_compute_wm0(dev
, PIPE_B
,
1389 &valleyview_wm_info
, latency_ns
,
1390 &valleyview_cursor_wm_info
, latency_ns
,
1391 &planeb_wm
, &cursorb_wm
))
1392 enabled
|= 1 << PIPE_B
;
1394 if (single_plane_enabled(enabled
) &&
1395 g4x_compute_srwm(dev
, ffs(enabled
) - 1,
1397 &valleyview_wm_info
,
1398 &valleyview_cursor_wm_info
,
1399 &plane_sr
, &ignore_cursor_sr
) &&
1400 g4x_compute_srwm(dev
, ffs(enabled
) - 1,
1402 &valleyview_wm_info
,
1403 &valleyview_cursor_wm_info
,
1404 &ignore_plane_sr
, &cursor_sr
)) {
1405 cxsr_enabled
= true;
1407 cxsr_enabled
= false;
1408 intel_set_memory_cxsr(dev_priv
, false);
1409 plane_sr
= cursor_sr
= 0;
1412 DRM_DEBUG_KMS("Setting FIFO watermarks - A: plane=%d, cursor=%d, "
1413 "B: plane=%d, cursor=%d, SR: plane=%d, cursor=%d\n",
1414 planea_wm
, cursora_wm
,
1415 planeb_wm
, cursorb_wm
,
1416 plane_sr
, cursor_sr
);
1419 (plane_sr
<< DSPFW_SR_SHIFT
) |
1420 (cursorb_wm
<< DSPFW_CURSORB_SHIFT
) |
1421 (planeb_wm
<< DSPFW_PLANEB_SHIFT
) |
1422 (planea_wm
<< DSPFW_PLANEA_SHIFT
));
1424 (I915_READ(DSPFW2
) & ~DSPFW_CURSORA_MASK
) |
1425 (cursora_wm
<< DSPFW_CURSORA_SHIFT
));
1427 (I915_READ(DSPFW3
) & ~DSPFW_CURSOR_SR_MASK
) |
1428 (cursor_sr
<< DSPFW_CURSOR_SR_SHIFT
));
1431 intel_set_memory_cxsr(dev_priv
, true);
1434 static void cherryview_update_wm(struct drm_crtc
*crtc
)
1436 struct drm_device
*dev
= crtc
->dev
;
1437 static const int sr_latency_ns
= 12000;
1438 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1439 int planea_wm
, planeb_wm
, planec_wm
;
1440 int cursora_wm
, cursorb_wm
, cursorc_wm
;
1441 int plane_sr
, cursor_sr
;
1442 int ignore_plane_sr
, ignore_cursor_sr
;
1443 unsigned int enabled
= 0;
1446 vlv_update_drain_latency(crtc
);
1448 if (g4x_compute_wm0(dev
, PIPE_A
,
1449 &valleyview_wm_info
, latency_ns
,
1450 &valleyview_cursor_wm_info
, latency_ns
,
1451 &planea_wm
, &cursora_wm
))
1452 enabled
|= 1 << PIPE_A
;
1454 if (g4x_compute_wm0(dev
, PIPE_B
,
1455 &valleyview_wm_info
, latency_ns
,
1456 &valleyview_cursor_wm_info
, latency_ns
,
1457 &planeb_wm
, &cursorb_wm
))
1458 enabled
|= 1 << PIPE_B
;
1460 if (g4x_compute_wm0(dev
, PIPE_C
,
1461 &valleyview_wm_info
, latency_ns
,
1462 &valleyview_cursor_wm_info
, latency_ns
,
1463 &planec_wm
, &cursorc_wm
))
1464 enabled
|= 1 << PIPE_C
;
1466 if (single_plane_enabled(enabled
) &&
1467 g4x_compute_srwm(dev
, ffs(enabled
) - 1,
1469 &valleyview_wm_info
,
1470 &valleyview_cursor_wm_info
,
1471 &plane_sr
, &ignore_cursor_sr
) &&
1472 g4x_compute_srwm(dev
, ffs(enabled
) - 1,
1474 &valleyview_wm_info
,
1475 &valleyview_cursor_wm_info
,
1476 &ignore_plane_sr
, &cursor_sr
)) {
1477 cxsr_enabled
= true;
1479 cxsr_enabled
= false;
1480 intel_set_memory_cxsr(dev_priv
, false);
1481 plane_sr
= cursor_sr
= 0;
1484 DRM_DEBUG_KMS("Setting FIFO watermarks - A: plane=%d, cursor=%d, "
1485 "B: plane=%d, cursor=%d, C: plane=%d, cursor=%d, "
1486 "SR: plane=%d, cursor=%d\n",
1487 planea_wm
, cursora_wm
,
1488 planeb_wm
, cursorb_wm
,
1489 planec_wm
, cursorc_wm
,
1490 plane_sr
, cursor_sr
);
1493 (plane_sr
<< DSPFW_SR_SHIFT
) |
1494 (cursorb_wm
<< DSPFW_CURSORB_SHIFT
) |
1495 (planeb_wm
<< DSPFW_PLANEB_SHIFT
) |
1496 (planea_wm
<< DSPFW_PLANEA_SHIFT
));
1498 (I915_READ(DSPFW2
) & ~DSPFW_CURSORA_MASK
) |
1499 (cursora_wm
<< DSPFW_CURSORA_SHIFT
));
1501 (I915_READ(DSPFW3
) & ~DSPFW_CURSOR_SR_MASK
) |
1502 (cursor_sr
<< DSPFW_CURSOR_SR_SHIFT
));
1503 I915_WRITE(DSPFW9_CHV
,
1504 (I915_READ(DSPFW9_CHV
) & ~(DSPFW_PLANEC_MASK
|
1505 DSPFW_CURSORC_MASK
)) |
1506 (planec_wm
<< DSPFW_PLANEC_SHIFT
) |
1507 (cursorc_wm
<< DSPFW_CURSORC_SHIFT
));
1510 intel_set_memory_cxsr(dev_priv
, true);
1513 static void valleyview_update_sprite_wm(struct drm_plane
*plane
,
1514 struct drm_crtc
*crtc
,
1515 uint32_t sprite_width
,
1516 uint32_t sprite_height
,
1518 bool enabled
, bool scaled
)
1520 struct drm_device
*dev
= crtc
->dev
;
1521 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1522 int pipe
= to_intel_plane(plane
)->pipe
;
1523 int sprite
= to_intel_plane(plane
)->plane
;
1529 sprite_dl
= I915_READ(VLV_DDL(pipe
)) & ~(DDL_SPRITE_PRECISION_64(sprite
) |
1530 (DRAIN_LATENCY_MASK
<< DDL_SPRITE_SHIFT(sprite
)));
1532 if (enabled
&& vlv_compute_drain_latency(crtc
, pixel_size
, &prec_mult
,
1534 plane_prec
= (prec_mult
== DRAIN_LATENCY_PRECISION_64
) ?
1535 DDL_SPRITE_PRECISION_64(sprite
) :
1536 DDL_SPRITE_PRECISION_32(sprite
);
1537 sprite_dl
|= plane_prec
|
1538 (drain_latency
<< DDL_SPRITE_SHIFT(sprite
));
1541 I915_WRITE(VLV_DDL(pipe
), sprite_dl
);
1544 static void g4x_update_wm(struct drm_crtc
*crtc
)
1546 struct drm_device
*dev
= crtc
->dev
;
1547 static const int sr_latency_ns
= 12000;
1548 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1549 int planea_wm
, planeb_wm
, cursora_wm
, cursorb_wm
;
1550 int plane_sr
, cursor_sr
;
1551 unsigned int enabled
= 0;
1554 if (g4x_compute_wm0(dev
, PIPE_A
,
1555 &g4x_wm_info
, latency_ns
,
1556 &g4x_cursor_wm_info
, latency_ns
,
1557 &planea_wm
, &cursora_wm
))
1558 enabled
|= 1 << PIPE_A
;
1560 if (g4x_compute_wm0(dev
, PIPE_B
,
1561 &g4x_wm_info
, latency_ns
,
1562 &g4x_cursor_wm_info
, latency_ns
,
1563 &planeb_wm
, &cursorb_wm
))
1564 enabled
|= 1 << PIPE_B
;
1566 if (single_plane_enabled(enabled
) &&
1567 g4x_compute_srwm(dev
, ffs(enabled
) - 1,
1570 &g4x_cursor_wm_info
,
1571 &plane_sr
, &cursor_sr
)) {
1572 cxsr_enabled
= true;
1574 cxsr_enabled
= false;
1575 intel_set_memory_cxsr(dev_priv
, false);
1576 plane_sr
= cursor_sr
= 0;
1579 DRM_DEBUG_KMS("Setting FIFO watermarks - A: plane=%d, cursor=%d, "
1580 "B: plane=%d, cursor=%d, SR: plane=%d, cursor=%d\n",
1581 planea_wm
, cursora_wm
,
1582 planeb_wm
, cursorb_wm
,
1583 plane_sr
, cursor_sr
);
1586 (plane_sr
<< DSPFW_SR_SHIFT
) |
1587 (cursorb_wm
<< DSPFW_CURSORB_SHIFT
) |
1588 (planeb_wm
<< DSPFW_PLANEB_SHIFT
) |
1589 (planea_wm
<< DSPFW_PLANEA_SHIFT
));
1591 (I915_READ(DSPFW2
) & ~DSPFW_CURSORA_MASK
) |
1592 (cursora_wm
<< DSPFW_CURSORA_SHIFT
));
1593 /* HPLL off in SR has some issues on G4x... disable it */
1595 (I915_READ(DSPFW3
) & ~(DSPFW_HPLL_SR_EN
| DSPFW_CURSOR_SR_MASK
)) |
1596 (cursor_sr
<< DSPFW_CURSOR_SR_SHIFT
));
1599 intel_set_memory_cxsr(dev_priv
, true);
1602 static void i965_update_wm(struct drm_crtc
*unused_crtc
)
1604 struct drm_device
*dev
= unused_crtc
->dev
;
1605 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1606 struct drm_crtc
*crtc
;
1611 /* Calc sr entries for one plane configs */
1612 crtc
= single_enabled_crtc(dev
);
1614 /* self-refresh has much higher latency */
1615 static const int sr_latency_ns
= 12000;
1616 const struct drm_display_mode
*adjusted_mode
=
1617 &to_intel_crtc(crtc
)->config
.adjusted_mode
;
1618 int clock
= adjusted_mode
->crtc_clock
;
1619 int htotal
= adjusted_mode
->crtc_htotal
;
1620 int hdisplay
= to_intel_crtc(crtc
)->config
.pipe_src_w
;
1621 int pixel_size
= crtc
->primary
->fb
->bits_per_pixel
/ 8;
1622 unsigned long line_time_us
;
1625 line_time_us
= max(htotal
* 1000 / clock
, 1);
1627 /* Use ns/us then divide to preserve precision */
1628 entries
= (((sr_latency_ns
/ line_time_us
) + 1000) / 1000) *
1629 pixel_size
* hdisplay
;
1630 entries
= DIV_ROUND_UP(entries
, I915_FIFO_LINE_SIZE
);
1631 srwm
= I965_FIFO_SIZE
- entries
;
1635 DRM_DEBUG_KMS("self-refresh entries: %d, wm: %d\n",
1638 entries
= (((sr_latency_ns
/ line_time_us
) + 1000) / 1000) *
1639 pixel_size
* to_intel_crtc(crtc
)->cursor_width
;
1640 entries
= DIV_ROUND_UP(entries
,
1641 i965_cursor_wm_info
.cacheline_size
);
1642 cursor_sr
= i965_cursor_wm_info
.fifo_size
-
1643 (entries
+ i965_cursor_wm_info
.guard_size
);
1645 if (cursor_sr
> i965_cursor_wm_info
.max_wm
)
1646 cursor_sr
= i965_cursor_wm_info
.max_wm
;
1648 DRM_DEBUG_KMS("self-refresh watermark: display plane %d "
1649 "cursor %d\n", srwm
, cursor_sr
);
1651 cxsr_enabled
= true;
1653 cxsr_enabled
= false;
1654 /* Turn off self refresh if both pipes are enabled */
1655 intel_set_memory_cxsr(dev_priv
, false);
1658 DRM_DEBUG_KMS("Setting FIFO watermarks - A: 8, B: 8, C: 8, SR %d\n",
1661 /* 965 has limitations... */
1662 I915_WRITE(DSPFW1
, (srwm
<< DSPFW_SR_SHIFT
) |
1663 (8 << DSPFW_CURSORB_SHIFT
) |
1664 (8 << DSPFW_PLANEB_SHIFT
) |
1665 (8 << DSPFW_PLANEA_SHIFT
));
1666 I915_WRITE(DSPFW2
, (8 << DSPFW_CURSORA_SHIFT
) |
1667 (8 << DSPFW_PLANEC_SHIFT_OLD
));
1668 /* update cursor SR watermark */
1669 I915_WRITE(DSPFW3
, (cursor_sr
<< DSPFW_CURSOR_SR_SHIFT
));
1672 intel_set_memory_cxsr(dev_priv
, true);
1675 static void i9xx_update_wm(struct drm_crtc
*unused_crtc
)
1677 struct drm_device
*dev
= unused_crtc
->dev
;
1678 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1679 const struct intel_watermark_params
*wm_info
;
1684 int planea_wm
, planeb_wm
;
1685 struct drm_crtc
*crtc
, *enabled
= NULL
;
1688 wm_info
= &i945_wm_info
;
1689 else if (!IS_GEN2(dev
))
1690 wm_info
= &i915_wm_info
;
1692 wm_info
= &i830_wm_info
;
1694 fifo_size
= dev_priv
->display
.get_fifo_size(dev
, 0);
1695 crtc
= intel_get_crtc_for_plane(dev
, 0);
1696 if (intel_crtc_active(crtc
)) {
1697 const struct drm_display_mode
*adjusted_mode
;
1698 int cpp
= crtc
->primary
->fb
->bits_per_pixel
/ 8;
1702 adjusted_mode
= &to_intel_crtc(crtc
)->config
.adjusted_mode
;
1703 planea_wm
= intel_calculate_wm(adjusted_mode
->crtc_clock
,
1704 wm_info
, fifo_size
, cpp
,
1708 planea_wm
= fifo_size
- wm_info
->guard_size
;
1710 fifo_size
= dev_priv
->display
.get_fifo_size(dev
, 1);
1711 crtc
= intel_get_crtc_for_plane(dev
, 1);
1712 if (intel_crtc_active(crtc
)) {
1713 const struct drm_display_mode
*adjusted_mode
;
1714 int cpp
= crtc
->primary
->fb
->bits_per_pixel
/ 8;
1718 adjusted_mode
= &to_intel_crtc(crtc
)->config
.adjusted_mode
;
1719 planeb_wm
= intel_calculate_wm(adjusted_mode
->crtc_clock
,
1720 wm_info
, fifo_size
, cpp
,
1722 if (enabled
== NULL
)
1727 planeb_wm
= fifo_size
- wm_info
->guard_size
;
1729 DRM_DEBUG_KMS("FIFO watermarks - A: %d, B: %d\n", planea_wm
, planeb_wm
);
1731 if (IS_I915GM(dev
) && enabled
) {
1732 struct drm_i915_gem_object
*obj
;
1734 obj
= intel_fb_obj(enabled
->primary
->fb
);
1736 /* self-refresh seems busted with untiled */
1737 if (obj
->tiling_mode
== I915_TILING_NONE
)
1742 * Overlay gets an aggressive default since video jitter is bad.
1746 /* Play safe and disable self-refresh before adjusting watermarks. */
1747 intel_set_memory_cxsr(dev_priv
, false);
1749 /* Calc sr entries for one plane configs */
1750 if (HAS_FW_BLC(dev
) && enabled
) {
1751 /* self-refresh has much higher latency */
1752 static const int sr_latency_ns
= 6000;
1753 const struct drm_display_mode
*adjusted_mode
=
1754 &to_intel_crtc(enabled
)->config
.adjusted_mode
;
1755 int clock
= adjusted_mode
->crtc_clock
;
1756 int htotal
= adjusted_mode
->crtc_htotal
;
1757 int hdisplay
= to_intel_crtc(enabled
)->config
.pipe_src_w
;
1758 int pixel_size
= enabled
->primary
->fb
->bits_per_pixel
/ 8;
1759 unsigned long line_time_us
;
1762 line_time_us
= max(htotal
* 1000 / clock
, 1);
1764 /* Use ns/us then divide to preserve precision */
1765 entries
= (((sr_latency_ns
/ line_time_us
) + 1000) / 1000) *
1766 pixel_size
* hdisplay
;
1767 entries
= DIV_ROUND_UP(entries
, wm_info
->cacheline_size
);
1768 DRM_DEBUG_KMS("self-refresh entries: %d\n", entries
);
1769 srwm
= wm_info
->fifo_size
- entries
;
1773 if (IS_I945G(dev
) || IS_I945GM(dev
))
1774 I915_WRITE(FW_BLC_SELF
,
1775 FW_BLC_SELF_FIFO_MASK
| (srwm
& 0xff));
1776 else if (IS_I915GM(dev
))
1777 I915_WRITE(FW_BLC_SELF
, srwm
& 0x3f);
1780 DRM_DEBUG_KMS("Setting FIFO watermarks - A: %d, B: %d, C: %d, SR %d\n",
1781 planea_wm
, planeb_wm
, cwm
, srwm
);
1783 fwater_lo
= ((planeb_wm
& 0x3f) << 16) | (planea_wm
& 0x3f);
1784 fwater_hi
= (cwm
& 0x1f);
1786 /* Set request length to 8 cachelines per fetch */
1787 fwater_lo
= fwater_lo
| (1 << 24) | (1 << 8);
1788 fwater_hi
= fwater_hi
| (1 << 8);
1790 I915_WRITE(FW_BLC
, fwater_lo
);
1791 I915_WRITE(FW_BLC2
, fwater_hi
);
1794 intel_set_memory_cxsr(dev_priv
, true);
1797 static void i845_update_wm(struct drm_crtc
*unused_crtc
)
1799 struct drm_device
*dev
= unused_crtc
->dev
;
1800 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
1801 struct drm_crtc
*crtc
;
1802 const struct drm_display_mode
*adjusted_mode
;
1806 crtc
= single_enabled_crtc(dev
);
1810 adjusted_mode
= &to_intel_crtc(crtc
)->config
.adjusted_mode
;
1811 planea_wm
= intel_calculate_wm(adjusted_mode
->crtc_clock
,
1813 dev_priv
->display
.get_fifo_size(dev
, 0),
1815 fwater_lo
= I915_READ(FW_BLC
) & ~0xfff;
1816 fwater_lo
|= (3<<8) | planea_wm
;
1818 DRM_DEBUG_KMS("Setting FIFO watermarks - A: %d\n", planea_wm
);
1820 I915_WRITE(FW_BLC
, fwater_lo
);
1823 static uint32_t ilk_pipe_pixel_rate(struct drm_device
*dev
,
1824 struct drm_crtc
*crtc
)
1826 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
1827 uint32_t pixel_rate
;
1829 pixel_rate
= intel_crtc
->config
.adjusted_mode
.crtc_clock
;
1831 /* We only use IF-ID interlacing. If we ever use PF-ID we'll need to
1832 * adjust the pixel_rate here. */
1834 if (intel_crtc
->config
.pch_pfit
.enabled
) {
1835 uint64_t pipe_w
, pipe_h
, pfit_w
, pfit_h
;
1836 uint32_t pfit_size
= intel_crtc
->config
.pch_pfit
.size
;
1838 pipe_w
= intel_crtc
->config
.pipe_src_w
;
1839 pipe_h
= intel_crtc
->config
.pipe_src_h
;
1840 pfit_w
= (pfit_size
>> 16) & 0xFFFF;
1841 pfit_h
= pfit_size
& 0xFFFF;
1842 if (pipe_w
< pfit_w
)
1844 if (pipe_h
< pfit_h
)
1847 pixel_rate
= div_u64((uint64_t) pixel_rate
* pipe_w
* pipe_h
,
1854 /* latency must be in 0.1us units. */
1855 static uint32_t ilk_wm_method1(uint32_t pixel_rate
, uint8_t bytes_per_pixel
,
1860 if (WARN(latency
== 0, "Latency value missing\n"))
1863 ret
= (uint64_t) pixel_rate
* bytes_per_pixel
* latency
;
1864 ret
= DIV_ROUND_UP_ULL(ret
, 64 * 10000) + 2;
1869 /* latency must be in 0.1us units. */
1870 static uint32_t ilk_wm_method2(uint32_t pixel_rate
, uint32_t pipe_htotal
,
1871 uint32_t horiz_pixels
, uint8_t bytes_per_pixel
,
1876 if (WARN(latency
== 0, "Latency value missing\n"))
1879 ret
= (latency
* pixel_rate
) / (pipe_htotal
* 10000);
1880 ret
= (ret
+ 1) * horiz_pixels
* bytes_per_pixel
;
1881 ret
= DIV_ROUND_UP(ret
, 64) + 2;
1885 static uint32_t ilk_wm_fbc(uint32_t pri_val
, uint32_t horiz_pixels
,
1886 uint8_t bytes_per_pixel
)
1888 return DIV_ROUND_UP(pri_val
* 64, horiz_pixels
* bytes_per_pixel
) + 2;
1891 struct ilk_pipe_wm_parameters
{
1893 uint32_t pipe_htotal
;
1894 uint32_t pixel_rate
;
1895 struct intel_plane_wm_parameters pri
;
1896 struct intel_plane_wm_parameters spr
;
1897 struct intel_plane_wm_parameters cur
;
1900 struct ilk_wm_maximums
{
1907 /* used in computing the new watermarks state */
1908 struct intel_wm_config
{
1909 unsigned int num_pipes_active
;
1910 bool sprites_enabled
;
1911 bool sprites_scaled
;
1915 * For both WM_PIPE and WM_LP.
1916 * mem_value must be in 0.1us units.
1918 static uint32_t ilk_compute_pri_wm(const struct ilk_pipe_wm_parameters
*params
,
1922 uint32_t method1
, method2
;
1924 if (!params
->active
|| !params
->pri
.enabled
)
1927 method1
= ilk_wm_method1(params
->pixel_rate
,
1928 params
->pri
.bytes_per_pixel
,
1934 method2
= ilk_wm_method2(params
->pixel_rate
,
1935 params
->pipe_htotal
,
1936 params
->pri
.horiz_pixels
,
1937 params
->pri
.bytes_per_pixel
,
1940 return min(method1
, method2
);
1944 * For both WM_PIPE and WM_LP.
1945 * mem_value must be in 0.1us units.
1947 static uint32_t ilk_compute_spr_wm(const struct ilk_pipe_wm_parameters
*params
,
1950 uint32_t method1
, method2
;
1952 if (!params
->active
|| !params
->spr
.enabled
)
1955 method1
= ilk_wm_method1(params
->pixel_rate
,
1956 params
->spr
.bytes_per_pixel
,
1958 method2
= ilk_wm_method2(params
->pixel_rate
,
1959 params
->pipe_htotal
,
1960 params
->spr
.horiz_pixels
,
1961 params
->spr
.bytes_per_pixel
,
1963 return min(method1
, method2
);
1967 * For both WM_PIPE and WM_LP.
1968 * mem_value must be in 0.1us units.
1970 static uint32_t ilk_compute_cur_wm(const struct ilk_pipe_wm_parameters
*params
,
1973 if (!params
->active
|| !params
->cur
.enabled
)
1976 return ilk_wm_method2(params
->pixel_rate
,
1977 params
->pipe_htotal
,
1978 params
->cur
.horiz_pixels
,
1979 params
->cur
.bytes_per_pixel
,
1983 /* Only for WM_LP. */
1984 static uint32_t ilk_compute_fbc_wm(const struct ilk_pipe_wm_parameters
*params
,
1987 if (!params
->active
|| !params
->pri
.enabled
)
1990 return ilk_wm_fbc(pri_val
,
1991 params
->pri
.horiz_pixels
,
1992 params
->pri
.bytes_per_pixel
);
1995 static unsigned int ilk_display_fifo_size(const struct drm_device
*dev
)
1997 if (INTEL_INFO(dev
)->gen
>= 8)
1999 else if (INTEL_INFO(dev
)->gen
>= 7)
2005 static unsigned int ilk_plane_wm_reg_max(const struct drm_device
*dev
,
2006 int level
, bool is_sprite
)
2008 if (INTEL_INFO(dev
)->gen
>= 8)
2009 /* BDW primary/sprite plane watermarks */
2010 return level
== 0 ? 255 : 2047;
2011 else if (INTEL_INFO(dev
)->gen
>= 7)
2012 /* IVB/HSW primary/sprite plane watermarks */
2013 return level
== 0 ? 127 : 1023;
2014 else if (!is_sprite
)
2015 /* ILK/SNB primary plane watermarks */
2016 return level
== 0 ? 127 : 511;
2018 /* ILK/SNB sprite plane watermarks */
2019 return level
== 0 ? 63 : 255;
2022 static unsigned int ilk_cursor_wm_reg_max(const struct drm_device
*dev
,
2025 if (INTEL_INFO(dev
)->gen
>= 7)
2026 return level
== 0 ? 63 : 255;
2028 return level
== 0 ? 31 : 63;
2031 static unsigned int ilk_fbc_wm_reg_max(const struct drm_device
*dev
)
2033 if (INTEL_INFO(dev
)->gen
>= 8)
2039 /* Calculate the maximum primary/sprite plane watermark */
2040 static unsigned int ilk_plane_wm_max(const struct drm_device
*dev
,
2042 const struct intel_wm_config
*config
,
2043 enum intel_ddb_partitioning ddb_partitioning
,
2046 unsigned int fifo_size
= ilk_display_fifo_size(dev
);
2048 /* if sprites aren't enabled, sprites get nothing */
2049 if (is_sprite
&& !config
->sprites_enabled
)
2052 /* HSW allows LP1+ watermarks even with multiple pipes */
2053 if (level
== 0 || config
->num_pipes_active
> 1) {
2054 fifo_size
/= INTEL_INFO(dev
)->num_pipes
;
2057 * For some reason the non self refresh
2058 * FIFO size is only half of the self
2059 * refresh FIFO size on ILK/SNB.
2061 if (INTEL_INFO(dev
)->gen
<= 6)
2065 if (config
->sprites_enabled
) {
2066 /* level 0 is always calculated with 1:1 split */
2067 if (level
> 0 && ddb_partitioning
== INTEL_DDB_PART_5_6
) {
2076 /* clamp to max that the registers can hold */
2077 return min(fifo_size
, ilk_plane_wm_reg_max(dev
, level
, is_sprite
));
2080 /* Calculate the maximum cursor plane watermark */
2081 static unsigned int ilk_cursor_wm_max(const struct drm_device
*dev
,
2083 const struct intel_wm_config
*config
)
2085 /* HSW LP1+ watermarks w/ multiple pipes */
2086 if (level
> 0 && config
->num_pipes_active
> 1)
2089 /* otherwise just report max that registers can hold */
2090 return ilk_cursor_wm_reg_max(dev
, level
);
2093 static void ilk_compute_wm_maximums(const struct drm_device
*dev
,
2095 const struct intel_wm_config
*config
,
2096 enum intel_ddb_partitioning ddb_partitioning
,
2097 struct ilk_wm_maximums
*max
)
2099 max
->pri
= ilk_plane_wm_max(dev
, level
, config
, ddb_partitioning
, false);
2100 max
->spr
= ilk_plane_wm_max(dev
, level
, config
, ddb_partitioning
, true);
2101 max
->cur
= ilk_cursor_wm_max(dev
, level
, config
);
2102 max
->fbc
= ilk_fbc_wm_reg_max(dev
);
2105 static void ilk_compute_wm_reg_maximums(struct drm_device
*dev
,
2107 struct ilk_wm_maximums
*max
)
2109 max
->pri
= ilk_plane_wm_reg_max(dev
, level
, false);
2110 max
->spr
= ilk_plane_wm_reg_max(dev
, level
, true);
2111 max
->cur
= ilk_cursor_wm_reg_max(dev
, level
);
2112 max
->fbc
= ilk_fbc_wm_reg_max(dev
);
2115 static bool ilk_validate_wm_level(int level
,
2116 const struct ilk_wm_maximums
*max
,
2117 struct intel_wm_level
*result
)
2121 /* already determined to be invalid? */
2122 if (!result
->enable
)
2125 result
->enable
= result
->pri_val
<= max
->pri
&&
2126 result
->spr_val
<= max
->spr
&&
2127 result
->cur_val
<= max
->cur
;
2129 ret
= result
->enable
;
2132 * HACK until we can pre-compute everything,
2133 * and thus fail gracefully if LP0 watermarks
2136 if (level
== 0 && !result
->enable
) {
2137 if (result
->pri_val
> max
->pri
)
2138 DRM_DEBUG_KMS("Primary WM%d too large %u (max %u)\n",
2139 level
, result
->pri_val
, max
->pri
);
2140 if (result
->spr_val
> max
->spr
)
2141 DRM_DEBUG_KMS("Sprite WM%d too large %u (max %u)\n",
2142 level
, result
->spr_val
, max
->spr
);
2143 if (result
->cur_val
> max
->cur
)
2144 DRM_DEBUG_KMS("Cursor WM%d too large %u (max %u)\n",
2145 level
, result
->cur_val
, max
->cur
);
2147 result
->pri_val
= min_t(uint32_t, result
->pri_val
, max
->pri
);
2148 result
->spr_val
= min_t(uint32_t, result
->spr_val
, max
->spr
);
2149 result
->cur_val
= min_t(uint32_t, result
->cur_val
, max
->cur
);
2150 result
->enable
= true;
2156 static void ilk_compute_wm_level(const struct drm_i915_private
*dev_priv
,
2158 const struct ilk_pipe_wm_parameters
*p
,
2159 struct intel_wm_level
*result
)
2161 uint16_t pri_latency
= dev_priv
->wm
.pri_latency
[level
];
2162 uint16_t spr_latency
= dev_priv
->wm
.spr_latency
[level
];
2163 uint16_t cur_latency
= dev_priv
->wm
.cur_latency
[level
];
2165 /* WM1+ latency values stored in 0.5us units */
2172 result
->pri_val
= ilk_compute_pri_wm(p
, pri_latency
, level
);
2173 result
->spr_val
= ilk_compute_spr_wm(p
, spr_latency
);
2174 result
->cur_val
= ilk_compute_cur_wm(p
, cur_latency
);
2175 result
->fbc_val
= ilk_compute_fbc_wm(p
, result
->pri_val
);
2176 result
->enable
= true;
2180 hsw_compute_linetime_wm(struct drm_device
*dev
, struct drm_crtc
*crtc
)
2182 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2183 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2184 struct drm_display_mode
*mode
= &intel_crtc
->config
.adjusted_mode
;
2185 u32 linetime
, ips_linetime
;
2187 if (!intel_crtc_active(crtc
))
2190 /* The WM are computed with base on how long it takes to fill a single
2191 * row at the given clock rate, multiplied by 8.
2193 linetime
= DIV_ROUND_CLOSEST(mode
->crtc_htotal
* 1000 * 8,
2195 ips_linetime
= DIV_ROUND_CLOSEST(mode
->crtc_htotal
* 1000 * 8,
2196 intel_ddi_get_cdclk_freq(dev_priv
));
2198 return PIPE_WM_LINETIME_IPS_LINETIME(ips_linetime
) |
2199 PIPE_WM_LINETIME_TIME(linetime
);
2202 static void intel_read_wm_latency(struct drm_device
*dev
, uint16_t wm
[5])
2204 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2206 if (IS_HASWELL(dev
) || IS_BROADWELL(dev
)) {
2207 uint64_t sskpd
= I915_READ64(MCH_SSKPD
);
2209 wm
[0] = (sskpd
>> 56) & 0xFF;
2211 wm
[0] = sskpd
& 0xF;
2212 wm
[1] = (sskpd
>> 4) & 0xFF;
2213 wm
[2] = (sskpd
>> 12) & 0xFF;
2214 wm
[3] = (sskpd
>> 20) & 0x1FF;
2215 wm
[4] = (sskpd
>> 32) & 0x1FF;
2216 } else if (INTEL_INFO(dev
)->gen
>= 6) {
2217 uint32_t sskpd
= I915_READ(MCH_SSKPD
);
2219 wm
[0] = (sskpd
>> SSKPD_WM0_SHIFT
) & SSKPD_WM_MASK
;
2220 wm
[1] = (sskpd
>> SSKPD_WM1_SHIFT
) & SSKPD_WM_MASK
;
2221 wm
[2] = (sskpd
>> SSKPD_WM2_SHIFT
) & SSKPD_WM_MASK
;
2222 wm
[3] = (sskpd
>> SSKPD_WM3_SHIFT
) & SSKPD_WM_MASK
;
2223 } else if (INTEL_INFO(dev
)->gen
>= 5) {
2224 uint32_t mltr
= I915_READ(MLTR_ILK
);
2226 /* ILK primary LP0 latency is 700 ns */
2228 wm
[1] = (mltr
>> MLTR_WM1_SHIFT
) & ILK_SRLT_MASK
;
2229 wm
[2] = (mltr
>> MLTR_WM2_SHIFT
) & ILK_SRLT_MASK
;
2233 static void intel_fixup_spr_wm_latency(struct drm_device
*dev
, uint16_t wm
[5])
2235 /* ILK sprite LP0 latency is 1300 ns */
2236 if (INTEL_INFO(dev
)->gen
== 5)
2240 static void intel_fixup_cur_wm_latency(struct drm_device
*dev
, uint16_t wm
[5])
2242 /* ILK cursor LP0 latency is 1300 ns */
2243 if (INTEL_INFO(dev
)->gen
== 5)
2246 /* WaDoubleCursorLP3Latency:ivb */
2247 if (IS_IVYBRIDGE(dev
))
2251 int ilk_wm_max_level(const struct drm_device
*dev
)
2253 /* how many WM levels are we expecting */
2254 if (IS_HASWELL(dev
) || IS_BROADWELL(dev
))
2256 else if (INTEL_INFO(dev
)->gen
>= 6)
2262 static void intel_print_wm_latency(struct drm_device
*dev
,
2264 const uint16_t wm
[5])
2266 int level
, max_level
= ilk_wm_max_level(dev
);
2268 for (level
= 0; level
<= max_level
; level
++) {
2269 unsigned int latency
= wm
[level
];
2272 DRM_ERROR("%s WM%d latency not provided\n",
2277 /* WM1+ latency values in 0.5us units */
2281 DRM_DEBUG_KMS("%s WM%d latency %u (%u.%u usec)\n",
2282 name
, level
, wm
[level
],
2283 latency
/ 10, latency
% 10);
2287 static bool ilk_increase_wm_latency(struct drm_i915_private
*dev_priv
,
2288 uint16_t wm
[5], uint16_t min
)
2290 int level
, max_level
= ilk_wm_max_level(dev_priv
->dev
);
2295 wm
[0] = max(wm
[0], min
);
2296 for (level
= 1; level
<= max_level
; level
++)
2297 wm
[level
] = max_t(uint16_t, wm
[level
], DIV_ROUND_UP(min
, 5));
2302 static void snb_wm_latency_quirk(struct drm_device
*dev
)
2304 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2308 * The BIOS provided WM memory latency values are often
2309 * inadequate for high resolution displays. Adjust them.
2311 changed
= ilk_increase_wm_latency(dev_priv
, dev_priv
->wm
.pri_latency
, 12) |
2312 ilk_increase_wm_latency(dev_priv
, dev_priv
->wm
.spr_latency
, 12) |
2313 ilk_increase_wm_latency(dev_priv
, dev_priv
->wm
.cur_latency
, 12);
2318 DRM_DEBUG_KMS("WM latency values increased to avoid potential underruns\n");
2319 intel_print_wm_latency(dev
, "Primary", dev_priv
->wm
.pri_latency
);
2320 intel_print_wm_latency(dev
, "Sprite", dev_priv
->wm
.spr_latency
);
2321 intel_print_wm_latency(dev
, "Cursor", dev_priv
->wm
.cur_latency
);
2324 static void ilk_setup_wm_latency(struct drm_device
*dev
)
2326 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2328 intel_read_wm_latency(dev
, dev_priv
->wm
.pri_latency
);
2330 memcpy(dev_priv
->wm
.spr_latency
, dev_priv
->wm
.pri_latency
,
2331 sizeof(dev_priv
->wm
.pri_latency
));
2332 memcpy(dev_priv
->wm
.cur_latency
, dev_priv
->wm
.pri_latency
,
2333 sizeof(dev_priv
->wm
.pri_latency
));
2335 intel_fixup_spr_wm_latency(dev
, dev_priv
->wm
.spr_latency
);
2336 intel_fixup_cur_wm_latency(dev
, dev_priv
->wm
.cur_latency
);
2338 intel_print_wm_latency(dev
, "Primary", dev_priv
->wm
.pri_latency
);
2339 intel_print_wm_latency(dev
, "Sprite", dev_priv
->wm
.spr_latency
);
2340 intel_print_wm_latency(dev
, "Cursor", dev_priv
->wm
.cur_latency
);
2343 snb_wm_latency_quirk(dev
);
2346 static void ilk_compute_wm_parameters(struct drm_crtc
*crtc
,
2347 struct ilk_pipe_wm_parameters
*p
)
2349 struct drm_device
*dev
= crtc
->dev
;
2350 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2351 enum pipe pipe
= intel_crtc
->pipe
;
2352 struct drm_plane
*plane
;
2354 if (!intel_crtc_active(crtc
))
2358 p
->pipe_htotal
= intel_crtc
->config
.adjusted_mode
.crtc_htotal
;
2359 p
->pixel_rate
= ilk_pipe_pixel_rate(dev
, crtc
);
2360 p
->pri
.bytes_per_pixel
= crtc
->primary
->fb
->bits_per_pixel
/ 8;
2361 p
->cur
.bytes_per_pixel
= 4;
2362 p
->pri
.horiz_pixels
= intel_crtc
->config
.pipe_src_w
;
2363 p
->cur
.horiz_pixels
= intel_crtc
->cursor_width
;
2364 /* TODO: for now, assume primary and cursor planes are always enabled. */
2365 p
->pri
.enabled
= true;
2366 p
->cur
.enabled
= true;
2368 drm_for_each_legacy_plane(plane
, &dev
->mode_config
.plane_list
) {
2369 struct intel_plane
*intel_plane
= to_intel_plane(plane
);
2371 if (intel_plane
->pipe
== pipe
) {
2372 p
->spr
= intel_plane
->wm
;
2378 static void ilk_compute_wm_config(struct drm_device
*dev
,
2379 struct intel_wm_config
*config
)
2381 struct intel_crtc
*intel_crtc
;
2383 /* Compute the currently _active_ config */
2384 for_each_intel_crtc(dev
, intel_crtc
) {
2385 const struct intel_pipe_wm
*wm
= &intel_crtc
->wm
.active
;
2387 if (!wm
->pipe_enabled
)
2390 config
->sprites_enabled
|= wm
->sprites_enabled
;
2391 config
->sprites_scaled
|= wm
->sprites_scaled
;
2392 config
->num_pipes_active
++;
2396 /* Compute new watermarks for the pipe */
2397 static bool intel_compute_pipe_wm(struct drm_crtc
*crtc
,
2398 const struct ilk_pipe_wm_parameters
*params
,
2399 struct intel_pipe_wm
*pipe_wm
)
2401 struct drm_device
*dev
= crtc
->dev
;
2402 const struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2403 int level
, max_level
= ilk_wm_max_level(dev
);
2404 /* LP0 watermark maximums depend on this pipe alone */
2405 struct intel_wm_config config
= {
2406 .num_pipes_active
= 1,
2407 .sprites_enabled
= params
->spr
.enabled
,
2408 .sprites_scaled
= params
->spr
.scaled
,
2410 struct ilk_wm_maximums max
;
2412 pipe_wm
->pipe_enabled
= params
->active
;
2413 pipe_wm
->sprites_enabled
= params
->spr
.enabled
;
2414 pipe_wm
->sprites_scaled
= params
->spr
.scaled
;
2416 /* ILK/SNB: LP2+ watermarks only w/o sprites */
2417 if (INTEL_INFO(dev
)->gen
<= 6 && params
->spr
.enabled
)
2420 /* ILK/SNB/IVB: LP1+ watermarks only w/o scaling */
2421 if (params
->spr
.scaled
)
2424 ilk_compute_wm_level(dev_priv
, 0, params
, &pipe_wm
->wm
[0]);
2426 if (IS_HASWELL(dev
) || IS_BROADWELL(dev
))
2427 pipe_wm
->linetime
= hsw_compute_linetime_wm(dev
, crtc
);
2429 /* LP0 watermarks always use 1/2 DDB partitioning */
2430 ilk_compute_wm_maximums(dev
, 0, &config
, INTEL_DDB_PART_1_2
, &max
);
2432 /* At least LP0 must be valid */
2433 if (!ilk_validate_wm_level(0, &max
, &pipe_wm
->wm
[0]))
2436 ilk_compute_wm_reg_maximums(dev
, 1, &max
);
2438 for (level
= 1; level
<= max_level
; level
++) {
2439 struct intel_wm_level wm
= {};
2441 ilk_compute_wm_level(dev_priv
, level
, params
, &wm
);
2444 * Disable any watermark level that exceeds the
2445 * register maximums since such watermarks are
2448 if (!ilk_validate_wm_level(level
, &max
, &wm
))
2451 pipe_wm
->wm
[level
] = wm
;
2458 * Merge the watermarks from all active pipes for a specific level.
2460 static void ilk_merge_wm_level(struct drm_device
*dev
,
2462 struct intel_wm_level
*ret_wm
)
2464 const struct intel_crtc
*intel_crtc
;
2466 ret_wm
->enable
= true;
2468 for_each_intel_crtc(dev
, intel_crtc
) {
2469 const struct intel_pipe_wm
*active
= &intel_crtc
->wm
.active
;
2470 const struct intel_wm_level
*wm
= &active
->wm
[level
];
2472 if (!active
->pipe_enabled
)
2476 * The watermark values may have been used in the past,
2477 * so we must maintain them in the registers for some
2478 * time even if the level is now disabled.
2481 ret_wm
->enable
= false;
2483 ret_wm
->pri_val
= max(ret_wm
->pri_val
, wm
->pri_val
);
2484 ret_wm
->spr_val
= max(ret_wm
->spr_val
, wm
->spr_val
);
2485 ret_wm
->cur_val
= max(ret_wm
->cur_val
, wm
->cur_val
);
2486 ret_wm
->fbc_val
= max(ret_wm
->fbc_val
, wm
->fbc_val
);
2491 * Merge all low power watermarks for all active pipes.
2493 static void ilk_wm_merge(struct drm_device
*dev
,
2494 const struct intel_wm_config
*config
,
2495 const struct ilk_wm_maximums
*max
,
2496 struct intel_pipe_wm
*merged
)
2498 int level
, max_level
= ilk_wm_max_level(dev
);
2499 int last_enabled_level
= max_level
;
2501 /* ILK/SNB/IVB: LP1+ watermarks only w/ single pipe */
2502 if ((INTEL_INFO(dev
)->gen
<= 6 || IS_IVYBRIDGE(dev
)) &&
2503 config
->num_pipes_active
> 1)
2506 /* ILK: FBC WM must be disabled always */
2507 merged
->fbc_wm_enabled
= INTEL_INFO(dev
)->gen
>= 6;
2509 /* merge each WM1+ level */
2510 for (level
= 1; level
<= max_level
; level
++) {
2511 struct intel_wm_level
*wm
= &merged
->wm
[level
];
2513 ilk_merge_wm_level(dev
, level
, wm
);
2515 if (level
> last_enabled_level
)
2517 else if (!ilk_validate_wm_level(level
, max
, wm
))
2518 /* make sure all following levels get disabled */
2519 last_enabled_level
= level
- 1;
2522 * The spec says it is preferred to disable
2523 * FBC WMs instead of disabling a WM level.
2525 if (wm
->fbc_val
> max
->fbc
) {
2527 merged
->fbc_wm_enabled
= false;
2532 /* ILK: LP2+ must be disabled when FBC WM is disabled but FBC enabled */
2534 * FIXME this is racy. FBC might get enabled later.
2535 * What we should check here is whether FBC can be
2536 * enabled sometime later.
2538 if (IS_GEN5(dev
) && !merged
->fbc_wm_enabled
&& intel_fbc_enabled(dev
)) {
2539 for (level
= 2; level
<= max_level
; level
++) {
2540 struct intel_wm_level
*wm
= &merged
->wm
[level
];
2547 static int ilk_wm_lp_to_level(int wm_lp
, const struct intel_pipe_wm
*pipe_wm
)
2549 /* LP1,LP2,LP3 levels are either 1,2,3 or 1,3,4 */
2550 return wm_lp
+ (wm_lp
>= 2 && pipe_wm
->wm
[4].enable
);
2553 /* The value we need to program into the WM_LPx latency field */
2554 static unsigned int ilk_wm_lp_latency(struct drm_device
*dev
, int level
)
2556 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2558 if (IS_HASWELL(dev
) || IS_BROADWELL(dev
))
2561 return dev_priv
->wm
.pri_latency
[level
];
2564 static void ilk_compute_wm_results(struct drm_device
*dev
,
2565 const struct intel_pipe_wm
*merged
,
2566 enum intel_ddb_partitioning partitioning
,
2567 struct ilk_wm_values
*results
)
2569 struct intel_crtc
*intel_crtc
;
2572 results
->enable_fbc_wm
= merged
->fbc_wm_enabled
;
2573 results
->partitioning
= partitioning
;
2575 /* LP1+ register values */
2576 for (wm_lp
= 1; wm_lp
<= 3; wm_lp
++) {
2577 const struct intel_wm_level
*r
;
2579 level
= ilk_wm_lp_to_level(wm_lp
, merged
);
2581 r
= &merged
->wm
[level
];
2584 * Maintain the watermark values even if the level is
2585 * disabled. Doing otherwise could cause underruns.
2587 results
->wm_lp
[wm_lp
- 1] =
2588 (ilk_wm_lp_latency(dev
, level
) << WM1_LP_LATENCY_SHIFT
) |
2589 (r
->pri_val
<< WM1_LP_SR_SHIFT
) |
2593 results
->wm_lp
[wm_lp
- 1] |= WM1_LP_SR_EN
;
2595 if (INTEL_INFO(dev
)->gen
>= 8)
2596 results
->wm_lp
[wm_lp
- 1] |=
2597 r
->fbc_val
<< WM1_LP_FBC_SHIFT_BDW
;
2599 results
->wm_lp
[wm_lp
- 1] |=
2600 r
->fbc_val
<< WM1_LP_FBC_SHIFT
;
2603 * Always set WM1S_LP_EN when spr_val != 0, even if the
2604 * level is disabled. Doing otherwise could cause underruns.
2606 if (INTEL_INFO(dev
)->gen
<= 6 && r
->spr_val
) {
2607 WARN_ON(wm_lp
!= 1);
2608 results
->wm_lp_spr
[wm_lp
- 1] = WM1S_LP_EN
| r
->spr_val
;
2610 results
->wm_lp_spr
[wm_lp
- 1] = r
->spr_val
;
2613 /* LP0 register values */
2614 for_each_intel_crtc(dev
, intel_crtc
) {
2615 enum pipe pipe
= intel_crtc
->pipe
;
2616 const struct intel_wm_level
*r
=
2617 &intel_crtc
->wm
.active
.wm
[0];
2619 if (WARN_ON(!r
->enable
))
2622 results
->wm_linetime
[pipe
] = intel_crtc
->wm
.active
.linetime
;
2624 results
->wm_pipe
[pipe
] =
2625 (r
->pri_val
<< WM0_PIPE_PLANE_SHIFT
) |
2626 (r
->spr_val
<< WM0_PIPE_SPRITE_SHIFT
) |
2631 /* Find the result with the highest level enabled. Check for enable_fbc_wm in
2632 * case both are at the same level. Prefer r1 in case they're the same. */
2633 static struct intel_pipe_wm
*ilk_find_best_result(struct drm_device
*dev
,
2634 struct intel_pipe_wm
*r1
,
2635 struct intel_pipe_wm
*r2
)
2637 int level
, max_level
= ilk_wm_max_level(dev
);
2638 int level1
= 0, level2
= 0;
2640 for (level
= 1; level
<= max_level
; level
++) {
2641 if (r1
->wm
[level
].enable
)
2643 if (r2
->wm
[level
].enable
)
2647 if (level1
== level2
) {
2648 if (r2
->fbc_wm_enabled
&& !r1
->fbc_wm_enabled
)
2652 } else if (level1
> level2
) {
2659 /* dirty bits used to track which watermarks need changes */
2660 #define WM_DIRTY_PIPE(pipe) (1 << (pipe))
2661 #define WM_DIRTY_LINETIME(pipe) (1 << (8 + (pipe)))
2662 #define WM_DIRTY_LP(wm_lp) (1 << (15 + (wm_lp)))
2663 #define WM_DIRTY_LP_ALL (WM_DIRTY_LP(1) | WM_DIRTY_LP(2) | WM_DIRTY_LP(3))
2664 #define WM_DIRTY_FBC (1 << 24)
2665 #define WM_DIRTY_DDB (1 << 25)
2667 static unsigned int ilk_compute_wm_dirty(struct drm_i915_private
*dev_priv
,
2668 const struct ilk_wm_values
*old
,
2669 const struct ilk_wm_values
*new)
2671 unsigned int dirty
= 0;
2675 for_each_pipe(dev_priv
, pipe
) {
2676 if (old
->wm_linetime
[pipe
] != new->wm_linetime
[pipe
]) {
2677 dirty
|= WM_DIRTY_LINETIME(pipe
);
2678 /* Must disable LP1+ watermarks too */
2679 dirty
|= WM_DIRTY_LP_ALL
;
2682 if (old
->wm_pipe
[pipe
] != new->wm_pipe
[pipe
]) {
2683 dirty
|= WM_DIRTY_PIPE(pipe
);
2684 /* Must disable LP1+ watermarks too */
2685 dirty
|= WM_DIRTY_LP_ALL
;
2689 if (old
->enable_fbc_wm
!= new->enable_fbc_wm
) {
2690 dirty
|= WM_DIRTY_FBC
;
2691 /* Must disable LP1+ watermarks too */
2692 dirty
|= WM_DIRTY_LP_ALL
;
2695 if (old
->partitioning
!= new->partitioning
) {
2696 dirty
|= WM_DIRTY_DDB
;
2697 /* Must disable LP1+ watermarks too */
2698 dirty
|= WM_DIRTY_LP_ALL
;
2701 /* LP1+ watermarks already deemed dirty, no need to continue */
2702 if (dirty
& WM_DIRTY_LP_ALL
)
2705 /* Find the lowest numbered LP1+ watermark in need of an update... */
2706 for (wm_lp
= 1; wm_lp
<= 3; wm_lp
++) {
2707 if (old
->wm_lp
[wm_lp
- 1] != new->wm_lp
[wm_lp
- 1] ||
2708 old
->wm_lp_spr
[wm_lp
- 1] != new->wm_lp_spr
[wm_lp
- 1])
2712 /* ...and mark it and all higher numbered LP1+ watermarks as dirty */
2713 for (; wm_lp
<= 3; wm_lp
++)
2714 dirty
|= WM_DIRTY_LP(wm_lp
);
2719 static bool _ilk_disable_lp_wm(struct drm_i915_private
*dev_priv
,
2722 struct ilk_wm_values
*previous
= &dev_priv
->wm
.hw
;
2723 bool changed
= false;
2725 if (dirty
& WM_DIRTY_LP(3) && previous
->wm_lp
[2] & WM1_LP_SR_EN
) {
2726 previous
->wm_lp
[2] &= ~WM1_LP_SR_EN
;
2727 I915_WRITE(WM3_LP_ILK
, previous
->wm_lp
[2]);
2730 if (dirty
& WM_DIRTY_LP(2) && previous
->wm_lp
[1] & WM1_LP_SR_EN
) {
2731 previous
->wm_lp
[1] &= ~WM1_LP_SR_EN
;
2732 I915_WRITE(WM2_LP_ILK
, previous
->wm_lp
[1]);
2735 if (dirty
& WM_DIRTY_LP(1) && previous
->wm_lp
[0] & WM1_LP_SR_EN
) {
2736 previous
->wm_lp
[0] &= ~WM1_LP_SR_EN
;
2737 I915_WRITE(WM1_LP_ILK
, previous
->wm_lp
[0]);
2742 * Don't touch WM1S_LP_EN here.
2743 * Doing so could cause underruns.
2750 * The spec says we shouldn't write when we don't need, because every write
2751 * causes WMs to be re-evaluated, expending some power.
2753 static void ilk_write_wm_values(struct drm_i915_private
*dev_priv
,
2754 struct ilk_wm_values
*results
)
2756 struct drm_device
*dev
= dev_priv
->dev
;
2757 struct ilk_wm_values
*previous
= &dev_priv
->wm
.hw
;
2761 dirty
= ilk_compute_wm_dirty(dev_priv
, previous
, results
);
2765 _ilk_disable_lp_wm(dev_priv
, dirty
);
2767 if (dirty
& WM_DIRTY_PIPE(PIPE_A
))
2768 I915_WRITE(WM0_PIPEA_ILK
, results
->wm_pipe
[0]);
2769 if (dirty
& WM_DIRTY_PIPE(PIPE_B
))
2770 I915_WRITE(WM0_PIPEB_ILK
, results
->wm_pipe
[1]);
2771 if (dirty
& WM_DIRTY_PIPE(PIPE_C
))
2772 I915_WRITE(WM0_PIPEC_IVB
, results
->wm_pipe
[2]);
2774 if (dirty
& WM_DIRTY_LINETIME(PIPE_A
))
2775 I915_WRITE(PIPE_WM_LINETIME(PIPE_A
), results
->wm_linetime
[0]);
2776 if (dirty
& WM_DIRTY_LINETIME(PIPE_B
))
2777 I915_WRITE(PIPE_WM_LINETIME(PIPE_B
), results
->wm_linetime
[1]);
2778 if (dirty
& WM_DIRTY_LINETIME(PIPE_C
))
2779 I915_WRITE(PIPE_WM_LINETIME(PIPE_C
), results
->wm_linetime
[2]);
2781 if (dirty
& WM_DIRTY_DDB
) {
2782 if (IS_HASWELL(dev
) || IS_BROADWELL(dev
)) {
2783 val
= I915_READ(WM_MISC
);
2784 if (results
->partitioning
== INTEL_DDB_PART_1_2
)
2785 val
&= ~WM_MISC_DATA_PARTITION_5_6
;
2787 val
|= WM_MISC_DATA_PARTITION_5_6
;
2788 I915_WRITE(WM_MISC
, val
);
2790 val
= I915_READ(DISP_ARB_CTL2
);
2791 if (results
->partitioning
== INTEL_DDB_PART_1_2
)
2792 val
&= ~DISP_DATA_PARTITION_5_6
;
2794 val
|= DISP_DATA_PARTITION_5_6
;
2795 I915_WRITE(DISP_ARB_CTL2
, val
);
2799 if (dirty
& WM_DIRTY_FBC
) {
2800 val
= I915_READ(DISP_ARB_CTL
);
2801 if (results
->enable_fbc_wm
)
2802 val
&= ~DISP_FBC_WM_DIS
;
2804 val
|= DISP_FBC_WM_DIS
;
2805 I915_WRITE(DISP_ARB_CTL
, val
);
2808 if (dirty
& WM_DIRTY_LP(1) &&
2809 previous
->wm_lp_spr
[0] != results
->wm_lp_spr
[0])
2810 I915_WRITE(WM1S_LP_ILK
, results
->wm_lp_spr
[0]);
2812 if (INTEL_INFO(dev
)->gen
>= 7) {
2813 if (dirty
& WM_DIRTY_LP(2) && previous
->wm_lp_spr
[1] != results
->wm_lp_spr
[1])
2814 I915_WRITE(WM2S_LP_IVB
, results
->wm_lp_spr
[1]);
2815 if (dirty
& WM_DIRTY_LP(3) && previous
->wm_lp_spr
[2] != results
->wm_lp_spr
[2])
2816 I915_WRITE(WM3S_LP_IVB
, results
->wm_lp_spr
[2]);
2819 if (dirty
& WM_DIRTY_LP(1) && previous
->wm_lp
[0] != results
->wm_lp
[0])
2820 I915_WRITE(WM1_LP_ILK
, results
->wm_lp
[0]);
2821 if (dirty
& WM_DIRTY_LP(2) && previous
->wm_lp
[1] != results
->wm_lp
[1])
2822 I915_WRITE(WM2_LP_ILK
, results
->wm_lp
[1]);
2823 if (dirty
& WM_DIRTY_LP(3) && previous
->wm_lp
[2] != results
->wm_lp
[2])
2824 I915_WRITE(WM3_LP_ILK
, results
->wm_lp
[2]);
2826 dev_priv
->wm
.hw
= *results
;
2829 static bool ilk_disable_lp_wm(struct drm_device
*dev
)
2831 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2833 return _ilk_disable_lp_wm(dev_priv
, WM_DIRTY_LP_ALL
);
2836 static void ilk_update_wm(struct drm_crtc
*crtc
)
2838 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2839 struct drm_device
*dev
= crtc
->dev
;
2840 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2841 struct ilk_wm_maximums max
;
2842 struct ilk_pipe_wm_parameters params
= {};
2843 struct ilk_wm_values results
= {};
2844 enum intel_ddb_partitioning partitioning
;
2845 struct intel_pipe_wm pipe_wm
= {};
2846 struct intel_pipe_wm lp_wm_1_2
= {}, lp_wm_5_6
= {}, *best_lp_wm
;
2847 struct intel_wm_config config
= {};
2849 ilk_compute_wm_parameters(crtc
, ¶ms
);
2851 intel_compute_pipe_wm(crtc
, ¶ms
, &pipe_wm
);
2853 if (!memcmp(&intel_crtc
->wm
.active
, &pipe_wm
, sizeof(pipe_wm
)))
2856 intel_crtc
->wm
.active
= pipe_wm
;
2858 ilk_compute_wm_config(dev
, &config
);
2860 ilk_compute_wm_maximums(dev
, 1, &config
, INTEL_DDB_PART_1_2
, &max
);
2861 ilk_wm_merge(dev
, &config
, &max
, &lp_wm_1_2
);
2863 /* 5/6 split only in single pipe config on IVB+ */
2864 if (INTEL_INFO(dev
)->gen
>= 7 &&
2865 config
.num_pipes_active
== 1 && config
.sprites_enabled
) {
2866 ilk_compute_wm_maximums(dev
, 1, &config
, INTEL_DDB_PART_5_6
, &max
);
2867 ilk_wm_merge(dev
, &config
, &max
, &lp_wm_5_6
);
2869 best_lp_wm
= ilk_find_best_result(dev
, &lp_wm_1_2
, &lp_wm_5_6
);
2871 best_lp_wm
= &lp_wm_1_2
;
2874 partitioning
= (best_lp_wm
== &lp_wm_1_2
) ?
2875 INTEL_DDB_PART_1_2
: INTEL_DDB_PART_5_6
;
2877 ilk_compute_wm_results(dev
, best_lp_wm
, partitioning
, &results
);
2879 ilk_write_wm_values(dev_priv
, &results
);
2883 ilk_update_sprite_wm(struct drm_plane
*plane
,
2884 struct drm_crtc
*crtc
,
2885 uint32_t sprite_width
, uint32_t sprite_height
,
2886 int pixel_size
, bool enabled
, bool scaled
)
2888 struct drm_device
*dev
= plane
->dev
;
2889 struct intel_plane
*intel_plane
= to_intel_plane(plane
);
2891 intel_plane
->wm
.enabled
= enabled
;
2892 intel_plane
->wm
.scaled
= scaled
;
2893 intel_plane
->wm
.horiz_pixels
= sprite_width
;
2894 intel_plane
->wm
.vert_pixels
= sprite_width
;
2895 intel_plane
->wm
.bytes_per_pixel
= pixel_size
;
2898 * IVB workaround: must disable low power watermarks for at least
2899 * one frame before enabling scaling. LP watermarks can be re-enabled
2900 * when scaling is disabled.
2902 * WaCxSRDisabledForSpriteScaling:ivb
2904 if (IS_IVYBRIDGE(dev
) && scaled
&& ilk_disable_lp_wm(dev
))
2905 intel_wait_for_vblank(dev
, intel_plane
->pipe
);
2907 ilk_update_wm(crtc
);
2910 static void ilk_pipe_wm_get_hw_state(struct drm_crtc
*crtc
)
2912 struct drm_device
*dev
= crtc
->dev
;
2913 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2914 struct ilk_wm_values
*hw
= &dev_priv
->wm
.hw
;
2915 struct intel_crtc
*intel_crtc
= to_intel_crtc(crtc
);
2916 struct intel_pipe_wm
*active
= &intel_crtc
->wm
.active
;
2917 enum pipe pipe
= intel_crtc
->pipe
;
2918 static const unsigned int wm0_pipe_reg
[] = {
2919 [PIPE_A
] = WM0_PIPEA_ILK
,
2920 [PIPE_B
] = WM0_PIPEB_ILK
,
2921 [PIPE_C
] = WM0_PIPEC_IVB
,
2924 hw
->wm_pipe
[pipe
] = I915_READ(wm0_pipe_reg
[pipe
]);
2925 if (IS_HASWELL(dev
) || IS_BROADWELL(dev
))
2926 hw
->wm_linetime
[pipe
] = I915_READ(PIPE_WM_LINETIME(pipe
));
2928 active
->pipe_enabled
= intel_crtc_active(crtc
);
2930 if (active
->pipe_enabled
) {
2931 u32 tmp
= hw
->wm_pipe
[pipe
];
2934 * For active pipes LP0 watermark is marked as
2935 * enabled, and LP1+ watermaks as disabled since
2936 * we can't really reverse compute them in case
2937 * multiple pipes are active.
2939 active
->wm
[0].enable
= true;
2940 active
->wm
[0].pri_val
= (tmp
& WM0_PIPE_PLANE_MASK
) >> WM0_PIPE_PLANE_SHIFT
;
2941 active
->wm
[0].spr_val
= (tmp
& WM0_PIPE_SPRITE_MASK
) >> WM0_PIPE_SPRITE_SHIFT
;
2942 active
->wm
[0].cur_val
= tmp
& WM0_PIPE_CURSOR_MASK
;
2943 active
->linetime
= hw
->wm_linetime
[pipe
];
2945 int level
, max_level
= ilk_wm_max_level(dev
);
2948 * For inactive pipes, all watermark levels
2949 * should be marked as enabled but zeroed,
2950 * which is what we'd compute them to.
2952 for (level
= 0; level
<= max_level
; level
++)
2953 active
->wm
[level
].enable
= true;
2957 void ilk_wm_get_hw_state(struct drm_device
*dev
)
2959 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
2960 struct ilk_wm_values
*hw
= &dev_priv
->wm
.hw
;
2961 struct drm_crtc
*crtc
;
2963 for_each_crtc(dev
, crtc
)
2964 ilk_pipe_wm_get_hw_state(crtc
);
2966 hw
->wm_lp
[0] = I915_READ(WM1_LP_ILK
);
2967 hw
->wm_lp
[1] = I915_READ(WM2_LP_ILK
);
2968 hw
->wm_lp
[2] = I915_READ(WM3_LP_ILK
);
2970 hw
->wm_lp_spr
[0] = I915_READ(WM1S_LP_ILK
);
2971 if (INTEL_INFO(dev
)->gen
>= 7) {
2972 hw
->wm_lp_spr
[1] = I915_READ(WM2S_LP_IVB
);
2973 hw
->wm_lp_spr
[2] = I915_READ(WM3S_LP_IVB
);
2976 if (IS_HASWELL(dev
) || IS_BROADWELL(dev
))
2977 hw
->partitioning
= (I915_READ(WM_MISC
) & WM_MISC_DATA_PARTITION_5_6
) ?
2978 INTEL_DDB_PART_5_6
: INTEL_DDB_PART_1_2
;
2979 else if (IS_IVYBRIDGE(dev
))
2980 hw
->partitioning
= (I915_READ(DISP_ARB_CTL2
) & DISP_DATA_PARTITION_5_6
) ?
2981 INTEL_DDB_PART_5_6
: INTEL_DDB_PART_1_2
;
2984 !(I915_READ(DISP_ARB_CTL
) & DISP_FBC_WM_DIS
);
2988 * intel_update_watermarks - update FIFO watermark values based on current modes
2990 * Calculate watermark values for the various WM regs based on current mode
2991 * and plane configuration.
2993 * There are several cases to deal with here:
2994 * - normal (i.e. non-self-refresh)
2995 * - self-refresh (SR) mode
2996 * - lines are large relative to FIFO size (buffer can hold up to 2)
2997 * - lines are small relative to FIFO size (buffer can hold more than 2
2998 * lines), so need to account for TLB latency
3000 * The normal calculation is:
3001 * watermark = dotclock * bytes per pixel * latency
3002 * where latency is platform & configuration dependent (we assume pessimal
3005 * The SR calculation is:
3006 * watermark = (trunc(latency/line time)+1) * surface width *
3009 * line time = htotal / dotclock
3010 * surface width = hdisplay for normal plane and 64 for cursor
3011 * and latency is assumed to be high, as above.
3013 * The final value programmed to the register should always be rounded up,
3014 * and include an extra 2 entries to account for clock crossings.
3016 * We don't use the sprite, so we can ignore that. And on Crestline we have
3017 * to set the non-SR watermarks to 8.
3019 void intel_update_watermarks(struct drm_crtc
*crtc
)
3021 struct drm_i915_private
*dev_priv
= crtc
->dev
->dev_private
;
3023 if (dev_priv
->display
.update_wm
)
3024 dev_priv
->display
.update_wm(crtc
);
3027 void intel_update_sprite_watermarks(struct drm_plane
*plane
,
3028 struct drm_crtc
*crtc
,
3029 uint32_t sprite_width
,
3030 uint32_t sprite_height
,
3032 bool enabled
, bool scaled
)
3034 struct drm_i915_private
*dev_priv
= plane
->dev
->dev_private
;
3036 if (dev_priv
->display
.update_sprite_wm
)
3037 dev_priv
->display
.update_sprite_wm(plane
, crtc
,
3038 sprite_width
, sprite_height
,
3039 pixel_size
, enabled
, scaled
);
3042 static struct drm_i915_gem_object
*
3043 intel_alloc_context_page(struct drm_device
*dev
)
3045 struct drm_i915_gem_object
*ctx
;
3048 WARN_ON(!mutex_is_locked(&dev
->struct_mutex
));
3050 ctx
= i915_gem_alloc_object(dev
, 4096);
3052 DRM_DEBUG("failed to alloc power context, RC6 disabled\n");
3056 ret
= i915_gem_obj_ggtt_pin(ctx
, 4096, 0);
3058 DRM_ERROR("failed to pin power context: %d\n", ret
);
3062 ret
= i915_gem_object_set_to_gtt_domain(ctx
, 1);
3064 DRM_ERROR("failed to set-domain on power context: %d\n", ret
);
3071 i915_gem_object_ggtt_unpin(ctx
);
3073 drm_gem_object_unreference(&ctx
->base
);
3078 * Lock protecting IPS related data structures
3080 DEFINE_SPINLOCK(mchdev_lock
);
3082 /* Global for IPS driver to get at the current i915 device. Protected by
3084 static struct drm_i915_private
*i915_mch_dev
;
3086 bool ironlake_set_drps(struct drm_device
*dev
, u8 val
)
3088 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3091 assert_spin_locked(&mchdev_lock
);
3093 rgvswctl
= I915_READ16(MEMSWCTL
);
3094 if (rgvswctl
& MEMCTL_CMD_STS
) {
3095 DRM_DEBUG("gpu busy, RCS change rejected\n");
3096 return false; /* still busy with another command */
3099 rgvswctl
= (MEMCTL_CMD_CHFREQ
<< MEMCTL_CMD_SHIFT
) |
3100 (val
<< MEMCTL_FREQ_SHIFT
) | MEMCTL_SFCAVM
;
3101 I915_WRITE16(MEMSWCTL
, rgvswctl
);
3102 POSTING_READ16(MEMSWCTL
);
3104 rgvswctl
|= MEMCTL_CMD_STS
;
3105 I915_WRITE16(MEMSWCTL
, rgvswctl
);
3110 static void ironlake_enable_drps(struct drm_device
*dev
)
3112 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3113 u32 rgvmodectl
= I915_READ(MEMMODECTL
);
3114 u8 fmax
, fmin
, fstart
, vstart
;
3116 spin_lock_irq(&mchdev_lock
);
3118 /* Enable temp reporting */
3119 I915_WRITE16(PMMISC
, I915_READ(PMMISC
) | MCPPCE_EN
);
3120 I915_WRITE16(TSC1
, I915_READ(TSC1
) | TSE
);
3122 /* 100ms RC evaluation intervals */
3123 I915_WRITE(RCUPEI
, 100000);
3124 I915_WRITE(RCDNEI
, 100000);
3126 /* Set max/min thresholds to 90ms and 80ms respectively */
3127 I915_WRITE(RCBMAXAVG
, 90000);
3128 I915_WRITE(RCBMINAVG
, 80000);
3130 I915_WRITE(MEMIHYST
, 1);
3132 /* Set up min, max, and cur for interrupt handling */
3133 fmax
= (rgvmodectl
& MEMMODE_FMAX_MASK
) >> MEMMODE_FMAX_SHIFT
;
3134 fmin
= (rgvmodectl
& MEMMODE_FMIN_MASK
);
3135 fstart
= (rgvmodectl
& MEMMODE_FSTART_MASK
) >>
3136 MEMMODE_FSTART_SHIFT
;
3138 vstart
= (I915_READ(PXVFREQ_BASE
+ (fstart
* 4)) & PXVFREQ_PX_MASK
) >>
3141 dev_priv
->ips
.fmax
= fmax
; /* IPS callback will increase this */
3142 dev_priv
->ips
.fstart
= fstart
;
3144 dev_priv
->ips
.max_delay
= fstart
;
3145 dev_priv
->ips
.min_delay
= fmin
;
3146 dev_priv
->ips
.cur_delay
= fstart
;
3148 DRM_DEBUG_DRIVER("fmax: %d, fmin: %d, fstart: %d\n",
3149 fmax
, fmin
, fstart
);
3151 I915_WRITE(MEMINTREN
, MEMINT_CX_SUPR_EN
| MEMINT_EVAL_CHG_EN
);
3154 * Interrupts will be enabled in ironlake_irq_postinstall
3157 I915_WRITE(VIDSTART
, vstart
);
3158 POSTING_READ(VIDSTART
);
3160 rgvmodectl
|= MEMMODE_SWMODE_EN
;
3161 I915_WRITE(MEMMODECTL
, rgvmodectl
);
3163 if (wait_for_atomic((I915_READ(MEMSWCTL
) & MEMCTL_CMD_STS
) == 0, 10))
3164 DRM_ERROR("stuck trying to change perf mode\n");
3167 ironlake_set_drps(dev
, fstart
);
3169 dev_priv
->ips
.last_count1
= I915_READ(0x112e4) + I915_READ(0x112e8) +
3171 dev_priv
->ips
.last_time1
= jiffies_to_msecs(jiffies
);
3172 dev_priv
->ips
.last_count2
= I915_READ(0x112f4);
3173 dev_priv
->ips
.last_time2
= ktime_get_raw_ns();
3175 spin_unlock_irq(&mchdev_lock
);
3178 static void ironlake_disable_drps(struct drm_device
*dev
)
3180 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3183 spin_lock_irq(&mchdev_lock
);
3185 rgvswctl
= I915_READ16(MEMSWCTL
);
3187 /* Ack interrupts, disable EFC interrupt */
3188 I915_WRITE(MEMINTREN
, I915_READ(MEMINTREN
) & ~MEMINT_EVAL_CHG_EN
);
3189 I915_WRITE(MEMINTRSTS
, MEMINT_EVAL_CHG
);
3190 I915_WRITE(DEIER
, I915_READ(DEIER
) & ~DE_PCU_EVENT
);
3191 I915_WRITE(DEIIR
, DE_PCU_EVENT
);
3192 I915_WRITE(DEIMR
, I915_READ(DEIMR
) | DE_PCU_EVENT
);
3194 /* Go back to the starting frequency */
3195 ironlake_set_drps(dev
, dev_priv
->ips
.fstart
);
3197 rgvswctl
|= MEMCTL_CMD_STS
;
3198 I915_WRITE(MEMSWCTL
, rgvswctl
);
3201 spin_unlock_irq(&mchdev_lock
);
3204 /* There's a funny hw issue where the hw returns all 0 when reading from
3205 * GEN6_RP_INTERRUPT_LIMITS. Hence we always need to compute the desired value
3206 * ourselves, instead of doing a rmw cycle (which might result in us clearing
3207 * all limits and the gpu stuck at whatever frequency it is at atm).
3209 static u32
gen6_rps_limits(struct drm_i915_private
*dev_priv
, u8 val
)
3213 /* Only set the down limit when we've reached the lowest level to avoid
3214 * getting more interrupts, otherwise leave this clear. This prevents a
3215 * race in the hw when coming out of rc6: There's a tiny window where
3216 * the hw runs at the minimal clock before selecting the desired
3217 * frequency, if the down threshold expires in that window we will not
3218 * receive a down interrupt. */
3219 limits
= dev_priv
->rps
.max_freq_softlimit
<< 24;
3220 if (val
<= dev_priv
->rps
.min_freq_softlimit
)
3221 limits
|= dev_priv
->rps
.min_freq_softlimit
<< 16;
3226 static void gen6_set_rps_thresholds(struct drm_i915_private
*dev_priv
, u8 val
)
3230 new_power
= dev_priv
->rps
.power
;
3231 switch (dev_priv
->rps
.power
) {
3233 if (val
> dev_priv
->rps
.efficient_freq
+ 1 && val
> dev_priv
->rps
.cur_freq
)
3234 new_power
= BETWEEN
;
3238 if (val
<= dev_priv
->rps
.efficient_freq
&& val
< dev_priv
->rps
.cur_freq
)
3239 new_power
= LOW_POWER
;
3240 else if (val
>= dev_priv
->rps
.rp0_freq
&& val
> dev_priv
->rps
.cur_freq
)
3241 new_power
= HIGH_POWER
;
3245 if (val
< (dev_priv
->rps
.rp1_freq
+ dev_priv
->rps
.rp0_freq
) >> 1 && val
< dev_priv
->rps
.cur_freq
)
3246 new_power
= BETWEEN
;
3249 /* Max/min bins are special */
3250 if (val
== dev_priv
->rps
.min_freq_softlimit
)
3251 new_power
= LOW_POWER
;
3252 if (val
== dev_priv
->rps
.max_freq_softlimit
)
3253 new_power
= HIGH_POWER
;
3254 if (new_power
== dev_priv
->rps
.power
)
3257 /* Note the units here are not exactly 1us, but 1280ns. */
3258 switch (new_power
) {
3260 /* Upclock if more than 95% busy over 16ms */
3261 I915_WRITE(GEN6_RP_UP_EI
, 12500);
3262 I915_WRITE(GEN6_RP_UP_THRESHOLD
, 11800);
3264 /* Downclock if less than 85% busy over 32ms */
3265 I915_WRITE(GEN6_RP_DOWN_EI
, 25000);
3266 I915_WRITE(GEN6_RP_DOWN_THRESHOLD
, 21250);
3268 I915_WRITE(GEN6_RP_CONTROL
,
3269 GEN6_RP_MEDIA_TURBO
|
3270 GEN6_RP_MEDIA_HW_NORMAL_MODE
|
3271 GEN6_RP_MEDIA_IS_GFX
|
3273 GEN6_RP_UP_BUSY_AVG
|
3274 GEN6_RP_DOWN_IDLE_AVG
);
3278 /* Upclock if more than 90% busy over 13ms */
3279 I915_WRITE(GEN6_RP_UP_EI
, 10250);
3280 I915_WRITE(GEN6_RP_UP_THRESHOLD
, 9225);
3282 /* Downclock if less than 75% busy over 32ms */
3283 I915_WRITE(GEN6_RP_DOWN_EI
, 25000);
3284 I915_WRITE(GEN6_RP_DOWN_THRESHOLD
, 18750);
3286 I915_WRITE(GEN6_RP_CONTROL
,
3287 GEN6_RP_MEDIA_TURBO
|
3288 GEN6_RP_MEDIA_HW_NORMAL_MODE
|
3289 GEN6_RP_MEDIA_IS_GFX
|
3291 GEN6_RP_UP_BUSY_AVG
|
3292 GEN6_RP_DOWN_IDLE_AVG
);
3296 /* Upclock if more than 85% busy over 10ms */
3297 I915_WRITE(GEN6_RP_UP_EI
, 8000);
3298 I915_WRITE(GEN6_RP_UP_THRESHOLD
, 6800);
3300 /* Downclock if less than 60% busy over 32ms */
3301 I915_WRITE(GEN6_RP_DOWN_EI
, 25000);
3302 I915_WRITE(GEN6_RP_DOWN_THRESHOLD
, 15000);
3304 I915_WRITE(GEN6_RP_CONTROL
,
3305 GEN6_RP_MEDIA_TURBO
|
3306 GEN6_RP_MEDIA_HW_NORMAL_MODE
|
3307 GEN6_RP_MEDIA_IS_GFX
|
3309 GEN6_RP_UP_BUSY_AVG
|
3310 GEN6_RP_DOWN_IDLE_AVG
);
3314 dev_priv
->rps
.power
= new_power
;
3315 dev_priv
->rps
.last_adj
= 0;
3318 static u32
gen6_rps_pm_mask(struct drm_i915_private
*dev_priv
, u8 val
)
3322 if (val
> dev_priv
->rps
.min_freq_softlimit
)
3323 mask
|= GEN6_PM_RP_DOWN_THRESHOLD
| GEN6_PM_RP_DOWN_TIMEOUT
;
3324 if (val
< dev_priv
->rps
.max_freq_softlimit
)
3325 mask
|= GEN6_PM_RP_UP_THRESHOLD
;
3327 mask
|= dev_priv
->pm_rps_events
& (GEN6_PM_RP_DOWN_EI_EXPIRED
| GEN6_PM_RP_UP_EI_EXPIRED
);
3328 mask
&= dev_priv
->pm_rps_events
;
3330 /* IVB and SNB hard hangs on looping batchbuffer
3331 * if GEN6_PM_UP_EI_EXPIRED is masked.
3333 if (INTEL_INFO(dev_priv
->dev
)->gen
<= 7 && !IS_HASWELL(dev_priv
->dev
))
3334 mask
|= GEN6_PM_RP_UP_EI_EXPIRED
;
3336 if (IS_GEN8(dev_priv
->dev
))
3337 mask
|= GEN8_PMINTR_REDIRECT_TO_NON_DISP
;
3342 /* gen6_set_rps is called to update the frequency request, but should also be
3343 * called when the range (min_delay and max_delay) is modified so that we can
3344 * update the GEN6_RP_INTERRUPT_LIMITS register accordingly. */
3345 void gen6_set_rps(struct drm_device
*dev
, u8 val
)
3347 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3349 WARN_ON(!mutex_is_locked(&dev_priv
->rps
.hw_lock
));
3350 WARN_ON(val
> dev_priv
->rps
.max_freq_softlimit
);
3351 WARN_ON(val
< dev_priv
->rps
.min_freq_softlimit
);
3353 /* min/max delay may still have been modified so be sure to
3354 * write the limits value.
3356 if (val
!= dev_priv
->rps
.cur_freq
) {
3357 gen6_set_rps_thresholds(dev_priv
, val
);
3359 if (IS_HASWELL(dev
) || IS_BROADWELL(dev
))
3360 I915_WRITE(GEN6_RPNSWREQ
,
3361 HSW_FREQUENCY(val
));
3363 I915_WRITE(GEN6_RPNSWREQ
,
3364 GEN6_FREQUENCY(val
) |
3366 GEN6_AGGRESSIVE_TURBO
);
3369 /* Make sure we continue to get interrupts
3370 * until we hit the minimum or maximum frequencies.
3372 I915_WRITE(GEN6_RP_INTERRUPT_LIMITS
, gen6_rps_limits(dev_priv
, val
));
3373 I915_WRITE(GEN6_PMINTRMSK
, gen6_rps_pm_mask(dev_priv
, val
));
3375 POSTING_READ(GEN6_RPNSWREQ
);
3377 dev_priv
->rps
.cur_freq
= val
;
3378 trace_intel_gpu_freq_change(val
* 50);
3381 /* vlv_set_rps_idle: Set the frequency to Rpn if Gfx clocks are down
3383 * * If Gfx is Idle, then
3384 * 1. Mask Turbo interrupts
3385 * 2. Bring up Gfx clock
3386 * 3. Change the freq to Rpn and wait till P-Unit updates freq
3387 * 4. Clear the Force GFX CLK ON bit so that Gfx can down
3388 * 5. Unmask Turbo interrupts
3390 static void vlv_set_rps_idle(struct drm_i915_private
*dev_priv
)
3392 struct drm_device
*dev
= dev_priv
->dev
;
3394 /* Latest VLV doesn't need to force the gfx clock */
3395 if (dev
->pdev
->revision
>= 0xd) {
3396 valleyview_set_rps(dev_priv
->dev
, dev_priv
->rps
.min_freq_softlimit
);
3401 * When we are idle. Drop to min voltage state.
3404 if (dev_priv
->rps
.cur_freq
<= dev_priv
->rps
.min_freq_softlimit
)
3407 /* Mask turbo interrupt so that they will not come in between */
3408 I915_WRITE(GEN6_PMINTRMSK
, 0xffffffff);
3410 vlv_force_gfx_clock(dev_priv
, true);
3412 dev_priv
->rps
.cur_freq
= dev_priv
->rps
.min_freq_softlimit
;
3414 vlv_punit_write(dev_priv
, PUNIT_REG_GPU_FREQ_REQ
,
3415 dev_priv
->rps
.min_freq_softlimit
);
3417 if (wait_for(((vlv_punit_read(dev_priv
, PUNIT_REG_GPU_FREQ_STS
))
3418 & GENFREQSTATUS
) == 0, 5))
3419 DRM_ERROR("timed out waiting for Punit\n");
3421 vlv_force_gfx_clock(dev_priv
, false);
3423 I915_WRITE(GEN6_PMINTRMSK
,
3424 gen6_rps_pm_mask(dev_priv
, dev_priv
->rps
.cur_freq
));
3427 void gen6_rps_idle(struct drm_i915_private
*dev_priv
)
3429 struct drm_device
*dev
= dev_priv
->dev
;
3431 mutex_lock(&dev_priv
->rps
.hw_lock
);
3432 if (dev_priv
->rps
.enabled
) {
3433 if (IS_CHERRYVIEW(dev
))
3434 valleyview_set_rps(dev_priv
->dev
, dev_priv
->rps
.min_freq_softlimit
);
3435 else if (IS_VALLEYVIEW(dev
))
3436 vlv_set_rps_idle(dev_priv
);
3438 gen6_set_rps(dev_priv
->dev
, dev_priv
->rps
.min_freq_softlimit
);
3439 dev_priv
->rps
.last_adj
= 0;
3441 mutex_unlock(&dev_priv
->rps
.hw_lock
);
3444 void gen6_rps_boost(struct drm_i915_private
*dev_priv
)
3446 struct drm_device
*dev
= dev_priv
->dev
;
3448 mutex_lock(&dev_priv
->rps
.hw_lock
);
3449 if (dev_priv
->rps
.enabled
) {
3450 if (IS_VALLEYVIEW(dev
))
3451 valleyview_set_rps(dev_priv
->dev
, dev_priv
->rps
.max_freq_softlimit
);
3453 gen6_set_rps(dev_priv
->dev
, dev_priv
->rps
.max_freq_softlimit
);
3454 dev_priv
->rps
.last_adj
= 0;
3456 mutex_unlock(&dev_priv
->rps
.hw_lock
);
3459 void valleyview_set_rps(struct drm_device
*dev
, u8 val
)
3461 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3463 WARN_ON(!mutex_is_locked(&dev_priv
->rps
.hw_lock
));
3464 WARN_ON(val
> dev_priv
->rps
.max_freq_softlimit
);
3465 WARN_ON(val
< dev_priv
->rps
.min_freq_softlimit
);
3467 DRM_DEBUG_DRIVER("GPU freq request from %d MHz (%u) to %d MHz (%u)\n",
3468 vlv_gpu_freq(dev_priv
, dev_priv
->rps
.cur_freq
),
3469 dev_priv
->rps
.cur_freq
,
3470 vlv_gpu_freq(dev_priv
, val
), val
);
3472 if (val
!= dev_priv
->rps
.cur_freq
)
3473 vlv_punit_write(dev_priv
, PUNIT_REG_GPU_FREQ_REQ
, val
);
3475 I915_WRITE(GEN6_PMINTRMSK
, gen6_rps_pm_mask(dev_priv
, val
));
3477 dev_priv
->rps
.cur_freq
= val
;
3478 trace_intel_gpu_freq_change(vlv_gpu_freq(dev_priv
, val
));
3481 static void gen8_disable_rps_interrupts(struct drm_device
*dev
)
3483 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3485 I915_WRITE(GEN6_PMINTRMSK
, ~GEN8_PMINTR_REDIRECT_TO_NON_DISP
);
3486 I915_WRITE(GEN8_GT_IER(2), I915_READ(GEN8_GT_IER(2)) &
3487 ~dev_priv
->pm_rps_events
);
3488 /* Complete PM interrupt masking here doesn't race with the rps work
3489 * item again unmasking PM interrupts because that is using a different
3490 * register (GEN8_GT_IMR(2)) to mask PM interrupts. The only risk is in
3491 * leaving stale bits in GEN8_GT_IIR(2) and GEN8_GT_IMR(2) which
3492 * gen8_enable_rps will clean up. */
3494 spin_lock_irq(&dev_priv
->irq_lock
);
3495 dev_priv
->rps
.pm_iir
= 0;
3496 spin_unlock_irq(&dev_priv
->irq_lock
);
3498 I915_WRITE(GEN8_GT_IIR(2), dev_priv
->pm_rps_events
);
3501 static void gen6_disable_rps_interrupts(struct drm_device
*dev
)
3503 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3505 I915_WRITE(GEN6_PMINTRMSK
, 0xffffffff);
3506 I915_WRITE(GEN6_PMIER
, I915_READ(GEN6_PMIER
) &
3507 ~dev_priv
->pm_rps_events
);
3508 /* Complete PM interrupt masking here doesn't race with the rps work
3509 * item again unmasking PM interrupts because that is using a different
3510 * register (PMIMR) to mask PM interrupts. The only risk is in leaving
3511 * stale bits in PMIIR and PMIMR which gen6_enable_rps will clean up. */
3513 spin_lock_irq(&dev_priv
->irq_lock
);
3514 dev_priv
->rps
.pm_iir
= 0;
3515 spin_unlock_irq(&dev_priv
->irq_lock
);
3517 I915_WRITE(GEN6_PMIIR
, dev_priv
->pm_rps_events
);
3520 static void gen6_disable_rps(struct drm_device
*dev
)
3522 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3524 I915_WRITE(GEN6_RC_CONTROL
, 0);
3525 I915_WRITE(GEN6_RPNSWREQ
, 1 << 31);
3527 if (IS_BROADWELL(dev
))
3528 gen8_disable_rps_interrupts(dev
);
3530 gen6_disable_rps_interrupts(dev
);
3533 static void cherryview_disable_rps(struct drm_device
*dev
)
3535 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3537 I915_WRITE(GEN6_RC_CONTROL
, 0);
3539 gen8_disable_rps_interrupts(dev
);
3542 static void valleyview_disable_rps(struct drm_device
*dev
)
3544 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3546 /* we're doing forcewake before Disabling RC6,
3547 * This what the BIOS expects when going into suspend */
3548 gen6_gt_force_wake_get(dev_priv
, FORCEWAKE_ALL
);
3550 I915_WRITE(GEN6_RC_CONTROL
, 0);
3552 gen6_gt_force_wake_put(dev_priv
, FORCEWAKE_ALL
);
3554 gen6_disable_rps_interrupts(dev
);
3557 static void intel_print_rc6_info(struct drm_device
*dev
, u32 mode
)
3559 if (IS_VALLEYVIEW(dev
)) {
3560 if (mode
& (GEN7_RC_CTL_TO_MODE
| GEN6_RC_CTL_EI_MODE(1)))
3561 mode
= GEN6_RC_CTL_RC6_ENABLE
;
3565 DRM_DEBUG_KMS("Enabling RC6 states: RC6 %s, RC6p %s, RC6pp %s\n",
3566 (mode
& GEN6_RC_CTL_RC6_ENABLE
) ? "on" : "off",
3567 (mode
& GEN6_RC_CTL_RC6p_ENABLE
) ? "on" : "off",
3568 (mode
& GEN6_RC_CTL_RC6pp_ENABLE
) ? "on" : "off");
3571 static int sanitize_rc6_option(const struct drm_device
*dev
, int enable_rc6
)
3573 /* No RC6 before Ironlake */
3574 if (INTEL_INFO(dev
)->gen
< 5)
3577 /* RC6 is only on Ironlake mobile not on desktop */
3578 if (INTEL_INFO(dev
)->gen
== 5 && !IS_IRONLAKE_M(dev
))
3581 /* Respect the kernel parameter if it is set */
3582 if (enable_rc6
>= 0) {
3585 if (INTEL_INFO(dev
)->gen
== 6 || IS_IVYBRIDGE(dev
))
3586 mask
= INTEL_RC6_ENABLE
| INTEL_RC6p_ENABLE
|
3589 mask
= INTEL_RC6_ENABLE
;
3591 if ((enable_rc6
& mask
) != enable_rc6
)
3592 DRM_DEBUG_KMS("Adjusting RC6 mask to %d (requested %d, valid %d)\n",
3593 enable_rc6
& mask
, enable_rc6
, mask
);
3595 return enable_rc6
& mask
;
3598 /* Disable RC6 on Ironlake */
3599 if (INTEL_INFO(dev
)->gen
== 5)
3602 if (IS_IVYBRIDGE(dev
))
3603 return (INTEL_RC6_ENABLE
| INTEL_RC6p_ENABLE
);
3605 return INTEL_RC6_ENABLE
;
3608 int intel_enable_rc6(const struct drm_device
*dev
)
3610 return i915
.enable_rc6
;
3613 static void gen8_enable_rps_interrupts(struct drm_device
*dev
)
3615 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3617 spin_lock_irq(&dev_priv
->irq_lock
);
3618 WARN_ON(dev_priv
->rps
.pm_iir
);
3619 gen8_enable_pm_irq(dev_priv
, dev_priv
->pm_rps_events
);
3620 I915_WRITE(GEN8_GT_IIR(2), dev_priv
->pm_rps_events
);
3621 spin_unlock_irq(&dev_priv
->irq_lock
);
3624 static void gen6_enable_rps_interrupts(struct drm_device
*dev
)
3626 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3628 spin_lock_irq(&dev_priv
->irq_lock
);
3629 WARN_ON(dev_priv
->rps
.pm_iir
);
3630 gen6_enable_pm_irq(dev_priv
, dev_priv
->pm_rps_events
);
3631 I915_WRITE(GEN6_PMIIR
, dev_priv
->pm_rps_events
);
3632 spin_unlock_irq(&dev_priv
->irq_lock
);
3635 static void parse_rp_state_cap(struct drm_i915_private
*dev_priv
, u32 rp_state_cap
)
3637 /* All of these values are in units of 50MHz */
3638 dev_priv
->rps
.cur_freq
= 0;
3639 /* static values from HW: RP0 < RPe < RP1 < RPn (min_freq) */
3640 dev_priv
->rps
.rp1_freq
= (rp_state_cap
>> 8) & 0xff;
3641 dev_priv
->rps
.rp0_freq
= (rp_state_cap
>> 0) & 0xff;
3642 dev_priv
->rps
.min_freq
= (rp_state_cap
>> 16) & 0xff;
3643 /* XXX: only BYT has a special efficient freq */
3644 dev_priv
->rps
.efficient_freq
= dev_priv
->rps
.rp1_freq
;
3645 /* hw_max = RP0 until we check for overclocking */
3646 dev_priv
->rps
.max_freq
= dev_priv
->rps
.rp0_freq
;
3648 /* Preserve min/max settings in case of re-init */
3649 if (dev_priv
->rps
.max_freq_softlimit
== 0)
3650 dev_priv
->rps
.max_freq_softlimit
= dev_priv
->rps
.max_freq
;
3652 if (dev_priv
->rps
.min_freq_softlimit
== 0)
3653 dev_priv
->rps
.min_freq_softlimit
= dev_priv
->rps
.min_freq
;
3656 static void gen8_enable_rps(struct drm_device
*dev
)
3658 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3659 struct intel_engine_cs
*ring
;
3660 uint32_t rc6_mask
= 0, rp_state_cap
;
3663 /* 1a: Software RC state - RC0 */
3664 I915_WRITE(GEN6_RC_STATE
, 0);
3666 /* 1c & 1d: Get forcewake during program sequence. Although the driver
3667 * hasn't enabled a state yet where we need forcewake, BIOS may have.*/
3668 gen6_gt_force_wake_get(dev_priv
, FORCEWAKE_ALL
);
3670 /* 2a: Disable RC states. */
3671 I915_WRITE(GEN6_RC_CONTROL
, 0);
3673 rp_state_cap
= I915_READ(GEN6_RP_STATE_CAP
);
3674 parse_rp_state_cap(dev_priv
, rp_state_cap
);
3676 /* 2b: Program RC6 thresholds.*/
3677 I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT
, 40 << 16);
3678 I915_WRITE(GEN6_RC_EVALUATION_INTERVAL
, 125000); /* 12500 * 1280ns */
3679 I915_WRITE(GEN6_RC_IDLE_HYSTERSIS
, 25); /* 25 * 1280ns */
3680 for_each_ring(ring
, dev_priv
, unused
)
3681 I915_WRITE(RING_MAX_IDLE(ring
->mmio_base
), 10);
3682 I915_WRITE(GEN6_RC_SLEEP
, 0);
3683 if (IS_BROADWELL(dev
))
3684 I915_WRITE(GEN6_RC6_THRESHOLD
, 625); /* 800us/1.28 for TO */
3686 I915_WRITE(GEN6_RC6_THRESHOLD
, 50000); /* 50/125ms per EI */
3689 if (intel_enable_rc6(dev
) & INTEL_RC6_ENABLE
)
3690 rc6_mask
= GEN6_RC_CTL_RC6_ENABLE
;
3691 intel_print_rc6_info(dev
, rc6_mask
);
3692 if (IS_BROADWELL(dev
))
3693 I915_WRITE(GEN6_RC_CONTROL
, GEN6_RC_CTL_HW_ENABLE
|
3694 GEN7_RC_CTL_TO_MODE
|
3697 I915_WRITE(GEN6_RC_CONTROL
, GEN6_RC_CTL_HW_ENABLE
|
3698 GEN6_RC_CTL_EI_MODE(1) |
3701 /* 4 Program defaults and thresholds for RPS*/
3702 I915_WRITE(GEN6_RPNSWREQ
,
3703 HSW_FREQUENCY(dev_priv
->rps
.rp1_freq
));
3704 I915_WRITE(GEN6_RC_VIDEO_FREQ
,
3705 HSW_FREQUENCY(dev_priv
->rps
.rp1_freq
));
3706 /* NB: Docs say 1s, and 1000000 - which aren't equivalent */
3707 I915_WRITE(GEN6_RP_DOWN_TIMEOUT
, 100000000 / 128); /* 1 second timeout */
3709 /* Docs recommend 900MHz, and 300 MHz respectively */
3710 I915_WRITE(GEN6_RP_INTERRUPT_LIMITS
,
3711 dev_priv
->rps
.max_freq_softlimit
<< 24 |
3712 dev_priv
->rps
.min_freq_softlimit
<< 16);
3714 I915_WRITE(GEN6_RP_UP_THRESHOLD
, 7600000 / 128); /* 76ms busyness per EI, 90% */
3715 I915_WRITE(GEN6_RP_DOWN_THRESHOLD
, 31300000 / 128); /* 313ms busyness per EI, 70%*/
3716 I915_WRITE(GEN6_RP_UP_EI
, 66000); /* 84.48ms, XXX: random? */
3717 I915_WRITE(GEN6_RP_DOWN_EI
, 350000); /* 448ms, XXX: random? */
3719 I915_WRITE(GEN6_RP_IDLE_HYSTERSIS
, 10);
3722 I915_WRITE(GEN6_RP_CONTROL
,
3723 GEN6_RP_MEDIA_TURBO
|
3724 GEN6_RP_MEDIA_HW_NORMAL_MODE
|
3725 GEN6_RP_MEDIA_IS_GFX
|
3727 GEN6_RP_UP_BUSY_AVG
|
3728 GEN6_RP_DOWN_IDLE_AVG
);
3730 /* 6: Ring frequency + overclocking (our driver does this later */
3732 gen6_set_rps(dev
, (I915_READ(GEN6_GT_PERF_STATUS
) & 0xff00) >> 8);
3734 gen8_enable_rps_interrupts(dev
);
3736 gen6_gt_force_wake_put(dev_priv
, FORCEWAKE_ALL
);
3739 static void gen6_enable_rps(struct drm_device
*dev
)
3741 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3742 struct intel_engine_cs
*ring
;
3744 u32 rc6vids
, pcu_mbox
= 0, rc6_mask
= 0;
3749 WARN_ON(!mutex_is_locked(&dev_priv
->rps
.hw_lock
));
3751 /* Here begins a magic sequence of register writes to enable
3752 * auto-downclocking.
3754 * Perhaps there might be some value in exposing these to
3757 I915_WRITE(GEN6_RC_STATE
, 0);
3759 /* Clear the DBG now so we don't confuse earlier errors */
3760 if ((gtfifodbg
= I915_READ(GTFIFODBG
))) {
3761 DRM_ERROR("GT fifo had a previous error %x\n", gtfifodbg
);
3762 I915_WRITE(GTFIFODBG
, gtfifodbg
);
3765 gen6_gt_force_wake_get(dev_priv
, FORCEWAKE_ALL
);
3767 rp_state_cap
= I915_READ(GEN6_RP_STATE_CAP
);
3769 parse_rp_state_cap(dev_priv
, rp_state_cap
);
3771 /* disable the counters and set deterministic thresholds */
3772 I915_WRITE(GEN6_RC_CONTROL
, 0);
3774 I915_WRITE(GEN6_RC1_WAKE_RATE_LIMIT
, 1000 << 16);
3775 I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT
, 40 << 16 | 30);
3776 I915_WRITE(GEN6_RC6pp_WAKE_RATE_LIMIT
, 30);
3777 I915_WRITE(GEN6_RC_EVALUATION_INTERVAL
, 125000);
3778 I915_WRITE(GEN6_RC_IDLE_HYSTERSIS
, 25);
3780 for_each_ring(ring
, dev_priv
, i
)
3781 I915_WRITE(RING_MAX_IDLE(ring
->mmio_base
), 10);
3783 I915_WRITE(GEN6_RC_SLEEP
, 0);
3784 I915_WRITE(GEN6_RC1e_THRESHOLD
, 1000);
3785 if (IS_IVYBRIDGE(dev
))
3786 I915_WRITE(GEN6_RC6_THRESHOLD
, 125000);
3788 I915_WRITE(GEN6_RC6_THRESHOLD
, 50000);
3789 I915_WRITE(GEN6_RC6p_THRESHOLD
, 150000);
3790 I915_WRITE(GEN6_RC6pp_THRESHOLD
, 64000); /* unused */
3792 /* Check if we are enabling RC6 */
3793 rc6_mode
= intel_enable_rc6(dev_priv
->dev
);
3794 if (rc6_mode
& INTEL_RC6_ENABLE
)
3795 rc6_mask
|= GEN6_RC_CTL_RC6_ENABLE
;
3797 /* We don't use those on Haswell */
3798 if (!IS_HASWELL(dev
)) {
3799 if (rc6_mode
& INTEL_RC6p_ENABLE
)
3800 rc6_mask
|= GEN6_RC_CTL_RC6p_ENABLE
;
3802 if (rc6_mode
& INTEL_RC6pp_ENABLE
)
3803 rc6_mask
|= GEN6_RC_CTL_RC6pp_ENABLE
;
3806 intel_print_rc6_info(dev
, rc6_mask
);
3808 I915_WRITE(GEN6_RC_CONTROL
,
3810 GEN6_RC_CTL_EI_MODE(1) |
3811 GEN6_RC_CTL_HW_ENABLE
);
3813 /* Power down if completely idle for over 50ms */
3814 I915_WRITE(GEN6_RP_DOWN_TIMEOUT
, 50000);
3815 I915_WRITE(GEN6_RP_IDLE_HYSTERSIS
, 10);
3817 ret
= sandybridge_pcode_write(dev_priv
, GEN6_PCODE_WRITE_MIN_FREQ_TABLE
, 0);
3819 DRM_DEBUG_DRIVER("Failed to set the min frequency\n");
3821 ret
= sandybridge_pcode_read(dev_priv
, GEN6_READ_OC_PARAMS
, &pcu_mbox
);
3822 if (!ret
&& (pcu_mbox
& (1<<31))) { /* OC supported */
3823 DRM_DEBUG_DRIVER("Overclocking supported. Max: %dMHz, Overclock max: %dMHz\n",
3824 (dev_priv
->rps
.max_freq_softlimit
& 0xff) * 50,
3825 (pcu_mbox
& 0xff) * 50);
3826 dev_priv
->rps
.max_freq
= pcu_mbox
& 0xff;
3829 dev_priv
->rps
.power
= HIGH_POWER
; /* force a reset */
3830 gen6_set_rps(dev_priv
->dev
, dev_priv
->rps
.min_freq_softlimit
);
3832 gen6_enable_rps_interrupts(dev
);
3835 ret
= sandybridge_pcode_read(dev_priv
, GEN6_PCODE_READ_RC6VIDS
, &rc6vids
);
3836 if (IS_GEN6(dev
) && ret
) {
3837 DRM_DEBUG_DRIVER("Couldn't check for BIOS workaround\n");
3838 } else if (IS_GEN6(dev
) && (GEN6_DECODE_RC6_VID(rc6vids
& 0xff) < 450)) {
3839 DRM_DEBUG_DRIVER("You should update your BIOS. Correcting minimum rc6 voltage (%dmV->%dmV)\n",
3840 GEN6_DECODE_RC6_VID(rc6vids
& 0xff), 450);
3841 rc6vids
&= 0xffff00;
3842 rc6vids
|= GEN6_ENCODE_RC6_VID(450);
3843 ret
= sandybridge_pcode_write(dev_priv
, GEN6_PCODE_WRITE_RC6VIDS
, rc6vids
);
3845 DRM_ERROR("Couldn't fix incorrect rc6 voltage\n");
3848 gen6_gt_force_wake_put(dev_priv
, FORCEWAKE_ALL
);
3851 static void __gen6_update_ring_freq(struct drm_device
*dev
)
3853 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3855 unsigned int gpu_freq
;
3856 unsigned int max_ia_freq
, min_ring_freq
;
3857 int scaling_factor
= 180;
3858 struct cpufreq_policy
*policy
;
3860 WARN_ON(!mutex_is_locked(&dev_priv
->rps
.hw_lock
));
3862 policy
= cpufreq_cpu_get(0);
3864 max_ia_freq
= policy
->cpuinfo
.max_freq
;
3865 cpufreq_cpu_put(policy
);
3868 * Default to measured freq if none found, PCU will ensure we
3871 max_ia_freq
= tsc_khz
;
3874 /* Convert from kHz to MHz */
3875 max_ia_freq
/= 1000;
3877 min_ring_freq
= I915_READ(DCLK
) & 0xf;
3878 /* convert DDR frequency from units of 266.6MHz to bandwidth */
3879 min_ring_freq
= mult_frac(min_ring_freq
, 8, 3);
3882 * For each potential GPU frequency, load a ring frequency we'd like
3883 * to use for memory access. We do this by specifying the IA frequency
3884 * the PCU should use as a reference to determine the ring frequency.
3886 for (gpu_freq
= dev_priv
->rps
.max_freq_softlimit
; gpu_freq
>= dev_priv
->rps
.min_freq_softlimit
;
3888 int diff
= dev_priv
->rps
.max_freq_softlimit
- gpu_freq
;
3889 unsigned int ia_freq
= 0, ring_freq
= 0;
3891 if (INTEL_INFO(dev
)->gen
>= 8) {
3892 /* max(2 * GT, DDR). NB: GT is 50MHz units */
3893 ring_freq
= max(min_ring_freq
, gpu_freq
);
3894 } else if (IS_HASWELL(dev
)) {
3895 ring_freq
= mult_frac(gpu_freq
, 5, 4);
3896 ring_freq
= max(min_ring_freq
, ring_freq
);
3897 /* leave ia_freq as the default, chosen by cpufreq */
3899 /* On older processors, there is no separate ring
3900 * clock domain, so in order to boost the bandwidth
3901 * of the ring, we need to upclock the CPU (ia_freq).
3903 * For GPU frequencies less than 750MHz,
3904 * just use the lowest ring freq.
3906 if (gpu_freq
< min_freq
)
3909 ia_freq
= max_ia_freq
- ((diff
* scaling_factor
) / 2);
3910 ia_freq
= DIV_ROUND_CLOSEST(ia_freq
, 100);
3913 sandybridge_pcode_write(dev_priv
,
3914 GEN6_PCODE_WRITE_MIN_FREQ_TABLE
,
3915 ia_freq
<< GEN6_PCODE_FREQ_IA_RATIO_SHIFT
|
3916 ring_freq
<< GEN6_PCODE_FREQ_RING_RATIO_SHIFT
|
3921 void gen6_update_ring_freq(struct drm_device
*dev
)
3923 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
3925 if (INTEL_INFO(dev
)->gen
< 6 || IS_VALLEYVIEW(dev
))
3928 mutex_lock(&dev_priv
->rps
.hw_lock
);
3929 __gen6_update_ring_freq(dev
);
3930 mutex_unlock(&dev_priv
->rps
.hw_lock
);
3933 static int cherryview_rps_max_freq(struct drm_i915_private
*dev_priv
)
3937 val
= vlv_punit_read(dev_priv
, PUNIT_GPU_STATUS_REG
);
3938 rp0
= (val
>> PUNIT_GPU_STATUS_MAX_FREQ_SHIFT
) & PUNIT_GPU_STATUS_MAX_FREQ_MASK
;
3943 static int cherryview_rps_rpe_freq(struct drm_i915_private
*dev_priv
)
3947 val
= vlv_punit_read(dev_priv
, PUNIT_GPU_DUTYCYCLE_REG
);
3948 rpe
= (val
>> PUNIT_GPU_DUTYCYCLE_RPE_FREQ_SHIFT
) & PUNIT_GPU_DUTYCYCLE_RPE_FREQ_MASK
;
3953 static int cherryview_rps_guar_freq(struct drm_i915_private
*dev_priv
)
3957 val
= vlv_punit_read(dev_priv
, PUNIT_REG_GPU_FREQ_STS
);
3958 rp1
= (val
>> PUNIT_GPU_STATUS_MAX_FREQ_SHIFT
) & PUNIT_GPU_STATUS_MAX_FREQ_MASK
;
3963 static int cherryview_rps_min_freq(struct drm_i915_private
*dev_priv
)
3967 val
= vlv_punit_read(dev_priv
, PUNIT_GPU_STATUS_REG
);
3968 rpn
= (val
>> PUNIT_GPU_STATIS_GFX_MIN_FREQ_SHIFT
) & PUNIT_GPU_STATUS_GFX_MIN_FREQ_MASK
;
3972 static int valleyview_rps_guar_freq(struct drm_i915_private
*dev_priv
)
3976 val
= vlv_nc_read(dev_priv
, IOSF_NC_FB_GFX_FREQ_FUSE
);
3978 rp1
= (val
& FB_GFX_FGUARANTEED_FREQ_FUSE_MASK
) >> FB_GFX_FGUARANTEED_FREQ_FUSE_SHIFT
;
3983 static int valleyview_rps_max_freq(struct drm_i915_private
*dev_priv
)
3987 val
= vlv_nc_read(dev_priv
, IOSF_NC_FB_GFX_FREQ_FUSE
);
3989 rp0
= (val
& FB_GFX_MAX_FREQ_FUSE_MASK
) >> FB_GFX_MAX_FREQ_FUSE_SHIFT
;
3991 rp0
= min_t(u32
, rp0
, 0xea);
3996 static int valleyview_rps_rpe_freq(struct drm_i915_private
*dev_priv
)
4000 val
= vlv_nc_read(dev_priv
, IOSF_NC_FB_GFX_FMAX_FUSE_LO
);
4001 rpe
= (val
& FB_FMAX_VMIN_FREQ_LO_MASK
) >> FB_FMAX_VMIN_FREQ_LO_SHIFT
;
4002 val
= vlv_nc_read(dev_priv
, IOSF_NC_FB_GFX_FMAX_FUSE_HI
);
4003 rpe
|= (val
& FB_FMAX_VMIN_FREQ_HI_MASK
) << 5;
4008 static int valleyview_rps_min_freq(struct drm_i915_private
*dev_priv
)
4010 return vlv_punit_read(dev_priv
, PUNIT_REG_GPU_LFM
) & 0xff;
4013 /* Check that the pctx buffer wasn't move under us. */
4014 static void valleyview_check_pctx(struct drm_i915_private
*dev_priv
)
4016 unsigned long pctx_addr
= I915_READ(VLV_PCBR
) & ~4095;
4018 WARN_ON(pctx_addr
!= dev_priv
->mm
.stolen_base
+
4019 dev_priv
->vlv_pctx
->stolen
->start
);
4023 /* Check that the pcbr address is not empty. */
4024 static void cherryview_check_pctx(struct drm_i915_private
*dev_priv
)
4026 unsigned long pctx_addr
= I915_READ(VLV_PCBR
) & ~4095;
4028 WARN_ON((pctx_addr
>> VLV_PCBR_ADDR_SHIFT
) == 0);
4031 static void cherryview_setup_pctx(struct drm_device
*dev
)
4033 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4034 unsigned long pctx_paddr
, paddr
;
4035 struct i915_gtt
*gtt
= &dev_priv
->gtt
;
4037 int pctx_size
= 32*1024;
4039 WARN_ON(!mutex_is_locked(&dev
->struct_mutex
));
4041 pcbr
= I915_READ(VLV_PCBR
);
4042 if ((pcbr
>> VLV_PCBR_ADDR_SHIFT
) == 0) {
4043 paddr
= (dev_priv
->mm
.stolen_base
+
4044 (gtt
->stolen_size
- pctx_size
));
4046 pctx_paddr
= (paddr
& (~4095));
4047 I915_WRITE(VLV_PCBR
, pctx_paddr
);
4051 static void valleyview_setup_pctx(struct drm_device
*dev
)
4053 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4054 struct drm_i915_gem_object
*pctx
;
4055 unsigned long pctx_paddr
;
4057 int pctx_size
= 24*1024;
4059 WARN_ON(!mutex_is_locked(&dev
->struct_mutex
));
4061 pcbr
= I915_READ(VLV_PCBR
);
4063 /* BIOS set it up already, grab the pre-alloc'd space */
4066 pcbr_offset
= (pcbr
& (~4095)) - dev_priv
->mm
.stolen_base
;
4067 pctx
= i915_gem_object_create_stolen_for_preallocated(dev_priv
->dev
,
4069 I915_GTT_OFFSET_NONE
,
4075 * From the Gunit register HAS:
4076 * The Gfx driver is expected to program this register and ensure
4077 * proper allocation within Gfx stolen memory. For example, this
4078 * register should be programmed such than the PCBR range does not
4079 * overlap with other ranges, such as the frame buffer, protected
4080 * memory, or any other relevant ranges.
4082 pctx
= i915_gem_object_create_stolen(dev
, pctx_size
);
4084 DRM_DEBUG("not enough stolen space for PCTX, disabling\n");
4088 pctx_paddr
= dev_priv
->mm
.stolen_base
+ pctx
->stolen
->start
;
4089 I915_WRITE(VLV_PCBR
, pctx_paddr
);
4092 dev_priv
->vlv_pctx
= pctx
;
4095 static void valleyview_cleanup_pctx(struct drm_device
*dev
)
4097 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4099 if (WARN_ON(!dev_priv
->vlv_pctx
))
4102 drm_gem_object_unreference(&dev_priv
->vlv_pctx
->base
);
4103 dev_priv
->vlv_pctx
= NULL
;
4106 static void valleyview_init_gt_powersave(struct drm_device
*dev
)
4108 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4111 valleyview_setup_pctx(dev
);
4113 mutex_lock(&dev_priv
->rps
.hw_lock
);
4115 val
= vlv_punit_read(dev_priv
, PUNIT_REG_GPU_FREQ_STS
);
4116 switch ((val
>> 6) & 3) {
4119 dev_priv
->mem_freq
= 800;
4122 dev_priv
->mem_freq
= 1066;
4125 dev_priv
->mem_freq
= 1333;
4128 DRM_DEBUG_DRIVER("DDR speed: %d MHz", dev_priv
->mem_freq
);
4130 dev_priv
->rps
.max_freq
= valleyview_rps_max_freq(dev_priv
);
4131 dev_priv
->rps
.rp0_freq
= dev_priv
->rps
.max_freq
;
4132 DRM_DEBUG_DRIVER("max GPU freq: %d MHz (%u)\n",
4133 vlv_gpu_freq(dev_priv
, dev_priv
->rps
.max_freq
),
4134 dev_priv
->rps
.max_freq
);
4136 dev_priv
->rps
.efficient_freq
= valleyview_rps_rpe_freq(dev_priv
);
4137 DRM_DEBUG_DRIVER("RPe GPU freq: %d MHz (%u)\n",
4138 vlv_gpu_freq(dev_priv
, dev_priv
->rps
.efficient_freq
),
4139 dev_priv
->rps
.efficient_freq
);
4141 dev_priv
->rps
.rp1_freq
= valleyview_rps_guar_freq(dev_priv
);
4142 DRM_DEBUG_DRIVER("RP1(Guar Freq) GPU freq: %d MHz (%u)\n",
4143 vlv_gpu_freq(dev_priv
, dev_priv
->rps
.rp1_freq
),
4144 dev_priv
->rps
.rp1_freq
);
4146 dev_priv
->rps
.min_freq
= valleyview_rps_min_freq(dev_priv
);
4147 DRM_DEBUG_DRIVER("min GPU freq: %d MHz (%u)\n",
4148 vlv_gpu_freq(dev_priv
, dev_priv
->rps
.min_freq
),
4149 dev_priv
->rps
.min_freq
);
4151 /* Preserve min/max settings in case of re-init */
4152 if (dev_priv
->rps
.max_freq_softlimit
== 0)
4153 dev_priv
->rps
.max_freq_softlimit
= dev_priv
->rps
.max_freq
;
4155 if (dev_priv
->rps
.min_freq_softlimit
== 0)
4156 dev_priv
->rps
.min_freq_softlimit
= dev_priv
->rps
.min_freq
;
4158 mutex_unlock(&dev_priv
->rps
.hw_lock
);
4161 static void cherryview_init_gt_powersave(struct drm_device
*dev
)
4163 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4166 cherryview_setup_pctx(dev
);
4168 mutex_lock(&dev_priv
->rps
.hw_lock
);
4170 val
= vlv_punit_read(dev_priv
, CCK_FUSE_REG
);
4171 switch ((val
>> 2) & 0x7) {
4174 dev_priv
->rps
.cz_freq
= 200;
4175 dev_priv
->mem_freq
= 1600;
4178 dev_priv
->rps
.cz_freq
= 267;
4179 dev_priv
->mem_freq
= 1600;
4182 dev_priv
->rps
.cz_freq
= 333;
4183 dev_priv
->mem_freq
= 2000;
4186 dev_priv
->rps
.cz_freq
= 320;
4187 dev_priv
->mem_freq
= 1600;
4190 dev_priv
->rps
.cz_freq
= 400;
4191 dev_priv
->mem_freq
= 1600;
4194 DRM_DEBUG_DRIVER("DDR speed: %d MHz", dev_priv
->mem_freq
);
4196 dev_priv
->rps
.max_freq
= cherryview_rps_max_freq(dev_priv
);
4197 dev_priv
->rps
.rp0_freq
= dev_priv
->rps
.max_freq
;
4198 DRM_DEBUG_DRIVER("max GPU freq: %d MHz (%u)\n",
4199 vlv_gpu_freq(dev_priv
, dev_priv
->rps
.max_freq
),
4200 dev_priv
->rps
.max_freq
);
4202 dev_priv
->rps
.efficient_freq
= cherryview_rps_rpe_freq(dev_priv
);
4203 DRM_DEBUG_DRIVER("RPe GPU freq: %d MHz (%u)\n",
4204 vlv_gpu_freq(dev_priv
, dev_priv
->rps
.efficient_freq
),
4205 dev_priv
->rps
.efficient_freq
);
4207 dev_priv
->rps
.rp1_freq
= cherryview_rps_guar_freq(dev_priv
);
4208 DRM_DEBUG_DRIVER("RP1(Guar) GPU freq: %d MHz (%u)\n",
4209 vlv_gpu_freq(dev_priv
, dev_priv
->rps
.rp1_freq
),
4210 dev_priv
->rps
.rp1_freq
);
4212 dev_priv
->rps
.min_freq
= cherryview_rps_min_freq(dev_priv
);
4213 DRM_DEBUG_DRIVER("min GPU freq: %d MHz (%u)\n",
4214 vlv_gpu_freq(dev_priv
, dev_priv
->rps
.min_freq
),
4215 dev_priv
->rps
.min_freq
);
4217 /* Preserve min/max settings in case of re-init */
4218 if (dev_priv
->rps
.max_freq_softlimit
== 0)
4219 dev_priv
->rps
.max_freq_softlimit
= dev_priv
->rps
.max_freq
;
4221 if (dev_priv
->rps
.min_freq_softlimit
== 0)
4222 dev_priv
->rps
.min_freq_softlimit
= dev_priv
->rps
.min_freq
;
4224 mutex_unlock(&dev_priv
->rps
.hw_lock
);
4227 static void valleyview_cleanup_gt_powersave(struct drm_device
*dev
)
4229 valleyview_cleanup_pctx(dev
);
4232 static void cherryview_enable_rps(struct drm_device
*dev
)
4234 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4235 struct intel_engine_cs
*ring
;
4236 u32 gtfifodbg
, val
, rc6_mode
= 0, pcbr
;
4239 WARN_ON(!mutex_is_locked(&dev_priv
->rps
.hw_lock
));
4241 gtfifodbg
= I915_READ(GTFIFODBG
);
4243 DRM_DEBUG_DRIVER("GT fifo had a previous error %x\n",
4245 I915_WRITE(GTFIFODBG
, gtfifodbg
);
4248 cherryview_check_pctx(dev_priv
);
4250 /* 1a & 1b: Get forcewake during program sequence. Although the driver
4251 * hasn't enabled a state yet where we need forcewake, BIOS may have.*/
4252 gen6_gt_force_wake_get(dev_priv
, FORCEWAKE_ALL
);
4254 /* 2a: Program RC6 thresholds.*/
4255 I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT
, 40 << 16);
4256 I915_WRITE(GEN6_RC_EVALUATION_INTERVAL
, 125000); /* 12500 * 1280ns */
4257 I915_WRITE(GEN6_RC_IDLE_HYSTERSIS
, 25); /* 25 * 1280ns */
4259 for_each_ring(ring
, dev_priv
, i
)
4260 I915_WRITE(RING_MAX_IDLE(ring
->mmio_base
), 10);
4261 I915_WRITE(GEN6_RC_SLEEP
, 0);
4263 I915_WRITE(GEN6_RC6_THRESHOLD
, 50000); /* 50/125ms per EI */
4265 /* allows RC6 residency counter to work */
4266 I915_WRITE(VLV_COUNTER_CONTROL
,
4267 _MASKED_BIT_ENABLE(VLV_COUNT_RANGE_HIGH
|
4268 VLV_MEDIA_RC6_COUNT_EN
|
4269 VLV_RENDER_RC6_COUNT_EN
));
4271 /* For now we assume BIOS is allocating and populating the PCBR */
4272 pcbr
= I915_READ(VLV_PCBR
);
4274 DRM_DEBUG_DRIVER("PCBR offset : 0x%x\n", pcbr
);
4277 if ((intel_enable_rc6(dev
) & INTEL_RC6_ENABLE
) &&
4278 (pcbr
>> VLV_PCBR_ADDR_SHIFT
))
4279 rc6_mode
= GEN6_RC_CTL_EI_MODE(1);
4281 I915_WRITE(GEN6_RC_CONTROL
, rc6_mode
);
4283 /* 4 Program defaults and thresholds for RPS*/
4284 I915_WRITE(GEN6_RP_UP_THRESHOLD
, 59400);
4285 I915_WRITE(GEN6_RP_DOWN_THRESHOLD
, 245000);
4286 I915_WRITE(GEN6_RP_UP_EI
, 66000);
4287 I915_WRITE(GEN6_RP_DOWN_EI
, 350000);
4289 I915_WRITE(GEN6_RP_IDLE_HYSTERSIS
, 10);
4291 /* WaDisablePwrmtrEvent:chv (pre-production hw) */
4292 I915_WRITE(0xA80C, I915_READ(0xA80C) & 0x00ffffff);
4293 I915_WRITE(0xA810, I915_READ(0xA810) & 0xffffff00);
4296 I915_WRITE(GEN6_RP_CONTROL
,
4297 GEN6_RP_MEDIA_HW_NORMAL_MODE
|
4298 GEN6_RP_MEDIA_IS_GFX
| /* WaSetMaskForGfxBusyness:chv (pre-production hw ?) */
4300 GEN6_RP_UP_BUSY_AVG
|
4301 GEN6_RP_DOWN_IDLE_AVG
);
4303 val
= vlv_punit_read(dev_priv
, PUNIT_REG_GPU_FREQ_STS
);
4305 DRM_DEBUG_DRIVER("GPLL enabled? %s\n", val
& 0x10 ? "yes" : "no");
4306 DRM_DEBUG_DRIVER("GPU status: 0x%08x\n", val
);
4308 dev_priv
->rps
.cur_freq
= (val
>> 8) & 0xff;
4309 DRM_DEBUG_DRIVER("current GPU freq: %d MHz (%u)\n",
4310 vlv_gpu_freq(dev_priv
, dev_priv
->rps
.cur_freq
),
4311 dev_priv
->rps
.cur_freq
);
4313 DRM_DEBUG_DRIVER("setting GPU freq to %d MHz (%u)\n",
4314 vlv_gpu_freq(dev_priv
, dev_priv
->rps
.efficient_freq
),
4315 dev_priv
->rps
.efficient_freq
);
4317 valleyview_set_rps(dev_priv
->dev
, dev_priv
->rps
.efficient_freq
);
4319 gen8_enable_rps_interrupts(dev
);
4321 gen6_gt_force_wake_put(dev_priv
, FORCEWAKE_ALL
);
4324 static void valleyview_enable_rps(struct drm_device
*dev
)
4326 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4327 struct intel_engine_cs
*ring
;
4328 u32 gtfifodbg
, val
, rc6_mode
= 0;
4331 WARN_ON(!mutex_is_locked(&dev_priv
->rps
.hw_lock
));
4333 valleyview_check_pctx(dev_priv
);
4335 if ((gtfifodbg
= I915_READ(GTFIFODBG
))) {
4336 DRM_DEBUG_DRIVER("GT fifo had a previous error %x\n",
4338 I915_WRITE(GTFIFODBG
, gtfifodbg
);
4341 /* If VLV, Forcewake all wells, else re-direct to regular path */
4342 gen6_gt_force_wake_get(dev_priv
, FORCEWAKE_ALL
);
4344 I915_WRITE(GEN6_RP_UP_THRESHOLD
, 59400);
4345 I915_WRITE(GEN6_RP_DOWN_THRESHOLD
, 245000);
4346 I915_WRITE(GEN6_RP_UP_EI
, 66000);
4347 I915_WRITE(GEN6_RP_DOWN_EI
, 350000);
4349 I915_WRITE(GEN6_RP_IDLE_HYSTERSIS
, 10);
4350 I915_WRITE(GEN6_RP_DOWN_TIMEOUT
, 0xf4240);
4352 I915_WRITE(GEN6_RP_CONTROL
,
4353 GEN6_RP_MEDIA_TURBO
|
4354 GEN6_RP_MEDIA_HW_NORMAL_MODE
|
4355 GEN6_RP_MEDIA_IS_GFX
|
4357 GEN6_RP_UP_BUSY_AVG
|
4358 GEN6_RP_DOWN_IDLE_CONT
);
4360 I915_WRITE(GEN6_RC6_WAKE_RATE_LIMIT
, 0x00280000);
4361 I915_WRITE(GEN6_RC_EVALUATION_INTERVAL
, 125000);
4362 I915_WRITE(GEN6_RC_IDLE_HYSTERSIS
, 25);
4364 for_each_ring(ring
, dev_priv
, i
)
4365 I915_WRITE(RING_MAX_IDLE(ring
->mmio_base
), 10);
4367 I915_WRITE(GEN6_RC6_THRESHOLD
, 0x557);
4369 /* allows RC6 residency counter to work */
4370 I915_WRITE(VLV_COUNTER_CONTROL
,
4371 _MASKED_BIT_ENABLE(VLV_MEDIA_RC0_COUNT_EN
|
4372 VLV_RENDER_RC0_COUNT_EN
|
4373 VLV_MEDIA_RC6_COUNT_EN
|
4374 VLV_RENDER_RC6_COUNT_EN
));
4376 if (intel_enable_rc6(dev
) & INTEL_RC6_ENABLE
)
4377 rc6_mode
= GEN7_RC_CTL_TO_MODE
| VLV_RC_CTL_CTX_RST_PARALLEL
;
4379 intel_print_rc6_info(dev
, rc6_mode
);
4381 I915_WRITE(GEN6_RC_CONTROL
, rc6_mode
);
4383 val
= vlv_punit_read(dev_priv
, PUNIT_REG_GPU_FREQ_STS
);
4385 DRM_DEBUG_DRIVER("GPLL enabled? %s\n", val
& 0x10 ? "yes" : "no");
4386 DRM_DEBUG_DRIVER("GPU status: 0x%08x\n", val
);
4388 dev_priv
->rps
.cur_freq
= (val
>> 8) & 0xff;
4389 DRM_DEBUG_DRIVER("current GPU freq: %d MHz (%u)\n",
4390 vlv_gpu_freq(dev_priv
, dev_priv
->rps
.cur_freq
),
4391 dev_priv
->rps
.cur_freq
);
4393 DRM_DEBUG_DRIVER("setting GPU freq to %d MHz (%u)\n",
4394 vlv_gpu_freq(dev_priv
, dev_priv
->rps
.efficient_freq
),
4395 dev_priv
->rps
.efficient_freq
);
4397 valleyview_set_rps(dev_priv
->dev
, dev_priv
->rps
.efficient_freq
);
4399 gen6_enable_rps_interrupts(dev
);
4401 gen6_gt_force_wake_put(dev_priv
, FORCEWAKE_ALL
);
4404 void ironlake_teardown_rc6(struct drm_device
*dev
)
4406 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4408 if (dev_priv
->ips
.renderctx
) {
4409 i915_gem_object_ggtt_unpin(dev_priv
->ips
.renderctx
);
4410 drm_gem_object_unreference(&dev_priv
->ips
.renderctx
->base
);
4411 dev_priv
->ips
.renderctx
= NULL
;
4414 if (dev_priv
->ips
.pwrctx
) {
4415 i915_gem_object_ggtt_unpin(dev_priv
->ips
.pwrctx
);
4416 drm_gem_object_unreference(&dev_priv
->ips
.pwrctx
->base
);
4417 dev_priv
->ips
.pwrctx
= NULL
;
4421 static void ironlake_disable_rc6(struct drm_device
*dev
)
4423 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4425 if (I915_READ(PWRCTXA
)) {
4426 /* Wake the GPU, prevent RC6, then restore RSTDBYCTL */
4427 I915_WRITE(RSTDBYCTL
, I915_READ(RSTDBYCTL
) | RCX_SW_EXIT
);
4428 wait_for(((I915_READ(RSTDBYCTL
) & RSX_STATUS_MASK
) == RSX_STATUS_ON
),
4431 I915_WRITE(PWRCTXA
, 0);
4432 POSTING_READ(PWRCTXA
);
4434 I915_WRITE(RSTDBYCTL
, I915_READ(RSTDBYCTL
) & ~RCX_SW_EXIT
);
4435 POSTING_READ(RSTDBYCTL
);
4439 static int ironlake_setup_rc6(struct drm_device
*dev
)
4441 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4443 if (dev_priv
->ips
.renderctx
== NULL
)
4444 dev_priv
->ips
.renderctx
= intel_alloc_context_page(dev
);
4445 if (!dev_priv
->ips
.renderctx
)
4448 if (dev_priv
->ips
.pwrctx
== NULL
)
4449 dev_priv
->ips
.pwrctx
= intel_alloc_context_page(dev
);
4450 if (!dev_priv
->ips
.pwrctx
) {
4451 ironlake_teardown_rc6(dev
);
4458 static void ironlake_enable_rc6(struct drm_device
*dev
)
4460 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
4461 struct intel_engine_cs
*ring
= &dev_priv
->ring
[RCS
];
4462 bool was_interruptible
;
4465 /* rc6 disabled by default due to repeated reports of hanging during
4468 if (!intel_enable_rc6(dev
))
4471 WARN_ON(!mutex_is_locked(&dev
->struct_mutex
));
4473 ret
= ironlake_setup_rc6(dev
);
4477 was_interruptible
= dev_priv
->mm
.interruptible
;
4478 dev_priv
->mm
.interruptible
= false;
4481 * GPU can automatically power down the render unit if given a page
4484 ret
= intel_ring_begin(ring
, 6);
4486 ironlake_teardown_rc6(dev
);
4487 dev_priv
->mm
.interruptible
= was_interruptible
;
4491 intel_ring_emit(ring
, MI_SUSPEND_FLUSH
| MI_SUSPEND_FLUSH_EN
);
4492 intel_ring_emit(ring
, MI_SET_CONTEXT
);
4493 intel_ring_emit(ring
, i915_gem_obj_ggtt_offset(dev_priv
->ips
.renderctx
) |
4495 MI_SAVE_EXT_STATE_EN
|
4496 MI_RESTORE_EXT_STATE_EN
|
4497 MI_RESTORE_INHIBIT
);
4498 intel_ring_emit(ring
, MI_SUSPEND_FLUSH
);
4499 intel_ring_emit(ring
, MI_NOOP
);
4500 intel_ring_emit(ring
, MI_FLUSH
);
4501 intel_ring_advance(ring
);
4504 * Wait for the command parser to advance past MI_SET_CONTEXT. The HW
4505 * does an implicit flush, combined with MI_FLUSH above, it should be
4506 * safe to assume that renderctx is valid
4508 ret
= intel_ring_idle(ring
);
4509 dev_priv
->mm
.interruptible
= was_interruptible
;
4511 DRM_ERROR("failed to enable ironlake power savings\n");
4512 ironlake_teardown_rc6(dev
);
4516 I915_WRITE(PWRCTXA
, i915_gem_obj_ggtt_offset(dev_priv
->ips
.pwrctx
) | PWRCTX_EN
);
4517 I915_WRITE(RSTDBYCTL
, I915_READ(RSTDBYCTL
) & ~RCX_SW_EXIT
);
4519 intel_print_rc6_info(dev
, GEN6_RC_CTL_RC6_ENABLE
);
4522 static unsigned long intel_pxfreq(u32 vidfreq
)
4525 int div
= (vidfreq
& 0x3f0000) >> 16;
4526 int post
= (vidfreq
& 0x3000) >> 12;
4527 int pre
= (vidfreq
& 0x7);
4532 freq
= ((div
* 133333) / ((1<<post
) * pre
));
4537 static const struct cparams
{
4543 { 1, 1333, 301, 28664 },
4544 { 1, 1066, 294, 24460 },
4545 { 1, 800, 294, 25192 },
4546 { 0, 1333, 276, 27605 },
4547 { 0, 1066, 276, 27605 },
4548 { 0, 800, 231, 23784 },
4551 static unsigned long __i915_chipset_val(struct drm_i915_private
*dev_priv
)
4553 u64 total_count
, diff
, ret
;
4554 u32 count1
, count2
, count3
, m
= 0, c
= 0;
4555 unsigned long now
= jiffies_to_msecs(jiffies
), diff1
;
4558 assert_spin_locked(&mchdev_lock
);
4560 diff1
= now
- dev_priv
->ips
.last_time1
;
4562 /* Prevent division-by-zero if we are asking too fast.
4563 * Also, we don't get interesting results if we are polling
4564 * faster than once in 10ms, so just return the saved value
4568 return dev_priv
->ips
.chipset_power
;
4570 count1
= I915_READ(DMIEC
);
4571 count2
= I915_READ(DDREC
);
4572 count3
= I915_READ(CSIEC
);
4574 total_count
= count1
+ count2
+ count3
;
4576 /* FIXME: handle per-counter overflow */
4577 if (total_count
< dev_priv
->ips
.last_count1
) {
4578 diff
= ~0UL - dev_priv
->ips
.last_count1
;
4579 diff
+= total_count
;
4581 diff
= total_count
- dev_priv
->ips
.last_count1
;
4584 for (i
= 0; i
< ARRAY_SIZE(cparams
); i
++) {
4585 if (cparams
[i
].i
== dev_priv
->ips
.c_m
&&
4586 cparams
[i
].t
== dev_priv
->ips
.r_t
) {
4593 diff
= div_u64(diff
, diff1
);
4594 ret
= ((m
* diff
) + c
);
4595 ret
= div_u64(ret
, 10);
4597 dev_priv
->ips
.last_count1
= total_count
;
4598 dev_priv
->ips
.last_time1
= now
;
4600 dev_priv
->ips
.chipset_power
= ret
;
4605 unsigned long i915_chipset_val(struct drm_i915_private
*dev_priv
)
4607 struct drm_device
*dev
= dev_priv
->dev
;
4610 if (INTEL_INFO(dev
)->gen
!= 5)
4613 spin_lock_irq(&mchdev_lock
);
4615 val
= __i915_chipset_val(dev_priv
);
4617 spin_unlock_irq(&mchdev_lock
);
4622 unsigned long i915_mch_val(struct drm_i915_private
*dev_priv
)
4624 unsigned long m
, x
, b
;
4627 tsfs
= I915_READ(TSFS
);
4629 m
= ((tsfs
& TSFS_SLOPE_MASK
) >> TSFS_SLOPE_SHIFT
);
4630 x
= I915_READ8(TR1
);
4632 b
= tsfs
& TSFS_INTR_MASK
;
4634 return ((m
* x
) / 127) - b
;
4637 static u16
pvid_to_extvid(struct drm_i915_private
*dev_priv
, u8 pxvid
)
4639 struct drm_device
*dev
= dev_priv
->dev
;
4640 static const struct v_table
{
4641 u16 vd
; /* in .1 mil */
4642 u16 vm
; /* in .1 mil */
4773 if (INTEL_INFO(dev
)->is_mobile
)
4774 return v_table
[pxvid
].vm
;
4776 return v_table
[pxvid
].vd
;
4779 static void __i915_update_gfx_val(struct drm_i915_private
*dev_priv
)
4781 u64 now
, diff
, diffms
;
4784 assert_spin_locked(&mchdev_lock
);
4786 now
= ktime_get_raw_ns();
4787 diffms
= now
- dev_priv
->ips
.last_time2
;
4788 do_div(diffms
, NSEC_PER_MSEC
);
4790 /* Don't divide by 0 */
4794 count
= I915_READ(GFXEC
);
4796 if (count
< dev_priv
->ips
.last_count2
) {
4797 diff
= ~0UL - dev_priv
->ips
.last_count2
;
4800 diff
= count
- dev_priv
->ips
.last_count2
;
4803 dev_priv
->ips
.last_count2
= count
;
4804 dev_priv
->ips
.last_time2
= now
;
4806 /* More magic constants... */
4808 diff
= div_u64(diff
, diffms
* 10);
4809 dev_priv
->ips
.gfx_power
= diff
;
4812 void i915_update_gfx_val(struct drm_i915_private
*dev_priv
)
4814 struct drm_device
*dev
= dev_priv
->dev
;
4816 if (INTEL_INFO(dev
)->gen
!= 5)
4819 spin_lock_irq(&mchdev_lock
);
4821 __i915_update_gfx_val(dev_priv
);
4823 spin_unlock_irq(&mchdev_lock
);
4826 static unsigned long __i915_gfx_val(struct drm_i915_private
*dev_priv
)
4828 unsigned long t
, corr
, state1
, corr2
, state2
;
4831 assert_spin_locked(&mchdev_lock
);
4833 pxvid
= I915_READ(PXVFREQ_BASE
+ (dev_priv
->rps
.cur_freq
* 4));
4834 pxvid
= (pxvid
>> 24) & 0x7f;
4835 ext_v
= pvid_to_extvid(dev_priv
, pxvid
);
4839 t
= i915_mch_val(dev_priv
);
4841 /* Revel in the empirically derived constants */
4843 /* Correction factor in 1/100000 units */
4845 corr
= ((t
* 2349) + 135940);
4847 corr
= ((t
* 964) + 29317);
4849 corr
= ((t
* 301) + 1004);
4851 corr
= corr
* ((150142 * state1
) / 10000 - 78642);
4853 corr2
= (corr
* dev_priv
->ips
.corr
);
4855 state2
= (corr2
* state1
) / 10000;
4856 state2
/= 100; /* convert to mW */
4858 __i915_update_gfx_val(dev_priv
);
4860 return dev_priv
->ips
.gfx_power
+ state2
;
4863 unsigned long i915_gfx_val(struct drm_i915_private
*dev_priv
)
4865 struct drm_device
*dev
= dev_priv
->dev
;
4868 if (INTEL_INFO(dev
)->gen
!= 5)
4871 spin_lock_irq(&mchdev_lock
);
4873 val
= __i915_gfx_val(dev_priv
);
4875 spin_unlock_irq(&mchdev_lock
);
4881 * i915_read_mch_val - return value for IPS use
4883 * Calculate and return a value for the IPS driver to use when deciding whether
4884 * we have thermal and power headroom to increase CPU or GPU power budget.
4886 unsigned long i915_read_mch_val(void)
4888 struct drm_i915_private
*dev_priv
;
4889 unsigned long chipset_val
, graphics_val
, ret
= 0;
4891 spin_lock_irq(&mchdev_lock
);
4894 dev_priv
= i915_mch_dev
;
4896 chipset_val
= __i915_chipset_val(dev_priv
);
4897 graphics_val
= __i915_gfx_val(dev_priv
);
4899 ret
= chipset_val
+ graphics_val
;
4902 spin_unlock_irq(&mchdev_lock
);
4906 EXPORT_SYMBOL_GPL(i915_read_mch_val
);
4909 * i915_gpu_raise - raise GPU frequency limit
4911 * Raise the limit; IPS indicates we have thermal headroom.
4913 bool i915_gpu_raise(void)
4915 struct drm_i915_private
*dev_priv
;
4918 spin_lock_irq(&mchdev_lock
);
4919 if (!i915_mch_dev
) {
4923 dev_priv
= i915_mch_dev
;
4925 if (dev_priv
->ips
.max_delay
> dev_priv
->ips
.fmax
)
4926 dev_priv
->ips
.max_delay
--;
4929 spin_unlock_irq(&mchdev_lock
);
4933 EXPORT_SYMBOL_GPL(i915_gpu_raise
);
4936 * i915_gpu_lower - lower GPU frequency limit
4938 * IPS indicates we're close to a thermal limit, so throttle back the GPU
4939 * frequency maximum.
4941 bool i915_gpu_lower(void)
4943 struct drm_i915_private
*dev_priv
;
4946 spin_lock_irq(&mchdev_lock
);
4947 if (!i915_mch_dev
) {
4951 dev_priv
= i915_mch_dev
;
4953 if (dev_priv
->ips
.max_delay
< dev_priv
->ips
.min_delay
)
4954 dev_priv
->ips
.max_delay
++;
4957 spin_unlock_irq(&mchdev_lock
);
4961 EXPORT_SYMBOL_GPL(i915_gpu_lower
);
4964 * i915_gpu_busy - indicate GPU business to IPS
4966 * Tell the IPS driver whether or not the GPU is busy.
4968 bool i915_gpu_busy(void)
4970 struct drm_i915_private
*dev_priv
;
4971 struct intel_engine_cs
*ring
;
4975 spin_lock_irq(&mchdev_lock
);
4978 dev_priv
= i915_mch_dev
;
4980 for_each_ring(ring
, dev_priv
, i
)
4981 ret
|= !list_empty(&ring
->request_list
);
4984 spin_unlock_irq(&mchdev_lock
);
4988 EXPORT_SYMBOL_GPL(i915_gpu_busy
);
4991 * i915_gpu_turbo_disable - disable graphics turbo
4993 * Disable graphics turbo by resetting the max frequency and setting the
4994 * current frequency to the default.
4996 bool i915_gpu_turbo_disable(void)
4998 struct drm_i915_private
*dev_priv
;
5001 spin_lock_irq(&mchdev_lock
);
5002 if (!i915_mch_dev
) {
5006 dev_priv
= i915_mch_dev
;
5008 dev_priv
->ips
.max_delay
= dev_priv
->ips
.fstart
;
5010 if (!ironlake_set_drps(dev_priv
->dev
, dev_priv
->ips
.fstart
))
5014 spin_unlock_irq(&mchdev_lock
);
5018 EXPORT_SYMBOL_GPL(i915_gpu_turbo_disable
);
5021 * Tells the intel_ips driver that the i915 driver is now loaded, if
5022 * IPS got loaded first.
5024 * This awkward dance is so that neither module has to depend on the
5025 * other in order for IPS to do the appropriate communication of
5026 * GPU turbo limits to i915.
5029 ips_ping_for_i915_load(void)
5033 link
= symbol_get(ips_link_to_i915_driver
);
5036 symbol_put(ips_link_to_i915_driver
);
5040 void intel_gpu_ips_init(struct drm_i915_private
*dev_priv
)
5042 /* We only register the i915 ips part with intel-ips once everything is
5043 * set up, to avoid intel-ips sneaking in and reading bogus values. */
5044 spin_lock_irq(&mchdev_lock
);
5045 i915_mch_dev
= dev_priv
;
5046 spin_unlock_irq(&mchdev_lock
);
5048 ips_ping_for_i915_load();
5051 void intel_gpu_ips_teardown(void)
5053 spin_lock_irq(&mchdev_lock
);
5054 i915_mch_dev
= NULL
;
5055 spin_unlock_irq(&mchdev_lock
);
5058 static void intel_init_emon(struct drm_device
*dev
)
5060 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5065 /* Disable to program */
5069 /* Program energy weights for various events */
5070 I915_WRITE(SDEW
, 0x15040d00);
5071 I915_WRITE(CSIEW0
, 0x007f0000);
5072 I915_WRITE(CSIEW1
, 0x1e220004);
5073 I915_WRITE(CSIEW2
, 0x04000004);
5075 for (i
= 0; i
< 5; i
++)
5076 I915_WRITE(PEW
+ (i
* 4), 0);
5077 for (i
= 0; i
< 3; i
++)
5078 I915_WRITE(DEW
+ (i
* 4), 0);
5080 /* Program P-state weights to account for frequency power adjustment */
5081 for (i
= 0; i
< 16; i
++) {
5082 u32 pxvidfreq
= I915_READ(PXVFREQ_BASE
+ (i
* 4));
5083 unsigned long freq
= intel_pxfreq(pxvidfreq
);
5084 unsigned long vid
= (pxvidfreq
& PXVFREQ_PX_MASK
) >>
5089 val
*= (freq
/ 1000);
5091 val
/= (127*127*900);
5093 DRM_ERROR("bad pxval: %ld\n", val
);
5096 /* Render standby states get 0 weight */
5100 for (i
= 0; i
< 4; i
++) {
5101 u32 val
= (pxw
[i
*4] << 24) | (pxw
[(i
*4)+1] << 16) |
5102 (pxw
[(i
*4)+2] << 8) | (pxw
[(i
*4)+3]);
5103 I915_WRITE(PXW
+ (i
* 4), val
);
5106 /* Adjust magic regs to magic values (more experimental results) */
5107 I915_WRITE(OGW0
, 0);
5108 I915_WRITE(OGW1
, 0);
5109 I915_WRITE(EG0
, 0x00007f00);
5110 I915_WRITE(EG1
, 0x0000000e);
5111 I915_WRITE(EG2
, 0x000e0000);
5112 I915_WRITE(EG3
, 0x68000300);
5113 I915_WRITE(EG4
, 0x42000000);
5114 I915_WRITE(EG5
, 0x00140031);
5118 for (i
= 0; i
< 8; i
++)
5119 I915_WRITE(PXWL
+ (i
* 4), 0);
5121 /* Enable PMON + select events */
5122 I915_WRITE(ECR
, 0x80000019);
5124 lcfuse
= I915_READ(LCFUSE02
);
5126 dev_priv
->ips
.corr
= (lcfuse
& LCFUSE_HIV_MASK
);
5129 void intel_init_gt_powersave(struct drm_device
*dev
)
5131 i915
.enable_rc6
= sanitize_rc6_option(dev
, i915
.enable_rc6
);
5133 if (IS_CHERRYVIEW(dev
))
5134 cherryview_init_gt_powersave(dev
);
5135 else if (IS_VALLEYVIEW(dev
))
5136 valleyview_init_gt_powersave(dev
);
5139 void intel_cleanup_gt_powersave(struct drm_device
*dev
)
5141 if (IS_CHERRYVIEW(dev
))
5143 else if (IS_VALLEYVIEW(dev
))
5144 valleyview_cleanup_gt_powersave(dev
);
5148 * intel_suspend_gt_powersave - suspend PM work and helper threads
5151 * We don't want to disable RC6 or other features here, we just want
5152 * to make sure any work we've queued has finished and won't bother
5153 * us while we're suspended.
5155 void intel_suspend_gt_powersave(struct drm_device
*dev
)
5157 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5159 /* Interrupts should be disabled already to avoid re-arming. */
5160 WARN_ON(intel_irqs_enabled(dev_priv
));
5162 flush_delayed_work(&dev_priv
->rps
.delayed_resume_work
);
5164 cancel_work_sync(&dev_priv
->rps
.work
);
5166 /* Force GPU to min freq during suspend */
5167 gen6_rps_idle(dev_priv
);
5170 void intel_disable_gt_powersave(struct drm_device
*dev
)
5172 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5174 /* Interrupts should be disabled already to avoid re-arming. */
5175 WARN_ON(intel_irqs_enabled(dev_priv
));
5177 if (IS_IRONLAKE_M(dev
)) {
5178 ironlake_disable_drps(dev
);
5179 ironlake_disable_rc6(dev
);
5180 } else if (INTEL_INFO(dev
)->gen
>= 6) {
5181 intel_suspend_gt_powersave(dev
);
5183 mutex_lock(&dev_priv
->rps
.hw_lock
);
5184 if (IS_CHERRYVIEW(dev
))
5185 cherryview_disable_rps(dev
);
5186 else if (IS_VALLEYVIEW(dev
))
5187 valleyview_disable_rps(dev
);
5189 gen6_disable_rps(dev
);
5190 dev_priv
->rps
.enabled
= false;
5191 mutex_unlock(&dev_priv
->rps
.hw_lock
);
5195 static void intel_gen6_powersave_work(struct work_struct
*work
)
5197 struct drm_i915_private
*dev_priv
=
5198 container_of(work
, struct drm_i915_private
,
5199 rps
.delayed_resume_work
.work
);
5200 struct drm_device
*dev
= dev_priv
->dev
;
5202 mutex_lock(&dev_priv
->rps
.hw_lock
);
5204 if (IS_CHERRYVIEW(dev
)) {
5205 cherryview_enable_rps(dev
);
5206 } else if (IS_VALLEYVIEW(dev
)) {
5207 valleyview_enable_rps(dev
);
5208 } else if (IS_BROADWELL(dev
)) {
5209 gen8_enable_rps(dev
);
5210 __gen6_update_ring_freq(dev
);
5212 gen6_enable_rps(dev
);
5213 __gen6_update_ring_freq(dev
);
5215 dev_priv
->rps
.enabled
= true;
5216 mutex_unlock(&dev_priv
->rps
.hw_lock
);
5218 intel_runtime_pm_put(dev_priv
);
5221 void intel_enable_gt_powersave(struct drm_device
*dev
)
5223 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5225 if (IS_IRONLAKE_M(dev
)) {
5226 mutex_lock(&dev
->struct_mutex
);
5227 ironlake_enable_drps(dev
);
5228 ironlake_enable_rc6(dev
);
5229 intel_init_emon(dev
);
5230 mutex_unlock(&dev
->struct_mutex
);
5231 } else if (INTEL_INFO(dev
)->gen
>= 6) {
5233 * PCU communication is slow and this doesn't need to be
5234 * done at any specific time, so do this out of our fast path
5235 * to make resume and init faster.
5237 * We depend on the HW RC6 power context save/restore
5238 * mechanism when entering D3 through runtime PM suspend. So
5239 * disable RPM until RPS/RC6 is properly setup. We can only
5240 * get here via the driver load/system resume/runtime resume
5241 * paths, so the _noresume version is enough (and in case of
5242 * runtime resume it's necessary).
5244 if (schedule_delayed_work(&dev_priv
->rps
.delayed_resume_work
,
5245 round_jiffies_up_relative(HZ
)))
5246 intel_runtime_pm_get_noresume(dev_priv
);
5250 void intel_reset_gt_powersave(struct drm_device
*dev
)
5252 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5254 dev_priv
->rps
.enabled
= false;
5255 intel_enable_gt_powersave(dev
);
5258 static void ibx_init_clock_gating(struct drm_device
*dev
)
5260 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5263 * On Ibex Peak and Cougar Point, we need to disable clock
5264 * gating for the panel power sequencer or it will fail to
5265 * start up when no ports are active.
5267 I915_WRITE(SOUTH_DSPCLK_GATE_D
, PCH_DPLSUNIT_CLOCK_GATE_DISABLE
);
5270 static void g4x_disable_trickle_feed(struct drm_device
*dev
)
5272 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5275 for_each_pipe(dev_priv
, pipe
) {
5276 I915_WRITE(DSPCNTR(pipe
),
5277 I915_READ(DSPCNTR(pipe
)) |
5278 DISPPLANE_TRICKLE_FEED_DISABLE
);
5279 intel_flush_primary_plane(dev_priv
, pipe
);
5283 static void ilk_init_lp_watermarks(struct drm_device
*dev
)
5285 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5287 I915_WRITE(WM3_LP_ILK
, I915_READ(WM3_LP_ILK
) & ~WM1_LP_SR_EN
);
5288 I915_WRITE(WM2_LP_ILK
, I915_READ(WM2_LP_ILK
) & ~WM1_LP_SR_EN
);
5289 I915_WRITE(WM1_LP_ILK
, I915_READ(WM1_LP_ILK
) & ~WM1_LP_SR_EN
);
5292 * Don't touch WM1S_LP_EN here.
5293 * Doing so could cause underruns.
5297 static void ironlake_init_clock_gating(struct drm_device
*dev
)
5299 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5300 uint32_t dspclk_gate
= ILK_VRHUNIT_CLOCK_GATE_DISABLE
;
5304 * WaFbcDisableDpfcClockGating:ilk
5306 dspclk_gate
|= ILK_DPFCRUNIT_CLOCK_GATE_DISABLE
|
5307 ILK_DPFCUNIT_CLOCK_GATE_DISABLE
|
5308 ILK_DPFDUNIT_CLOCK_GATE_ENABLE
;
5310 I915_WRITE(PCH_3DCGDIS0
,
5311 MARIUNIT_CLOCK_GATE_DISABLE
|
5312 SVSMUNIT_CLOCK_GATE_DISABLE
);
5313 I915_WRITE(PCH_3DCGDIS1
,
5314 VFMUNIT_CLOCK_GATE_DISABLE
);
5317 * According to the spec the following bits should be set in
5318 * order to enable memory self-refresh
5319 * The bit 22/21 of 0x42004
5320 * The bit 5 of 0x42020
5321 * The bit 15 of 0x45000
5323 I915_WRITE(ILK_DISPLAY_CHICKEN2
,
5324 (I915_READ(ILK_DISPLAY_CHICKEN2
) |
5325 ILK_DPARB_GATE
| ILK_VSDPFD_FULL
));
5326 dspclk_gate
|= ILK_DPARBUNIT_CLOCK_GATE_ENABLE
;
5327 I915_WRITE(DISP_ARB_CTL
,
5328 (I915_READ(DISP_ARB_CTL
) |
5331 ilk_init_lp_watermarks(dev
);
5334 * Based on the document from hardware guys the following bits
5335 * should be set unconditionally in order to enable FBC.
5336 * The bit 22 of 0x42000
5337 * The bit 22 of 0x42004
5338 * The bit 7,8,9 of 0x42020.
5340 if (IS_IRONLAKE_M(dev
)) {
5341 /* WaFbcAsynchFlipDisableFbcQueue:ilk */
5342 I915_WRITE(ILK_DISPLAY_CHICKEN1
,
5343 I915_READ(ILK_DISPLAY_CHICKEN1
) |
5345 I915_WRITE(ILK_DISPLAY_CHICKEN2
,
5346 I915_READ(ILK_DISPLAY_CHICKEN2
) |
5350 I915_WRITE(ILK_DSPCLK_GATE_D
, dspclk_gate
);
5352 I915_WRITE(ILK_DISPLAY_CHICKEN2
,
5353 I915_READ(ILK_DISPLAY_CHICKEN2
) |
5354 ILK_ELPIN_409_SELECT
);
5355 I915_WRITE(_3D_CHICKEN2
,
5356 _3D_CHICKEN2_WM_READ_PIPELINED
<< 16 |
5357 _3D_CHICKEN2_WM_READ_PIPELINED
);
5359 /* WaDisableRenderCachePipelinedFlush:ilk */
5360 I915_WRITE(CACHE_MODE_0
,
5361 _MASKED_BIT_ENABLE(CM0_PIPELINED_RENDER_FLUSH_DISABLE
));
5363 /* WaDisable_RenderCache_OperationalFlush:ilk */
5364 I915_WRITE(CACHE_MODE_0
, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE
));
5366 g4x_disable_trickle_feed(dev
);
5368 ibx_init_clock_gating(dev
);
5371 static void cpt_init_clock_gating(struct drm_device
*dev
)
5373 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5378 * On Ibex Peak and Cougar Point, we need to disable clock
5379 * gating for the panel power sequencer or it will fail to
5380 * start up when no ports are active.
5382 I915_WRITE(SOUTH_DSPCLK_GATE_D
, PCH_DPLSUNIT_CLOCK_GATE_DISABLE
|
5383 PCH_DPLUNIT_CLOCK_GATE_DISABLE
|
5384 PCH_CPUNIT_CLOCK_GATE_DISABLE
);
5385 I915_WRITE(SOUTH_CHICKEN2
, I915_READ(SOUTH_CHICKEN2
) |
5386 DPLS_EDP_PPS_FIX_DIS
);
5387 /* The below fixes the weird display corruption, a few pixels shifted
5388 * downward, on (only) LVDS of some HP laptops with IVY.
5390 for_each_pipe(dev_priv
, pipe
) {
5391 val
= I915_READ(TRANS_CHICKEN2(pipe
));
5392 val
|= TRANS_CHICKEN2_TIMING_OVERRIDE
;
5393 val
&= ~TRANS_CHICKEN2_FDI_POLARITY_REVERSED
;
5394 if (dev_priv
->vbt
.fdi_rx_polarity_inverted
)
5395 val
|= TRANS_CHICKEN2_FDI_POLARITY_REVERSED
;
5396 val
&= ~TRANS_CHICKEN2_FRAME_START_DELAY_MASK
;
5397 val
&= ~TRANS_CHICKEN2_DISABLE_DEEP_COLOR_COUNTER
;
5398 val
&= ~TRANS_CHICKEN2_DISABLE_DEEP_COLOR_MODESWITCH
;
5399 I915_WRITE(TRANS_CHICKEN2(pipe
), val
);
5401 /* WADP0ClockGatingDisable */
5402 for_each_pipe(dev_priv
, pipe
) {
5403 I915_WRITE(TRANS_CHICKEN1(pipe
),
5404 TRANS_CHICKEN1_DP0UNIT_GC_DISABLE
);
5408 static void gen6_check_mch_setup(struct drm_device
*dev
)
5410 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5413 tmp
= I915_READ(MCH_SSKPD
);
5414 if ((tmp
& MCH_SSKPD_WM0_MASK
) != MCH_SSKPD_WM0_VAL
)
5415 DRM_DEBUG_KMS("Wrong MCH_SSKPD value: 0x%08x This can cause underruns.\n",
5419 static void gen6_init_clock_gating(struct drm_device
*dev
)
5421 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5422 uint32_t dspclk_gate
= ILK_VRHUNIT_CLOCK_GATE_DISABLE
;
5424 I915_WRITE(ILK_DSPCLK_GATE_D
, dspclk_gate
);
5426 I915_WRITE(ILK_DISPLAY_CHICKEN2
,
5427 I915_READ(ILK_DISPLAY_CHICKEN2
) |
5428 ILK_ELPIN_409_SELECT
);
5430 /* WaDisableHiZPlanesWhenMSAAEnabled:snb */
5431 I915_WRITE(_3D_CHICKEN
,
5432 _MASKED_BIT_ENABLE(_3D_CHICKEN_HIZ_PLANE_DISABLE_MSAA_4X_SNB
));
5434 /* WaSetupGtModeTdRowDispatch:snb */
5435 if (IS_SNB_GT1(dev
))
5436 I915_WRITE(GEN6_GT_MODE
,
5437 _MASKED_BIT_ENABLE(GEN6_TD_FOUR_ROW_DISPATCH_DISABLE
));
5439 /* WaDisable_RenderCache_OperationalFlush:snb */
5440 I915_WRITE(CACHE_MODE_0
, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE
));
5443 * BSpec recoomends 8x4 when MSAA is used,
5444 * however in practice 16x4 seems fastest.
5446 * Note that PS/WM thread counts depend on the WIZ hashing
5447 * disable bit, which we don't touch here, but it's good
5448 * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM).
5450 I915_WRITE(GEN6_GT_MODE
,
5451 GEN6_WIZ_HASHING_MASK
| GEN6_WIZ_HASHING_16x4
);
5453 ilk_init_lp_watermarks(dev
);
5455 I915_WRITE(CACHE_MODE_0
,
5456 _MASKED_BIT_DISABLE(CM0_STC_EVICT_DISABLE_LRA_SNB
));
5458 I915_WRITE(GEN6_UCGCTL1
,
5459 I915_READ(GEN6_UCGCTL1
) |
5460 GEN6_BLBUNIT_CLOCK_GATE_DISABLE
|
5461 GEN6_CSUNIT_CLOCK_GATE_DISABLE
);
5463 /* According to the BSpec vol1g, bit 12 (RCPBUNIT) clock
5464 * gating disable must be set. Failure to set it results in
5465 * flickering pixels due to Z write ordering failures after
5466 * some amount of runtime in the Mesa "fire" demo, and Unigine
5467 * Sanctuary and Tropics, and apparently anything else with
5468 * alpha test or pixel discard.
5470 * According to the spec, bit 11 (RCCUNIT) must also be set,
5471 * but we didn't debug actual testcases to find it out.
5473 * WaDisableRCCUnitClockGating:snb
5474 * WaDisableRCPBUnitClockGating:snb
5476 I915_WRITE(GEN6_UCGCTL2
,
5477 GEN6_RCPBUNIT_CLOCK_GATE_DISABLE
|
5478 GEN6_RCCUNIT_CLOCK_GATE_DISABLE
);
5480 /* WaStripsFansDisableFastClipPerformanceFix:snb */
5481 I915_WRITE(_3D_CHICKEN3
,
5482 _MASKED_BIT_ENABLE(_3D_CHICKEN3_SF_DISABLE_FASTCLIP_CULL
));
5486 * "This bit must be set if 3DSTATE_CLIP clip mode is set to normal and
5487 * 3DSTATE_SF number of SF output attributes is more than 16."
5489 I915_WRITE(_3D_CHICKEN3
,
5490 _MASKED_BIT_ENABLE(_3D_CHICKEN3_SF_DISABLE_PIPELINED_ATTR_FETCH
));
5493 * According to the spec the following bits should be
5494 * set in order to enable memory self-refresh and fbc:
5495 * The bit21 and bit22 of 0x42000
5496 * The bit21 and bit22 of 0x42004
5497 * The bit5 and bit7 of 0x42020
5498 * The bit14 of 0x70180
5499 * The bit14 of 0x71180
5501 * WaFbcAsynchFlipDisableFbcQueue:snb
5503 I915_WRITE(ILK_DISPLAY_CHICKEN1
,
5504 I915_READ(ILK_DISPLAY_CHICKEN1
) |
5505 ILK_FBCQ_DIS
| ILK_PABSTRETCH_DIS
);
5506 I915_WRITE(ILK_DISPLAY_CHICKEN2
,
5507 I915_READ(ILK_DISPLAY_CHICKEN2
) |
5508 ILK_DPARB_GATE
| ILK_VSDPFD_FULL
);
5509 I915_WRITE(ILK_DSPCLK_GATE_D
,
5510 I915_READ(ILK_DSPCLK_GATE_D
) |
5511 ILK_DPARBUNIT_CLOCK_GATE_ENABLE
|
5512 ILK_DPFDUNIT_CLOCK_GATE_ENABLE
);
5514 g4x_disable_trickle_feed(dev
);
5516 cpt_init_clock_gating(dev
);
5518 gen6_check_mch_setup(dev
);
5521 static void gen7_setup_fixed_func_scheduler(struct drm_i915_private
*dev_priv
)
5523 uint32_t reg
= I915_READ(GEN7_FF_THREAD_MODE
);
5526 * WaVSThreadDispatchOverride:ivb,vlv
5528 * This actually overrides the dispatch
5529 * mode for all thread types.
5531 reg
&= ~GEN7_FF_SCHED_MASK
;
5532 reg
|= GEN7_FF_TS_SCHED_HW
;
5533 reg
|= GEN7_FF_VS_SCHED_HW
;
5534 reg
|= GEN7_FF_DS_SCHED_HW
;
5536 I915_WRITE(GEN7_FF_THREAD_MODE
, reg
);
5539 static void lpt_init_clock_gating(struct drm_device
*dev
)
5541 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5544 * TODO: this bit should only be enabled when really needed, then
5545 * disabled when not needed anymore in order to save power.
5547 if (dev_priv
->pch_id
== INTEL_PCH_LPT_LP_DEVICE_ID_TYPE
)
5548 I915_WRITE(SOUTH_DSPCLK_GATE_D
,
5549 I915_READ(SOUTH_DSPCLK_GATE_D
) |
5550 PCH_LP_PARTITION_LEVEL_DISABLE
);
5552 /* WADPOClockGatingDisable:hsw */
5553 I915_WRITE(_TRANSA_CHICKEN1
,
5554 I915_READ(_TRANSA_CHICKEN1
) |
5555 TRANS_CHICKEN1_DP0UNIT_GC_DISABLE
);
5558 static void lpt_suspend_hw(struct drm_device
*dev
)
5560 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5562 if (dev_priv
->pch_id
== INTEL_PCH_LPT_LP_DEVICE_ID_TYPE
) {
5563 uint32_t val
= I915_READ(SOUTH_DSPCLK_GATE_D
);
5565 val
&= ~PCH_LP_PARTITION_LEVEL_DISABLE
;
5566 I915_WRITE(SOUTH_DSPCLK_GATE_D
, val
);
5570 static void broadwell_init_clock_gating(struct drm_device
*dev
)
5572 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5575 I915_WRITE(WM3_LP_ILK
, 0);
5576 I915_WRITE(WM2_LP_ILK
, 0);
5577 I915_WRITE(WM1_LP_ILK
, 0);
5579 /* FIXME(BDW): Check all the w/a, some might only apply to
5580 * pre-production hw. */
5583 I915_WRITE(GAMTARBMODE
, _MASKED_BIT_ENABLE(ARB_MODE_BWGTLB_DISABLE
));
5585 I915_WRITE(_3D_CHICKEN3
,
5586 _MASKED_BIT_ENABLE(_3D_CHICKEN_SDE_LIMIT_FIFO_POLY_DEPTH(2)));
5589 /* WaSwitchSolVfFArbitrationPriority:bdw */
5590 I915_WRITE(GAM_ECOCHK
, I915_READ(GAM_ECOCHK
) | HSW_ECOCHK_ARB_PRIO_SOL
);
5592 /* WaPsrDPAMaskVBlankInSRD:bdw */
5593 I915_WRITE(CHICKEN_PAR1_1
,
5594 I915_READ(CHICKEN_PAR1_1
) | DPA_MASK_VBLANK_SRD
);
5596 /* WaPsrDPRSUnmaskVBlankInSRD:bdw */
5597 for_each_pipe(dev_priv
, pipe
) {
5598 I915_WRITE(CHICKEN_PIPESL_1(pipe
),
5599 I915_READ(CHICKEN_PIPESL_1(pipe
)) |
5600 BDW_DPRS_MASK_VBLANK_SRD
);
5603 /* WaVSRefCountFullforceMissDisable:bdw */
5604 /* WaDSRefCountFullforceMissDisable:bdw */
5605 I915_WRITE(GEN7_FF_THREAD_MODE
,
5606 I915_READ(GEN7_FF_THREAD_MODE
) &
5607 ~(GEN8_FF_DS_REF_CNT_FFME
| GEN7_FF_VS_REF_CNT_FFME
));
5609 I915_WRITE(GEN6_RC_SLEEP_PSMI_CONTROL
,
5610 _MASKED_BIT_ENABLE(GEN8_RC_SEMA_IDLE_MSG_DISABLE
));
5612 /* WaDisableSDEUnitClockGating:bdw */
5613 I915_WRITE(GEN8_UCGCTL6
, I915_READ(GEN8_UCGCTL6
) |
5614 GEN8_SDEUNIT_CLOCK_GATE_DISABLE
);
5616 lpt_init_clock_gating(dev
);
5619 static void haswell_init_clock_gating(struct drm_device
*dev
)
5621 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5623 ilk_init_lp_watermarks(dev
);
5625 /* L3 caching of data atomics doesn't work -- disable it. */
5626 I915_WRITE(HSW_SCRATCH1
, HSW_SCRATCH1_L3_DATA_ATOMICS_DISABLE
);
5627 I915_WRITE(HSW_ROW_CHICKEN3
,
5628 _MASKED_BIT_ENABLE(HSW_ROW_CHICKEN3_L3_GLOBAL_ATOMICS_DISABLE
));
5630 /* This is required by WaCatErrorRejectionIssue:hsw */
5631 I915_WRITE(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG
,
5632 I915_READ(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG
) |
5633 GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB
);
5635 /* WaVSRefCountFullforceMissDisable:hsw */
5636 I915_WRITE(GEN7_FF_THREAD_MODE
,
5637 I915_READ(GEN7_FF_THREAD_MODE
) & ~GEN7_FF_VS_REF_CNT_FFME
);
5639 /* WaDisable_RenderCache_OperationalFlush:hsw */
5640 I915_WRITE(CACHE_MODE_0_GEN7
, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE
));
5642 /* enable HiZ Raw Stall Optimization */
5643 I915_WRITE(CACHE_MODE_0_GEN7
,
5644 _MASKED_BIT_DISABLE(HIZ_RAW_STALL_OPT_DISABLE
));
5646 /* WaDisable4x2SubspanOptimization:hsw */
5647 I915_WRITE(CACHE_MODE_1
,
5648 _MASKED_BIT_ENABLE(PIXEL_SUBSPAN_COLLECT_OPT_DISABLE
));
5651 * BSpec recommends 8x4 when MSAA is used,
5652 * however in practice 16x4 seems fastest.
5654 * Note that PS/WM thread counts depend on the WIZ hashing
5655 * disable bit, which we don't touch here, but it's good
5656 * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM).
5658 I915_WRITE(GEN7_GT_MODE
,
5659 GEN6_WIZ_HASHING_MASK
| GEN6_WIZ_HASHING_16x4
);
5661 /* WaSwitchSolVfFArbitrationPriority:hsw */
5662 I915_WRITE(GAM_ECOCHK
, I915_READ(GAM_ECOCHK
) | HSW_ECOCHK_ARB_PRIO_SOL
);
5664 /* WaRsPkgCStateDisplayPMReq:hsw */
5665 I915_WRITE(CHICKEN_PAR1_1
,
5666 I915_READ(CHICKEN_PAR1_1
) | FORCE_ARB_IDLE_PLANES
);
5668 lpt_init_clock_gating(dev
);
5671 static void ivybridge_init_clock_gating(struct drm_device
*dev
)
5673 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5676 ilk_init_lp_watermarks(dev
);
5678 I915_WRITE(ILK_DSPCLK_GATE_D
, ILK_VRHUNIT_CLOCK_GATE_DISABLE
);
5680 /* WaDisableEarlyCull:ivb */
5681 I915_WRITE(_3D_CHICKEN3
,
5682 _MASKED_BIT_ENABLE(_3D_CHICKEN_SF_DISABLE_OBJEND_CULL
));
5684 /* WaDisableBackToBackFlipFix:ivb */
5685 I915_WRITE(IVB_CHICKEN3
,
5686 CHICKEN3_DGMG_REQ_OUT_FIX_DISABLE
|
5687 CHICKEN3_DGMG_DONE_FIX_DISABLE
);
5689 /* WaDisablePSDDualDispatchEnable:ivb */
5690 if (IS_IVB_GT1(dev
))
5691 I915_WRITE(GEN7_HALF_SLICE_CHICKEN1
,
5692 _MASKED_BIT_ENABLE(GEN7_PSD_SINGLE_PORT_DISPATCH_ENABLE
));
5694 /* WaDisable_RenderCache_OperationalFlush:ivb */
5695 I915_WRITE(CACHE_MODE_0_GEN7
, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE
));
5697 /* Apply the WaDisableRHWOOptimizationForRenderHang:ivb workaround. */
5698 I915_WRITE(GEN7_COMMON_SLICE_CHICKEN1
,
5699 GEN7_CSC1_RHWO_OPT_DISABLE_IN_RCC
);
5701 /* WaApplyL3ControlAndL3ChickenMode:ivb */
5702 I915_WRITE(GEN7_L3CNTLREG1
,
5703 GEN7_WA_FOR_GEN7_L3_CONTROL
);
5704 I915_WRITE(GEN7_L3_CHICKEN_MODE_REGISTER
,
5705 GEN7_WA_L3_CHICKEN_MODE
);
5706 if (IS_IVB_GT1(dev
))
5707 I915_WRITE(GEN7_ROW_CHICKEN2
,
5708 _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE
));
5710 /* must write both registers */
5711 I915_WRITE(GEN7_ROW_CHICKEN2
,
5712 _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE
));
5713 I915_WRITE(GEN7_ROW_CHICKEN2_GT2
,
5714 _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE
));
5717 /* WaForceL3Serialization:ivb */
5718 I915_WRITE(GEN7_L3SQCREG4
, I915_READ(GEN7_L3SQCREG4
) &
5719 ~L3SQ_URB_READ_CAM_MATCH_DISABLE
);
5722 * According to the spec, bit 13 (RCZUNIT) must be set on IVB.
5723 * This implements the WaDisableRCZUnitClockGating:ivb workaround.
5725 I915_WRITE(GEN6_UCGCTL2
,
5726 GEN6_RCZUNIT_CLOCK_GATE_DISABLE
);
5728 /* This is required by WaCatErrorRejectionIssue:ivb */
5729 I915_WRITE(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG
,
5730 I915_READ(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG
) |
5731 GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB
);
5733 g4x_disable_trickle_feed(dev
);
5735 gen7_setup_fixed_func_scheduler(dev_priv
);
5737 if (0) { /* causes HiZ corruption on ivb:gt1 */
5738 /* enable HiZ Raw Stall Optimization */
5739 I915_WRITE(CACHE_MODE_0_GEN7
,
5740 _MASKED_BIT_DISABLE(HIZ_RAW_STALL_OPT_DISABLE
));
5743 /* WaDisable4x2SubspanOptimization:ivb */
5744 I915_WRITE(CACHE_MODE_1
,
5745 _MASKED_BIT_ENABLE(PIXEL_SUBSPAN_COLLECT_OPT_DISABLE
));
5748 * BSpec recommends 8x4 when MSAA is used,
5749 * however in practice 16x4 seems fastest.
5751 * Note that PS/WM thread counts depend on the WIZ hashing
5752 * disable bit, which we don't touch here, but it's good
5753 * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM).
5755 I915_WRITE(GEN7_GT_MODE
,
5756 GEN6_WIZ_HASHING_MASK
| GEN6_WIZ_HASHING_16x4
);
5758 snpcr
= I915_READ(GEN6_MBCUNIT_SNPCR
);
5759 snpcr
&= ~GEN6_MBC_SNPCR_MASK
;
5760 snpcr
|= GEN6_MBC_SNPCR_MED
;
5761 I915_WRITE(GEN6_MBCUNIT_SNPCR
, snpcr
);
5763 if (!HAS_PCH_NOP(dev
))
5764 cpt_init_clock_gating(dev
);
5766 gen6_check_mch_setup(dev
);
5769 static void valleyview_init_clock_gating(struct drm_device
*dev
)
5771 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5773 I915_WRITE(DSPCLK_GATE_D
, VRHUNIT_CLOCK_GATE_DISABLE
);
5775 /* WaDisableEarlyCull:vlv */
5776 I915_WRITE(_3D_CHICKEN3
,
5777 _MASKED_BIT_ENABLE(_3D_CHICKEN_SF_DISABLE_OBJEND_CULL
));
5779 /* WaDisableBackToBackFlipFix:vlv */
5780 I915_WRITE(IVB_CHICKEN3
,
5781 CHICKEN3_DGMG_REQ_OUT_FIX_DISABLE
|
5782 CHICKEN3_DGMG_DONE_FIX_DISABLE
);
5784 /* WaPsdDispatchEnable:vlv */
5785 /* WaDisablePSDDualDispatchEnable:vlv */
5786 I915_WRITE(GEN7_HALF_SLICE_CHICKEN1
,
5787 _MASKED_BIT_ENABLE(GEN7_MAX_PS_THREAD_DEP
|
5788 GEN7_PSD_SINGLE_PORT_DISPATCH_ENABLE
));
5790 /* WaDisable_RenderCache_OperationalFlush:vlv */
5791 I915_WRITE(CACHE_MODE_0_GEN7
, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE
));
5793 /* WaForceL3Serialization:vlv */
5794 I915_WRITE(GEN7_L3SQCREG4
, I915_READ(GEN7_L3SQCREG4
) &
5795 ~L3SQ_URB_READ_CAM_MATCH_DISABLE
);
5797 /* WaDisableDopClockGating:vlv */
5798 I915_WRITE(GEN7_ROW_CHICKEN2
,
5799 _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE
));
5801 /* This is required by WaCatErrorRejectionIssue:vlv */
5802 I915_WRITE(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG
,
5803 I915_READ(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG
) |
5804 GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB
);
5806 gen7_setup_fixed_func_scheduler(dev_priv
);
5809 * According to the spec, bit 13 (RCZUNIT) must be set on IVB.
5810 * This implements the WaDisableRCZUnitClockGating:vlv workaround.
5812 I915_WRITE(GEN6_UCGCTL2
,
5813 GEN6_RCZUNIT_CLOCK_GATE_DISABLE
);
5815 /* WaDisableL3Bank2xClockGate:vlv
5816 * Disabling L3 clock gating- MMIO 940c[25] = 1
5817 * Set bit 25, to disable L3_BANK_2x_CLK_GATING */
5818 I915_WRITE(GEN7_UCGCTL4
,
5819 I915_READ(GEN7_UCGCTL4
) | GEN7_L3BANK2X_CLOCK_GATE_DISABLE
);
5821 I915_WRITE(MI_ARB_VLV
, MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE
);
5824 * BSpec says this must be set, even though
5825 * WaDisable4x2SubspanOptimization isn't listed for VLV.
5827 I915_WRITE(CACHE_MODE_1
,
5828 _MASKED_BIT_ENABLE(PIXEL_SUBSPAN_COLLECT_OPT_DISABLE
));
5831 * WaIncreaseL3CreditsForVLVB0:vlv
5832 * This is the hardware default actually.
5834 I915_WRITE(GEN7_L3SQCREG1
, VLV_B0_WA_L3SQCREG1_VALUE
);
5837 * WaDisableVLVClockGating_VBIIssue:vlv
5838 * Disable clock gating on th GCFG unit to prevent a delay
5839 * in the reporting of vblank events.
5841 I915_WRITE(VLV_GUNIT_CLOCK_GATE
, GCFG_DIS
);
5844 static void cherryview_init_clock_gating(struct drm_device
*dev
)
5846 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5848 I915_WRITE(DSPCLK_GATE_D
, VRHUNIT_CLOCK_GATE_DISABLE
);
5850 I915_WRITE(MI_ARB_VLV
, MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE
);
5852 /* WaDisablePartialInstShootdown:chv */
5853 I915_WRITE(GEN8_ROW_CHICKEN
,
5854 _MASKED_BIT_ENABLE(PARTIAL_INSTRUCTION_SHOOTDOWN_DISABLE
));
5856 /* WaDisableThreadStallDopClockGating:chv */
5857 I915_WRITE(GEN8_ROW_CHICKEN
,
5858 _MASKED_BIT_ENABLE(STALL_DOP_GATING_DISABLE
));
5860 /* WaVSRefCountFullforceMissDisable:chv */
5861 /* WaDSRefCountFullforceMissDisable:chv */
5862 I915_WRITE(GEN7_FF_THREAD_MODE
,
5863 I915_READ(GEN7_FF_THREAD_MODE
) &
5864 ~(GEN8_FF_DS_REF_CNT_FFME
| GEN7_FF_VS_REF_CNT_FFME
));
5866 /* WaDisableSemaphoreAndSyncFlipWait:chv */
5867 I915_WRITE(GEN6_RC_SLEEP_PSMI_CONTROL
,
5868 _MASKED_BIT_ENABLE(GEN8_RC_SEMA_IDLE_MSG_DISABLE
));
5870 /* WaDisableCSUnitClockGating:chv */
5871 I915_WRITE(GEN6_UCGCTL1
, I915_READ(GEN6_UCGCTL1
) |
5872 GEN6_CSUNIT_CLOCK_GATE_DISABLE
);
5874 /* WaDisableSDEUnitClockGating:chv */
5875 I915_WRITE(GEN8_UCGCTL6
, I915_READ(GEN8_UCGCTL6
) |
5876 GEN8_SDEUNIT_CLOCK_GATE_DISABLE
);
5878 /* WaDisableSamplerPowerBypass:chv (pre-production hw) */
5879 I915_WRITE(HALF_SLICE_CHICKEN3
,
5880 _MASKED_BIT_ENABLE(GEN8_SAMPLER_POWER_BYPASS_DIS
));
5882 /* WaDisableGunitClockGating:chv (pre-production hw) */
5883 I915_WRITE(VLV_GUNIT_CLOCK_GATE
, I915_READ(VLV_GUNIT_CLOCK_GATE
) |
5886 /* WaDisableFfDopClockGating:chv (pre-production hw) */
5887 I915_WRITE(GEN6_RC_SLEEP_PSMI_CONTROL
,
5888 _MASKED_BIT_ENABLE(GEN8_FF_DOP_CLOCK_GATE_DISABLE
));
5890 /* WaDisableDopClockGating:chv (pre-production hw) */
5891 I915_WRITE(GEN7_ROW_CHICKEN2
,
5892 _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE
));
5893 I915_WRITE(GEN6_UCGCTL1
, I915_READ(GEN6_UCGCTL1
) |
5894 GEN6_EU_TCUNIT_CLOCK_GATE_DISABLE
);
5897 static void g4x_init_clock_gating(struct drm_device
*dev
)
5899 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5900 uint32_t dspclk_gate
;
5902 I915_WRITE(RENCLK_GATE_D1
, 0);
5903 I915_WRITE(RENCLK_GATE_D2
, VF_UNIT_CLOCK_GATE_DISABLE
|
5904 GS_UNIT_CLOCK_GATE_DISABLE
|
5905 CL_UNIT_CLOCK_GATE_DISABLE
);
5906 I915_WRITE(RAMCLK_GATE_D
, 0);
5907 dspclk_gate
= VRHUNIT_CLOCK_GATE_DISABLE
|
5908 OVRUNIT_CLOCK_GATE_DISABLE
|
5909 OVCUNIT_CLOCK_GATE_DISABLE
;
5911 dspclk_gate
|= DSSUNIT_CLOCK_GATE_DISABLE
;
5912 I915_WRITE(DSPCLK_GATE_D
, dspclk_gate
);
5914 /* WaDisableRenderCachePipelinedFlush */
5915 I915_WRITE(CACHE_MODE_0
,
5916 _MASKED_BIT_ENABLE(CM0_PIPELINED_RENDER_FLUSH_DISABLE
));
5918 /* WaDisable_RenderCache_OperationalFlush:g4x */
5919 I915_WRITE(CACHE_MODE_0
, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE
));
5921 g4x_disable_trickle_feed(dev
);
5924 static void crestline_init_clock_gating(struct drm_device
*dev
)
5926 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5928 I915_WRITE(RENCLK_GATE_D1
, I965_RCC_CLOCK_GATE_DISABLE
);
5929 I915_WRITE(RENCLK_GATE_D2
, 0);
5930 I915_WRITE(DSPCLK_GATE_D
, 0);
5931 I915_WRITE(RAMCLK_GATE_D
, 0);
5932 I915_WRITE16(DEUC
, 0);
5933 I915_WRITE(MI_ARB_STATE
,
5934 _MASKED_BIT_ENABLE(MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE
));
5936 /* WaDisable_RenderCache_OperationalFlush:gen4 */
5937 I915_WRITE(CACHE_MODE_0
, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE
));
5940 static void broadwater_init_clock_gating(struct drm_device
*dev
)
5942 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5944 I915_WRITE(RENCLK_GATE_D1
, I965_RCZ_CLOCK_GATE_DISABLE
|
5945 I965_RCC_CLOCK_GATE_DISABLE
|
5946 I965_RCPB_CLOCK_GATE_DISABLE
|
5947 I965_ISC_CLOCK_GATE_DISABLE
|
5948 I965_FBC_CLOCK_GATE_DISABLE
);
5949 I915_WRITE(RENCLK_GATE_D2
, 0);
5950 I915_WRITE(MI_ARB_STATE
,
5951 _MASKED_BIT_ENABLE(MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE
));
5953 /* WaDisable_RenderCache_OperationalFlush:gen4 */
5954 I915_WRITE(CACHE_MODE_0
, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE
));
5957 static void gen3_init_clock_gating(struct drm_device
*dev
)
5959 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5960 u32 dstate
= I915_READ(D_STATE
);
5962 dstate
|= DSTATE_PLL_D3_OFF
| DSTATE_GFX_CLOCK_GATING
|
5963 DSTATE_DOT_CLOCK_GATING
;
5964 I915_WRITE(D_STATE
, dstate
);
5966 if (IS_PINEVIEW(dev
))
5967 I915_WRITE(ECOSKPD
, _MASKED_BIT_ENABLE(ECO_GATING_CX_ONLY
));
5969 /* IIR "flip pending" means done if this bit is set */
5970 I915_WRITE(ECOSKPD
, _MASKED_BIT_DISABLE(ECO_FLIP_DONE
));
5972 /* interrupts should cause a wake up from C3 */
5973 I915_WRITE(INSTPM
, _MASKED_BIT_ENABLE(INSTPM_AGPBUSY_INT_EN
));
5975 /* On GEN3 we really need to make sure the ARB C3 LP bit is set */
5976 I915_WRITE(MI_ARB_STATE
, _MASKED_BIT_ENABLE(MI_ARB_C3_LP_WRITE_ENABLE
));
5979 static void i85x_init_clock_gating(struct drm_device
*dev
)
5981 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5983 I915_WRITE(RENCLK_GATE_D1
, SV_CLOCK_GATE_DISABLE
);
5985 /* interrupts should cause a wake up from C3 */
5986 I915_WRITE(MI_STATE
, _MASKED_BIT_ENABLE(MI_AGPBUSY_INT_EN
) |
5987 _MASKED_BIT_DISABLE(MI_AGPBUSY_830_MODE
));
5990 static void i830_init_clock_gating(struct drm_device
*dev
)
5992 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
5994 I915_WRITE(DSPCLK_GATE_D
, OVRUNIT_CLOCK_GATE_DISABLE
);
5997 void intel_init_clock_gating(struct drm_device
*dev
)
5999 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
6001 dev_priv
->display
.init_clock_gating(dev
);
6004 void intel_suspend_hw(struct drm_device
*dev
)
6006 if (HAS_PCH_LPT(dev
))
6007 lpt_suspend_hw(dev
);
6010 #define for_each_power_well(i, power_well, domain_mask, power_domains) \
6012 i < (power_domains)->power_well_count && \
6013 ((power_well) = &(power_domains)->power_wells[i]); \
6015 if ((power_well)->domains & (domain_mask))
6017 #define for_each_power_well_rev(i, power_well, domain_mask, power_domains) \
6018 for (i = (power_domains)->power_well_count - 1; \
6019 i >= 0 && ((power_well) = &(power_domains)->power_wells[i]);\
6021 if ((power_well)->domains & (domain_mask))
6024 * We should only use the power well if we explicitly asked the hardware to
6025 * enable it, so check if it's enabled and also check if we've requested it to
6028 static bool hsw_power_well_enabled(struct drm_i915_private
*dev_priv
,
6029 struct i915_power_well
*power_well
)
6031 return I915_READ(HSW_PWR_WELL_DRIVER
) ==
6032 (HSW_PWR_WELL_ENABLE_REQUEST
| HSW_PWR_WELL_STATE_ENABLED
);
6035 bool intel_display_power_enabled_unlocked(struct drm_i915_private
*dev_priv
,
6036 enum intel_display_power_domain domain
)
6038 struct i915_power_domains
*power_domains
;
6039 struct i915_power_well
*power_well
;
6043 if (dev_priv
->pm
.suspended
)
6046 power_domains
= &dev_priv
->power_domains
;
6050 for_each_power_well_rev(i
, power_well
, BIT(domain
), power_domains
) {
6051 if (power_well
->always_on
)
6054 if (!power_well
->hw_enabled
) {
6063 bool intel_display_power_enabled(struct drm_i915_private
*dev_priv
,
6064 enum intel_display_power_domain domain
)
6066 struct i915_power_domains
*power_domains
;
6069 power_domains
= &dev_priv
->power_domains
;
6071 mutex_lock(&power_domains
->lock
);
6072 ret
= intel_display_power_enabled_unlocked(dev_priv
, domain
);
6073 mutex_unlock(&power_domains
->lock
);
6079 * Starting with Haswell, we have a "Power Down Well" that can be turned off
6080 * when not needed anymore. We have 4 registers that can request the power well
6081 * to be enabled, and it will only be disabled if none of the registers is
6082 * requesting it to be enabled.
6084 static void hsw_power_well_post_enable(struct drm_i915_private
*dev_priv
)
6086 struct drm_device
*dev
= dev_priv
->dev
;
6089 * After we re-enable the power well, if we touch VGA register 0x3d5
6090 * we'll get unclaimed register interrupts. This stops after we write
6091 * anything to the VGA MSR register. The vgacon module uses this
6092 * register all the time, so if we unbind our driver and, as a
6093 * consequence, bind vgacon, we'll get stuck in an infinite loop at
6094 * console_unlock(). So make here we touch the VGA MSR register, making
6095 * sure vgacon can keep working normally without triggering interrupts
6096 * and error messages.
6098 vga_get_uninterruptible(dev
->pdev
, VGA_RSRC_LEGACY_IO
);
6099 outb(inb(VGA_MSR_READ
), VGA_MSR_WRITE
);
6100 vga_put(dev
->pdev
, VGA_RSRC_LEGACY_IO
);
6102 if (IS_BROADWELL(dev
))
6103 gen8_irq_power_well_post_enable(dev_priv
);
6106 static void hsw_set_power_well(struct drm_i915_private
*dev_priv
,
6107 struct i915_power_well
*power_well
, bool enable
)
6109 bool is_enabled
, enable_requested
;
6112 tmp
= I915_READ(HSW_PWR_WELL_DRIVER
);
6113 is_enabled
= tmp
& HSW_PWR_WELL_STATE_ENABLED
;
6114 enable_requested
= tmp
& HSW_PWR_WELL_ENABLE_REQUEST
;
6117 if (!enable_requested
)
6118 I915_WRITE(HSW_PWR_WELL_DRIVER
,
6119 HSW_PWR_WELL_ENABLE_REQUEST
);
6122 DRM_DEBUG_KMS("Enabling power well\n");
6123 if (wait_for((I915_READ(HSW_PWR_WELL_DRIVER
) &
6124 HSW_PWR_WELL_STATE_ENABLED
), 20))
6125 DRM_ERROR("Timeout enabling power well\n");
6128 hsw_power_well_post_enable(dev_priv
);
6130 if (enable_requested
) {
6131 I915_WRITE(HSW_PWR_WELL_DRIVER
, 0);
6132 POSTING_READ(HSW_PWR_WELL_DRIVER
);
6133 DRM_DEBUG_KMS("Requesting to disable the power well\n");
6138 static void hsw_power_well_sync_hw(struct drm_i915_private
*dev_priv
,
6139 struct i915_power_well
*power_well
)
6141 hsw_set_power_well(dev_priv
, power_well
, power_well
->count
> 0);
6144 * We're taking over the BIOS, so clear any requests made by it since
6145 * the driver is in charge now.
6147 if (I915_READ(HSW_PWR_WELL_BIOS
) & HSW_PWR_WELL_ENABLE_REQUEST
)
6148 I915_WRITE(HSW_PWR_WELL_BIOS
, 0);
6151 static void hsw_power_well_enable(struct drm_i915_private
*dev_priv
,
6152 struct i915_power_well
*power_well
)
6154 hsw_set_power_well(dev_priv
, power_well
, true);
6157 static void hsw_power_well_disable(struct drm_i915_private
*dev_priv
,
6158 struct i915_power_well
*power_well
)
6160 hsw_set_power_well(dev_priv
, power_well
, false);
6163 static void i9xx_always_on_power_well_noop(struct drm_i915_private
*dev_priv
,
6164 struct i915_power_well
*power_well
)
6168 static bool i9xx_always_on_power_well_enabled(struct drm_i915_private
*dev_priv
,
6169 struct i915_power_well
*power_well
)
6174 static void vlv_set_power_well(struct drm_i915_private
*dev_priv
,
6175 struct i915_power_well
*power_well
, bool enable
)
6177 enum punit_power_well power_well_id
= power_well
->data
;
6182 mask
= PUNIT_PWRGT_MASK(power_well_id
);
6183 state
= enable
? PUNIT_PWRGT_PWR_ON(power_well_id
) :
6184 PUNIT_PWRGT_PWR_GATE(power_well_id
);
6186 mutex_lock(&dev_priv
->rps
.hw_lock
);
6189 ((vlv_punit_read(dev_priv, PUNIT_REG_PWRGT_STATUS) & mask) == state)
6194 ctrl
= vlv_punit_read(dev_priv
, PUNIT_REG_PWRGT_CTRL
);
6197 vlv_punit_write(dev_priv
, PUNIT_REG_PWRGT_CTRL
, ctrl
);
6199 if (wait_for(COND
, 100))
6200 DRM_ERROR("timout setting power well state %08x (%08x)\n",
6202 vlv_punit_read(dev_priv
, PUNIT_REG_PWRGT_CTRL
));
6207 mutex_unlock(&dev_priv
->rps
.hw_lock
);
6210 static void vlv_power_well_sync_hw(struct drm_i915_private
*dev_priv
,
6211 struct i915_power_well
*power_well
)
6213 vlv_set_power_well(dev_priv
, power_well
, power_well
->count
> 0);
6216 static void vlv_power_well_enable(struct drm_i915_private
*dev_priv
,
6217 struct i915_power_well
*power_well
)
6219 vlv_set_power_well(dev_priv
, power_well
, true);
6222 static void vlv_power_well_disable(struct drm_i915_private
*dev_priv
,
6223 struct i915_power_well
*power_well
)
6225 vlv_set_power_well(dev_priv
, power_well
, false);
6228 static bool vlv_power_well_enabled(struct drm_i915_private
*dev_priv
,
6229 struct i915_power_well
*power_well
)
6231 int power_well_id
= power_well
->data
;
6232 bool enabled
= false;
6237 mask
= PUNIT_PWRGT_MASK(power_well_id
);
6238 ctrl
= PUNIT_PWRGT_PWR_ON(power_well_id
);
6240 mutex_lock(&dev_priv
->rps
.hw_lock
);
6242 state
= vlv_punit_read(dev_priv
, PUNIT_REG_PWRGT_STATUS
) & mask
;
6244 * We only ever set the power-on and power-gate states, anything
6245 * else is unexpected.
6247 WARN_ON(state
!= PUNIT_PWRGT_PWR_ON(power_well_id
) &&
6248 state
!= PUNIT_PWRGT_PWR_GATE(power_well_id
));
6253 * A transient state at this point would mean some unexpected party
6254 * is poking at the power controls too.
6256 ctrl
= vlv_punit_read(dev_priv
, PUNIT_REG_PWRGT_CTRL
) & mask
;
6257 WARN_ON(ctrl
!= state
);
6259 mutex_unlock(&dev_priv
->rps
.hw_lock
);
6264 static void vlv_display_power_well_enable(struct drm_i915_private
*dev_priv
,
6265 struct i915_power_well
*power_well
)
6267 WARN_ON_ONCE(power_well
->data
!= PUNIT_POWER_WELL_DISP2D
);
6269 vlv_set_power_well(dev_priv
, power_well
, true);
6271 spin_lock_irq(&dev_priv
->irq_lock
);
6272 valleyview_enable_display_irqs(dev_priv
);
6273 spin_unlock_irq(&dev_priv
->irq_lock
);
6276 * During driver initialization/resume we can avoid restoring the
6277 * part of the HW/SW state that will be inited anyway explicitly.
6279 if (dev_priv
->power_domains
.initializing
)
6282 intel_hpd_init(dev_priv
->dev
);
6284 i915_redisable_vga_power_on(dev_priv
->dev
);
6287 static void vlv_display_power_well_disable(struct drm_i915_private
*dev_priv
,
6288 struct i915_power_well
*power_well
)
6290 WARN_ON_ONCE(power_well
->data
!= PUNIT_POWER_WELL_DISP2D
);
6292 spin_lock_irq(&dev_priv
->irq_lock
);
6293 valleyview_disable_display_irqs(dev_priv
);
6294 spin_unlock_irq(&dev_priv
->irq_lock
);
6296 vlv_set_power_well(dev_priv
, power_well
, false);
6299 static void vlv_dpio_cmn_power_well_enable(struct drm_i915_private
*dev_priv
,
6300 struct i915_power_well
*power_well
)
6302 WARN_ON_ONCE(power_well
->data
!= PUNIT_POWER_WELL_DPIO_CMN_BC
);
6305 * Enable the CRI clock source so we can get at the
6306 * display and the reference clock for VGA
6307 * hotplug / manual detection.
6309 I915_WRITE(DPLL(PIPE_B
), I915_READ(DPLL(PIPE_B
)) |
6310 DPLL_REFA_CLK_ENABLE_VLV
| DPLL_INTEGRATED_CRI_CLK_VLV
);
6311 udelay(1); /* >10ns for cmnreset, >0ns for sidereset */
6313 vlv_set_power_well(dev_priv
, power_well
, true);
6316 * From VLV2A0_DP_eDP_DPIO_driver_vbios_notes_10.docx -
6317 * 6. De-assert cmn_reset/side_reset. Same as VLV X0.
6318 * a. GUnit 0x2110 bit[0] set to 1 (def 0)
6319 * b. The other bits such as sfr settings / modesel may all
6322 * This should only be done on init and resume from S3 with
6323 * both PLLs disabled, or we risk losing DPIO and PLL
6326 I915_WRITE(DPIO_CTL
, I915_READ(DPIO_CTL
) | DPIO_CMNRST
);
6329 static void vlv_dpio_cmn_power_well_disable(struct drm_i915_private
*dev_priv
,
6330 struct i915_power_well
*power_well
)
6334 WARN_ON_ONCE(power_well
->data
!= PUNIT_POWER_WELL_DPIO_CMN_BC
);
6336 for_each_pipe(dev_priv
, pipe
)
6337 assert_pll_disabled(dev_priv
, pipe
);
6339 /* Assert common reset */
6340 I915_WRITE(DPIO_CTL
, I915_READ(DPIO_CTL
) & ~DPIO_CMNRST
);
6342 vlv_set_power_well(dev_priv
, power_well
, false);
6345 static void chv_dpio_cmn_power_well_enable(struct drm_i915_private
*dev_priv
,
6346 struct i915_power_well
*power_well
)
6350 WARN_ON_ONCE(power_well
->data
!= PUNIT_POWER_WELL_DPIO_CMN_BC
&&
6351 power_well
->data
!= PUNIT_POWER_WELL_DPIO_CMN_D
);
6354 * Enable the CRI clock source so we can get at the
6355 * display and the reference clock for VGA
6356 * hotplug / manual detection.
6358 if (power_well
->data
== PUNIT_POWER_WELL_DPIO_CMN_BC
) {
6360 I915_WRITE(DPLL(PIPE_B
), I915_READ(DPLL(PIPE_B
)) |
6361 DPLL_REFA_CLK_ENABLE_VLV
);
6362 I915_WRITE(DPLL(PIPE_B
), I915_READ(DPLL(PIPE_B
)) |
6363 DPLL_REFA_CLK_ENABLE_VLV
| DPLL_INTEGRATED_CRI_CLK_VLV
);
6366 I915_WRITE(DPLL(PIPE_C
), I915_READ(DPLL(PIPE_C
)) |
6367 DPLL_REFA_CLK_ENABLE_VLV
| DPLL_INTEGRATED_CRI_CLK_VLV
);
6369 udelay(1); /* >10ns for cmnreset, >0ns for sidereset */
6370 vlv_set_power_well(dev_priv
, power_well
, true);
6372 /* Poll for phypwrgood signal */
6373 if (wait_for(I915_READ(DISPLAY_PHY_STATUS
) & PHY_POWERGOOD(phy
), 1))
6374 DRM_ERROR("Display PHY %d is not power up\n", phy
);
6376 I915_WRITE(DISPLAY_PHY_CONTROL
, I915_READ(DISPLAY_PHY_CONTROL
) |
6377 PHY_COM_LANE_RESET_DEASSERT(phy
));
6380 static void chv_dpio_cmn_power_well_disable(struct drm_i915_private
*dev_priv
,
6381 struct i915_power_well
*power_well
)
6385 WARN_ON_ONCE(power_well
->data
!= PUNIT_POWER_WELL_DPIO_CMN_BC
&&
6386 power_well
->data
!= PUNIT_POWER_WELL_DPIO_CMN_D
);
6388 if (power_well
->data
== PUNIT_POWER_WELL_DPIO_CMN_BC
) {
6390 assert_pll_disabled(dev_priv
, PIPE_A
);
6391 assert_pll_disabled(dev_priv
, PIPE_B
);
6394 assert_pll_disabled(dev_priv
, PIPE_C
);
6397 I915_WRITE(DISPLAY_PHY_CONTROL
, I915_READ(DISPLAY_PHY_CONTROL
) &
6398 ~PHY_COM_LANE_RESET_DEASSERT(phy
));
6400 vlv_set_power_well(dev_priv
, power_well
, false);
6403 static bool chv_pipe_power_well_enabled(struct drm_i915_private
*dev_priv
,
6404 struct i915_power_well
*power_well
)
6406 enum pipe pipe
= power_well
->data
;
6410 mutex_lock(&dev_priv
->rps
.hw_lock
);
6412 state
= vlv_punit_read(dev_priv
, PUNIT_REG_DSPFREQ
) & DP_SSS_MASK(pipe
);
6414 * We only ever set the power-on and power-gate states, anything
6415 * else is unexpected.
6417 WARN_ON(state
!= DP_SSS_PWR_ON(pipe
) && state
!= DP_SSS_PWR_GATE(pipe
));
6418 enabled
= state
== DP_SSS_PWR_ON(pipe
);
6421 * A transient state at this point would mean some unexpected party
6422 * is poking at the power controls too.
6424 ctrl
= vlv_punit_read(dev_priv
, PUNIT_REG_DSPFREQ
) & DP_SSC_MASK(pipe
);
6425 WARN_ON(ctrl
<< 16 != state
);
6427 mutex_unlock(&dev_priv
->rps
.hw_lock
);
6432 static void chv_set_pipe_power_well(struct drm_i915_private
*dev_priv
,
6433 struct i915_power_well
*power_well
,
6436 enum pipe pipe
= power_well
->data
;
6440 state
= enable
? DP_SSS_PWR_ON(pipe
) : DP_SSS_PWR_GATE(pipe
);
6442 mutex_lock(&dev_priv
->rps
.hw_lock
);
6445 ((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & DP_SSS_MASK(pipe)) == state)
6450 ctrl
= vlv_punit_read(dev_priv
, PUNIT_REG_DSPFREQ
);
6451 ctrl
&= ~DP_SSC_MASK(pipe
);
6452 ctrl
|= enable
? DP_SSC_PWR_ON(pipe
) : DP_SSC_PWR_GATE(pipe
);
6453 vlv_punit_write(dev_priv
, PUNIT_REG_DSPFREQ
, ctrl
);
6455 if (wait_for(COND
, 100))
6456 DRM_ERROR("timout setting power well state %08x (%08x)\n",
6458 vlv_punit_read(dev_priv
, PUNIT_REG_DSPFREQ
));
6463 mutex_unlock(&dev_priv
->rps
.hw_lock
);
6466 static void chv_pipe_power_well_sync_hw(struct drm_i915_private
*dev_priv
,
6467 struct i915_power_well
*power_well
)
6469 chv_set_pipe_power_well(dev_priv
, power_well
, power_well
->count
> 0);
6472 static void chv_pipe_power_well_enable(struct drm_i915_private
*dev_priv
,
6473 struct i915_power_well
*power_well
)
6475 WARN_ON_ONCE(power_well
->data
!= PIPE_A
&&
6476 power_well
->data
!= PIPE_B
&&
6477 power_well
->data
!= PIPE_C
);
6479 chv_set_pipe_power_well(dev_priv
, power_well
, true);
6482 static void chv_pipe_power_well_disable(struct drm_i915_private
*dev_priv
,
6483 struct i915_power_well
*power_well
)
6485 WARN_ON_ONCE(power_well
->data
!= PIPE_A
&&
6486 power_well
->data
!= PIPE_B
&&
6487 power_well
->data
!= PIPE_C
);
6489 chv_set_pipe_power_well(dev_priv
, power_well
, false);
6492 static void check_power_well_state(struct drm_i915_private
*dev_priv
,
6493 struct i915_power_well
*power_well
)
6495 bool enabled
= power_well
->ops
->is_enabled(dev_priv
, power_well
);
6497 if (power_well
->always_on
|| !i915
.disable_power_well
) {
6504 if (enabled
!= (power_well
->count
> 0))
6510 WARN(1, "state mismatch for '%s' (always_on %d hw state %d use-count %d disable_power_well %d\n",
6511 power_well
->name
, power_well
->always_on
, enabled
,
6512 power_well
->count
, i915
.disable_power_well
);
6515 void intel_display_power_get(struct drm_i915_private
*dev_priv
,
6516 enum intel_display_power_domain domain
)
6518 struct i915_power_domains
*power_domains
;
6519 struct i915_power_well
*power_well
;
6522 intel_runtime_pm_get(dev_priv
);
6524 power_domains
= &dev_priv
->power_domains
;
6526 mutex_lock(&power_domains
->lock
);
6528 for_each_power_well(i
, power_well
, BIT(domain
), power_domains
) {
6529 if (!power_well
->count
++) {
6530 DRM_DEBUG_KMS("enabling %s\n", power_well
->name
);
6531 power_well
->ops
->enable(dev_priv
, power_well
);
6532 power_well
->hw_enabled
= true;
6535 check_power_well_state(dev_priv
, power_well
);
6538 power_domains
->domain_use_count
[domain
]++;
6540 mutex_unlock(&power_domains
->lock
);
6543 void intel_display_power_put(struct drm_i915_private
*dev_priv
,
6544 enum intel_display_power_domain domain
)
6546 struct i915_power_domains
*power_domains
;
6547 struct i915_power_well
*power_well
;
6550 power_domains
= &dev_priv
->power_domains
;
6552 mutex_lock(&power_domains
->lock
);
6554 WARN_ON(!power_domains
->domain_use_count
[domain
]);
6555 power_domains
->domain_use_count
[domain
]--;
6557 for_each_power_well_rev(i
, power_well
, BIT(domain
), power_domains
) {
6558 WARN_ON(!power_well
->count
);
6560 if (!--power_well
->count
&& i915
.disable_power_well
) {
6561 DRM_DEBUG_KMS("disabling %s\n", power_well
->name
);
6562 power_well
->hw_enabled
= false;
6563 power_well
->ops
->disable(dev_priv
, power_well
);
6566 check_power_well_state(dev_priv
, power_well
);
6569 mutex_unlock(&power_domains
->lock
);
6571 intel_runtime_pm_put(dev_priv
);
6574 static struct i915_power_domains
*hsw_pwr
;
6576 /* Display audio driver power well request */
6577 int i915_request_power_well(void)
6579 struct drm_i915_private
*dev_priv
;
6584 dev_priv
= container_of(hsw_pwr
, struct drm_i915_private
,
6586 intel_display_power_get(dev_priv
, POWER_DOMAIN_AUDIO
);
6589 EXPORT_SYMBOL_GPL(i915_request_power_well
);
6591 /* Display audio driver power well release */
6592 int i915_release_power_well(void)
6594 struct drm_i915_private
*dev_priv
;
6599 dev_priv
= container_of(hsw_pwr
, struct drm_i915_private
,
6601 intel_display_power_put(dev_priv
, POWER_DOMAIN_AUDIO
);
6604 EXPORT_SYMBOL_GPL(i915_release_power_well
);
6607 * Private interface for the audio driver to get CDCLK in kHz.
6609 * Caller must request power well using i915_request_power_well() prior to
6612 int i915_get_cdclk_freq(void)
6614 struct drm_i915_private
*dev_priv
;
6619 dev_priv
= container_of(hsw_pwr
, struct drm_i915_private
,
6622 return intel_ddi_get_cdclk_freq(dev_priv
);
6624 EXPORT_SYMBOL_GPL(i915_get_cdclk_freq
);
6627 #define POWER_DOMAIN_MASK (BIT(POWER_DOMAIN_NUM) - 1)
6629 #define HSW_ALWAYS_ON_POWER_DOMAINS ( \
6630 BIT(POWER_DOMAIN_PIPE_A) | \
6631 BIT(POWER_DOMAIN_TRANSCODER_EDP) | \
6632 BIT(POWER_DOMAIN_PORT_DDI_A_2_LANES) | \
6633 BIT(POWER_DOMAIN_PORT_DDI_A_4_LANES) | \
6634 BIT(POWER_DOMAIN_PORT_DDI_B_2_LANES) | \
6635 BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \
6636 BIT(POWER_DOMAIN_PORT_DDI_C_2_LANES) | \
6637 BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \
6638 BIT(POWER_DOMAIN_PORT_DDI_D_2_LANES) | \
6639 BIT(POWER_DOMAIN_PORT_DDI_D_4_LANES) | \
6640 BIT(POWER_DOMAIN_PORT_CRT) | \
6641 BIT(POWER_DOMAIN_PLLS) | \
6642 BIT(POWER_DOMAIN_INIT))
6643 #define HSW_DISPLAY_POWER_DOMAINS ( \
6644 (POWER_DOMAIN_MASK & ~HSW_ALWAYS_ON_POWER_DOMAINS) | \
6645 BIT(POWER_DOMAIN_INIT))
6647 #define BDW_ALWAYS_ON_POWER_DOMAINS ( \
6648 HSW_ALWAYS_ON_POWER_DOMAINS | \
6649 BIT(POWER_DOMAIN_PIPE_A_PANEL_FITTER))
6650 #define BDW_DISPLAY_POWER_DOMAINS ( \
6651 (POWER_DOMAIN_MASK & ~BDW_ALWAYS_ON_POWER_DOMAINS) | \
6652 BIT(POWER_DOMAIN_INIT))
6654 #define VLV_ALWAYS_ON_POWER_DOMAINS BIT(POWER_DOMAIN_INIT)
6655 #define VLV_DISPLAY_POWER_DOMAINS POWER_DOMAIN_MASK
6657 #define VLV_DPIO_CMN_BC_POWER_DOMAINS ( \
6658 BIT(POWER_DOMAIN_PORT_DDI_B_2_LANES) | \
6659 BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \
6660 BIT(POWER_DOMAIN_PORT_DDI_C_2_LANES) | \
6661 BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \
6662 BIT(POWER_DOMAIN_PORT_CRT) | \
6663 BIT(POWER_DOMAIN_INIT))
6665 #define VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS ( \
6666 BIT(POWER_DOMAIN_PORT_DDI_B_2_LANES) | \
6667 BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \
6668 BIT(POWER_DOMAIN_INIT))
6670 #define VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS ( \
6671 BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \
6672 BIT(POWER_DOMAIN_INIT))
6674 #define VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS ( \
6675 BIT(POWER_DOMAIN_PORT_DDI_C_2_LANES) | \
6676 BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \
6677 BIT(POWER_DOMAIN_INIT))
6679 #define VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS ( \
6680 BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \
6681 BIT(POWER_DOMAIN_INIT))
6683 #define CHV_PIPE_A_POWER_DOMAINS ( \
6684 BIT(POWER_DOMAIN_PIPE_A) | \
6685 BIT(POWER_DOMAIN_INIT))
6687 #define CHV_PIPE_B_POWER_DOMAINS ( \
6688 BIT(POWER_DOMAIN_PIPE_B) | \
6689 BIT(POWER_DOMAIN_INIT))
6691 #define CHV_PIPE_C_POWER_DOMAINS ( \
6692 BIT(POWER_DOMAIN_PIPE_C) | \
6693 BIT(POWER_DOMAIN_INIT))
6695 #define CHV_DPIO_CMN_BC_POWER_DOMAINS ( \
6696 BIT(POWER_DOMAIN_PORT_DDI_B_2_LANES) | \
6697 BIT(POWER_DOMAIN_PORT_DDI_B_4_LANES) | \
6698 BIT(POWER_DOMAIN_PORT_DDI_C_2_LANES) | \
6699 BIT(POWER_DOMAIN_PORT_DDI_C_4_LANES) | \
6700 BIT(POWER_DOMAIN_INIT))
6702 #define CHV_DPIO_CMN_D_POWER_DOMAINS ( \
6703 BIT(POWER_DOMAIN_PORT_DDI_D_2_LANES) | \
6704 BIT(POWER_DOMAIN_PORT_DDI_D_4_LANES) | \
6705 BIT(POWER_DOMAIN_INIT))
6707 #define CHV_DPIO_TX_D_LANES_01_POWER_DOMAINS ( \
6708 BIT(POWER_DOMAIN_PORT_DDI_D_2_LANES) | \
6709 BIT(POWER_DOMAIN_PORT_DDI_D_4_LANES) | \
6710 BIT(POWER_DOMAIN_INIT))
6712 #define CHV_DPIO_TX_D_LANES_23_POWER_DOMAINS ( \
6713 BIT(POWER_DOMAIN_PORT_DDI_D_4_LANES) | \
6714 BIT(POWER_DOMAIN_INIT))
6716 static const struct i915_power_well_ops i9xx_always_on_power_well_ops
= {
6717 .sync_hw
= i9xx_always_on_power_well_noop
,
6718 .enable
= i9xx_always_on_power_well_noop
,
6719 .disable
= i9xx_always_on_power_well_noop
,
6720 .is_enabled
= i9xx_always_on_power_well_enabled
,
6723 static const struct i915_power_well_ops chv_pipe_power_well_ops
= {
6724 .sync_hw
= chv_pipe_power_well_sync_hw
,
6725 .enable
= chv_pipe_power_well_enable
,
6726 .disable
= chv_pipe_power_well_disable
,
6727 .is_enabled
= chv_pipe_power_well_enabled
,
6730 static const struct i915_power_well_ops chv_dpio_cmn_power_well_ops
= {
6731 .sync_hw
= vlv_power_well_sync_hw
,
6732 .enable
= chv_dpio_cmn_power_well_enable
,
6733 .disable
= chv_dpio_cmn_power_well_disable
,
6734 .is_enabled
= vlv_power_well_enabled
,
6737 static struct i915_power_well i9xx_always_on_power_well
[] = {
6739 .name
= "always-on",
6741 .domains
= POWER_DOMAIN_MASK
,
6742 .ops
= &i9xx_always_on_power_well_ops
,
6746 static const struct i915_power_well_ops hsw_power_well_ops
= {
6747 .sync_hw
= hsw_power_well_sync_hw
,
6748 .enable
= hsw_power_well_enable
,
6749 .disable
= hsw_power_well_disable
,
6750 .is_enabled
= hsw_power_well_enabled
,
6753 static struct i915_power_well hsw_power_wells
[] = {
6755 .name
= "always-on",
6757 .domains
= HSW_ALWAYS_ON_POWER_DOMAINS
,
6758 .ops
= &i9xx_always_on_power_well_ops
,
6762 .domains
= HSW_DISPLAY_POWER_DOMAINS
,
6763 .ops
= &hsw_power_well_ops
,
6767 static struct i915_power_well bdw_power_wells
[] = {
6769 .name
= "always-on",
6771 .domains
= BDW_ALWAYS_ON_POWER_DOMAINS
,
6772 .ops
= &i9xx_always_on_power_well_ops
,
6776 .domains
= BDW_DISPLAY_POWER_DOMAINS
,
6777 .ops
= &hsw_power_well_ops
,
6781 static const struct i915_power_well_ops vlv_display_power_well_ops
= {
6782 .sync_hw
= vlv_power_well_sync_hw
,
6783 .enable
= vlv_display_power_well_enable
,
6784 .disable
= vlv_display_power_well_disable
,
6785 .is_enabled
= vlv_power_well_enabled
,
6788 static const struct i915_power_well_ops vlv_dpio_cmn_power_well_ops
= {
6789 .sync_hw
= vlv_power_well_sync_hw
,
6790 .enable
= vlv_dpio_cmn_power_well_enable
,
6791 .disable
= vlv_dpio_cmn_power_well_disable
,
6792 .is_enabled
= vlv_power_well_enabled
,
6795 static const struct i915_power_well_ops vlv_dpio_power_well_ops
= {
6796 .sync_hw
= vlv_power_well_sync_hw
,
6797 .enable
= vlv_power_well_enable
,
6798 .disable
= vlv_power_well_disable
,
6799 .is_enabled
= vlv_power_well_enabled
,
6802 static struct i915_power_well vlv_power_wells
[] = {
6804 .name
= "always-on",
6806 .domains
= VLV_ALWAYS_ON_POWER_DOMAINS
,
6807 .ops
= &i9xx_always_on_power_well_ops
,
6811 .domains
= VLV_DISPLAY_POWER_DOMAINS
,
6812 .data
= PUNIT_POWER_WELL_DISP2D
,
6813 .ops
= &vlv_display_power_well_ops
,
6816 .name
= "dpio-tx-b-01",
6817 .domains
= VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS
|
6818 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS
|
6819 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS
|
6820 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS
,
6821 .ops
= &vlv_dpio_power_well_ops
,
6822 .data
= PUNIT_POWER_WELL_DPIO_TX_B_LANES_01
,
6825 .name
= "dpio-tx-b-23",
6826 .domains
= VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS
|
6827 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS
|
6828 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS
|
6829 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS
,
6830 .ops
= &vlv_dpio_power_well_ops
,
6831 .data
= PUNIT_POWER_WELL_DPIO_TX_B_LANES_23
,
6834 .name
= "dpio-tx-c-01",
6835 .domains
= VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS
|
6836 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS
|
6837 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS
|
6838 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS
,
6839 .ops
= &vlv_dpio_power_well_ops
,
6840 .data
= PUNIT_POWER_WELL_DPIO_TX_C_LANES_01
,
6843 .name
= "dpio-tx-c-23",
6844 .domains
= VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS
|
6845 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS
|
6846 VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS
|
6847 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS
,
6848 .ops
= &vlv_dpio_power_well_ops
,
6849 .data
= PUNIT_POWER_WELL_DPIO_TX_C_LANES_23
,
6852 .name
= "dpio-common",
6853 .domains
= VLV_DPIO_CMN_BC_POWER_DOMAINS
,
6854 .data
= PUNIT_POWER_WELL_DPIO_CMN_BC
,
6855 .ops
= &vlv_dpio_cmn_power_well_ops
,
6859 static struct i915_power_well chv_power_wells
[] = {
6861 .name
= "always-on",
6863 .domains
= VLV_ALWAYS_ON_POWER_DOMAINS
,
6864 .ops
= &i9xx_always_on_power_well_ops
,
6869 .domains
= VLV_DISPLAY_POWER_DOMAINS
,
6870 .data
= PUNIT_POWER_WELL_DISP2D
,
6871 .ops
= &vlv_display_power_well_ops
,
6875 .domains
= CHV_PIPE_A_POWER_DOMAINS
,
6877 .ops
= &chv_pipe_power_well_ops
,
6881 .domains
= CHV_PIPE_B_POWER_DOMAINS
,
6883 .ops
= &chv_pipe_power_well_ops
,
6887 .domains
= CHV_PIPE_C_POWER_DOMAINS
,
6889 .ops
= &chv_pipe_power_well_ops
,
6893 .name
= "dpio-common-bc",
6895 * XXX: cmnreset for one PHY seems to disturb the other.
6896 * As a workaround keep both powered on at the same
6899 .domains
= CHV_DPIO_CMN_BC_POWER_DOMAINS
| CHV_DPIO_CMN_D_POWER_DOMAINS
,
6900 .data
= PUNIT_POWER_WELL_DPIO_CMN_BC
,
6901 .ops
= &chv_dpio_cmn_power_well_ops
,
6904 .name
= "dpio-common-d",
6906 * XXX: cmnreset for one PHY seems to disturb the other.
6907 * As a workaround keep both powered on at the same
6910 .domains
= CHV_DPIO_CMN_BC_POWER_DOMAINS
| CHV_DPIO_CMN_D_POWER_DOMAINS
,
6911 .data
= PUNIT_POWER_WELL_DPIO_CMN_D
,
6912 .ops
= &chv_dpio_cmn_power_well_ops
,
6916 .name
= "dpio-tx-b-01",
6917 .domains
= VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS
|
6918 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS
,
6919 .ops
= &vlv_dpio_power_well_ops
,
6920 .data
= PUNIT_POWER_WELL_DPIO_TX_B_LANES_01
,
6923 .name
= "dpio-tx-b-23",
6924 .domains
= VLV_DPIO_TX_B_LANES_01_POWER_DOMAINS
|
6925 VLV_DPIO_TX_B_LANES_23_POWER_DOMAINS
,
6926 .ops
= &vlv_dpio_power_well_ops
,
6927 .data
= PUNIT_POWER_WELL_DPIO_TX_B_LANES_23
,
6930 .name
= "dpio-tx-c-01",
6931 .domains
= VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS
|
6932 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS
,
6933 .ops
= &vlv_dpio_power_well_ops
,
6934 .data
= PUNIT_POWER_WELL_DPIO_TX_C_LANES_01
,
6937 .name
= "dpio-tx-c-23",
6938 .domains
= VLV_DPIO_TX_C_LANES_01_POWER_DOMAINS
|
6939 VLV_DPIO_TX_C_LANES_23_POWER_DOMAINS
,
6940 .ops
= &vlv_dpio_power_well_ops
,
6941 .data
= PUNIT_POWER_WELL_DPIO_TX_C_LANES_23
,
6944 .name
= "dpio-tx-d-01",
6945 .domains
= CHV_DPIO_TX_D_LANES_01_POWER_DOMAINS
|
6946 CHV_DPIO_TX_D_LANES_23_POWER_DOMAINS
,
6947 .ops
= &vlv_dpio_power_well_ops
,
6948 .data
= PUNIT_POWER_WELL_DPIO_TX_D_LANES_01
,
6951 .name
= "dpio-tx-d-23",
6952 .domains
= CHV_DPIO_TX_D_LANES_01_POWER_DOMAINS
|
6953 CHV_DPIO_TX_D_LANES_23_POWER_DOMAINS
,
6954 .ops
= &vlv_dpio_power_well_ops
,
6955 .data
= PUNIT_POWER_WELL_DPIO_TX_D_LANES_23
,
6960 static struct i915_power_well
*lookup_power_well(struct drm_i915_private
*dev_priv
,
6961 enum punit_power_well power_well_id
)
6963 struct i915_power_domains
*power_domains
= &dev_priv
->power_domains
;
6964 struct i915_power_well
*power_well
;
6967 for_each_power_well(i
, power_well
, POWER_DOMAIN_MASK
, power_domains
) {
6968 if (power_well
->data
== power_well_id
)
6975 #define set_power_wells(power_domains, __power_wells) ({ \
6976 (power_domains)->power_wells = (__power_wells); \
6977 (power_domains)->power_well_count = ARRAY_SIZE(__power_wells); \
6980 int intel_power_domains_init(struct drm_i915_private
*dev_priv
)
6982 struct i915_power_domains
*power_domains
= &dev_priv
->power_domains
;
6984 mutex_init(&power_domains
->lock
);
6987 * The enabling order will be from lower to higher indexed wells,
6988 * the disabling order is reversed.
6990 if (IS_HASWELL(dev_priv
->dev
)) {
6991 set_power_wells(power_domains
, hsw_power_wells
);
6992 hsw_pwr
= power_domains
;
6993 } else if (IS_BROADWELL(dev_priv
->dev
)) {
6994 set_power_wells(power_domains
, bdw_power_wells
);
6995 hsw_pwr
= power_domains
;
6996 } else if (IS_CHERRYVIEW(dev_priv
->dev
)) {
6997 set_power_wells(power_domains
, chv_power_wells
);
6998 } else if (IS_VALLEYVIEW(dev_priv
->dev
)) {
6999 set_power_wells(power_domains
, vlv_power_wells
);
7001 set_power_wells(power_domains
, i9xx_always_on_power_well
);
7007 void intel_power_domains_remove(struct drm_i915_private
*dev_priv
)
7012 static void intel_power_domains_resume(struct drm_i915_private
*dev_priv
)
7014 struct i915_power_domains
*power_domains
= &dev_priv
->power_domains
;
7015 struct i915_power_well
*power_well
;
7018 mutex_lock(&power_domains
->lock
);
7019 for_each_power_well(i
, power_well
, POWER_DOMAIN_MASK
, power_domains
) {
7020 power_well
->ops
->sync_hw(dev_priv
, power_well
);
7021 power_well
->hw_enabled
= power_well
->ops
->is_enabled(dev_priv
,
7024 mutex_unlock(&power_domains
->lock
);
7027 static void vlv_cmnlane_wa(struct drm_i915_private
*dev_priv
)
7029 struct i915_power_well
*cmn
=
7030 lookup_power_well(dev_priv
, PUNIT_POWER_WELL_DPIO_CMN_BC
);
7031 struct i915_power_well
*disp2d
=
7032 lookup_power_well(dev_priv
, PUNIT_POWER_WELL_DISP2D
);
7034 /* nothing to do if common lane is already off */
7035 if (!cmn
->ops
->is_enabled(dev_priv
, cmn
))
7038 /* If the display might be already active skip this */
7039 if (disp2d
->ops
->is_enabled(dev_priv
, disp2d
) &&
7040 I915_READ(DPIO_CTL
) & DPIO_CMNRST
)
7043 DRM_DEBUG_KMS("toggling display PHY side reset\n");
7045 /* cmnlane needs DPLL registers */
7046 disp2d
->ops
->enable(dev_priv
, disp2d
);
7049 * From VLV2A0_DP_eDP_HDMI_DPIO_driver_vbios_notes_11.docx:
7050 * Need to assert and de-assert PHY SB reset by gating the
7051 * common lane power, then un-gating it.
7052 * Simply ungating isn't enough to reset the PHY enough to get
7053 * ports and lanes running.
7055 cmn
->ops
->disable(dev_priv
, cmn
);
7058 void intel_power_domains_init_hw(struct drm_i915_private
*dev_priv
)
7060 struct drm_device
*dev
= dev_priv
->dev
;
7061 struct i915_power_domains
*power_domains
= &dev_priv
->power_domains
;
7063 power_domains
->initializing
= true;
7065 if (IS_VALLEYVIEW(dev
) && !IS_CHERRYVIEW(dev
)) {
7066 mutex_lock(&power_domains
->lock
);
7067 vlv_cmnlane_wa(dev_priv
);
7068 mutex_unlock(&power_domains
->lock
);
7071 /* For now, we need the power well to be always enabled. */
7072 intel_display_set_init_power(dev_priv
, true);
7073 intel_power_domains_resume(dev_priv
);
7074 power_domains
->initializing
= false;
7077 void intel_aux_display_runtime_get(struct drm_i915_private
*dev_priv
)
7079 intel_runtime_pm_get(dev_priv
);
7082 void intel_aux_display_runtime_put(struct drm_i915_private
*dev_priv
)
7084 intel_runtime_pm_put(dev_priv
);
7087 void intel_runtime_pm_get(struct drm_i915_private
*dev_priv
)
7089 struct drm_device
*dev
= dev_priv
->dev
;
7090 struct device
*device
= &dev
->pdev
->dev
;
7092 if (!HAS_RUNTIME_PM(dev
))
7095 pm_runtime_get_sync(device
);
7096 WARN(dev_priv
->pm
.suspended
, "Device still suspended.\n");
7099 void intel_runtime_pm_get_noresume(struct drm_i915_private
*dev_priv
)
7101 struct drm_device
*dev
= dev_priv
->dev
;
7102 struct device
*device
= &dev
->pdev
->dev
;
7104 if (!HAS_RUNTIME_PM(dev
))
7107 WARN(dev_priv
->pm
.suspended
, "Getting nosync-ref while suspended.\n");
7108 pm_runtime_get_noresume(device
);
7111 void intel_runtime_pm_put(struct drm_i915_private
*dev_priv
)
7113 struct drm_device
*dev
= dev_priv
->dev
;
7114 struct device
*device
= &dev
->pdev
->dev
;
7116 if (!HAS_RUNTIME_PM(dev
))
7119 pm_runtime_mark_last_busy(device
);
7120 pm_runtime_put_autosuspend(device
);
7123 void intel_init_runtime_pm(struct drm_i915_private
*dev_priv
)
7125 struct drm_device
*dev
= dev_priv
->dev
;
7126 struct device
*device
= &dev
->pdev
->dev
;
7128 if (!HAS_RUNTIME_PM(dev
))
7131 pm_runtime_set_active(device
);
7134 * RPM depends on RC6 to save restore the GT HW context, so make RC6 a
7137 if (!intel_enable_rc6(dev
)) {
7138 DRM_INFO("RC6 disabled, disabling runtime PM support\n");
7142 pm_runtime_set_autosuspend_delay(device
, 10000); /* 10s */
7143 pm_runtime_mark_last_busy(device
);
7144 pm_runtime_use_autosuspend(device
);
7146 pm_runtime_put_autosuspend(device
);
7149 void intel_fini_runtime_pm(struct drm_i915_private
*dev_priv
)
7151 struct drm_device
*dev
= dev_priv
->dev
;
7152 struct device
*device
= &dev
->pdev
->dev
;
7154 if (!HAS_RUNTIME_PM(dev
))
7157 if (!intel_enable_rc6(dev
))
7160 /* Make sure we're not suspended first. */
7161 pm_runtime_get_sync(device
);
7162 pm_runtime_disable(device
);
7165 /* Set up chip specific power management-related functions */
7166 void intel_init_pm(struct drm_device
*dev
)
7168 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7171 if (INTEL_INFO(dev
)->gen
>= 7) {
7172 dev_priv
->display
.fbc_enabled
= ironlake_fbc_enabled
;
7173 dev_priv
->display
.enable_fbc
= gen7_enable_fbc
;
7174 dev_priv
->display
.disable_fbc
= ironlake_disable_fbc
;
7175 } else if (INTEL_INFO(dev
)->gen
>= 5) {
7176 dev_priv
->display
.fbc_enabled
= ironlake_fbc_enabled
;
7177 dev_priv
->display
.enable_fbc
= ironlake_enable_fbc
;
7178 dev_priv
->display
.disable_fbc
= ironlake_disable_fbc
;
7179 } else if (IS_GM45(dev
)) {
7180 dev_priv
->display
.fbc_enabled
= g4x_fbc_enabled
;
7181 dev_priv
->display
.enable_fbc
= g4x_enable_fbc
;
7182 dev_priv
->display
.disable_fbc
= g4x_disable_fbc
;
7184 dev_priv
->display
.fbc_enabled
= i8xx_fbc_enabled
;
7185 dev_priv
->display
.enable_fbc
= i8xx_enable_fbc
;
7186 dev_priv
->display
.disable_fbc
= i8xx_disable_fbc
;
7188 /* This value was pulled out of someone's hat */
7189 I915_WRITE(FBC_CONTROL
, 500 << FBC_CTL_INTERVAL_SHIFT
);
7194 if (IS_PINEVIEW(dev
))
7195 i915_pineview_get_mem_freq(dev
);
7196 else if (IS_GEN5(dev
))
7197 i915_ironlake_get_mem_freq(dev
);
7199 /* For FIFO watermark updates */
7200 if (HAS_PCH_SPLIT(dev
)) {
7201 ilk_setup_wm_latency(dev
);
7203 if ((IS_GEN5(dev
) && dev_priv
->wm
.pri_latency
[1] &&
7204 dev_priv
->wm
.spr_latency
[1] && dev_priv
->wm
.cur_latency
[1]) ||
7205 (!IS_GEN5(dev
) && dev_priv
->wm
.pri_latency
[0] &&
7206 dev_priv
->wm
.spr_latency
[0] && dev_priv
->wm
.cur_latency
[0])) {
7207 dev_priv
->display
.update_wm
= ilk_update_wm
;
7208 dev_priv
->display
.update_sprite_wm
= ilk_update_sprite_wm
;
7210 DRM_DEBUG_KMS("Failed to read display plane latency. "
7215 dev_priv
->display
.init_clock_gating
= ironlake_init_clock_gating
;
7216 else if (IS_GEN6(dev
))
7217 dev_priv
->display
.init_clock_gating
= gen6_init_clock_gating
;
7218 else if (IS_IVYBRIDGE(dev
))
7219 dev_priv
->display
.init_clock_gating
= ivybridge_init_clock_gating
;
7220 else if (IS_HASWELL(dev
))
7221 dev_priv
->display
.init_clock_gating
= haswell_init_clock_gating
;
7222 else if (INTEL_INFO(dev
)->gen
== 8)
7223 dev_priv
->display
.init_clock_gating
= broadwell_init_clock_gating
;
7224 } else if (IS_CHERRYVIEW(dev
)) {
7225 dev_priv
->display
.update_wm
= cherryview_update_wm
;
7226 dev_priv
->display
.update_sprite_wm
= valleyview_update_sprite_wm
;
7227 dev_priv
->display
.init_clock_gating
=
7228 cherryview_init_clock_gating
;
7229 } else if (IS_VALLEYVIEW(dev
)) {
7230 dev_priv
->display
.update_wm
= valleyview_update_wm
;
7231 dev_priv
->display
.update_sprite_wm
= valleyview_update_sprite_wm
;
7232 dev_priv
->display
.init_clock_gating
=
7233 valleyview_init_clock_gating
;
7234 } else if (IS_PINEVIEW(dev
)) {
7235 if (!intel_get_cxsr_latency(IS_PINEVIEW_G(dev
),
7238 dev_priv
->mem_freq
)) {
7239 DRM_INFO("failed to find known CxSR latency "
7240 "(found ddr%s fsb freq %d, mem freq %d), "
7242 (dev_priv
->is_ddr3
== 1) ? "3" : "2",
7243 dev_priv
->fsb_freq
, dev_priv
->mem_freq
);
7244 /* Disable CxSR and never update its watermark again */
7245 intel_set_memory_cxsr(dev_priv
, false);
7246 dev_priv
->display
.update_wm
= NULL
;
7248 dev_priv
->display
.update_wm
= pineview_update_wm
;
7249 dev_priv
->display
.init_clock_gating
= gen3_init_clock_gating
;
7250 } else if (IS_G4X(dev
)) {
7251 dev_priv
->display
.update_wm
= g4x_update_wm
;
7252 dev_priv
->display
.init_clock_gating
= g4x_init_clock_gating
;
7253 } else if (IS_GEN4(dev
)) {
7254 dev_priv
->display
.update_wm
= i965_update_wm
;
7255 if (IS_CRESTLINE(dev
))
7256 dev_priv
->display
.init_clock_gating
= crestline_init_clock_gating
;
7257 else if (IS_BROADWATER(dev
))
7258 dev_priv
->display
.init_clock_gating
= broadwater_init_clock_gating
;
7259 } else if (IS_GEN3(dev
)) {
7260 dev_priv
->display
.update_wm
= i9xx_update_wm
;
7261 dev_priv
->display
.get_fifo_size
= i9xx_get_fifo_size
;
7262 dev_priv
->display
.init_clock_gating
= gen3_init_clock_gating
;
7263 } else if (IS_GEN2(dev
)) {
7264 if (INTEL_INFO(dev
)->num_pipes
== 1) {
7265 dev_priv
->display
.update_wm
= i845_update_wm
;
7266 dev_priv
->display
.get_fifo_size
= i845_get_fifo_size
;
7268 dev_priv
->display
.update_wm
= i9xx_update_wm
;
7269 dev_priv
->display
.get_fifo_size
= i830_get_fifo_size
;
7272 if (IS_I85X(dev
) || IS_I865G(dev
))
7273 dev_priv
->display
.init_clock_gating
= i85x_init_clock_gating
;
7275 dev_priv
->display
.init_clock_gating
= i830_init_clock_gating
;
7277 DRM_ERROR("unexpected fall-through in intel_init_pm\n");
7281 int sandybridge_pcode_read(struct drm_i915_private
*dev_priv
, u8 mbox
, u32
*val
)
7283 WARN_ON(!mutex_is_locked(&dev_priv
->rps
.hw_lock
));
7285 if (I915_READ(GEN6_PCODE_MAILBOX
) & GEN6_PCODE_READY
) {
7286 DRM_DEBUG_DRIVER("warning: pcode (read) mailbox access failed\n");
7290 I915_WRITE(GEN6_PCODE_DATA
, *val
);
7291 I915_WRITE(GEN6_PCODE_MAILBOX
, GEN6_PCODE_READY
| mbox
);
7293 if (wait_for((I915_READ(GEN6_PCODE_MAILBOX
) & GEN6_PCODE_READY
) == 0,
7295 DRM_ERROR("timeout waiting for pcode read (%d) to finish\n", mbox
);
7299 *val
= I915_READ(GEN6_PCODE_DATA
);
7300 I915_WRITE(GEN6_PCODE_DATA
, 0);
7305 int sandybridge_pcode_write(struct drm_i915_private
*dev_priv
, u8 mbox
, u32 val
)
7307 WARN_ON(!mutex_is_locked(&dev_priv
->rps
.hw_lock
));
7309 if (I915_READ(GEN6_PCODE_MAILBOX
) & GEN6_PCODE_READY
) {
7310 DRM_DEBUG_DRIVER("warning: pcode (write) mailbox access failed\n");
7314 I915_WRITE(GEN6_PCODE_DATA
, val
);
7315 I915_WRITE(GEN6_PCODE_MAILBOX
, GEN6_PCODE_READY
| mbox
);
7317 if (wait_for((I915_READ(GEN6_PCODE_MAILBOX
) & GEN6_PCODE_READY
) == 0,
7319 DRM_ERROR("timeout waiting for pcode write (%d) to finish\n", mbox
);
7323 I915_WRITE(GEN6_PCODE_DATA
, 0);
7328 static int byt_gpu_freq(struct drm_i915_private
*dev_priv
, int val
)
7333 switch (dev_priv
->mem_freq
) {
7347 return DIV_ROUND_CLOSEST(dev_priv
->mem_freq
* (val
+ 6 - 0xbd), 4 * div
);
7350 static int byt_freq_opcode(struct drm_i915_private
*dev_priv
, int val
)
7355 switch (dev_priv
->mem_freq
) {
7369 return DIV_ROUND_CLOSEST(4 * mul
* val
, dev_priv
->mem_freq
) + 0xbd - 6;
7372 static int chv_gpu_freq(struct drm_i915_private
*dev_priv
, int val
)
7376 switch (dev_priv
->rps
.cz_freq
) {
7392 freq
= (DIV_ROUND_CLOSEST((dev_priv
->rps
.cz_freq
* val
), 2 * div
) / 2);
7397 static int chv_freq_opcode(struct drm_i915_private
*dev_priv
, int val
)
7401 switch (dev_priv
->rps
.cz_freq
) {
7417 opcode
= (DIV_ROUND_CLOSEST((val
* 2 * mul
), dev_priv
->rps
.cz_freq
) * 2);
7422 int vlv_gpu_freq(struct drm_i915_private
*dev_priv
, int val
)
7426 if (IS_CHERRYVIEW(dev_priv
->dev
))
7427 ret
= chv_gpu_freq(dev_priv
, val
);
7428 else if (IS_VALLEYVIEW(dev_priv
->dev
))
7429 ret
= byt_gpu_freq(dev_priv
, val
);
7434 int vlv_freq_opcode(struct drm_i915_private
*dev_priv
, int val
)
7438 if (IS_CHERRYVIEW(dev_priv
->dev
))
7439 ret
= chv_freq_opcode(dev_priv
, val
);
7440 else if (IS_VALLEYVIEW(dev_priv
->dev
))
7441 ret
= byt_freq_opcode(dev_priv
, val
);
7446 void intel_pm_setup(struct drm_device
*dev
)
7448 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
7450 mutex_init(&dev_priv
->rps
.hw_lock
);
7452 INIT_DELAYED_WORK(&dev_priv
->rps
.delayed_resume_work
,
7453 intel_gen6_powersave_work
);
7455 dev_priv
->pm
.suspended
= false;
7456 dev_priv
->pm
._irqs_disabled
= false;