blob: c9a470f9d8800756dbd9a53eff54a1c949af403d [file] [log] [blame]
Rodrigo Vivi7ff0ebc2014-12-08 14:09:10 -02001/*
2 * Copyright © 2014 Intel Corporation
3 *
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:
10 *
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
13 * Software.
14 *
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
21 * DEALINGS IN THE SOFTWARE.
22 */
23
Rodrigo Vivi94b839572014-12-08 06:46:31 -080024/**
25 * DOC: Frame Buffer Compression (FBC)
26 *
27 * FBC tries to save memory bandwidth (and so power consumption) by
28 * compressing the amount of memory used by the display. It is total
29 * transparent to user space and completely handled in the kernel.
Rodrigo Vivi7ff0ebc2014-12-08 14:09:10 -020030 *
31 * The benefits of FBC are mostly visible with solid backgrounds and
Rodrigo Vivi94b839572014-12-08 06:46:31 -080032 * variation-less patterns. It comes from keeping the memory footprint small
33 * and having fewer memory pages opened and accessed for refreshing the display.
Rodrigo Vivi7ff0ebc2014-12-08 14:09:10 -020034 *
Rodrigo Vivi94b839572014-12-08 06:46:31 -080035 * i915 is responsible to reserve stolen memory for FBC and configure its
36 * offset on proper registers. The hardware takes care of all
37 * compress/decompress. However there are many known cases where we have to
38 * forcibly disable it to allow proper screen updates.
Rodrigo Vivi7ff0ebc2014-12-08 14:09:10 -020039 */
40
Rodrigo Vivi94b839572014-12-08 06:46:31 -080041#include "intel_drv.h"
42#include "i915_drv.h"
43
Rodrigo Vivi7ff0ebc2014-12-08 14:09:10 -020044static void i8xx_fbc_disable(struct drm_device *dev)
45{
46 struct drm_i915_private *dev_priv = dev->dev_private;
47 u32 fbc_ctl;
48
49 dev_priv->fbc.enabled = false;
50
51 /* Disable compression */
52 fbc_ctl = I915_READ(FBC_CONTROL);
53 if ((fbc_ctl & FBC_CTL_EN) == 0)
54 return;
55
56 fbc_ctl &= ~FBC_CTL_EN;
57 I915_WRITE(FBC_CONTROL, fbc_ctl);
58
59 /* Wait for compressing bit to clear */
60 if (wait_for((I915_READ(FBC_STATUS) & FBC_STAT_COMPRESSING) == 0, 10)) {
61 DRM_DEBUG_KMS("FBC idle timed out\n");
62 return;
63 }
64
65 DRM_DEBUG_KMS("disabled FBC\n");
66}
67
68static void i8xx_fbc_enable(struct drm_crtc *crtc)
69{
70 struct drm_device *dev = crtc->dev;
71 struct drm_i915_private *dev_priv = dev->dev_private;
72 struct drm_framebuffer *fb = crtc->primary->fb;
73 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
74 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
75 int cfb_pitch;
76 int i;
77 u32 fbc_ctl;
78
79 dev_priv->fbc.enabled = true;
80
Jani Nikula60ee5cd2015-02-05 12:04:27 +020081 /* Note: fbc.threshold == 1 for i8xx */
82 cfb_pitch = dev_priv->fbc.uncompressed_size / FBC_LL_SIZE;
Rodrigo Vivi7ff0ebc2014-12-08 14:09:10 -020083 if (fb->pitches[0] < cfb_pitch)
84 cfb_pitch = fb->pitches[0];
85
86 /* FBC_CTL wants 32B or 64B units */
87 if (IS_GEN2(dev))
88 cfb_pitch = (cfb_pitch / 32) - 1;
89 else
90 cfb_pitch = (cfb_pitch / 64) - 1;
91
92 /* Clear old tags */
93 for (i = 0; i < (FBC_LL_SIZE / 32) + 1; i++)
94 I915_WRITE(FBC_TAG + (i * 4), 0);
95
96 if (IS_GEN4(dev)) {
97 u32 fbc_ctl2;
98
99 /* Set it up... */
100 fbc_ctl2 = FBC_CTL_FENCE_DBL | FBC_CTL_IDLE_IMM | FBC_CTL_CPU_FENCE;
101 fbc_ctl2 |= FBC_CTL_PLANE(intel_crtc->plane);
102 I915_WRITE(FBC_CONTROL2, fbc_ctl2);
103 I915_WRITE(FBC_FENCE_OFF, crtc->y);
104 }
105
106 /* enable it... */
107 fbc_ctl = I915_READ(FBC_CONTROL);
108 fbc_ctl &= 0x3fff << FBC_CTL_INTERVAL_SHIFT;
109 fbc_ctl |= FBC_CTL_EN | FBC_CTL_PERIODIC;
110 if (IS_I945GM(dev))
111 fbc_ctl |= FBC_CTL_C3_IDLE; /* 945 needs special SR handling */
112 fbc_ctl |= (cfb_pitch & 0xff) << FBC_CTL_STRIDE_SHIFT;
113 fbc_ctl |= obj->fence_reg;
114 I915_WRITE(FBC_CONTROL, fbc_ctl);
115
116 DRM_DEBUG_KMS("enabled FBC, pitch %d, yoff %d, plane %c\n",
117 cfb_pitch, crtc->y, plane_name(intel_crtc->plane));
118}
119
120static bool i8xx_fbc_enabled(struct drm_device *dev)
121{
122 struct drm_i915_private *dev_priv = dev->dev_private;
123
124 return I915_READ(FBC_CONTROL) & FBC_CTL_EN;
125}
126
127static void g4x_fbc_enable(struct drm_crtc *crtc)
128{
129 struct drm_device *dev = crtc->dev;
130 struct drm_i915_private *dev_priv = dev->dev_private;
131 struct drm_framebuffer *fb = crtc->primary->fb;
132 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
133 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
134 u32 dpfc_ctl;
135
136 dev_priv->fbc.enabled = true;
137
138 dpfc_ctl = DPFC_CTL_PLANE(intel_crtc->plane) | DPFC_SR_EN;
139 if (drm_format_plane_cpp(fb->pixel_format, 0) == 2)
140 dpfc_ctl |= DPFC_CTL_LIMIT_2X;
141 else
142 dpfc_ctl |= DPFC_CTL_LIMIT_1X;
143 dpfc_ctl |= DPFC_CTL_FENCE_EN | obj->fence_reg;
144
145 I915_WRITE(DPFC_FENCE_YOFF, crtc->y);
146
147 /* enable it... */
148 I915_WRITE(DPFC_CONTROL, dpfc_ctl | DPFC_CTL_EN);
149
150 DRM_DEBUG_KMS("enabled fbc on plane %c\n", plane_name(intel_crtc->plane));
151}
152
153static void g4x_fbc_disable(struct drm_device *dev)
154{
155 struct drm_i915_private *dev_priv = dev->dev_private;
156 u32 dpfc_ctl;
157
158 dev_priv->fbc.enabled = false;
159
160 /* Disable compression */
161 dpfc_ctl = I915_READ(DPFC_CONTROL);
162 if (dpfc_ctl & DPFC_CTL_EN) {
163 dpfc_ctl &= ~DPFC_CTL_EN;
164 I915_WRITE(DPFC_CONTROL, dpfc_ctl);
165
166 DRM_DEBUG_KMS("disabled FBC\n");
167 }
168}
169
170static bool g4x_fbc_enabled(struct drm_device *dev)
171{
172 struct drm_i915_private *dev_priv = dev->dev_private;
173
174 return I915_READ(DPFC_CONTROL) & DPFC_CTL_EN;
175}
176
177static void snb_fbc_blit_update(struct drm_device *dev)
178{
179 struct drm_i915_private *dev_priv = dev->dev_private;
180 u32 blt_ecoskpd;
181
182 /* Make sure blitter notifies FBC of writes */
183
184 /* Blitter is part of Media powerwell on VLV. No impact of
185 * his param in other platforms for now */
Mika Kuoppala59bad942015-01-16 11:34:40 +0200186 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_MEDIA);
Rodrigo Vivi7ff0ebc2014-12-08 14:09:10 -0200187
188 blt_ecoskpd = I915_READ(GEN6_BLITTER_ECOSKPD);
189 blt_ecoskpd |= GEN6_BLITTER_FBC_NOTIFY <<
190 GEN6_BLITTER_LOCK_SHIFT;
191 I915_WRITE(GEN6_BLITTER_ECOSKPD, blt_ecoskpd);
192 blt_ecoskpd |= GEN6_BLITTER_FBC_NOTIFY;
193 I915_WRITE(GEN6_BLITTER_ECOSKPD, blt_ecoskpd);
194 blt_ecoskpd &= ~(GEN6_BLITTER_FBC_NOTIFY <<
195 GEN6_BLITTER_LOCK_SHIFT);
196 I915_WRITE(GEN6_BLITTER_ECOSKPD, blt_ecoskpd);
197 POSTING_READ(GEN6_BLITTER_ECOSKPD);
198
Mika Kuoppala59bad942015-01-16 11:34:40 +0200199 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_MEDIA);
Rodrigo Vivi7ff0ebc2014-12-08 14:09:10 -0200200}
201
202static void ilk_fbc_enable(struct drm_crtc *crtc)
203{
204 struct drm_device *dev = crtc->dev;
205 struct drm_i915_private *dev_priv = dev->dev_private;
206 struct drm_framebuffer *fb = crtc->primary->fb;
207 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
208 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
209 u32 dpfc_ctl;
210
211 dev_priv->fbc.enabled = true;
212
213 dpfc_ctl = DPFC_CTL_PLANE(intel_crtc->plane);
214 if (drm_format_plane_cpp(fb->pixel_format, 0) == 2)
215 dev_priv->fbc.threshold++;
216
217 switch (dev_priv->fbc.threshold) {
218 case 4:
219 case 3:
220 dpfc_ctl |= DPFC_CTL_LIMIT_4X;
221 break;
222 case 2:
223 dpfc_ctl |= DPFC_CTL_LIMIT_2X;
224 break;
225 case 1:
226 dpfc_ctl |= DPFC_CTL_LIMIT_1X;
227 break;
228 }
229 dpfc_ctl |= DPFC_CTL_FENCE_EN;
230 if (IS_GEN5(dev))
231 dpfc_ctl |= obj->fence_reg;
232
233 I915_WRITE(ILK_DPFC_FENCE_YOFF, crtc->y);
234 I915_WRITE(ILK_FBC_RT_BASE, i915_gem_obj_ggtt_offset(obj) | ILK_FBC_RT_VALID);
235 /* enable it... */
236 I915_WRITE(ILK_DPFC_CONTROL, dpfc_ctl | DPFC_CTL_EN);
237
238 if (IS_GEN6(dev)) {
239 I915_WRITE(SNB_DPFC_CTL_SA,
240 SNB_CPU_FENCE_ENABLE | obj->fence_reg);
241 I915_WRITE(DPFC_CPU_FENCE_OFFSET, crtc->y);
242 snb_fbc_blit_update(dev);
243 }
244
245 DRM_DEBUG_KMS("enabled fbc on plane %c\n", plane_name(intel_crtc->plane));
246}
247
248static void ilk_fbc_disable(struct drm_device *dev)
249{
250 struct drm_i915_private *dev_priv = dev->dev_private;
251 u32 dpfc_ctl;
252
253 dev_priv->fbc.enabled = false;
254
255 /* Disable compression */
256 dpfc_ctl = I915_READ(ILK_DPFC_CONTROL);
257 if (dpfc_ctl & DPFC_CTL_EN) {
258 dpfc_ctl &= ~DPFC_CTL_EN;
259 I915_WRITE(ILK_DPFC_CONTROL, dpfc_ctl);
260
261 DRM_DEBUG_KMS("disabled FBC\n");
262 }
263}
264
265static bool ilk_fbc_enabled(struct drm_device *dev)
266{
267 struct drm_i915_private *dev_priv = dev->dev_private;
268
269 return I915_READ(ILK_DPFC_CONTROL) & DPFC_CTL_EN;
270}
271
272static void gen7_fbc_enable(struct drm_crtc *crtc)
273{
274 struct drm_device *dev = crtc->dev;
275 struct drm_i915_private *dev_priv = dev->dev_private;
276 struct drm_framebuffer *fb = crtc->primary->fb;
277 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
278 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
279 u32 dpfc_ctl;
280
281 dev_priv->fbc.enabled = true;
282
283 dpfc_ctl = IVB_DPFC_CTL_PLANE(intel_crtc->plane);
284 if (drm_format_plane_cpp(fb->pixel_format, 0) == 2)
285 dev_priv->fbc.threshold++;
286
287 switch (dev_priv->fbc.threshold) {
288 case 4:
289 case 3:
290 dpfc_ctl |= DPFC_CTL_LIMIT_4X;
291 break;
292 case 2:
293 dpfc_ctl |= DPFC_CTL_LIMIT_2X;
294 break;
295 case 1:
296 dpfc_ctl |= DPFC_CTL_LIMIT_1X;
297 break;
298 }
299
300 dpfc_ctl |= IVB_DPFC_CTL_FENCE_EN;
301
302 if (dev_priv->fbc.false_color)
303 dpfc_ctl |= FBC_CTL_FALSE_COLOR;
304
305 I915_WRITE(ILK_DPFC_CONTROL, dpfc_ctl | DPFC_CTL_EN);
306
307 if (IS_IVYBRIDGE(dev)) {
308 /* WaFbcAsynchFlipDisableFbcQueue:ivb */
309 I915_WRITE(ILK_DISPLAY_CHICKEN1,
310 I915_READ(ILK_DISPLAY_CHICKEN1) |
311 ILK_FBCQ_DIS);
312 } else {
313 /* WaFbcAsynchFlipDisableFbcQueue:hsw,bdw */
314 I915_WRITE(CHICKEN_PIPESL_1(intel_crtc->pipe),
315 I915_READ(CHICKEN_PIPESL_1(intel_crtc->pipe)) |
316 HSW_FBCQ_DIS);
317 }
318
319 I915_WRITE(SNB_DPFC_CTL_SA,
320 SNB_CPU_FENCE_ENABLE | obj->fence_reg);
321 I915_WRITE(DPFC_CPU_FENCE_OFFSET, crtc->y);
322
323 snb_fbc_blit_update(dev);
324
325 DRM_DEBUG_KMS("enabled fbc on plane %c\n", plane_name(intel_crtc->plane));
326}
327
Rodrigo Vivi94b839572014-12-08 06:46:31 -0800328/**
329 * intel_fbc_enabled - Is FBC enabled?
330 * @dev: the drm_device
331 *
332 * This function is used to verify the current state of FBC.
333 * FIXME: This should be tracked in the plane config eventually
334 * instead of queried at runtime for most callers.
335 */
Rodrigo Vivi7ff0ebc2014-12-08 14:09:10 -0200336bool intel_fbc_enabled(struct drm_device *dev)
337{
338 struct drm_i915_private *dev_priv = dev->dev_private;
339
340 return dev_priv->fbc.enabled;
341}
342
343void bdw_fbc_sw_flush(struct drm_device *dev, u32 value)
344{
345 struct drm_i915_private *dev_priv = dev->dev_private;
346
347 if (!IS_GEN8(dev))
348 return;
349
350 if (!intel_fbc_enabled(dev))
351 return;
352
353 I915_WRITE(MSG_FBC_REND_STATE, value);
354}
355
356static void intel_fbc_work_fn(struct work_struct *__work)
357{
358 struct intel_fbc_work *work =
359 container_of(to_delayed_work(__work),
360 struct intel_fbc_work, work);
361 struct drm_device *dev = work->crtc->dev;
362 struct drm_i915_private *dev_priv = dev->dev_private;
363
364 mutex_lock(&dev->struct_mutex);
365 if (work == dev_priv->fbc.fbc_work) {
366 /* Double check that we haven't switched fb without cancelling
367 * the prior work.
368 */
369 if (work->crtc->primary->fb == work->fb) {
370 dev_priv->display.enable_fbc(work->crtc);
371
372 dev_priv->fbc.plane = to_intel_crtc(work->crtc)->plane;
373 dev_priv->fbc.fb_id = work->crtc->primary->fb->base.id;
374 dev_priv->fbc.y = work->crtc->y;
375 }
376
377 dev_priv->fbc.fbc_work = NULL;
378 }
379 mutex_unlock(&dev->struct_mutex);
380
381 kfree(work);
382}
383
384static void intel_fbc_cancel_work(struct drm_i915_private *dev_priv)
385{
386 if (dev_priv->fbc.fbc_work == NULL)
387 return;
388
389 DRM_DEBUG_KMS("cancelling pending FBC enable\n");
390
391 /* Synchronisation is provided by struct_mutex and checking of
392 * dev_priv->fbc.fbc_work, so we can perform the cancellation
393 * entirely asynchronously.
394 */
395 if (cancel_delayed_work(&dev_priv->fbc.fbc_work->work))
396 /* tasklet was killed before being run, clean up */
397 kfree(dev_priv->fbc.fbc_work);
398
399 /* Mark the work as no longer wanted so that if it does
400 * wake-up (because the work was already running and waiting
401 * for our mutex), it will discover that is no longer
402 * necessary to run.
403 */
404 dev_priv->fbc.fbc_work = NULL;
405}
406
407static void intel_fbc_enable(struct drm_crtc *crtc)
408{
409 struct intel_fbc_work *work;
410 struct drm_device *dev = crtc->dev;
411 struct drm_i915_private *dev_priv = dev->dev_private;
412
413 if (!dev_priv->display.enable_fbc)
414 return;
415
416 intel_fbc_cancel_work(dev_priv);
417
418 work = kzalloc(sizeof(*work), GFP_KERNEL);
419 if (work == NULL) {
420 DRM_ERROR("Failed to allocate FBC work structure\n");
421 dev_priv->display.enable_fbc(crtc);
422 return;
423 }
424
425 work->crtc = crtc;
426 work->fb = crtc->primary->fb;
427 INIT_DELAYED_WORK(&work->work, intel_fbc_work_fn);
428
429 dev_priv->fbc.fbc_work = work;
430
431 /* Delay the actual enabling to let pageflipping cease and the
432 * display to settle before starting the compression. Note that
433 * this delay also serves a second purpose: it allows for a
434 * vblank to pass after disabling the FBC before we attempt
435 * to modify the control registers.
436 *
437 * A more complicated solution would involve tracking vblanks
438 * following the termination of the page-flipping sequence
439 * and indeed performing the enable as a co-routine and not
440 * waiting synchronously upon the vblank.
441 *
442 * WaFbcWaitForVBlankBeforeEnable:ilk,snb
443 */
444 schedule_delayed_work(&work->work, msecs_to_jiffies(50));
445}
446
Rodrigo Vivi94b839572014-12-08 06:46:31 -0800447/**
448 * intel_fbc_disable - disable FBC
449 * @dev: the drm_device
450 *
451 * This function disables FBC.
452 */
Rodrigo Vivi7ff0ebc2014-12-08 14:09:10 -0200453void intel_fbc_disable(struct drm_device *dev)
454{
455 struct drm_i915_private *dev_priv = dev->dev_private;
456
457 intel_fbc_cancel_work(dev_priv);
458
459 if (!dev_priv->display.disable_fbc)
460 return;
461
462 dev_priv->display.disable_fbc(dev);
463 dev_priv->fbc.plane = -1;
464}
465
466static bool set_no_fbc_reason(struct drm_i915_private *dev_priv,
467 enum no_fbc_reason reason)
468{
469 if (dev_priv->fbc.no_fbc_reason == reason)
470 return false;
471
472 dev_priv->fbc.no_fbc_reason = reason;
473 return true;
474}
475
476/**
477 * intel_fbc_update - enable/disable FBC as needed
478 * @dev: the drm_device
479 *
480 * Set up the framebuffer compression hardware at mode set time. We
481 * enable it if possible:
482 * - plane A only (on pre-965)
483 * - no pixel mulitply/line duplication
484 * - no alpha buffer discard
485 * - no dual wide
486 * - framebuffer <= max_hdisplay in width, max_vdisplay in height
487 *
488 * We can't assume that any compression will take place (worst case),
489 * so the compressed buffer has to be the same size as the uncompressed
490 * one. It also must reside (along with the line length buffer) in
491 * stolen memory.
492 *
493 * We need to enable/disable FBC on a global basis.
494 */
495void intel_fbc_update(struct drm_device *dev)
496{
497 struct drm_i915_private *dev_priv = dev->dev_private;
498 struct drm_crtc *crtc = NULL, *tmp_crtc;
499 struct intel_crtc *intel_crtc;
500 struct drm_framebuffer *fb;
501 struct drm_i915_gem_object *obj;
502 const struct drm_display_mode *adjusted_mode;
503 unsigned int max_width, max_height;
504
505 if (!HAS_FBC(dev)) {
506 set_no_fbc_reason(dev_priv, FBC_UNSUPPORTED);
507 return;
508 }
509
Paulo Zanoni7cc65742015-02-09 14:46:27 -0200510 if (i915.enable_fbc < 0) {
511 if (set_no_fbc_reason(dev_priv, FBC_CHIP_DEFAULT))
512 DRM_DEBUG_KMS("disabled per chip default\n");
513 goto out_disable;
514 }
515
516 if (!i915.enable_fbc || !i915.powersave) {
Rodrigo Vivi7ff0ebc2014-12-08 14:09:10 -0200517 if (set_no_fbc_reason(dev_priv, FBC_MODULE_PARAM))
518 DRM_DEBUG_KMS("fbc disabled per module param\n");
Paulo Zanoni7cc65742015-02-09 14:46:27 -0200519 goto out_disable;
Rodrigo Vivi7ff0ebc2014-12-08 14:09:10 -0200520 }
521
522 /*
523 * If FBC is already on, we just have to verify that we can
524 * keep it that way...
525 * Need to disable if:
526 * - more than one pipe is active
527 * - changing FBC params (stride, fence, mode)
528 * - new fb is too large to fit in compressed buffer
529 * - going to an unsupported config (interlace, pixel multiply, etc.)
530 */
531 for_each_crtc(dev, tmp_crtc) {
532 if (intel_crtc_active(tmp_crtc) &&
533 to_intel_crtc(tmp_crtc)->primary_enabled) {
534 if (crtc) {
535 if (set_no_fbc_reason(dev_priv, FBC_MULTIPLE_PIPES))
536 DRM_DEBUG_KMS("more than one pipe active, disabling compression\n");
537 goto out_disable;
538 }
539 crtc = tmp_crtc;
540 }
541 }
542
543 if (!crtc || crtc->primary->fb == NULL) {
544 if (set_no_fbc_reason(dev_priv, FBC_NO_OUTPUT))
545 DRM_DEBUG_KMS("no output, disabling\n");
546 goto out_disable;
547 }
548
549 intel_crtc = to_intel_crtc(crtc);
550 fb = crtc->primary->fb;
551 obj = intel_fb_obj(fb);
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +0200552 adjusted_mode = &intel_crtc->config->base.adjusted_mode;
Rodrigo Vivi7ff0ebc2014-12-08 14:09:10 -0200553
Rodrigo Vivi7ff0ebc2014-12-08 14:09:10 -0200554 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, "
558 "disabling\n");
559 goto out_disable;
560 }
561
562 if (INTEL_INFO(dev)->gen >= 8 || IS_HASWELL(dev)) {
563 max_width = 4096;
564 max_height = 4096;
565 } else if (IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) {
566 max_width = 4096;
567 max_height = 2048;
568 } else {
569 max_width = 2048;
570 max_height = 1536;
571 }
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +0200572 if (intel_crtc->config->pipe_src_w > max_width ||
573 intel_crtc->config->pipe_src_h > max_height) {
Rodrigo Vivi7ff0ebc2014-12-08 14:09:10 -0200574 if (set_no_fbc_reason(dev_priv, FBC_MODE_TOO_LARGE))
575 DRM_DEBUG_KMS("mode too large for compression, disabling\n");
576 goto out_disable;
577 }
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");
582 goto out_disable;
583 }
584
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.
587 */
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");
592 goto out_disable;
593 }
594 if (INTEL_INFO(dev)->gen <= 4 && !IS_G4X(dev) &&
Matt Roper8e7d6882015-01-21 16:35:41 -0800595 crtc->primary->state->rotation != BIT(DRM_ROTATE_0)) {
Rodrigo Vivi7ff0ebc2014-12-08 14:09:10 -0200596 if (set_no_fbc_reason(dev_priv, FBC_UNSUPPORTED_MODE))
597 DRM_DEBUG_KMS("Rotation unsupported, disabling\n");
598 goto out_disable;
599 }
600
601 /* If the kernel debugger is active, always disable compression */
602 if (in_dbg_master())
603 goto out_disable;
604
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");
609 goto out_disable;
610 }
611
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.
616 */
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)
620 return;
621
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.
628 *
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
637 * callback.
638 *
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.
645 */
646 DRM_DEBUG_KMS("disabling active FBC for update\n");
647 intel_fbc_disable(dev);
648 }
649
650 intel_fbc_enable(crtc);
651 dev_priv->fbc.no_fbc_reason = FBC_OK;
652 return;
653
654out_disable:
655 /* Multiple disables should be harmless */
656 if (intel_fbc_enabled(dev)) {
657 DRM_DEBUG_KMS("unsupported config, disabling FBC\n");
658 intel_fbc_disable(dev);
659 }
660 i915_gem_stolen_cleanup_compression(dev);
661}
662
Rodrigo Vivi94b839572014-12-08 06:46:31 -0800663/**
664 * intel_fbc_init - Initialize FBC
665 * @dev_priv: the i915 device
666 *
667 * This function might be called during PM init process.
668 */
Rodrigo Vivi7ff0ebc2014-12-08 14:09:10 -0200669void intel_fbc_init(struct drm_i915_private *dev_priv)
670{
671 if (!HAS_FBC(dev_priv)) {
672 dev_priv->fbc.enabled = false;
673 return;
674 }
675
676 if (INTEL_INFO(dev_priv)->gen >= 7) {
677 dev_priv->display.fbc_enabled = ilk_fbc_enabled;
678 dev_priv->display.enable_fbc = gen7_fbc_enable;
679 dev_priv->display.disable_fbc = ilk_fbc_disable;
680 } else if (INTEL_INFO(dev_priv)->gen >= 5) {
681 dev_priv->display.fbc_enabled = ilk_fbc_enabled;
682 dev_priv->display.enable_fbc = ilk_fbc_enable;
683 dev_priv->display.disable_fbc = ilk_fbc_disable;
684 } else if (IS_GM45(dev_priv)) {
685 dev_priv->display.fbc_enabled = g4x_fbc_enabled;
686 dev_priv->display.enable_fbc = g4x_fbc_enable;
687 dev_priv->display.disable_fbc = g4x_fbc_disable;
688 } else {
689 dev_priv->display.fbc_enabled = i8xx_fbc_enabled;
690 dev_priv->display.enable_fbc = i8xx_fbc_enable;
691 dev_priv->display.disable_fbc = i8xx_fbc_disable;
692
693 /* This value was pulled out of someone's hat */
694 I915_WRITE(FBC_CONTROL, 500 << FBC_CTL_INTERVAL_SHIFT);
695 }
696
697 dev_priv->fbc.enabled = dev_priv->display.fbc_enabled(dev_priv->dev);
698}