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