Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 1 | /* |
| 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 Vivi | 94b8395 | 2014-12-08 06:46:31 -0800 | [diff] [blame] | 24 | /** |
| 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 Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 30 | * |
| 31 | * The benefits of FBC are mostly visible with solid backgrounds and |
Rodrigo Vivi | 94b8395 | 2014-12-08 06:46:31 -0800 | [diff] [blame] | 32 | * 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 Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 34 | * |
Rodrigo Vivi | 94b8395 | 2014-12-08 06:46:31 -0800 | [diff] [blame] | 35 | * 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 Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 39 | */ |
| 40 | |
Rodrigo Vivi | 94b8395 | 2014-12-08 06:46:31 -0800 | [diff] [blame] | 41 | #include "intel_drv.h" |
| 42 | #include "i915_drv.h" |
| 43 | |
Paulo Zanoni | 7733b49 | 2015-07-07 15:26:04 -0300 | [diff] [blame] | 44 | static void i8xx_fbc_disable(struct drm_i915_private *dev_priv) |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 45 | { |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 46 | u32 fbc_ctl; |
| 47 | |
| 48 | dev_priv->fbc.enabled = false; |
| 49 | |
| 50 | /* Disable compression */ |
| 51 | fbc_ctl = I915_READ(FBC_CONTROL); |
| 52 | if ((fbc_ctl & FBC_CTL_EN) == 0) |
| 53 | return; |
| 54 | |
| 55 | fbc_ctl &= ~FBC_CTL_EN; |
| 56 | I915_WRITE(FBC_CONTROL, fbc_ctl); |
| 57 | |
| 58 | /* Wait for compressing bit to clear */ |
| 59 | if (wait_for((I915_READ(FBC_STATUS) & FBC_STAT_COMPRESSING) == 0, 10)) { |
| 60 | DRM_DEBUG_KMS("FBC idle timed out\n"); |
| 61 | return; |
| 62 | } |
| 63 | |
| 64 | DRM_DEBUG_KMS("disabled FBC\n"); |
| 65 | } |
| 66 | |
Paulo Zanoni | 220285f | 2015-07-07 15:26:05 -0300 | [diff] [blame] | 67 | static void i8xx_fbc_enable(struct intel_crtc *crtc) |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 68 | { |
Paulo Zanoni | 220285f | 2015-07-07 15:26:05 -0300 | [diff] [blame] | 69 | struct drm_i915_private *dev_priv = crtc->base.dev->dev_private; |
| 70 | struct drm_framebuffer *fb = crtc->base.primary->fb; |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 71 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 72 | int cfb_pitch; |
| 73 | int i; |
| 74 | u32 fbc_ctl; |
| 75 | |
| 76 | dev_priv->fbc.enabled = true; |
| 77 | |
Jani Nikula | 60ee5cd | 2015-02-05 12:04:27 +0200 | [diff] [blame] | 78 | /* Note: fbc.threshold == 1 for i8xx */ |
| 79 | cfb_pitch = dev_priv->fbc.uncompressed_size / FBC_LL_SIZE; |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 80 | if (fb->pitches[0] < cfb_pitch) |
| 81 | cfb_pitch = fb->pitches[0]; |
| 82 | |
| 83 | /* FBC_CTL wants 32B or 64B units */ |
Paulo Zanoni | 7733b49 | 2015-07-07 15:26:04 -0300 | [diff] [blame] | 84 | if (IS_GEN2(dev_priv)) |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 85 | cfb_pitch = (cfb_pitch / 32) - 1; |
| 86 | else |
| 87 | cfb_pitch = (cfb_pitch / 64) - 1; |
| 88 | |
| 89 | /* Clear old tags */ |
| 90 | for (i = 0; i < (FBC_LL_SIZE / 32) + 1; i++) |
| 91 | I915_WRITE(FBC_TAG + (i * 4), 0); |
| 92 | |
Paulo Zanoni | 7733b49 | 2015-07-07 15:26:04 -0300 | [diff] [blame] | 93 | if (IS_GEN4(dev_priv)) { |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 94 | u32 fbc_ctl2; |
| 95 | |
| 96 | /* Set it up... */ |
| 97 | fbc_ctl2 = FBC_CTL_FENCE_DBL | FBC_CTL_IDLE_IMM | FBC_CTL_CPU_FENCE; |
Paulo Zanoni | 220285f | 2015-07-07 15:26:05 -0300 | [diff] [blame] | 98 | fbc_ctl2 |= FBC_CTL_PLANE(crtc->plane); |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 99 | I915_WRITE(FBC_CONTROL2, fbc_ctl2); |
Paulo Zanoni | 220285f | 2015-07-07 15:26:05 -0300 | [diff] [blame] | 100 | I915_WRITE(FBC_FENCE_OFF, crtc->base.y); |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | /* enable it... */ |
| 104 | fbc_ctl = I915_READ(FBC_CONTROL); |
| 105 | fbc_ctl &= 0x3fff << FBC_CTL_INTERVAL_SHIFT; |
| 106 | fbc_ctl |= FBC_CTL_EN | FBC_CTL_PERIODIC; |
Paulo Zanoni | 7733b49 | 2015-07-07 15:26:04 -0300 | [diff] [blame] | 107 | if (IS_I945GM(dev_priv)) |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 108 | fbc_ctl |= FBC_CTL_C3_IDLE; /* 945 needs special SR handling */ |
| 109 | fbc_ctl |= (cfb_pitch & 0xff) << FBC_CTL_STRIDE_SHIFT; |
| 110 | fbc_ctl |= obj->fence_reg; |
| 111 | I915_WRITE(FBC_CONTROL, fbc_ctl); |
| 112 | |
| 113 | DRM_DEBUG_KMS("enabled FBC, pitch %d, yoff %d, plane %c\n", |
Paulo Zanoni | 220285f | 2015-07-07 15:26:05 -0300 | [diff] [blame] | 114 | cfb_pitch, crtc->base.y, plane_name(crtc->plane)); |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 115 | } |
| 116 | |
Paulo Zanoni | 7733b49 | 2015-07-07 15:26:04 -0300 | [diff] [blame] | 117 | static bool i8xx_fbc_enabled(struct drm_i915_private *dev_priv) |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 118 | { |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 119 | return I915_READ(FBC_CONTROL) & FBC_CTL_EN; |
| 120 | } |
| 121 | |
Paulo Zanoni | 220285f | 2015-07-07 15:26:05 -0300 | [diff] [blame] | 122 | static void g4x_fbc_enable(struct intel_crtc *crtc) |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 123 | { |
Paulo Zanoni | 220285f | 2015-07-07 15:26:05 -0300 | [diff] [blame] | 124 | struct drm_i915_private *dev_priv = crtc->base.dev->dev_private; |
| 125 | struct drm_framebuffer *fb = crtc->base.primary->fb; |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 126 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 127 | u32 dpfc_ctl; |
| 128 | |
| 129 | dev_priv->fbc.enabled = true; |
| 130 | |
Paulo Zanoni | 220285f | 2015-07-07 15:26:05 -0300 | [diff] [blame] | 131 | dpfc_ctl = DPFC_CTL_PLANE(crtc->plane) | DPFC_SR_EN; |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 132 | if (drm_format_plane_cpp(fb->pixel_format, 0) == 2) |
| 133 | dpfc_ctl |= DPFC_CTL_LIMIT_2X; |
| 134 | else |
| 135 | dpfc_ctl |= DPFC_CTL_LIMIT_1X; |
| 136 | dpfc_ctl |= DPFC_CTL_FENCE_EN | obj->fence_reg; |
| 137 | |
Paulo Zanoni | 220285f | 2015-07-07 15:26:05 -0300 | [diff] [blame] | 138 | I915_WRITE(DPFC_FENCE_YOFF, crtc->base.y); |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 139 | |
| 140 | /* enable it... */ |
| 141 | I915_WRITE(DPFC_CONTROL, dpfc_ctl | DPFC_CTL_EN); |
| 142 | |
Paulo Zanoni | 220285f | 2015-07-07 15:26:05 -0300 | [diff] [blame] | 143 | DRM_DEBUG_KMS("enabled fbc on plane %c\n", plane_name(crtc->plane)); |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 144 | } |
| 145 | |
Paulo Zanoni | 7733b49 | 2015-07-07 15:26:04 -0300 | [diff] [blame] | 146 | static void g4x_fbc_disable(struct drm_i915_private *dev_priv) |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 147 | { |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 148 | u32 dpfc_ctl; |
| 149 | |
| 150 | dev_priv->fbc.enabled = false; |
| 151 | |
| 152 | /* Disable compression */ |
| 153 | dpfc_ctl = I915_READ(DPFC_CONTROL); |
| 154 | if (dpfc_ctl & DPFC_CTL_EN) { |
| 155 | dpfc_ctl &= ~DPFC_CTL_EN; |
| 156 | I915_WRITE(DPFC_CONTROL, dpfc_ctl); |
| 157 | |
| 158 | DRM_DEBUG_KMS("disabled FBC\n"); |
| 159 | } |
| 160 | } |
| 161 | |
Paulo Zanoni | 7733b49 | 2015-07-07 15:26:04 -0300 | [diff] [blame] | 162 | static bool g4x_fbc_enabled(struct drm_i915_private *dev_priv) |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 163 | { |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 164 | return I915_READ(DPFC_CONTROL) & DPFC_CTL_EN; |
| 165 | } |
| 166 | |
Paulo Zanoni | dbef0f1 | 2015-02-13 17:23:46 -0200 | [diff] [blame] | 167 | static void intel_fbc_nuke(struct drm_i915_private *dev_priv) |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 168 | { |
Paulo Zanoni | dbef0f1 | 2015-02-13 17:23:46 -0200 | [diff] [blame] | 169 | I915_WRITE(MSG_FBC_REND_STATE, FBC_REND_NUKE); |
| 170 | POSTING_READ(MSG_FBC_REND_STATE); |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 171 | } |
| 172 | |
Paulo Zanoni | 220285f | 2015-07-07 15:26:05 -0300 | [diff] [blame] | 173 | static void ilk_fbc_enable(struct intel_crtc *crtc) |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 174 | { |
Paulo Zanoni | 220285f | 2015-07-07 15:26:05 -0300 | [diff] [blame] | 175 | struct drm_i915_private *dev_priv = crtc->base.dev->dev_private; |
| 176 | struct drm_framebuffer *fb = crtc->base.primary->fb; |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 177 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 178 | u32 dpfc_ctl; |
Paulo Zanoni | ce65e47 | 2015-06-30 10:53:05 -0300 | [diff] [blame] | 179 | int threshold = dev_priv->fbc.threshold; |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 180 | |
| 181 | dev_priv->fbc.enabled = true; |
| 182 | |
Paulo Zanoni | 220285f | 2015-07-07 15:26:05 -0300 | [diff] [blame] | 183 | dpfc_ctl = DPFC_CTL_PLANE(crtc->plane); |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 184 | if (drm_format_plane_cpp(fb->pixel_format, 0) == 2) |
Paulo Zanoni | ce65e47 | 2015-06-30 10:53:05 -0300 | [diff] [blame] | 185 | threshold++; |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 186 | |
Paulo Zanoni | ce65e47 | 2015-06-30 10:53:05 -0300 | [diff] [blame] | 187 | switch (threshold) { |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 188 | case 4: |
| 189 | case 3: |
| 190 | dpfc_ctl |= DPFC_CTL_LIMIT_4X; |
| 191 | break; |
| 192 | case 2: |
| 193 | dpfc_ctl |= DPFC_CTL_LIMIT_2X; |
| 194 | break; |
| 195 | case 1: |
| 196 | dpfc_ctl |= DPFC_CTL_LIMIT_1X; |
| 197 | break; |
| 198 | } |
| 199 | dpfc_ctl |= DPFC_CTL_FENCE_EN; |
Paulo Zanoni | 7733b49 | 2015-07-07 15:26:04 -0300 | [diff] [blame] | 200 | if (IS_GEN5(dev_priv)) |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 201 | dpfc_ctl |= obj->fence_reg; |
| 202 | |
Paulo Zanoni | 220285f | 2015-07-07 15:26:05 -0300 | [diff] [blame] | 203 | I915_WRITE(ILK_DPFC_FENCE_YOFF, crtc->base.y); |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 204 | I915_WRITE(ILK_FBC_RT_BASE, i915_gem_obj_ggtt_offset(obj) | ILK_FBC_RT_VALID); |
| 205 | /* enable it... */ |
| 206 | I915_WRITE(ILK_DPFC_CONTROL, dpfc_ctl | DPFC_CTL_EN); |
| 207 | |
Paulo Zanoni | 7733b49 | 2015-07-07 15:26:04 -0300 | [diff] [blame] | 208 | if (IS_GEN6(dev_priv)) { |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 209 | I915_WRITE(SNB_DPFC_CTL_SA, |
| 210 | SNB_CPU_FENCE_ENABLE | obj->fence_reg); |
Paulo Zanoni | 220285f | 2015-07-07 15:26:05 -0300 | [diff] [blame] | 211 | I915_WRITE(DPFC_CPU_FENCE_OFFSET, crtc->base.y); |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 212 | } |
| 213 | |
Paulo Zanoni | dbef0f1 | 2015-02-13 17:23:46 -0200 | [diff] [blame] | 214 | intel_fbc_nuke(dev_priv); |
| 215 | |
Paulo Zanoni | 220285f | 2015-07-07 15:26:05 -0300 | [diff] [blame] | 216 | DRM_DEBUG_KMS("enabled fbc on plane %c\n", plane_name(crtc->plane)); |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 217 | } |
| 218 | |
Paulo Zanoni | 7733b49 | 2015-07-07 15:26:04 -0300 | [diff] [blame] | 219 | static void ilk_fbc_disable(struct drm_i915_private *dev_priv) |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 220 | { |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 221 | u32 dpfc_ctl; |
| 222 | |
| 223 | dev_priv->fbc.enabled = false; |
| 224 | |
| 225 | /* Disable compression */ |
| 226 | dpfc_ctl = I915_READ(ILK_DPFC_CONTROL); |
| 227 | if (dpfc_ctl & DPFC_CTL_EN) { |
| 228 | dpfc_ctl &= ~DPFC_CTL_EN; |
| 229 | I915_WRITE(ILK_DPFC_CONTROL, dpfc_ctl); |
| 230 | |
| 231 | DRM_DEBUG_KMS("disabled FBC\n"); |
| 232 | } |
| 233 | } |
| 234 | |
Paulo Zanoni | 7733b49 | 2015-07-07 15:26:04 -0300 | [diff] [blame] | 235 | static bool ilk_fbc_enabled(struct drm_i915_private *dev_priv) |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 236 | { |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 237 | return I915_READ(ILK_DPFC_CONTROL) & DPFC_CTL_EN; |
| 238 | } |
| 239 | |
Paulo Zanoni | 220285f | 2015-07-07 15:26:05 -0300 | [diff] [blame] | 240 | static void gen7_fbc_enable(struct intel_crtc *crtc) |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 241 | { |
Paulo Zanoni | 220285f | 2015-07-07 15:26:05 -0300 | [diff] [blame] | 242 | struct drm_i915_private *dev_priv = crtc->base.dev->dev_private; |
| 243 | struct drm_framebuffer *fb = crtc->base.primary->fb; |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 244 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 245 | u32 dpfc_ctl; |
Paulo Zanoni | ce65e47 | 2015-06-30 10:53:05 -0300 | [diff] [blame] | 246 | int threshold = dev_priv->fbc.threshold; |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 247 | |
| 248 | dev_priv->fbc.enabled = true; |
| 249 | |
Paulo Zanoni | d8514d6 | 2015-06-12 14:36:21 -0300 | [diff] [blame] | 250 | dpfc_ctl = 0; |
Paulo Zanoni | 7733b49 | 2015-07-07 15:26:04 -0300 | [diff] [blame] | 251 | if (IS_IVYBRIDGE(dev_priv)) |
Paulo Zanoni | 220285f | 2015-07-07 15:26:05 -0300 | [diff] [blame] | 252 | dpfc_ctl |= IVB_DPFC_CTL_PLANE(crtc->plane); |
Paulo Zanoni | d8514d6 | 2015-06-12 14:36:21 -0300 | [diff] [blame] | 253 | |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 254 | if (drm_format_plane_cpp(fb->pixel_format, 0) == 2) |
Paulo Zanoni | ce65e47 | 2015-06-30 10:53:05 -0300 | [diff] [blame] | 255 | threshold++; |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 256 | |
Paulo Zanoni | ce65e47 | 2015-06-30 10:53:05 -0300 | [diff] [blame] | 257 | switch (threshold) { |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 258 | case 4: |
| 259 | case 3: |
| 260 | dpfc_ctl |= DPFC_CTL_LIMIT_4X; |
| 261 | break; |
| 262 | case 2: |
| 263 | dpfc_ctl |= DPFC_CTL_LIMIT_2X; |
| 264 | break; |
| 265 | case 1: |
| 266 | dpfc_ctl |= DPFC_CTL_LIMIT_1X; |
| 267 | break; |
| 268 | } |
| 269 | |
| 270 | dpfc_ctl |= IVB_DPFC_CTL_FENCE_EN; |
| 271 | |
| 272 | if (dev_priv->fbc.false_color) |
| 273 | dpfc_ctl |= FBC_CTL_FALSE_COLOR; |
| 274 | |
| 275 | I915_WRITE(ILK_DPFC_CONTROL, dpfc_ctl | DPFC_CTL_EN); |
| 276 | |
Paulo Zanoni | 7733b49 | 2015-07-07 15:26:04 -0300 | [diff] [blame] | 277 | if (IS_IVYBRIDGE(dev_priv)) { |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 278 | /* WaFbcAsynchFlipDisableFbcQueue:ivb */ |
| 279 | I915_WRITE(ILK_DISPLAY_CHICKEN1, |
| 280 | I915_READ(ILK_DISPLAY_CHICKEN1) | |
| 281 | ILK_FBCQ_DIS); |
| 282 | } else { |
| 283 | /* WaFbcAsynchFlipDisableFbcQueue:hsw,bdw */ |
Paulo Zanoni | 220285f | 2015-07-07 15:26:05 -0300 | [diff] [blame] | 284 | I915_WRITE(CHICKEN_PIPESL_1(crtc->pipe), |
| 285 | I915_READ(CHICKEN_PIPESL_1(crtc->pipe)) | |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 286 | HSW_FBCQ_DIS); |
| 287 | } |
| 288 | |
| 289 | I915_WRITE(SNB_DPFC_CTL_SA, |
| 290 | SNB_CPU_FENCE_ENABLE | obj->fence_reg); |
Paulo Zanoni | 220285f | 2015-07-07 15:26:05 -0300 | [diff] [blame] | 291 | I915_WRITE(DPFC_CPU_FENCE_OFFSET, crtc->base.y); |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 292 | |
Paulo Zanoni | dbef0f1 | 2015-02-13 17:23:46 -0200 | [diff] [blame] | 293 | intel_fbc_nuke(dev_priv); |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 294 | |
Paulo Zanoni | 220285f | 2015-07-07 15:26:05 -0300 | [diff] [blame] | 295 | DRM_DEBUG_KMS("enabled fbc on plane %c\n", plane_name(crtc->plane)); |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 296 | } |
| 297 | |
Rodrigo Vivi | 94b8395 | 2014-12-08 06:46:31 -0800 | [diff] [blame] | 298 | /** |
| 299 | * intel_fbc_enabled - Is FBC enabled? |
Paulo Zanoni | 7733b49 | 2015-07-07 15:26:04 -0300 | [diff] [blame] | 300 | * @dev_priv: i915 device instance |
Rodrigo Vivi | 94b8395 | 2014-12-08 06:46:31 -0800 | [diff] [blame] | 301 | * |
| 302 | * This function is used to verify the current state of FBC. |
| 303 | * FIXME: This should be tracked in the plane config eventually |
| 304 | * instead of queried at runtime for most callers. |
| 305 | */ |
Paulo Zanoni | 7733b49 | 2015-07-07 15:26:04 -0300 | [diff] [blame] | 306 | bool intel_fbc_enabled(struct drm_i915_private *dev_priv) |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 307 | { |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 308 | return dev_priv->fbc.enabled; |
| 309 | } |
| 310 | |
Paulo Zanoni | e8cb8d6 | 2015-09-14 15:19:55 -0300 | [diff] [blame] | 311 | static void intel_fbc_enable(struct intel_crtc *crtc, |
| 312 | const struct drm_framebuffer *fb) |
| 313 | { |
| 314 | struct drm_i915_private *dev_priv = crtc->base.dev->dev_private; |
| 315 | |
| 316 | dev_priv->fbc.enable_fbc(crtc); |
| 317 | |
| 318 | dev_priv->fbc.crtc = crtc; |
| 319 | dev_priv->fbc.fb_id = fb->base.id; |
| 320 | dev_priv->fbc.y = crtc->base.y; |
| 321 | } |
| 322 | |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 323 | static void intel_fbc_work_fn(struct work_struct *__work) |
| 324 | { |
| 325 | struct intel_fbc_work *work = |
| 326 | container_of(to_delayed_work(__work), |
| 327 | struct intel_fbc_work, work); |
Paulo Zanoni | 220285f | 2015-07-07 15:26:05 -0300 | [diff] [blame] | 328 | struct drm_i915_private *dev_priv = work->crtc->base.dev->dev_private; |
| 329 | struct drm_framebuffer *crtc_fb = work->crtc->base.primary->fb; |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 330 | |
Paulo Zanoni | 25ad93f | 2015-07-02 19:25:10 -0300 | [diff] [blame] | 331 | mutex_lock(&dev_priv->fbc.lock); |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 332 | if (work == dev_priv->fbc.fbc_work) { |
| 333 | /* Double check that we haven't switched fb without cancelling |
| 334 | * the prior work. |
| 335 | */ |
Paulo Zanoni | e8cb8d6 | 2015-09-14 15:19:55 -0300 | [diff] [blame] | 336 | if (crtc_fb == work->fb) |
| 337 | intel_fbc_enable(work->crtc, work->fb); |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 338 | |
| 339 | dev_priv->fbc.fbc_work = NULL; |
| 340 | } |
Paulo Zanoni | 25ad93f | 2015-07-02 19:25:10 -0300 | [diff] [blame] | 341 | mutex_unlock(&dev_priv->fbc.lock); |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 342 | |
| 343 | kfree(work); |
| 344 | } |
| 345 | |
| 346 | static void intel_fbc_cancel_work(struct drm_i915_private *dev_priv) |
| 347 | { |
Paulo Zanoni | 25ad93f | 2015-07-02 19:25:10 -0300 | [diff] [blame] | 348 | WARN_ON(!mutex_is_locked(&dev_priv->fbc.lock)); |
| 349 | |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 350 | if (dev_priv->fbc.fbc_work == NULL) |
| 351 | return; |
| 352 | |
| 353 | DRM_DEBUG_KMS("cancelling pending FBC enable\n"); |
| 354 | |
| 355 | /* Synchronisation is provided by struct_mutex and checking of |
| 356 | * dev_priv->fbc.fbc_work, so we can perform the cancellation |
| 357 | * entirely asynchronously. |
| 358 | */ |
| 359 | if (cancel_delayed_work(&dev_priv->fbc.fbc_work->work)) |
| 360 | /* tasklet was killed before being run, clean up */ |
| 361 | kfree(dev_priv->fbc.fbc_work); |
| 362 | |
| 363 | /* Mark the work as no longer wanted so that if it does |
| 364 | * wake-up (because the work was already running and waiting |
| 365 | * for our mutex), it will discover that is no longer |
| 366 | * necessary to run. |
| 367 | */ |
| 368 | dev_priv->fbc.fbc_work = NULL; |
| 369 | } |
| 370 | |
Paulo Zanoni | e8cb8d6 | 2015-09-14 15:19:55 -0300 | [diff] [blame] | 371 | static void intel_fbc_schedule_enable(struct intel_crtc *crtc) |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 372 | { |
| 373 | struct intel_fbc_work *work; |
Paulo Zanoni | 220285f | 2015-07-07 15:26:05 -0300 | [diff] [blame] | 374 | struct drm_i915_private *dev_priv = crtc->base.dev->dev_private; |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 375 | |
Paulo Zanoni | 25ad93f | 2015-07-02 19:25:10 -0300 | [diff] [blame] | 376 | WARN_ON(!mutex_is_locked(&dev_priv->fbc.lock)); |
| 377 | |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 378 | intel_fbc_cancel_work(dev_priv); |
| 379 | |
| 380 | work = kzalloc(sizeof(*work), GFP_KERNEL); |
| 381 | if (work == NULL) { |
| 382 | DRM_ERROR("Failed to allocate FBC work structure\n"); |
Paulo Zanoni | e8cb8d6 | 2015-09-14 15:19:55 -0300 | [diff] [blame] | 383 | intel_fbc_enable(crtc, crtc->base.primary->fb); |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 384 | return; |
| 385 | } |
| 386 | |
| 387 | work->crtc = crtc; |
Paulo Zanoni | 220285f | 2015-07-07 15:26:05 -0300 | [diff] [blame] | 388 | work->fb = crtc->base.primary->fb; |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 389 | INIT_DELAYED_WORK(&work->work, intel_fbc_work_fn); |
| 390 | |
| 391 | dev_priv->fbc.fbc_work = work; |
| 392 | |
| 393 | /* Delay the actual enabling to let pageflipping cease and the |
| 394 | * display to settle before starting the compression. Note that |
| 395 | * this delay also serves a second purpose: it allows for a |
| 396 | * vblank to pass after disabling the FBC before we attempt |
| 397 | * to modify the control registers. |
| 398 | * |
| 399 | * A more complicated solution would involve tracking vblanks |
| 400 | * following the termination of the page-flipping sequence |
| 401 | * and indeed performing the enable as a co-routine and not |
| 402 | * waiting synchronously upon the vblank. |
| 403 | * |
| 404 | * WaFbcWaitForVBlankBeforeEnable:ilk,snb |
| 405 | */ |
| 406 | schedule_delayed_work(&work->work, msecs_to_jiffies(50)); |
| 407 | } |
| 408 | |
Paulo Zanoni | 7733b49 | 2015-07-07 15:26:04 -0300 | [diff] [blame] | 409 | static void __intel_fbc_disable(struct drm_i915_private *dev_priv) |
Paulo Zanoni | 25ad93f | 2015-07-02 19:25:10 -0300 | [diff] [blame] | 410 | { |
Paulo Zanoni | 25ad93f | 2015-07-02 19:25:10 -0300 | [diff] [blame] | 411 | WARN_ON(!mutex_is_locked(&dev_priv->fbc.lock)); |
| 412 | |
| 413 | intel_fbc_cancel_work(dev_priv); |
| 414 | |
Paulo Zanoni | 7733b49 | 2015-07-07 15:26:04 -0300 | [diff] [blame] | 415 | dev_priv->fbc.disable_fbc(dev_priv); |
Paulo Zanoni | 25ad93f | 2015-07-02 19:25:10 -0300 | [diff] [blame] | 416 | dev_priv->fbc.crtc = NULL; |
| 417 | } |
| 418 | |
Rodrigo Vivi | 94b8395 | 2014-12-08 06:46:31 -0800 | [diff] [blame] | 419 | /** |
| 420 | * intel_fbc_disable - disable FBC |
Paulo Zanoni | 7733b49 | 2015-07-07 15:26:04 -0300 | [diff] [blame] | 421 | * @dev_priv: i915 device instance |
Rodrigo Vivi | 94b8395 | 2014-12-08 06:46:31 -0800 | [diff] [blame] | 422 | * |
| 423 | * This function disables FBC. |
| 424 | */ |
Paulo Zanoni | 7733b49 | 2015-07-07 15:26:04 -0300 | [diff] [blame] | 425 | void intel_fbc_disable(struct drm_i915_private *dev_priv) |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 426 | { |
Paulo Zanoni | ff2a311 | 2015-07-07 15:26:03 -0300 | [diff] [blame] | 427 | if (!dev_priv->fbc.enable_fbc) |
Paulo Zanoni | 0bf73c3 | 2015-07-03 15:40:54 -0300 | [diff] [blame] | 428 | return; |
| 429 | |
Paulo Zanoni | 25ad93f | 2015-07-02 19:25:10 -0300 | [diff] [blame] | 430 | mutex_lock(&dev_priv->fbc.lock); |
Paulo Zanoni | 7733b49 | 2015-07-07 15:26:04 -0300 | [diff] [blame] | 431 | __intel_fbc_disable(dev_priv); |
Paulo Zanoni | 25ad93f | 2015-07-02 19:25:10 -0300 | [diff] [blame] | 432 | mutex_unlock(&dev_priv->fbc.lock); |
| 433 | } |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 434 | |
Paulo Zanoni | 25ad93f | 2015-07-02 19:25:10 -0300 | [diff] [blame] | 435 | /* |
| 436 | * intel_fbc_disable_crtc - disable FBC if it's associated with crtc |
| 437 | * @crtc: the CRTC |
| 438 | * |
| 439 | * This function disables FBC if it's associated with the provided CRTC. |
| 440 | */ |
| 441 | void intel_fbc_disable_crtc(struct intel_crtc *crtc) |
| 442 | { |
Paulo Zanoni | 7733b49 | 2015-07-07 15:26:04 -0300 | [diff] [blame] | 443 | struct drm_i915_private *dev_priv = crtc->base.dev->dev_private; |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 444 | |
Paulo Zanoni | ff2a311 | 2015-07-07 15:26:03 -0300 | [diff] [blame] | 445 | if (!dev_priv->fbc.enable_fbc) |
Paulo Zanoni | 0bf73c3 | 2015-07-03 15:40:54 -0300 | [diff] [blame] | 446 | return; |
| 447 | |
Paulo Zanoni | 25ad93f | 2015-07-02 19:25:10 -0300 | [diff] [blame] | 448 | mutex_lock(&dev_priv->fbc.lock); |
| 449 | if (dev_priv->fbc.crtc == crtc) |
Paulo Zanoni | 7733b49 | 2015-07-07 15:26:04 -0300 | [diff] [blame] | 450 | __intel_fbc_disable(dev_priv); |
Paulo Zanoni | 25ad93f | 2015-07-02 19:25:10 -0300 | [diff] [blame] | 451 | mutex_unlock(&dev_priv->fbc.lock); |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 452 | } |
| 453 | |
Paulo Zanoni | 2e8144a | 2015-06-12 14:36:20 -0300 | [diff] [blame] | 454 | const char *intel_no_fbc_reason_str(enum no_fbc_reason reason) |
| 455 | { |
| 456 | switch (reason) { |
| 457 | case FBC_OK: |
| 458 | return "FBC enabled but currently disabled in hardware"; |
| 459 | case FBC_UNSUPPORTED: |
| 460 | return "unsupported by this chipset"; |
| 461 | case FBC_NO_OUTPUT: |
| 462 | return "no output"; |
| 463 | case FBC_STOLEN_TOO_SMALL: |
| 464 | return "not enough stolen memory"; |
| 465 | case FBC_UNSUPPORTED_MODE: |
| 466 | return "mode incompatible with compression"; |
| 467 | case FBC_MODE_TOO_LARGE: |
| 468 | return "mode too large for compression"; |
| 469 | case FBC_BAD_PLANE: |
| 470 | return "FBC unsupported on plane"; |
| 471 | case FBC_NOT_TILED: |
| 472 | return "framebuffer not tiled or fenced"; |
| 473 | case FBC_MULTIPLE_PIPES: |
| 474 | return "more than one pipe active"; |
| 475 | case FBC_MODULE_PARAM: |
| 476 | return "disabled per module param"; |
| 477 | case FBC_CHIP_DEFAULT: |
| 478 | return "disabled per chip default"; |
| 479 | case FBC_ROTATION: |
| 480 | return "rotation unsupported"; |
Paulo Zanoni | 8935108 | 2015-07-07 15:26:06 -0300 | [diff] [blame] | 481 | case FBC_IN_DBG_MASTER: |
| 482 | return "Kernel debugger is active"; |
Paulo Zanoni | adf70c6 | 2015-09-14 15:19:56 -0300 | [diff] [blame^] | 483 | case FBC_BAD_STRIDE: |
| 484 | return "framebuffer stride not supported"; |
Paulo Zanoni | 2e8144a | 2015-06-12 14:36:20 -0300 | [diff] [blame] | 485 | default: |
| 486 | MISSING_CASE(reason); |
| 487 | return "unknown reason"; |
| 488 | } |
| 489 | } |
| 490 | |
| 491 | static void set_no_fbc_reason(struct drm_i915_private *dev_priv, |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 492 | enum no_fbc_reason reason) |
| 493 | { |
| 494 | if (dev_priv->fbc.no_fbc_reason == reason) |
Paulo Zanoni | 2e8144a | 2015-06-12 14:36:20 -0300 | [diff] [blame] | 495 | return; |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 496 | |
| 497 | dev_priv->fbc.no_fbc_reason = reason; |
Paulo Zanoni | 2e8144a | 2015-06-12 14:36:20 -0300 | [diff] [blame] | 498 | DRM_DEBUG_KMS("Disabling FBC: %s\n", intel_no_fbc_reason_str(reason)); |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 499 | } |
| 500 | |
Paulo Zanoni | 9510675 | 2015-02-13 17:23:41 -0200 | [diff] [blame] | 501 | static struct drm_crtc *intel_fbc_find_crtc(struct drm_i915_private *dev_priv) |
| 502 | { |
Paulo Zanoni | 9510675 | 2015-02-13 17:23:41 -0200 | [diff] [blame] | 503 | struct drm_crtc *crtc = NULL, *tmp_crtc; |
Paulo Zanoni | 68b9214 | 2015-02-13 17:23:42 -0200 | [diff] [blame] | 504 | enum pipe pipe; |
Paulo Zanoni | 232fd93 | 2015-07-07 15:26:07 -0300 | [diff] [blame] | 505 | bool pipe_a_only = false; |
Paulo Zanoni | 9510675 | 2015-02-13 17:23:41 -0200 | [diff] [blame] | 506 | |
Paulo Zanoni | 68b9214 | 2015-02-13 17:23:42 -0200 | [diff] [blame] | 507 | if (IS_HASWELL(dev_priv) || INTEL_INFO(dev_priv)->gen >= 8) |
| 508 | pipe_a_only = true; |
| 509 | |
| 510 | for_each_pipe(dev_priv, pipe) { |
| 511 | tmp_crtc = dev_priv->pipe_to_crtc_mapping[pipe]; |
| 512 | |
Paulo Zanoni | 9510675 | 2015-02-13 17:23:41 -0200 | [diff] [blame] | 513 | if (intel_crtc_active(tmp_crtc) && |
Paulo Zanoni | 232fd93 | 2015-07-07 15:26:07 -0300 | [diff] [blame] | 514 | to_intel_plane_state(tmp_crtc->primary->state)->visible) |
Paulo Zanoni | 9510675 | 2015-02-13 17:23:41 -0200 | [diff] [blame] | 515 | crtc = tmp_crtc; |
Paulo Zanoni | 68b9214 | 2015-02-13 17:23:42 -0200 | [diff] [blame] | 516 | |
| 517 | if (pipe_a_only) |
| 518 | break; |
Paulo Zanoni | 9510675 | 2015-02-13 17:23:41 -0200 | [diff] [blame] | 519 | } |
| 520 | |
Paulo Zanoni | 8df5dd5 | 2015-07-07 15:26:08 -0300 | [diff] [blame] | 521 | if (!crtc || crtc->primary->fb == NULL) |
Paulo Zanoni | 9510675 | 2015-02-13 17:23:41 -0200 | [diff] [blame] | 522 | return NULL; |
Paulo Zanoni | 9510675 | 2015-02-13 17:23:41 -0200 | [diff] [blame] | 523 | |
| 524 | return crtc; |
| 525 | } |
| 526 | |
Paulo Zanoni | 232fd93 | 2015-07-07 15:26:07 -0300 | [diff] [blame] | 527 | static bool multiple_pipes_ok(struct drm_i915_private *dev_priv) |
| 528 | { |
| 529 | enum pipe pipe; |
| 530 | int n_pipes = 0; |
| 531 | struct drm_crtc *crtc; |
| 532 | |
| 533 | if (INTEL_INFO(dev_priv)->gen > 4) |
| 534 | return true; |
| 535 | |
| 536 | for_each_pipe(dev_priv, pipe) { |
| 537 | crtc = dev_priv->pipe_to_crtc_mapping[pipe]; |
| 538 | |
| 539 | if (intel_crtc_active(crtc) && |
| 540 | to_intel_plane_state(crtc->primary->state)->visible) |
| 541 | n_pipes++; |
| 542 | } |
| 543 | |
| 544 | return (n_pipes < 2); |
| 545 | } |
| 546 | |
Paulo Zanoni | 7733b49 | 2015-07-07 15:26:04 -0300 | [diff] [blame] | 547 | static int find_compression_threshold(struct drm_i915_private *dev_priv, |
Paulo Zanoni | fc78672 | 2015-07-02 19:25:08 -0300 | [diff] [blame] | 548 | struct drm_mm_node *node, |
| 549 | int size, |
| 550 | int fb_cpp) |
| 551 | { |
Paulo Zanoni | fc78672 | 2015-07-02 19:25:08 -0300 | [diff] [blame] | 552 | int compression_threshold = 1; |
| 553 | int ret; |
| 554 | |
| 555 | /* HACK: This code depends on what we will do in *_enable_fbc. If that |
| 556 | * code changes, this code needs to change as well. |
| 557 | * |
| 558 | * The enable_fbc code will attempt to use one of our 2 compression |
| 559 | * thresholds, therefore, in that case, we only have 1 resort. |
| 560 | */ |
| 561 | |
| 562 | /* Try to over-allocate to reduce reallocations and fragmentation. */ |
| 563 | ret = i915_gem_stolen_insert_node(dev_priv, node, size <<= 1, 4096); |
| 564 | if (ret == 0) |
| 565 | return compression_threshold; |
| 566 | |
| 567 | again: |
| 568 | /* HW's ability to limit the CFB is 1:4 */ |
| 569 | if (compression_threshold > 4 || |
| 570 | (fb_cpp == 2 && compression_threshold == 2)) |
| 571 | return 0; |
| 572 | |
| 573 | ret = i915_gem_stolen_insert_node(dev_priv, node, size >>= 1, 4096); |
Paulo Zanoni | 7733b49 | 2015-07-07 15:26:04 -0300 | [diff] [blame] | 574 | if (ret && INTEL_INFO(dev_priv)->gen <= 4) { |
Paulo Zanoni | fc78672 | 2015-07-02 19:25:08 -0300 | [diff] [blame] | 575 | return 0; |
| 576 | } else if (ret) { |
| 577 | compression_threshold <<= 1; |
| 578 | goto again; |
| 579 | } else { |
| 580 | return compression_threshold; |
| 581 | } |
| 582 | } |
| 583 | |
Paulo Zanoni | 7733b49 | 2015-07-07 15:26:04 -0300 | [diff] [blame] | 584 | static int intel_fbc_alloc_cfb(struct drm_i915_private *dev_priv, int size, |
| 585 | int fb_cpp) |
Paulo Zanoni | fc78672 | 2015-07-02 19:25:08 -0300 | [diff] [blame] | 586 | { |
Paulo Zanoni | fc78672 | 2015-07-02 19:25:08 -0300 | [diff] [blame] | 587 | struct drm_mm_node *uninitialized_var(compressed_llb); |
| 588 | int ret; |
| 589 | |
Paulo Zanoni | 7733b49 | 2015-07-07 15:26:04 -0300 | [diff] [blame] | 590 | ret = find_compression_threshold(dev_priv, &dev_priv->fbc.compressed_fb, |
Paulo Zanoni | fc78672 | 2015-07-02 19:25:08 -0300 | [diff] [blame] | 591 | size, fb_cpp); |
| 592 | if (!ret) |
| 593 | goto err_llb; |
| 594 | else if (ret > 1) { |
| 595 | DRM_INFO("Reducing the compressed framebuffer size. This may lead to less power savings than a non-reduced-size. Try to increase stolen memory size if available in BIOS.\n"); |
| 596 | |
| 597 | } |
| 598 | |
| 599 | dev_priv->fbc.threshold = ret; |
| 600 | |
| 601 | if (INTEL_INFO(dev_priv)->gen >= 5) |
| 602 | I915_WRITE(ILK_DPFC_CB_BASE, dev_priv->fbc.compressed_fb.start); |
Paulo Zanoni | 7733b49 | 2015-07-07 15:26:04 -0300 | [diff] [blame] | 603 | else if (IS_GM45(dev_priv)) { |
Paulo Zanoni | fc78672 | 2015-07-02 19:25:08 -0300 | [diff] [blame] | 604 | I915_WRITE(DPFC_CB_BASE, dev_priv->fbc.compressed_fb.start); |
| 605 | } else { |
| 606 | compressed_llb = kzalloc(sizeof(*compressed_llb), GFP_KERNEL); |
| 607 | if (!compressed_llb) |
| 608 | goto err_fb; |
| 609 | |
| 610 | ret = i915_gem_stolen_insert_node(dev_priv, compressed_llb, |
| 611 | 4096, 4096); |
| 612 | if (ret) |
| 613 | goto err_fb; |
| 614 | |
| 615 | dev_priv->fbc.compressed_llb = compressed_llb; |
| 616 | |
| 617 | I915_WRITE(FBC_CFB_BASE, |
| 618 | dev_priv->mm.stolen_base + dev_priv->fbc.compressed_fb.start); |
| 619 | I915_WRITE(FBC_LL_BASE, |
| 620 | dev_priv->mm.stolen_base + compressed_llb->start); |
| 621 | } |
| 622 | |
| 623 | dev_priv->fbc.uncompressed_size = size; |
| 624 | |
| 625 | DRM_DEBUG_KMS("reserved %d bytes of contiguous stolen space for FBC\n", |
| 626 | size); |
| 627 | |
| 628 | return 0; |
| 629 | |
| 630 | err_fb: |
| 631 | kfree(compressed_llb); |
| 632 | i915_gem_stolen_remove_node(dev_priv, &dev_priv->fbc.compressed_fb); |
| 633 | err_llb: |
| 634 | pr_info_once("drm: not enough stolen space for compressed buffer (need %d more bytes), disabling. Hint: you may be able to increase stolen memory size in the BIOS to avoid this.\n", size); |
| 635 | return -ENOSPC; |
| 636 | } |
| 637 | |
Paulo Zanoni | 7733b49 | 2015-07-07 15:26:04 -0300 | [diff] [blame] | 638 | static void __intel_fbc_cleanup_cfb(struct drm_i915_private *dev_priv) |
Paulo Zanoni | fc78672 | 2015-07-02 19:25:08 -0300 | [diff] [blame] | 639 | { |
Paulo Zanoni | fc78672 | 2015-07-02 19:25:08 -0300 | [diff] [blame] | 640 | if (dev_priv->fbc.uncompressed_size == 0) |
| 641 | return; |
| 642 | |
| 643 | i915_gem_stolen_remove_node(dev_priv, &dev_priv->fbc.compressed_fb); |
| 644 | |
| 645 | if (dev_priv->fbc.compressed_llb) { |
| 646 | i915_gem_stolen_remove_node(dev_priv, |
| 647 | dev_priv->fbc.compressed_llb); |
| 648 | kfree(dev_priv->fbc.compressed_llb); |
| 649 | } |
| 650 | |
| 651 | dev_priv->fbc.uncompressed_size = 0; |
| 652 | } |
| 653 | |
Paulo Zanoni | 7733b49 | 2015-07-07 15:26:04 -0300 | [diff] [blame] | 654 | void intel_fbc_cleanup_cfb(struct drm_i915_private *dev_priv) |
Paulo Zanoni | 25ad93f | 2015-07-02 19:25:10 -0300 | [diff] [blame] | 655 | { |
Paulo Zanoni | ff2a311 | 2015-07-07 15:26:03 -0300 | [diff] [blame] | 656 | if (!dev_priv->fbc.enable_fbc) |
Paulo Zanoni | 0bf73c3 | 2015-07-03 15:40:54 -0300 | [diff] [blame] | 657 | return; |
| 658 | |
Paulo Zanoni | 25ad93f | 2015-07-02 19:25:10 -0300 | [diff] [blame] | 659 | mutex_lock(&dev_priv->fbc.lock); |
Paulo Zanoni | 7733b49 | 2015-07-07 15:26:04 -0300 | [diff] [blame] | 660 | __intel_fbc_cleanup_cfb(dev_priv); |
Paulo Zanoni | 25ad93f | 2015-07-02 19:25:10 -0300 | [diff] [blame] | 661 | mutex_unlock(&dev_priv->fbc.lock); |
| 662 | } |
| 663 | |
Paulo Zanoni | 7733b49 | 2015-07-07 15:26:04 -0300 | [diff] [blame] | 664 | static int intel_fbc_setup_cfb(struct drm_i915_private *dev_priv, int size, |
| 665 | int fb_cpp) |
Paulo Zanoni | fc78672 | 2015-07-02 19:25:08 -0300 | [diff] [blame] | 666 | { |
Paulo Zanoni | fc78672 | 2015-07-02 19:25:08 -0300 | [diff] [blame] | 667 | if (size <= dev_priv->fbc.uncompressed_size) |
| 668 | return 0; |
| 669 | |
| 670 | /* Release any current block */ |
Paulo Zanoni | 7733b49 | 2015-07-07 15:26:04 -0300 | [diff] [blame] | 671 | __intel_fbc_cleanup_cfb(dev_priv); |
Paulo Zanoni | fc78672 | 2015-07-02 19:25:08 -0300 | [diff] [blame] | 672 | |
Paulo Zanoni | 7733b49 | 2015-07-07 15:26:04 -0300 | [diff] [blame] | 673 | return intel_fbc_alloc_cfb(dev_priv, size, fb_cpp); |
Paulo Zanoni | fc78672 | 2015-07-02 19:25:08 -0300 | [diff] [blame] | 674 | } |
| 675 | |
Paulo Zanoni | adf70c6 | 2015-09-14 15:19:56 -0300 | [diff] [blame^] | 676 | static bool stride_is_valid(struct drm_i915_private *dev_priv, |
| 677 | unsigned int stride) |
| 678 | { |
| 679 | /* These should have been caught earlier. */ |
| 680 | WARN_ON(stride < 512); |
| 681 | WARN_ON((stride & (64 - 1)) != 0); |
| 682 | |
| 683 | /* Below are the additional FBC restrictions. */ |
| 684 | |
| 685 | if (IS_GEN2(dev_priv) || IS_GEN3(dev_priv)) |
| 686 | return stride == 4096 || stride == 8192; |
| 687 | |
| 688 | if (IS_GEN4(dev_priv) && !IS_G4X(dev_priv) && stride < 2048) |
| 689 | return false; |
| 690 | |
| 691 | if (stride > 16384) |
| 692 | return false; |
| 693 | |
| 694 | return true; |
| 695 | } |
| 696 | |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 697 | /** |
Paulo Zanoni | 25ad93f | 2015-07-02 19:25:10 -0300 | [diff] [blame] | 698 | * __intel_fbc_update - enable/disable FBC as needed, unlocked |
Paulo Zanoni | 7733b49 | 2015-07-07 15:26:04 -0300 | [diff] [blame] | 699 | * @dev_priv: i915 device instance |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 700 | * |
| 701 | * Set up the framebuffer compression hardware at mode set time. We |
| 702 | * enable it if possible: |
| 703 | * - plane A only (on pre-965) |
| 704 | * - no pixel mulitply/line duplication |
| 705 | * - no alpha buffer discard |
| 706 | * - no dual wide |
| 707 | * - framebuffer <= max_hdisplay in width, max_vdisplay in height |
| 708 | * |
| 709 | * We can't assume that any compression will take place (worst case), |
| 710 | * so the compressed buffer has to be the same size as the uncompressed |
| 711 | * one. It also must reside (along with the line length buffer) in |
| 712 | * stolen memory. |
| 713 | * |
| 714 | * We need to enable/disable FBC on a global basis. |
| 715 | */ |
Paulo Zanoni | 7733b49 | 2015-07-07 15:26:04 -0300 | [diff] [blame] | 716 | static void __intel_fbc_update(struct drm_i915_private *dev_priv) |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 717 | { |
Paulo Zanoni | 9510675 | 2015-02-13 17:23:41 -0200 | [diff] [blame] | 718 | struct drm_crtc *crtc = NULL; |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 719 | struct intel_crtc *intel_crtc; |
| 720 | struct drm_framebuffer *fb; |
| 721 | struct drm_i915_gem_object *obj; |
| 722 | const struct drm_display_mode *adjusted_mode; |
| 723 | unsigned int max_width, max_height; |
| 724 | |
Paulo Zanoni | 25ad93f | 2015-07-02 19:25:10 -0300 | [diff] [blame] | 725 | WARN_ON(!mutex_is_locked(&dev_priv->fbc.lock)); |
| 726 | |
Yu Zhang | bd49234 | 2015-02-10 19:05:50 +0800 | [diff] [blame] | 727 | /* disable framebuffer compression in vGPU */ |
Paulo Zanoni | 7733b49 | 2015-07-07 15:26:04 -0300 | [diff] [blame] | 728 | if (intel_vgpu_active(dev_priv->dev)) |
Yu Zhang | bd49234 | 2015-02-10 19:05:50 +0800 | [diff] [blame] | 729 | i915.enable_fbc = 0; |
| 730 | |
Paulo Zanoni | 7cc6574 | 2015-02-09 14:46:27 -0200 | [diff] [blame] | 731 | if (i915.enable_fbc < 0) { |
Paulo Zanoni | 2e8144a | 2015-06-12 14:36:20 -0300 | [diff] [blame] | 732 | set_no_fbc_reason(dev_priv, FBC_CHIP_DEFAULT); |
Paulo Zanoni | 7cc6574 | 2015-02-09 14:46:27 -0200 | [diff] [blame] | 733 | goto out_disable; |
| 734 | } |
| 735 | |
Rodrigo Vivi | ab585de | 2015-03-24 12:40:09 -0700 | [diff] [blame] | 736 | if (!i915.enable_fbc) { |
Paulo Zanoni | 2e8144a | 2015-06-12 14:36:20 -0300 | [diff] [blame] | 737 | set_no_fbc_reason(dev_priv, FBC_MODULE_PARAM); |
Paulo Zanoni | 7cc6574 | 2015-02-09 14:46:27 -0200 | [diff] [blame] | 738 | goto out_disable; |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 739 | } |
| 740 | |
| 741 | /* |
| 742 | * If FBC is already on, we just have to verify that we can |
| 743 | * keep it that way... |
| 744 | * Need to disable if: |
| 745 | * - more than one pipe is active |
| 746 | * - changing FBC params (stride, fence, mode) |
| 747 | * - new fb is too large to fit in compressed buffer |
| 748 | * - going to an unsupported config (interlace, pixel multiply, etc.) |
| 749 | */ |
Paulo Zanoni | 9510675 | 2015-02-13 17:23:41 -0200 | [diff] [blame] | 750 | crtc = intel_fbc_find_crtc(dev_priv); |
Paulo Zanoni | 8df5dd5 | 2015-07-07 15:26:08 -0300 | [diff] [blame] | 751 | if (!crtc) { |
| 752 | set_no_fbc_reason(dev_priv, FBC_NO_OUTPUT); |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 753 | goto out_disable; |
Paulo Zanoni | 8df5dd5 | 2015-07-07 15:26:08 -0300 | [diff] [blame] | 754 | } |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 755 | |
Paulo Zanoni | 232fd93 | 2015-07-07 15:26:07 -0300 | [diff] [blame] | 756 | if (!multiple_pipes_ok(dev_priv)) { |
| 757 | set_no_fbc_reason(dev_priv, FBC_MULTIPLE_PIPES); |
| 758 | goto out_disable; |
| 759 | } |
| 760 | |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 761 | intel_crtc = to_intel_crtc(crtc); |
| 762 | fb = crtc->primary->fb; |
| 763 | obj = intel_fb_obj(fb); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 764 | adjusted_mode = &intel_crtc->config->base.adjusted_mode; |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 765 | |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 766 | if ((adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) || |
| 767 | (adjusted_mode->flags & DRM_MODE_FLAG_DBLSCAN)) { |
Paulo Zanoni | 2e8144a | 2015-06-12 14:36:20 -0300 | [diff] [blame] | 768 | set_no_fbc_reason(dev_priv, FBC_UNSUPPORTED_MODE); |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 769 | goto out_disable; |
| 770 | } |
| 771 | |
Paulo Zanoni | 7733b49 | 2015-07-07 15:26:04 -0300 | [diff] [blame] | 772 | if (INTEL_INFO(dev_priv)->gen >= 8 || IS_HASWELL(dev_priv)) { |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 773 | max_width = 4096; |
| 774 | max_height = 4096; |
Paulo Zanoni | 7733b49 | 2015-07-07 15:26:04 -0300 | [diff] [blame] | 775 | } else if (IS_G4X(dev_priv) || INTEL_INFO(dev_priv)->gen >= 5) { |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 776 | max_width = 4096; |
| 777 | max_height = 2048; |
| 778 | } else { |
| 779 | max_width = 2048; |
| 780 | max_height = 1536; |
| 781 | } |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 782 | if (intel_crtc->config->pipe_src_w > max_width || |
| 783 | intel_crtc->config->pipe_src_h > max_height) { |
Paulo Zanoni | 2e8144a | 2015-06-12 14:36:20 -0300 | [diff] [blame] | 784 | set_no_fbc_reason(dev_priv, FBC_MODE_TOO_LARGE); |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 785 | goto out_disable; |
| 786 | } |
Paulo Zanoni | 7733b49 | 2015-07-07 15:26:04 -0300 | [diff] [blame] | 787 | if ((INTEL_INFO(dev_priv)->gen < 4 || HAS_DDI(dev_priv)) && |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 788 | intel_crtc->plane != PLANE_A) { |
Paulo Zanoni | 2e8144a | 2015-06-12 14:36:20 -0300 | [diff] [blame] | 789 | set_no_fbc_reason(dev_priv, FBC_BAD_PLANE); |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 790 | goto out_disable; |
| 791 | } |
| 792 | |
| 793 | /* The use of a CPU fence is mandatory in order to detect writes |
| 794 | * by the CPU to the scanout and trigger updates to the FBC. |
| 795 | */ |
| 796 | if (obj->tiling_mode != I915_TILING_X || |
| 797 | obj->fence_reg == I915_FENCE_REG_NONE) { |
Paulo Zanoni | 2e8144a | 2015-06-12 14:36:20 -0300 | [diff] [blame] | 798 | set_no_fbc_reason(dev_priv, FBC_NOT_TILED); |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 799 | goto out_disable; |
| 800 | } |
Paulo Zanoni | 7733b49 | 2015-07-07 15:26:04 -0300 | [diff] [blame] | 801 | if (INTEL_INFO(dev_priv)->gen <= 4 && !IS_G4X(dev_priv) && |
Matt Roper | 8e7d688 | 2015-01-21 16:35:41 -0800 | [diff] [blame] | 802 | crtc->primary->state->rotation != BIT(DRM_ROTATE_0)) { |
Paulo Zanoni | 2e8144a | 2015-06-12 14:36:20 -0300 | [diff] [blame] | 803 | set_no_fbc_reason(dev_priv, FBC_ROTATION); |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 804 | goto out_disable; |
| 805 | } |
| 806 | |
Paulo Zanoni | adf70c6 | 2015-09-14 15:19:56 -0300 | [diff] [blame^] | 807 | if (!stride_is_valid(dev_priv, fb->pitches[0])) { |
| 808 | set_no_fbc_reason(dev_priv, FBC_BAD_STRIDE); |
| 809 | goto out_disable; |
| 810 | } |
| 811 | |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 812 | /* If the kernel debugger is active, always disable compression */ |
Paulo Zanoni | 8935108 | 2015-07-07 15:26:06 -0300 | [diff] [blame] | 813 | if (in_dbg_master()) { |
| 814 | set_no_fbc_reason(dev_priv, FBC_IN_DBG_MASTER); |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 815 | goto out_disable; |
Paulo Zanoni | 8935108 | 2015-07-07 15:26:06 -0300 | [diff] [blame] | 816 | } |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 817 | |
Paulo Zanoni | 7733b49 | 2015-07-07 15:26:04 -0300 | [diff] [blame] | 818 | if (intel_fbc_setup_cfb(dev_priv, obj->base.size, |
Paulo Zanoni | fc78672 | 2015-07-02 19:25:08 -0300 | [diff] [blame] | 819 | drm_format_plane_cpp(fb->pixel_format, 0))) { |
Paulo Zanoni | 2e8144a | 2015-06-12 14:36:20 -0300 | [diff] [blame] | 820 | set_no_fbc_reason(dev_priv, FBC_STOLEN_TOO_SMALL); |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 821 | goto out_disable; |
| 822 | } |
| 823 | |
| 824 | /* If the scanout has not changed, don't modify the FBC settings. |
| 825 | * Note that we make the fundamental assumption that the fb->obj |
| 826 | * cannot be unpinned (and have its GTT offset and fence revoked) |
| 827 | * without first being decoupled from the scanout and FBC disabled. |
| 828 | */ |
Paulo Zanoni | e35fef2 | 2015-02-09 14:46:29 -0200 | [diff] [blame] | 829 | if (dev_priv->fbc.crtc == intel_crtc && |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 830 | dev_priv->fbc.fb_id == fb->base.id && |
| 831 | dev_priv->fbc.y == crtc->y) |
| 832 | return; |
| 833 | |
Paulo Zanoni | 7733b49 | 2015-07-07 15:26:04 -0300 | [diff] [blame] | 834 | if (intel_fbc_enabled(dev_priv)) { |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 835 | /* We update FBC along two paths, after changing fb/crtc |
| 836 | * configuration (modeswitching) and after page-flipping |
| 837 | * finishes. For the latter, we know that not only did |
| 838 | * we disable the FBC at the start of the page-flip |
| 839 | * sequence, but also more than one vblank has passed. |
| 840 | * |
| 841 | * For the former case of modeswitching, it is possible |
| 842 | * to switch between two FBC valid configurations |
| 843 | * instantaneously so we do need to disable the FBC |
| 844 | * before we can modify its control registers. We also |
| 845 | * have to wait for the next vblank for that to take |
| 846 | * effect. However, since we delay enabling FBC we can |
| 847 | * assume that a vblank has passed since disabling and |
| 848 | * that we can safely alter the registers in the deferred |
| 849 | * callback. |
| 850 | * |
| 851 | * In the scenario that we go from a valid to invalid |
| 852 | * and then back to valid FBC configuration we have |
| 853 | * no strict enforcement that a vblank occurred since |
| 854 | * disabling the FBC. However, along all current pipe |
| 855 | * disabling paths we do need to wait for a vblank at |
| 856 | * some point. And we wait before enabling FBC anyway. |
| 857 | */ |
| 858 | DRM_DEBUG_KMS("disabling active FBC for update\n"); |
Paulo Zanoni | 7733b49 | 2015-07-07 15:26:04 -0300 | [diff] [blame] | 859 | __intel_fbc_disable(dev_priv); |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 860 | } |
| 861 | |
Paulo Zanoni | e8cb8d6 | 2015-09-14 15:19:55 -0300 | [diff] [blame] | 862 | intel_fbc_schedule_enable(intel_crtc); |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 863 | dev_priv->fbc.no_fbc_reason = FBC_OK; |
| 864 | return; |
| 865 | |
| 866 | out_disable: |
| 867 | /* Multiple disables should be harmless */ |
Paulo Zanoni | 7733b49 | 2015-07-07 15:26:04 -0300 | [diff] [blame] | 868 | if (intel_fbc_enabled(dev_priv)) { |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 869 | DRM_DEBUG_KMS("unsupported config, disabling FBC\n"); |
Paulo Zanoni | 7733b49 | 2015-07-07 15:26:04 -0300 | [diff] [blame] | 870 | __intel_fbc_disable(dev_priv); |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 871 | } |
Paulo Zanoni | 7733b49 | 2015-07-07 15:26:04 -0300 | [diff] [blame] | 872 | __intel_fbc_cleanup_cfb(dev_priv); |
Paulo Zanoni | 25ad93f | 2015-07-02 19:25:10 -0300 | [diff] [blame] | 873 | } |
| 874 | |
| 875 | /* |
| 876 | * intel_fbc_update - enable/disable FBC as needed |
Paulo Zanoni | 7733b49 | 2015-07-07 15:26:04 -0300 | [diff] [blame] | 877 | * @dev_priv: i915 device instance |
Paulo Zanoni | 25ad93f | 2015-07-02 19:25:10 -0300 | [diff] [blame] | 878 | * |
| 879 | * This function reevaluates the overall state and enables or disables FBC. |
| 880 | */ |
Paulo Zanoni | 7733b49 | 2015-07-07 15:26:04 -0300 | [diff] [blame] | 881 | void intel_fbc_update(struct drm_i915_private *dev_priv) |
Paulo Zanoni | 25ad93f | 2015-07-02 19:25:10 -0300 | [diff] [blame] | 882 | { |
Paulo Zanoni | ff2a311 | 2015-07-07 15:26:03 -0300 | [diff] [blame] | 883 | if (!dev_priv->fbc.enable_fbc) |
Paulo Zanoni | 0bf73c3 | 2015-07-03 15:40:54 -0300 | [diff] [blame] | 884 | return; |
| 885 | |
Paulo Zanoni | 25ad93f | 2015-07-02 19:25:10 -0300 | [diff] [blame] | 886 | mutex_lock(&dev_priv->fbc.lock); |
Paulo Zanoni | 7733b49 | 2015-07-07 15:26:04 -0300 | [diff] [blame] | 887 | __intel_fbc_update(dev_priv); |
Paulo Zanoni | 25ad93f | 2015-07-02 19:25:10 -0300 | [diff] [blame] | 888 | mutex_unlock(&dev_priv->fbc.lock); |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 889 | } |
| 890 | |
Paulo Zanoni | dbef0f1 | 2015-02-13 17:23:46 -0200 | [diff] [blame] | 891 | void intel_fbc_invalidate(struct drm_i915_private *dev_priv, |
| 892 | unsigned int frontbuffer_bits, |
| 893 | enum fb_op_origin origin) |
| 894 | { |
Paulo Zanoni | dbef0f1 | 2015-02-13 17:23:46 -0200 | [diff] [blame] | 895 | unsigned int fbc_bits; |
| 896 | |
Paulo Zanoni | ff2a311 | 2015-07-07 15:26:03 -0300 | [diff] [blame] | 897 | if (!dev_priv->fbc.enable_fbc) |
Paulo Zanoni | 0bf73c3 | 2015-07-03 15:40:54 -0300 | [diff] [blame] | 898 | return; |
| 899 | |
Paulo Zanoni | dbef0f1 | 2015-02-13 17:23:46 -0200 | [diff] [blame] | 900 | if (origin == ORIGIN_GTT) |
| 901 | return; |
| 902 | |
Paulo Zanoni | 25ad93f | 2015-07-02 19:25:10 -0300 | [diff] [blame] | 903 | mutex_lock(&dev_priv->fbc.lock); |
| 904 | |
Paulo Zanoni | dbef0f1 | 2015-02-13 17:23:46 -0200 | [diff] [blame] | 905 | if (dev_priv->fbc.enabled) |
| 906 | fbc_bits = INTEL_FRONTBUFFER_PRIMARY(dev_priv->fbc.crtc->pipe); |
| 907 | else if (dev_priv->fbc.fbc_work) |
| 908 | fbc_bits = INTEL_FRONTBUFFER_PRIMARY( |
Paulo Zanoni | 220285f | 2015-07-07 15:26:05 -0300 | [diff] [blame] | 909 | dev_priv->fbc.fbc_work->crtc->pipe); |
Paulo Zanoni | dbef0f1 | 2015-02-13 17:23:46 -0200 | [diff] [blame] | 910 | else |
| 911 | fbc_bits = dev_priv->fbc.possible_framebuffer_bits; |
| 912 | |
| 913 | dev_priv->fbc.busy_bits |= (fbc_bits & frontbuffer_bits); |
| 914 | |
| 915 | if (dev_priv->fbc.busy_bits) |
Paulo Zanoni | 7733b49 | 2015-07-07 15:26:04 -0300 | [diff] [blame] | 916 | __intel_fbc_disable(dev_priv); |
Paulo Zanoni | 25ad93f | 2015-07-02 19:25:10 -0300 | [diff] [blame] | 917 | |
| 918 | mutex_unlock(&dev_priv->fbc.lock); |
Paulo Zanoni | dbef0f1 | 2015-02-13 17:23:46 -0200 | [diff] [blame] | 919 | } |
| 920 | |
| 921 | void intel_fbc_flush(struct drm_i915_private *dev_priv, |
Paulo Zanoni | 6f4551f | 2015-07-14 16:29:10 -0300 | [diff] [blame] | 922 | unsigned int frontbuffer_bits, enum fb_op_origin origin) |
Paulo Zanoni | dbef0f1 | 2015-02-13 17:23:46 -0200 | [diff] [blame] | 923 | { |
Paulo Zanoni | ff2a311 | 2015-07-07 15:26:03 -0300 | [diff] [blame] | 924 | if (!dev_priv->fbc.enable_fbc) |
Paulo Zanoni | 0bf73c3 | 2015-07-03 15:40:54 -0300 | [diff] [blame] | 925 | return; |
| 926 | |
Paulo Zanoni | 6f4551f | 2015-07-14 16:29:10 -0300 | [diff] [blame] | 927 | if (origin == ORIGIN_GTT) |
| 928 | return; |
Paulo Zanoni | 25ad93f | 2015-07-02 19:25:10 -0300 | [diff] [blame] | 929 | |
Paulo Zanoni | 6f4551f | 2015-07-14 16:29:10 -0300 | [diff] [blame] | 930 | mutex_lock(&dev_priv->fbc.lock); |
Paulo Zanoni | dbef0f1 | 2015-02-13 17:23:46 -0200 | [diff] [blame] | 931 | |
| 932 | dev_priv->fbc.busy_bits &= ~frontbuffer_bits; |
| 933 | |
Paulo Zanoni | 6f4551f | 2015-07-14 16:29:10 -0300 | [diff] [blame] | 934 | if (!dev_priv->fbc.busy_bits) { |
| 935 | __intel_fbc_disable(dev_priv); |
Paulo Zanoni | 7733b49 | 2015-07-07 15:26:04 -0300 | [diff] [blame] | 936 | __intel_fbc_update(dev_priv); |
Paulo Zanoni | 6f4551f | 2015-07-14 16:29:10 -0300 | [diff] [blame] | 937 | } |
Paulo Zanoni | 25ad93f | 2015-07-02 19:25:10 -0300 | [diff] [blame] | 938 | |
Paulo Zanoni | 25ad93f | 2015-07-02 19:25:10 -0300 | [diff] [blame] | 939 | mutex_unlock(&dev_priv->fbc.lock); |
Paulo Zanoni | dbef0f1 | 2015-02-13 17:23:46 -0200 | [diff] [blame] | 940 | } |
| 941 | |
Rodrigo Vivi | 94b8395 | 2014-12-08 06:46:31 -0800 | [diff] [blame] | 942 | /** |
| 943 | * intel_fbc_init - Initialize FBC |
| 944 | * @dev_priv: the i915 device |
| 945 | * |
| 946 | * This function might be called during PM init process. |
| 947 | */ |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 948 | void intel_fbc_init(struct drm_i915_private *dev_priv) |
| 949 | { |
Paulo Zanoni | dbef0f1 | 2015-02-13 17:23:46 -0200 | [diff] [blame] | 950 | enum pipe pipe; |
| 951 | |
Paulo Zanoni | 25ad93f | 2015-07-02 19:25:10 -0300 | [diff] [blame] | 952 | mutex_init(&dev_priv->fbc.lock); |
| 953 | |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 954 | if (!HAS_FBC(dev_priv)) { |
| 955 | dev_priv->fbc.enabled = false; |
Paulo Zanoni | 104618b | 2015-02-09 14:46:28 -0200 | [diff] [blame] | 956 | dev_priv->fbc.no_fbc_reason = FBC_UNSUPPORTED; |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 957 | return; |
| 958 | } |
| 959 | |
Paulo Zanoni | dbef0f1 | 2015-02-13 17:23:46 -0200 | [diff] [blame] | 960 | for_each_pipe(dev_priv, pipe) { |
| 961 | dev_priv->fbc.possible_framebuffer_bits |= |
| 962 | INTEL_FRONTBUFFER_PRIMARY(pipe); |
| 963 | |
| 964 | if (IS_HASWELL(dev_priv) || INTEL_INFO(dev_priv)->gen >= 8) |
| 965 | break; |
| 966 | } |
| 967 | |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 968 | if (INTEL_INFO(dev_priv)->gen >= 7) { |
Paulo Zanoni | ff2a311 | 2015-07-07 15:26:03 -0300 | [diff] [blame] | 969 | dev_priv->fbc.fbc_enabled = ilk_fbc_enabled; |
| 970 | dev_priv->fbc.enable_fbc = gen7_fbc_enable; |
| 971 | dev_priv->fbc.disable_fbc = ilk_fbc_disable; |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 972 | } else if (INTEL_INFO(dev_priv)->gen >= 5) { |
Paulo Zanoni | ff2a311 | 2015-07-07 15:26:03 -0300 | [diff] [blame] | 973 | dev_priv->fbc.fbc_enabled = ilk_fbc_enabled; |
| 974 | dev_priv->fbc.enable_fbc = ilk_fbc_enable; |
| 975 | dev_priv->fbc.disable_fbc = ilk_fbc_disable; |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 976 | } else if (IS_GM45(dev_priv)) { |
Paulo Zanoni | ff2a311 | 2015-07-07 15:26:03 -0300 | [diff] [blame] | 977 | dev_priv->fbc.fbc_enabled = g4x_fbc_enabled; |
| 978 | dev_priv->fbc.enable_fbc = g4x_fbc_enable; |
| 979 | dev_priv->fbc.disable_fbc = g4x_fbc_disable; |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 980 | } else { |
Paulo Zanoni | ff2a311 | 2015-07-07 15:26:03 -0300 | [diff] [blame] | 981 | dev_priv->fbc.fbc_enabled = i8xx_fbc_enabled; |
| 982 | dev_priv->fbc.enable_fbc = i8xx_fbc_enable; |
| 983 | dev_priv->fbc.disable_fbc = i8xx_fbc_disable; |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 984 | |
| 985 | /* This value was pulled out of someone's hat */ |
| 986 | I915_WRITE(FBC_CONTROL, 500 << FBC_CTL_INTERVAL_SHIFT); |
| 987 | } |
| 988 | |
Paulo Zanoni | 7733b49 | 2015-07-07 15:26:04 -0300 | [diff] [blame] | 989 | dev_priv->fbc.enabled = dev_priv->fbc.fbc_enabled(dev_priv); |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 990 | } |