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