Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2011 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 FROM, |
| 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 21 | * SOFTWARE. |
| 22 | * |
| 23 | * Authors: |
| 24 | * Jesse Barnes <jbarnes@virtuousgeek.org> |
| 25 | * |
| 26 | * New plane/sprite handling. |
| 27 | * |
| 28 | * The older chips had a separate interface for programming plane related |
| 29 | * registers; newer ones are much simpler and we can use the new DRM plane |
| 30 | * support. |
| 31 | */ |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 32 | #include <drm/drmP.h> |
| 33 | #include <drm/drm_crtc.h> |
| 34 | #include <drm/drm_fourcc.h> |
Ville Syrjälä | 1731693 | 2013-04-24 18:52:38 +0300 | [diff] [blame] | 35 | #include <drm/drm_rect.h> |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 36 | #include "intel_drv.h" |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 37 | #include <drm/i915_drm.h> |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 38 | #include "i915_drv.h" |
| 39 | |
Ville Syrjälä | 8d7849d | 2014-04-29 13:35:46 +0300 | [diff] [blame] | 40 | static int usecs_to_scanlines(const struct drm_display_mode *mode, int usecs) |
| 41 | { |
| 42 | /* paranoia */ |
| 43 | if (!mode->crtc_htotal) |
| 44 | return 1; |
| 45 | |
| 46 | return DIV_ROUND_UP(usecs * mode->crtc_clock, 1000 * mode->crtc_htotal); |
| 47 | } |
| 48 | |
| 49 | static bool intel_pipe_update_start(struct intel_crtc *crtc, uint32_t *start_vbl_count) |
| 50 | { |
| 51 | struct drm_device *dev = crtc->base.dev; |
| 52 | const struct drm_display_mode *mode = &crtc->config.adjusted_mode; |
| 53 | enum pipe pipe = crtc->pipe; |
| 54 | long timeout = msecs_to_jiffies_timeout(1); |
| 55 | int scanline, min, max, vblank_start; |
| 56 | DEFINE_WAIT(wait); |
| 57 | |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 58 | WARN_ON(!drm_modeset_is_locked(&crtc->base.mutex)); |
Ville Syrjälä | 8d7849d | 2014-04-29 13:35:46 +0300 | [diff] [blame] | 59 | |
| 60 | vblank_start = mode->crtc_vblank_start; |
| 61 | if (mode->flags & DRM_MODE_FLAG_INTERLACE) |
| 62 | vblank_start = DIV_ROUND_UP(vblank_start, 2); |
| 63 | |
| 64 | /* FIXME needs to be calibrated sensibly */ |
| 65 | min = vblank_start - usecs_to_scanlines(mode, 100); |
| 66 | max = vblank_start - 1; |
| 67 | |
| 68 | if (min <= 0 || max <= 0) |
| 69 | return false; |
| 70 | |
| 71 | if (WARN_ON(drm_vblank_get(dev, pipe))) |
| 72 | return false; |
| 73 | |
| 74 | local_irq_disable(); |
| 75 | |
Ville Syrjälä | 25ef284 | 2014-04-29 13:35:48 +0300 | [diff] [blame] | 76 | trace_i915_pipe_update_start(crtc, min, max); |
| 77 | |
Ville Syrjälä | 8d7849d | 2014-04-29 13:35:46 +0300 | [diff] [blame] | 78 | for (;;) { |
| 79 | /* |
| 80 | * prepare_to_wait() has a memory barrier, which guarantees |
| 81 | * other CPUs can see the task state update by the time we |
| 82 | * read the scanline. |
| 83 | */ |
| 84 | prepare_to_wait(&crtc->vbl_wait, &wait, TASK_UNINTERRUPTIBLE); |
| 85 | |
| 86 | scanline = intel_get_crtc_scanline(crtc); |
| 87 | if (scanline < min || scanline > max) |
| 88 | break; |
| 89 | |
| 90 | if (timeout <= 0) { |
| 91 | DRM_ERROR("Potential atomic update failure on pipe %c\n", |
| 92 | pipe_name(crtc->pipe)); |
| 93 | break; |
| 94 | } |
| 95 | |
| 96 | local_irq_enable(); |
| 97 | |
| 98 | timeout = schedule_timeout(timeout); |
| 99 | |
| 100 | local_irq_disable(); |
| 101 | } |
| 102 | |
| 103 | finish_wait(&crtc->vbl_wait, &wait); |
| 104 | |
| 105 | drm_vblank_put(dev, pipe); |
| 106 | |
| 107 | *start_vbl_count = dev->driver->get_vblank_counter(dev, pipe); |
| 108 | |
Ville Syrjälä | 25ef284 | 2014-04-29 13:35:48 +0300 | [diff] [blame] | 109 | trace_i915_pipe_update_vblank_evaded(crtc, min, max, *start_vbl_count); |
| 110 | |
Ville Syrjälä | 8d7849d | 2014-04-29 13:35:46 +0300 | [diff] [blame] | 111 | return true; |
| 112 | } |
| 113 | |
| 114 | static void intel_pipe_update_end(struct intel_crtc *crtc, u32 start_vbl_count) |
| 115 | { |
| 116 | struct drm_device *dev = crtc->base.dev; |
| 117 | enum pipe pipe = crtc->pipe; |
| 118 | u32 end_vbl_count = dev->driver->get_vblank_counter(dev, pipe); |
| 119 | |
Ville Syrjälä | 25ef284 | 2014-04-29 13:35:48 +0300 | [diff] [blame] | 120 | trace_i915_pipe_update_end(crtc, end_vbl_count); |
| 121 | |
Ville Syrjälä | 8d7849d | 2014-04-29 13:35:46 +0300 | [diff] [blame] | 122 | local_irq_enable(); |
| 123 | |
| 124 | if (start_vbl_count != end_vbl_count) |
| 125 | DRM_ERROR("Atomic update failure on pipe %c (start=%u end=%u)\n", |
| 126 | pipe_name(pipe), start_vbl_count, end_vbl_count); |
| 127 | } |
| 128 | |
Ville Syrjälä | 5b633d6 | 2014-04-29 13:35:47 +0300 | [diff] [blame] | 129 | static void intel_update_primary_plane(struct intel_crtc *crtc) |
| 130 | { |
| 131 | struct drm_i915_private *dev_priv = crtc->base.dev->dev_private; |
| 132 | int reg = DSPCNTR(crtc->plane); |
| 133 | |
| 134 | if (crtc->primary_enabled) |
| 135 | I915_WRITE(reg, I915_READ(reg) | DISPLAY_PLANE_ENABLE); |
| 136 | else |
| 137 | I915_WRITE(reg, I915_READ(reg) & ~DISPLAY_PLANE_ENABLE); |
| 138 | } |
| 139 | |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 140 | static void |
Ville Syrjälä | b39d53f | 2013-08-06 22:24:09 +0300 | [diff] [blame] | 141 | vlv_update_plane(struct drm_plane *dplane, struct drm_crtc *crtc, |
| 142 | struct drm_framebuffer *fb, |
Jesse Barnes | 7f1f385 | 2013-04-02 11:22:20 -0700 | [diff] [blame] | 143 | struct drm_i915_gem_object *obj, int crtc_x, int crtc_y, |
| 144 | unsigned int crtc_w, unsigned int crtc_h, |
| 145 | uint32_t x, uint32_t y, |
| 146 | uint32_t src_w, uint32_t src_h) |
| 147 | { |
| 148 | struct drm_device *dev = dplane->dev; |
| 149 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 150 | struct intel_plane *intel_plane = to_intel_plane(dplane); |
Ville Syrjälä | 8d7849d | 2014-04-29 13:35:46 +0300 | [diff] [blame] | 151 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Jesse Barnes | 7f1f385 | 2013-04-02 11:22:20 -0700 | [diff] [blame] | 152 | int pipe = intel_plane->pipe; |
| 153 | int plane = intel_plane->plane; |
| 154 | u32 sprctl; |
| 155 | unsigned long sprsurf_offset, linear_offset; |
| 156 | int pixel_size = drm_format_plane_cpp(fb->pixel_format, 0); |
Ville Syrjälä | 8d7849d | 2014-04-29 13:35:46 +0300 | [diff] [blame] | 157 | u32 start_vbl_count; |
| 158 | bool atomic_update; |
Jesse Barnes | 7f1f385 | 2013-04-02 11:22:20 -0700 | [diff] [blame] | 159 | |
| 160 | sprctl = I915_READ(SPCNTR(pipe, plane)); |
| 161 | |
| 162 | /* Mask out pixel format bits in case we change it */ |
| 163 | sprctl &= ~SP_PIXFORMAT_MASK; |
| 164 | sprctl &= ~SP_YUV_BYTE_ORDER_MASK; |
| 165 | sprctl &= ~SP_TILED; |
| 166 | |
| 167 | switch (fb->pixel_format) { |
| 168 | case DRM_FORMAT_YUYV: |
| 169 | sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_YUYV; |
| 170 | break; |
| 171 | case DRM_FORMAT_YVYU: |
| 172 | sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_YVYU; |
| 173 | break; |
| 174 | case DRM_FORMAT_UYVY: |
| 175 | sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_UYVY; |
| 176 | break; |
| 177 | case DRM_FORMAT_VYUY: |
| 178 | sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_VYUY; |
| 179 | break; |
| 180 | case DRM_FORMAT_RGB565: |
| 181 | sprctl |= SP_FORMAT_BGR565; |
| 182 | break; |
| 183 | case DRM_FORMAT_XRGB8888: |
| 184 | sprctl |= SP_FORMAT_BGRX8888; |
| 185 | break; |
| 186 | case DRM_FORMAT_ARGB8888: |
| 187 | sprctl |= SP_FORMAT_BGRA8888; |
| 188 | break; |
| 189 | case DRM_FORMAT_XBGR2101010: |
| 190 | sprctl |= SP_FORMAT_RGBX1010102; |
| 191 | break; |
| 192 | case DRM_FORMAT_ABGR2101010: |
| 193 | sprctl |= SP_FORMAT_RGBA1010102; |
| 194 | break; |
| 195 | case DRM_FORMAT_XBGR8888: |
| 196 | sprctl |= SP_FORMAT_RGBX8888; |
| 197 | break; |
| 198 | case DRM_FORMAT_ABGR8888: |
| 199 | sprctl |= SP_FORMAT_RGBA8888; |
| 200 | break; |
| 201 | default: |
| 202 | /* |
| 203 | * If we get here one of the upper layers failed to filter |
| 204 | * out the unsupported plane formats |
| 205 | */ |
| 206 | BUG(); |
| 207 | break; |
| 208 | } |
| 209 | |
Ville Syrjälä | 4ea67bc | 2013-11-18 18:32:38 -0800 | [diff] [blame] | 210 | /* |
| 211 | * Enable gamma to match primary/cursor plane behaviour. |
| 212 | * FIXME should be user controllable via propertiesa. |
| 213 | */ |
| 214 | sprctl |= SP_GAMMA_ENABLE; |
| 215 | |
Jesse Barnes | 7f1f385 | 2013-04-02 11:22:20 -0700 | [diff] [blame] | 216 | if (obj->tiling_mode != I915_TILING_NONE) |
| 217 | sprctl |= SP_TILED; |
| 218 | |
| 219 | sprctl |= SP_ENABLE; |
| 220 | |
Ville Syrjälä | adf3d35 | 2013-08-06 22:24:11 +0300 | [diff] [blame] | 221 | intel_update_sprite_watermarks(dplane, crtc, src_w, pixel_size, true, |
Ville Syrjälä | 67ca28f | 2013-07-05 11:57:14 +0300 | [diff] [blame] | 222 | src_w != crtc_w || src_h != crtc_h); |
| 223 | |
Jesse Barnes | 7f1f385 | 2013-04-02 11:22:20 -0700 | [diff] [blame] | 224 | /* Sizes are 0 based */ |
| 225 | src_w--; |
| 226 | src_h--; |
| 227 | crtc_w--; |
| 228 | crtc_h--; |
| 229 | |
Jesse Barnes | 7f1f385 | 2013-04-02 11:22:20 -0700 | [diff] [blame] | 230 | linear_offset = y * fb->pitches[0] + x * pixel_size; |
| 231 | sprsurf_offset = intel_gen4_compute_page_offset(&x, &y, |
| 232 | obj->tiling_mode, |
| 233 | pixel_size, |
| 234 | fb->pitches[0]); |
| 235 | linear_offset -= sprsurf_offset; |
| 236 | |
Ville Syrjälä | 8d7849d | 2014-04-29 13:35:46 +0300 | [diff] [blame] | 237 | atomic_update = intel_pipe_update_start(intel_crtc, &start_vbl_count); |
| 238 | |
Ville Syrjälä | 5b633d6 | 2014-04-29 13:35:47 +0300 | [diff] [blame] | 239 | intel_update_primary_plane(intel_crtc); |
| 240 | |
Ville Syrjälä | ca6ad02 | 2014-01-17 20:09:03 +0200 | [diff] [blame] | 241 | I915_WRITE(SPSTRIDE(pipe, plane), fb->pitches[0]); |
| 242 | I915_WRITE(SPPOS(pipe, plane), (crtc_y << 16) | crtc_x); |
| 243 | |
Jesse Barnes | 7f1f385 | 2013-04-02 11:22:20 -0700 | [diff] [blame] | 244 | if (obj->tiling_mode != I915_TILING_NONE) |
| 245 | I915_WRITE(SPTILEOFF(pipe, plane), (y << 16) | x); |
| 246 | else |
| 247 | I915_WRITE(SPLINOFF(pipe, plane), linear_offset); |
| 248 | |
| 249 | I915_WRITE(SPSIZE(pipe, plane), (crtc_h << 16) | crtc_w); |
| 250 | I915_WRITE(SPCNTR(pipe, plane), sprctl); |
Daniel Vetter | 85ba7b7 | 2014-01-24 10:31:44 +0100 | [diff] [blame] | 251 | I915_WRITE(SPSURF(pipe, plane), i915_gem_obj_ggtt_offset(obj) + |
| 252 | sprsurf_offset); |
Ville Syrjälä | 5b633d6 | 2014-04-29 13:35:47 +0300 | [diff] [blame] | 253 | |
| 254 | intel_flush_primary_plane(dev_priv, intel_crtc->plane); |
Ville Syrjälä | 8d7849d | 2014-04-29 13:35:46 +0300 | [diff] [blame] | 255 | |
| 256 | if (atomic_update) |
| 257 | intel_pipe_update_end(intel_crtc, start_vbl_count); |
Jesse Barnes | 7f1f385 | 2013-04-02 11:22:20 -0700 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | static void |
Ville Syrjälä | b39d53f | 2013-08-06 22:24:09 +0300 | [diff] [blame] | 261 | vlv_disable_plane(struct drm_plane *dplane, struct drm_crtc *crtc) |
Jesse Barnes | 7f1f385 | 2013-04-02 11:22:20 -0700 | [diff] [blame] | 262 | { |
| 263 | struct drm_device *dev = dplane->dev; |
| 264 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 265 | struct intel_plane *intel_plane = to_intel_plane(dplane); |
Ville Syrjälä | 8d7849d | 2014-04-29 13:35:46 +0300 | [diff] [blame] | 266 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Jesse Barnes | 7f1f385 | 2013-04-02 11:22:20 -0700 | [diff] [blame] | 267 | int pipe = intel_plane->pipe; |
| 268 | int plane = intel_plane->plane; |
Ville Syrjälä | 8d7849d | 2014-04-29 13:35:46 +0300 | [diff] [blame] | 269 | u32 start_vbl_count; |
| 270 | bool atomic_update; |
| 271 | |
| 272 | atomic_update = intel_pipe_update_start(intel_crtc, &start_vbl_count); |
Jesse Barnes | 7f1f385 | 2013-04-02 11:22:20 -0700 | [diff] [blame] | 273 | |
Ville Syrjälä | 5b633d6 | 2014-04-29 13:35:47 +0300 | [diff] [blame] | 274 | intel_update_primary_plane(intel_crtc); |
| 275 | |
Jesse Barnes | 7f1f385 | 2013-04-02 11:22:20 -0700 | [diff] [blame] | 276 | I915_WRITE(SPCNTR(pipe, plane), I915_READ(SPCNTR(pipe, plane)) & |
| 277 | ~SP_ENABLE); |
| 278 | /* Activate double buffered register update */ |
Daniel Vetter | 85ba7b7 | 2014-01-24 10:31:44 +0100 | [diff] [blame] | 279 | I915_WRITE(SPSURF(pipe, plane), 0); |
Ville Syrjälä | 5b633d6 | 2014-04-29 13:35:47 +0300 | [diff] [blame] | 280 | |
| 281 | intel_flush_primary_plane(dev_priv, intel_crtc->plane); |
Ville Syrjälä | a95fd8c | 2013-08-06 22:24:12 +0300 | [diff] [blame] | 282 | |
Ville Syrjälä | 8d7849d | 2014-04-29 13:35:46 +0300 | [diff] [blame] | 283 | if (atomic_update) |
| 284 | intel_pipe_update_end(intel_crtc, start_vbl_count); |
| 285 | |
Ville Syrjälä | a95fd8c | 2013-08-06 22:24:12 +0300 | [diff] [blame] | 286 | intel_update_sprite_watermarks(dplane, crtc, 0, 0, false, false); |
Jesse Barnes | 7f1f385 | 2013-04-02 11:22:20 -0700 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | static int |
| 290 | vlv_update_colorkey(struct drm_plane *dplane, |
| 291 | struct drm_intel_sprite_colorkey *key) |
| 292 | { |
| 293 | struct drm_device *dev = dplane->dev; |
| 294 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 295 | struct intel_plane *intel_plane = to_intel_plane(dplane); |
| 296 | int pipe = intel_plane->pipe; |
| 297 | int plane = intel_plane->plane; |
| 298 | u32 sprctl; |
| 299 | |
| 300 | if (key->flags & I915_SET_COLORKEY_DESTINATION) |
| 301 | return -EINVAL; |
| 302 | |
| 303 | I915_WRITE(SPKEYMINVAL(pipe, plane), key->min_value); |
| 304 | I915_WRITE(SPKEYMAXVAL(pipe, plane), key->max_value); |
| 305 | I915_WRITE(SPKEYMSK(pipe, plane), key->channel_mask); |
| 306 | |
| 307 | sprctl = I915_READ(SPCNTR(pipe, plane)); |
| 308 | sprctl &= ~SP_SOURCE_KEY; |
| 309 | if (key->flags & I915_SET_COLORKEY_SOURCE) |
| 310 | sprctl |= SP_SOURCE_KEY; |
| 311 | I915_WRITE(SPCNTR(pipe, plane), sprctl); |
| 312 | |
| 313 | POSTING_READ(SPKEYMSK(pipe, plane)); |
| 314 | |
| 315 | return 0; |
| 316 | } |
| 317 | |
| 318 | static void |
| 319 | vlv_get_colorkey(struct drm_plane *dplane, |
| 320 | struct drm_intel_sprite_colorkey *key) |
| 321 | { |
| 322 | struct drm_device *dev = dplane->dev; |
| 323 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 324 | struct intel_plane *intel_plane = to_intel_plane(dplane); |
| 325 | int pipe = intel_plane->pipe; |
| 326 | int plane = intel_plane->plane; |
| 327 | u32 sprctl; |
| 328 | |
| 329 | key->min_value = I915_READ(SPKEYMINVAL(pipe, plane)); |
| 330 | key->max_value = I915_READ(SPKEYMAXVAL(pipe, plane)); |
| 331 | key->channel_mask = I915_READ(SPKEYMSK(pipe, plane)); |
| 332 | |
| 333 | sprctl = I915_READ(SPCNTR(pipe, plane)); |
| 334 | if (sprctl & SP_SOURCE_KEY) |
| 335 | key->flags = I915_SET_COLORKEY_SOURCE; |
| 336 | else |
| 337 | key->flags = I915_SET_COLORKEY_NONE; |
| 338 | } |
| 339 | |
| 340 | static void |
Ville Syrjälä | b39d53f | 2013-08-06 22:24:09 +0300 | [diff] [blame] | 341 | ivb_update_plane(struct drm_plane *plane, struct drm_crtc *crtc, |
| 342 | struct drm_framebuffer *fb, |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 343 | struct drm_i915_gem_object *obj, int crtc_x, int crtc_y, |
| 344 | unsigned int crtc_w, unsigned int crtc_h, |
| 345 | uint32_t x, uint32_t y, |
| 346 | uint32_t src_w, uint32_t src_h) |
| 347 | { |
| 348 | struct drm_device *dev = plane->dev; |
| 349 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 350 | struct intel_plane *intel_plane = to_intel_plane(plane); |
Ville Syrjälä | 8d7849d | 2014-04-29 13:35:46 +0300 | [diff] [blame] | 351 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 352 | int pipe = intel_plane->pipe; |
| 353 | u32 sprctl, sprscale = 0; |
Damien Lespiau | 5a35e99 | 2012-10-26 18:20:12 +0100 | [diff] [blame] | 354 | unsigned long sprsurf_offset, linear_offset; |
Ville Syrjälä | 2bd3c3c | 2012-10-31 17:50:20 +0200 | [diff] [blame] | 355 | int pixel_size = drm_format_plane_cpp(fb->pixel_format, 0); |
Ville Syrjälä | 8d7849d | 2014-04-29 13:35:46 +0300 | [diff] [blame] | 356 | u32 start_vbl_count; |
| 357 | bool atomic_update; |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 358 | |
| 359 | sprctl = I915_READ(SPRCTL(pipe)); |
| 360 | |
| 361 | /* Mask out pixel format bits in case we change it */ |
| 362 | sprctl &= ~SPRITE_PIXFORMAT_MASK; |
| 363 | sprctl &= ~SPRITE_RGB_ORDER_RGBX; |
| 364 | sprctl &= ~SPRITE_YUV_BYTE_ORDER_MASK; |
Jesse Barnes | e86fe0d | 2012-06-26 13:10:11 -0700 | [diff] [blame] | 365 | sprctl &= ~SPRITE_TILED; |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 366 | |
| 367 | switch (fb->pixel_format) { |
| 368 | case DRM_FORMAT_XBGR8888: |
Vijay Purushothaman | 5ee3691 | 2012-08-23 12:08:57 +0530 | [diff] [blame] | 369 | sprctl |= SPRITE_FORMAT_RGBX888 | SPRITE_RGB_ORDER_RGBX; |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 370 | break; |
| 371 | case DRM_FORMAT_XRGB8888: |
Vijay Purushothaman | 5ee3691 | 2012-08-23 12:08:57 +0530 | [diff] [blame] | 372 | sprctl |= SPRITE_FORMAT_RGBX888; |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 373 | break; |
| 374 | case DRM_FORMAT_YUYV: |
| 375 | sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_YUYV; |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 376 | break; |
| 377 | case DRM_FORMAT_YVYU: |
| 378 | sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_YVYU; |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 379 | break; |
| 380 | case DRM_FORMAT_UYVY: |
| 381 | sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_UYVY; |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 382 | break; |
| 383 | case DRM_FORMAT_VYUY: |
| 384 | sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_VYUY; |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 385 | break; |
| 386 | default: |
Ville Syrjälä | 28d491d | 2012-10-31 17:50:21 +0200 | [diff] [blame] | 387 | BUG(); |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 388 | } |
| 389 | |
Ville Syrjälä | 4ea67bc | 2013-11-18 18:32:38 -0800 | [diff] [blame] | 390 | /* |
| 391 | * Enable gamma to match primary/cursor plane behaviour. |
| 392 | * FIXME should be user controllable via propertiesa. |
| 393 | */ |
| 394 | sprctl |= SPRITE_GAMMA_ENABLE; |
| 395 | |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 396 | if (obj->tiling_mode != I915_TILING_NONE) |
| 397 | sprctl |= SPRITE_TILED; |
| 398 | |
Ville Syrjälä | b42c600 | 2013-11-03 13:47:27 +0200 | [diff] [blame] | 399 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
Paulo Zanoni | 1f5d76d | 2013-08-23 19:51:28 -0300 | [diff] [blame] | 400 | sprctl &= ~SPRITE_TRICKLE_FEED_DISABLE; |
| 401 | else |
| 402 | sprctl |= SPRITE_TRICKLE_FEED_DISABLE; |
| 403 | |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 404 | sprctl |= SPRITE_ENABLE; |
| 405 | |
Ville Syrjälä | 6bbfa1c | 2013-11-02 21:07:39 -0700 | [diff] [blame] | 406 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
Ville Syrjälä | 86d3efc | 2013-01-18 19:11:38 +0200 | [diff] [blame] | 407 | sprctl |= SPRITE_PIPE_CSC_ENABLE; |
| 408 | |
Ville Syrjälä | adf3d35 | 2013-08-06 22:24:11 +0300 | [diff] [blame] | 409 | intel_update_sprite_watermarks(plane, crtc, src_w, pixel_size, true, |
Ville Syrjälä | 67ca28f | 2013-07-05 11:57:14 +0300 | [diff] [blame] | 410 | src_w != crtc_w || src_h != crtc_h); |
| 411 | |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 412 | /* Sizes are 0 based */ |
| 413 | src_w--; |
| 414 | src_h--; |
| 415 | crtc_w--; |
| 416 | crtc_h--; |
| 417 | |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 418 | if (crtc_w != src_w || crtc_h != src_h) |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 419 | sprscale = SPRITE_SCALE_ENABLE | (src_w << 16) | src_h; |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 420 | |
Chris Wilson | ca320ac | 2012-12-19 12:14:22 +0000 | [diff] [blame] | 421 | linear_offset = y * fb->pitches[0] + x * pixel_size; |
Damien Lespiau | 5a35e99 | 2012-10-26 18:20:12 +0100 | [diff] [blame] | 422 | sprsurf_offset = |
Chris Wilson | bc75286 | 2013-02-21 20:04:31 +0000 | [diff] [blame] | 423 | intel_gen4_compute_page_offset(&x, &y, obj->tiling_mode, |
| 424 | pixel_size, fb->pitches[0]); |
Damien Lespiau | 5a35e99 | 2012-10-26 18:20:12 +0100 | [diff] [blame] | 425 | linear_offset -= sprsurf_offset; |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 426 | |
Ville Syrjälä | 8d7849d | 2014-04-29 13:35:46 +0300 | [diff] [blame] | 427 | atomic_update = intel_pipe_update_start(intel_crtc, &start_vbl_count); |
| 428 | |
Ville Syrjälä | 5b633d6 | 2014-04-29 13:35:47 +0300 | [diff] [blame] | 429 | intel_update_primary_plane(intel_crtc); |
| 430 | |
Ville Syrjälä | ca6ad02 | 2014-01-17 20:09:03 +0200 | [diff] [blame] | 431 | I915_WRITE(SPRSTRIDE(pipe), fb->pitches[0]); |
| 432 | I915_WRITE(SPRPOS(pipe), (crtc_y << 16) | crtc_x); |
| 433 | |
Damien Lespiau | 5a35e99 | 2012-10-26 18:20:12 +0100 | [diff] [blame] | 434 | /* HSW consolidates SPRTILEOFF and SPRLINOFF into a single SPROFFSET |
| 435 | * register */ |
Paulo Zanoni | b3dc685 | 2013-11-02 21:07:33 -0700 | [diff] [blame] | 436 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
Damien Lespiau | 5a35e99 | 2012-10-26 18:20:12 +0100 | [diff] [blame] | 437 | I915_WRITE(SPROFFSET(pipe), (y << 16) | x); |
| 438 | else if (obj->tiling_mode != I915_TILING_NONE) |
| 439 | I915_WRITE(SPRTILEOFF(pipe), (y << 16) | x); |
| 440 | else |
| 441 | I915_WRITE(SPRLINOFF(pipe), linear_offset); |
Damien Lespiau | c54173a | 2012-10-26 18:20:11 +0100 | [diff] [blame] | 442 | |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 443 | I915_WRITE(SPRSIZE(pipe), (crtc_h << 16) | crtc_w); |
Damien Lespiau | 2d354c3 | 2012-10-22 18:19:27 +0100 | [diff] [blame] | 444 | if (intel_plane->can_scale) |
| 445 | I915_WRITE(SPRSCALE(pipe), sprscale); |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 446 | I915_WRITE(SPRCTL(pipe), sprctl); |
Daniel Vetter | 85ba7b7 | 2014-01-24 10:31:44 +0100 | [diff] [blame] | 447 | I915_WRITE(SPRSURF(pipe), |
| 448 | i915_gem_obj_ggtt_offset(obj) + sprsurf_offset); |
Ville Syrjälä | 5b633d6 | 2014-04-29 13:35:47 +0300 | [diff] [blame] | 449 | |
| 450 | intel_flush_primary_plane(dev_priv, intel_crtc->plane); |
Ville Syrjälä | 8d7849d | 2014-04-29 13:35:46 +0300 | [diff] [blame] | 451 | |
| 452 | if (atomic_update) |
| 453 | intel_pipe_update_end(intel_crtc, start_vbl_count); |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 454 | } |
| 455 | |
| 456 | static void |
Ville Syrjälä | b39d53f | 2013-08-06 22:24:09 +0300 | [diff] [blame] | 457 | ivb_disable_plane(struct drm_plane *plane, struct drm_crtc *crtc) |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 458 | { |
| 459 | struct drm_device *dev = plane->dev; |
| 460 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 461 | struct intel_plane *intel_plane = to_intel_plane(plane); |
Ville Syrjälä | 8d7849d | 2014-04-29 13:35:46 +0300 | [diff] [blame] | 462 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 463 | int pipe = intel_plane->pipe; |
Ville Syrjälä | 8d7849d | 2014-04-29 13:35:46 +0300 | [diff] [blame] | 464 | u32 start_vbl_count; |
| 465 | bool atomic_update; |
| 466 | |
| 467 | atomic_update = intel_pipe_update_start(intel_crtc, &start_vbl_count); |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 468 | |
Ville Syrjälä | 5b633d6 | 2014-04-29 13:35:47 +0300 | [diff] [blame] | 469 | intel_update_primary_plane(intel_crtc); |
| 470 | |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 471 | I915_WRITE(SPRCTL(pipe), I915_READ(SPRCTL(pipe)) & ~SPRITE_ENABLE); |
| 472 | /* Can't leave the scaler enabled... */ |
Damien Lespiau | 2d354c3 | 2012-10-22 18:19:27 +0100 | [diff] [blame] | 473 | if (intel_plane->can_scale) |
| 474 | I915_WRITE(SPRSCALE(pipe), 0); |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 475 | /* Activate double buffered register update */ |
Daniel Vetter | 85ba7b7 | 2014-01-24 10:31:44 +0100 | [diff] [blame] | 476 | I915_WRITE(SPRSURF(pipe), 0); |
Ville Syrjälä | 5b633d6 | 2014-04-29 13:35:47 +0300 | [diff] [blame] | 477 | |
| 478 | intel_flush_primary_plane(dev_priv, intel_crtc->plane); |
Chris Wilson | 828ed3e | 2012-04-18 17:12:26 +0100 | [diff] [blame] | 479 | |
Ville Syrjälä | 8d7849d | 2014-04-29 13:35:46 +0300 | [diff] [blame] | 480 | if (atomic_update) |
| 481 | intel_pipe_update_end(intel_crtc, start_vbl_count); |
| 482 | |
Ville Syrjälä | 1bd09ec | 2013-12-05 15:51:41 +0200 | [diff] [blame] | 483 | /* |
| 484 | * Avoid underruns when disabling the sprite. |
| 485 | * FIXME remove once watermark updates are done properly. |
| 486 | */ |
| 487 | intel_wait_for_vblank(dev, pipe); |
| 488 | |
Ville Syrjälä | adf3d35 | 2013-08-06 22:24:11 +0300 | [diff] [blame] | 489 | intel_update_sprite_watermarks(plane, crtc, 0, 0, false, false); |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 490 | } |
| 491 | |
Jesse Barnes | 8ea3086 | 2012-01-03 08:05:39 -0800 | [diff] [blame] | 492 | static int |
| 493 | ivb_update_colorkey(struct drm_plane *plane, |
| 494 | struct drm_intel_sprite_colorkey *key) |
| 495 | { |
| 496 | struct drm_device *dev = plane->dev; |
| 497 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 498 | struct intel_plane *intel_plane; |
| 499 | u32 sprctl; |
| 500 | int ret = 0; |
| 501 | |
| 502 | intel_plane = to_intel_plane(plane); |
| 503 | |
| 504 | I915_WRITE(SPRKEYVAL(intel_plane->pipe), key->min_value); |
| 505 | I915_WRITE(SPRKEYMAX(intel_plane->pipe), key->max_value); |
| 506 | I915_WRITE(SPRKEYMSK(intel_plane->pipe), key->channel_mask); |
| 507 | |
| 508 | sprctl = I915_READ(SPRCTL(intel_plane->pipe)); |
| 509 | sprctl &= ~(SPRITE_SOURCE_KEY | SPRITE_DEST_KEY); |
| 510 | if (key->flags & I915_SET_COLORKEY_DESTINATION) |
| 511 | sprctl |= SPRITE_DEST_KEY; |
| 512 | else if (key->flags & I915_SET_COLORKEY_SOURCE) |
| 513 | sprctl |= SPRITE_SOURCE_KEY; |
| 514 | I915_WRITE(SPRCTL(intel_plane->pipe), sprctl); |
| 515 | |
| 516 | POSTING_READ(SPRKEYMSK(intel_plane->pipe)); |
| 517 | |
| 518 | return ret; |
| 519 | } |
| 520 | |
| 521 | static void |
| 522 | ivb_get_colorkey(struct drm_plane *plane, struct drm_intel_sprite_colorkey *key) |
| 523 | { |
| 524 | struct drm_device *dev = plane->dev; |
| 525 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 526 | struct intel_plane *intel_plane; |
| 527 | u32 sprctl; |
| 528 | |
| 529 | intel_plane = to_intel_plane(plane); |
| 530 | |
| 531 | key->min_value = I915_READ(SPRKEYVAL(intel_plane->pipe)); |
| 532 | key->max_value = I915_READ(SPRKEYMAX(intel_plane->pipe)); |
| 533 | key->channel_mask = I915_READ(SPRKEYMSK(intel_plane->pipe)); |
| 534 | key->flags = 0; |
| 535 | |
| 536 | sprctl = I915_READ(SPRCTL(intel_plane->pipe)); |
| 537 | |
| 538 | if (sprctl & SPRITE_DEST_KEY) |
| 539 | key->flags = I915_SET_COLORKEY_DESTINATION; |
| 540 | else if (sprctl & SPRITE_SOURCE_KEY) |
| 541 | key->flags = I915_SET_COLORKEY_SOURCE; |
| 542 | else |
| 543 | key->flags = I915_SET_COLORKEY_NONE; |
| 544 | } |
| 545 | |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 546 | static void |
Ville Syrjälä | b39d53f | 2013-08-06 22:24:09 +0300 | [diff] [blame] | 547 | ilk_update_plane(struct drm_plane *plane, struct drm_crtc *crtc, |
| 548 | struct drm_framebuffer *fb, |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 549 | struct drm_i915_gem_object *obj, int crtc_x, int crtc_y, |
| 550 | unsigned int crtc_w, unsigned int crtc_h, |
| 551 | uint32_t x, uint32_t y, |
| 552 | uint32_t src_w, uint32_t src_h) |
| 553 | { |
| 554 | struct drm_device *dev = plane->dev; |
| 555 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 556 | struct intel_plane *intel_plane = to_intel_plane(plane); |
Ville Syrjälä | 8d7849d | 2014-04-29 13:35:46 +0300 | [diff] [blame] | 557 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ville Syrjälä | 2bd3c3c | 2012-10-31 17:50:20 +0200 | [diff] [blame] | 558 | int pipe = intel_plane->pipe; |
Damien Lespiau | 5a35e99 | 2012-10-26 18:20:12 +0100 | [diff] [blame] | 559 | unsigned long dvssurf_offset, linear_offset; |
Chris Wilson | 8aaa81a | 2012-04-14 22:14:26 +0100 | [diff] [blame] | 560 | u32 dvscntr, dvsscale; |
Ville Syrjälä | 2bd3c3c | 2012-10-31 17:50:20 +0200 | [diff] [blame] | 561 | int pixel_size = drm_format_plane_cpp(fb->pixel_format, 0); |
Ville Syrjälä | 8d7849d | 2014-04-29 13:35:46 +0300 | [diff] [blame] | 562 | u32 start_vbl_count; |
| 563 | bool atomic_update; |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 564 | |
| 565 | dvscntr = I915_READ(DVSCNTR(pipe)); |
| 566 | |
| 567 | /* Mask out pixel format bits in case we change it */ |
| 568 | dvscntr &= ~DVS_PIXFORMAT_MASK; |
Jesse Barnes | ab2f9df | 2012-02-27 12:40:10 -0800 | [diff] [blame] | 569 | dvscntr &= ~DVS_RGB_ORDER_XBGR; |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 570 | dvscntr &= ~DVS_YUV_BYTE_ORDER_MASK; |
Ander Conselvan de Oliveira | 7962652 | 2012-07-13 15:50:33 +0300 | [diff] [blame] | 571 | dvscntr &= ~DVS_TILED; |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 572 | |
| 573 | switch (fb->pixel_format) { |
| 574 | case DRM_FORMAT_XBGR8888: |
Jesse Barnes | ab2f9df | 2012-02-27 12:40:10 -0800 | [diff] [blame] | 575 | dvscntr |= DVS_FORMAT_RGBX888 | DVS_RGB_ORDER_XBGR; |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 576 | break; |
| 577 | case DRM_FORMAT_XRGB8888: |
Jesse Barnes | ab2f9df | 2012-02-27 12:40:10 -0800 | [diff] [blame] | 578 | dvscntr |= DVS_FORMAT_RGBX888; |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 579 | break; |
| 580 | case DRM_FORMAT_YUYV: |
| 581 | dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_YUYV; |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 582 | break; |
| 583 | case DRM_FORMAT_YVYU: |
| 584 | dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_YVYU; |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 585 | break; |
| 586 | case DRM_FORMAT_UYVY: |
| 587 | dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_UYVY; |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 588 | break; |
| 589 | case DRM_FORMAT_VYUY: |
| 590 | dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_VYUY; |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 591 | break; |
| 592 | default: |
Ville Syrjälä | 28d491d | 2012-10-31 17:50:21 +0200 | [diff] [blame] | 593 | BUG(); |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 594 | } |
| 595 | |
Ville Syrjälä | 4ea67bc | 2013-11-18 18:32:38 -0800 | [diff] [blame] | 596 | /* |
| 597 | * Enable gamma to match primary/cursor plane behaviour. |
| 598 | * FIXME should be user controllable via propertiesa. |
| 599 | */ |
| 600 | dvscntr |= DVS_GAMMA_ENABLE; |
| 601 | |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 602 | if (obj->tiling_mode != I915_TILING_NONE) |
| 603 | dvscntr |= DVS_TILED; |
| 604 | |
Chris Wilson | d1686ae | 2012-04-10 11:41:49 +0100 | [diff] [blame] | 605 | if (IS_GEN6(dev)) |
| 606 | dvscntr |= DVS_TRICKLE_FEED_DISABLE; /* must disable */ |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 607 | dvscntr |= DVS_ENABLE; |
| 608 | |
Ville Syrjälä | adf3d35 | 2013-08-06 22:24:11 +0300 | [diff] [blame] | 609 | intel_update_sprite_watermarks(plane, crtc, src_w, pixel_size, true, |
Ville Syrjälä | 67ca28f | 2013-07-05 11:57:14 +0300 | [diff] [blame] | 610 | src_w != crtc_w || src_h != crtc_h); |
| 611 | |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 612 | /* Sizes are 0 based */ |
| 613 | src_w--; |
| 614 | src_h--; |
| 615 | crtc_w--; |
| 616 | crtc_h--; |
| 617 | |
Chris Wilson | 8aaa81a | 2012-04-14 22:14:26 +0100 | [diff] [blame] | 618 | dvsscale = 0; |
Ville Syrjälä | 8368f01 | 2013-12-05 15:51:31 +0200 | [diff] [blame] | 619 | if (crtc_w != src_w || crtc_h != src_h) |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 620 | dvsscale = DVS_SCALE_ENABLE | (src_w << 16) | src_h; |
| 621 | |
Chris Wilson | ca320ac | 2012-12-19 12:14:22 +0000 | [diff] [blame] | 622 | linear_offset = y * fb->pitches[0] + x * pixel_size; |
Damien Lespiau | 5a35e99 | 2012-10-26 18:20:12 +0100 | [diff] [blame] | 623 | dvssurf_offset = |
Chris Wilson | bc75286 | 2013-02-21 20:04:31 +0000 | [diff] [blame] | 624 | intel_gen4_compute_page_offset(&x, &y, obj->tiling_mode, |
| 625 | pixel_size, fb->pitches[0]); |
Damien Lespiau | 5a35e99 | 2012-10-26 18:20:12 +0100 | [diff] [blame] | 626 | linear_offset -= dvssurf_offset; |
| 627 | |
Ville Syrjälä | 8d7849d | 2014-04-29 13:35:46 +0300 | [diff] [blame] | 628 | atomic_update = intel_pipe_update_start(intel_crtc, &start_vbl_count); |
| 629 | |
Ville Syrjälä | 5b633d6 | 2014-04-29 13:35:47 +0300 | [diff] [blame] | 630 | intel_update_primary_plane(intel_crtc); |
| 631 | |
Ville Syrjälä | ca6ad02 | 2014-01-17 20:09:03 +0200 | [diff] [blame] | 632 | I915_WRITE(DVSSTRIDE(pipe), fb->pitches[0]); |
| 633 | I915_WRITE(DVSPOS(pipe), (crtc_y << 16) | crtc_x); |
| 634 | |
Damien Lespiau | 5a35e99 | 2012-10-26 18:20:12 +0100 | [diff] [blame] | 635 | if (obj->tiling_mode != I915_TILING_NONE) |
| 636 | I915_WRITE(DVSTILEOFF(pipe), (y << 16) | x); |
| 637 | else |
| 638 | I915_WRITE(DVSLINOFF(pipe), linear_offset); |
| 639 | |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 640 | I915_WRITE(DVSSIZE(pipe), (crtc_h << 16) | crtc_w); |
| 641 | I915_WRITE(DVSSCALE(pipe), dvsscale); |
| 642 | I915_WRITE(DVSCNTR(pipe), dvscntr); |
Daniel Vetter | 85ba7b7 | 2014-01-24 10:31:44 +0100 | [diff] [blame] | 643 | I915_WRITE(DVSSURF(pipe), |
| 644 | i915_gem_obj_ggtt_offset(obj) + dvssurf_offset); |
Ville Syrjälä | 5b633d6 | 2014-04-29 13:35:47 +0300 | [diff] [blame] | 645 | |
| 646 | intel_flush_primary_plane(dev_priv, intel_crtc->plane); |
Ville Syrjälä | 8d7849d | 2014-04-29 13:35:46 +0300 | [diff] [blame] | 647 | |
| 648 | if (atomic_update) |
| 649 | intel_pipe_update_end(intel_crtc, start_vbl_count); |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 650 | } |
| 651 | |
| 652 | static void |
Ville Syrjälä | b39d53f | 2013-08-06 22:24:09 +0300 | [diff] [blame] | 653 | ilk_disable_plane(struct drm_plane *plane, struct drm_crtc *crtc) |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 654 | { |
| 655 | struct drm_device *dev = plane->dev; |
| 656 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 657 | struct intel_plane *intel_plane = to_intel_plane(plane); |
Ville Syrjälä | 8d7849d | 2014-04-29 13:35:46 +0300 | [diff] [blame] | 658 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 659 | int pipe = intel_plane->pipe; |
Ville Syrjälä | 8d7849d | 2014-04-29 13:35:46 +0300 | [diff] [blame] | 660 | u32 start_vbl_count; |
| 661 | bool atomic_update; |
| 662 | |
| 663 | atomic_update = intel_pipe_update_start(intel_crtc, &start_vbl_count); |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 664 | |
Ville Syrjälä | 5b633d6 | 2014-04-29 13:35:47 +0300 | [diff] [blame] | 665 | intel_update_primary_plane(intel_crtc); |
| 666 | |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 667 | I915_WRITE(DVSCNTR(pipe), I915_READ(DVSCNTR(pipe)) & ~DVS_ENABLE); |
| 668 | /* Disable the scaler */ |
| 669 | I915_WRITE(DVSSCALE(pipe), 0); |
| 670 | /* Flush double buffered register updates */ |
Daniel Vetter | 85ba7b7 | 2014-01-24 10:31:44 +0100 | [diff] [blame] | 671 | I915_WRITE(DVSSURF(pipe), 0); |
Ville Syrjälä | 5b633d6 | 2014-04-29 13:35:47 +0300 | [diff] [blame] | 672 | |
| 673 | intel_flush_primary_plane(dev_priv, intel_crtc->plane); |
Ville Syrjälä | a95fd8c | 2013-08-06 22:24:12 +0300 | [diff] [blame] | 674 | |
Ville Syrjälä | 8d7849d | 2014-04-29 13:35:46 +0300 | [diff] [blame] | 675 | if (atomic_update) |
| 676 | intel_pipe_update_end(intel_crtc, start_vbl_count); |
| 677 | |
Ville Syrjälä | 1bd09ec | 2013-12-05 15:51:41 +0200 | [diff] [blame] | 678 | /* |
| 679 | * Avoid underruns when disabling the sprite. |
| 680 | * FIXME remove once watermark updates are done properly. |
| 681 | */ |
| 682 | intel_wait_for_vblank(dev, pipe); |
| 683 | |
Ville Syrjälä | a95fd8c | 2013-08-06 22:24:12 +0300 | [diff] [blame] | 684 | intel_update_sprite_watermarks(plane, crtc, 0, 0, false, false); |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 685 | } |
| 686 | |
Jesse Barnes | 175bd42 | 2011-12-13 13:19:39 -0800 | [diff] [blame] | 687 | static void |
Ville Syrjälä | 5b633d6 | 2014-04-29 13:35:47 +0300 | [diff] [blame] | 688 | intel_post_enable_primary(struct drm_crtc *crtc) |
Jesse Barnes | 175bd42 | 2011-12-13 13:19:39 -0800 | [diff] [blame] | 689 | { |
| 690 | struct drm_device *dev = crtc->dev; |
Jesse Barnes | 175bd42 | 2011-12-13 13:19:39 -0800 | [diff] [blame] | 691 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ville Syrjälä | abae50e | 2013-10-01 18:02:16 +0300 | [diff] [blame] | 692 | |
Ville Syrjälä | 20bc8673 | 2013-10-01 18:02:17 +0300 | [diff] [blame] | 693 | /* |
Ville Syrjälä | 33c3b0d | 2014-06-24 13:59:28 +0300 | [diff] [blame] | 694 | * BDW signals flip done immediately if the plane |
| 695 | * is disabled, even if the plane enable is already |
| 696 | * armed to occur at the next vblank :( |
| 697 | */ |
| 698 | if (IS_BROADWELL(dev)) |
| 699 | intel_wait_for_vblank(dev, intel_crtc->pipe); |
| 700 | |
| 701 | /* |
Ville Syrjälä | 20bc8673 | 2013-10-01 18:02:17 +0300 | [diff] [blame] | 702 | * FIXME IPS should be fine as long as one plane is |
| 703 | * enabled, but in practice it seems to have problems |
| 704 | * when going from primary only to sprite only and vice |
| 705 | * versa. |
| 706 | */ |
Ville Syrjälä | cea165c | 2014-04-15 21:41:35 +0300 | [diff] [blame] | 707 | hsw_enable_ips(intel_crtc); |
Ville Syrjälä | 20bc8673 | 2013-10-01 18:02:17 +0300 | [diff] [blame] | 708 | |
Ville Syrjälä | 82284b6 | 2013-10-01 18:02:12 +0300 | [diff] [blame] | 709 | mutex_lock(&dev->struct_mutex); |
Chris Wilson | 93314b5 | 2012-06-13 17:36:55 +0100 | [diff] [blame] | 710 | intel_update_fbc(dev); |
Ville Syrjälä | 82284b6 | 2013-10-01 18:02:12 +0300 | [diff] [blame] | 711 | mutex_unlock(&dev->struct_mutex); |
Jesse Barnes | 175bd42 | 2011-12-13 13:19:39 -0800 | [diff] [blame] | 712 | } |
| 713 | |
| 714 | static void |
Ville Syrjälä | 5b633d6 | 2014-04-29 13:35:47 +0300 | [diff] [blame] | 715 | intel_pre_disable_primary(struct drm_crtc *crtc) |
Jesse Barnes | 175bd42 | 2011-12-13 13:19:39 -0800 | [diff] [blame] | 716 | { |
| 717 | struct drm_device *dev = crtc->dev; |
| 718 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 719 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ville Syrjälä | 82284b6 | 2013-10-01 18:02:12 +0300 | [diff] [blame] | 720 | |
| 721 | mutex_lock(&dev->struct_mutex); |
Ville Syrjälä | abae50e | 2013-10-01 18:02:16 +0300 | [diff] [blame] | 722 | if (dev_priv->fbc.plane == intel_crtc->plane) |
| 723 | intel_disable_fbc(dev); |
Ville Syrjälä | 82284b6 | 2013-10-01 18:02:12 +0300 | [diff] [blame] | 724 | mutex_unlock(&dev->struct_mutex); |
Ville Syrjälä | abae50e | 2013-10-01 18:02:16 +0300 | [diff] [blame] | 725 | |
Ville Syrjälä | 20bc8673 | 2013-10-01 18:02:17 +0300 | [diff] [blame] | 726 | /* |
| 727 | * FIXME IPS should be fine as long as one plane is |
| 728 | * enabled, but in practice it seems to have problems |
| 729 | * when going from primary only to sprite only and vice |
| 730 | * versa. |
| 731 | */ |
| 732 | hsw_disable_ips(intel_crtc); |
Jesse Barnes | 175bd42 | 2011-12-13 13:19:39 -0800 | [diff] [blame] | 733 | } |
| 734 | |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 735 | static int |
Chris Wilson | d1686ae | 2012-04-10 11:41:49 +0100 | [diff] [blame] | 736 | ilk_update_colorkey(struct drm_plane *plane, |
Jesse Barnes | 8ea3086 | 2012-01-03 08:05:39 -0800 | [diff] [blame] | 737 | struct drm_intel_sprite_colorkey *key) |
| 738 | { |
| 739 | struct drm_device *dev = plane->dev; |
| 740 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 741 | struct intel_plane *intel_plane; |
| 742 | u32 dvscntr; |
| 743 | int ret = 0; |
| 744 | |
| 745 | intel_plane = to_intel_plane(plane); |
| 746 | |
| 747 | I915_WRITE(DVSKEYVAL(intel_plane->pipe), key->min_value); |
| 748 | I915_WRITE(DVSKEYMAX(intel_plane->pipe), key->max_value); |
| 749 | I915_WRITE(DVSKEYMSK(intel_plane->pipe), key->channel_mask); |
| 750 | |
| 751 | dvscntr = I915_READ(DVSCNTR(intel_plane->pipe)); |
| 752 | dvscntr &= ~(DVS_SOURCE_KEY | DVS_DEST_KEY); |
| 753 | if (key->flags & I915_SET_COLORKEY_DESTINATION) |
| 754 | dvscntr |= DVS_DEST_KEY; |
| 755 | else if (key->flags & I915_SET_COLORKEY_SOURCE) |
| 756 | dvscntr |= DVS_SOURCE_KEY; |
| 757 | I915_WRITE(DVSCNTR(intel_plane->pipe), dvscntr); |
| 758 | |
| 759 | POSTING_READ(DVSKEYMSK(intel_plane->pipe)); |
| 760 | |
| 761 | return ret; |
| 762 | } |
| 763 | |
| 764 | static void |
Chris Wilson | d1686ae | 2012-04-10 11:41:49 +0100 | [diff] [blame] | 765 | ilk_get_colorkey(struct drm_plane *plane, struct drm_intel_sprite_colorkey *key) |
Jesse Barnes | 8ea3086 | 2012-01-03 08:05:39 -0800 | [diff] [blame] | 766 | { |
| 767 | struct drm_device *dev = plane->dev; |
| 768 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 769 | struct intel_plane *intel_plane; |
| 770 | u32 dvscntr; |
| 771 | |
| 772 | intel_plane = to_intel_plane(plane); |
| 773 | |
| 774 | key->min_value = I915_READ(DVSKEYVAL(intel_plane->pipe)); |
| 775 | key->max_value = I915_READ(DVSKEYMAX(intel_plane->pipe)); |
| 776 | key->channel_mask = I915_READ(DVSKEYMSK(intel_plane->pipe)); |
| 777 | key->flags = 0; |
| 778 | |
| 779 | dvscntr = I915_READ(DVSCNTR(intel_plane->pipe)); |
| 780 | |
| 781 | if (dvscntr & DVS_DEST_KEY) |
| 782 | key->flags = I915_SET_COLORKEY_DESTINATION; |
| 783 | else if (dvscntr & DVS_SOURCE_KEY) |
| 784 | key->flags = I915_SET_COLORKEY_SOURCE; |
| 785 | else |
| 786 | key->flags = I915_SET_COLORKEY_NONE; |
| 787 | } |
| 788 | |
Ville Syrjälä | 1731693 | 2013-04-24 18:52:38 +0300 | [diff] [blame] | 789 | static bool |
| 790 | format_is_yuv(uint32_t format) |
| 791 | { |
| 792 | switch (format) { |
| 793 | case DRM_FORMAT_YUYV: |
| 794 | case DRM_FORMAT_UYVY: |
| 795 | case DRM_FORMAT_VYUY: |
| 796 | case DRM_FORMAT_YVYU: |
| 797 | return true; |
| 798 | default: |
| 799 | return false; |
| 800 | } |
| 801 | } |
| 802 | |
Ville Syrjälä | efb31d1 | 2013-12-05 15:51:40 +0200 | [diff] [blame] | 803 | static bool colorkey_enabled(struct intel_plane *intel_plane) |
| 804 | { |
| 805 | struct drm_intel_sprite_colorkey key; |
| 806 | |
| 807 | intel_plane->get_colorkey(&intel_plane->base, &key); |
| 808 | |
| 809 | return key.flags != I915_SET_COLORKEY_NONE; |
| 810 | } |
| 811 | |
Jesse Barnes | 8ea3086 | 2012-01-03 08:05:39 -0800 | [diff] [blame] | 812 | static int |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 813 | intel_update_plane(struct drm_plane *plane, struct drm_crtc *crtc, |
| 814 | struct drm_framebuffer *fb, int crtc_x, int crtc_y, |
| 815 | unsigned int crtc_w, unsigned int crtc_h, |
| 816 | uint32_t src_x, uint32_t src_y, |
| 817 | uint32_t src_w, uint32_t src_h) |
| 818 | { |
| 819 | struct drm_device *dev = plane->dev; |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 820 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 821 | struct intel_plane *intel_plane = to_intel_plane(plane); |
Daniel Vetter | a071fa0 | 2014-06-18 23:28:09 +0200 | [diff] [blame] | 822 | enum pipe pipe = intel_crtc->pipe; |
Ville Syrjälä | 2afd9ef | 2013-10-01 18:02:14 +0300 | [diff] [blame] | 823 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); |
| 824 | struct drm_i915_gem_object *obj = intel_fb->obj; |
| 825 | struct drm_i915_gem_object *old_obj = intel_plane->obj; |
| 826 | int ret; |
Ville Syrjälä | 5b633d6 | 2014-04-29 13:35:47 +0300 | [diff] [blame] | 827 | bool primary_enabled; |
Ville Syrjälä | 1731693 | 2013-04-24 18:52:38 +0300 | [diff] [blame] | 828 | bool visible; |
| 829 | int hscale, vscale; |
| 830 | int max_scale, min_scale; |
| 831 | int pixel_size = drm_format_plane_cpp(fb->pixel_format, 0); |
| 832 | struct drm_rect src = { |
| 833 | /* sample coordinates in 16.16 fixed point */ |
| 834 | .x1 = src_x, |
| 835 | .x2 = src_x + src_w, |
| 836 | .y1 = src_y, |
| 837 | .y2 = src_y + src_h, |
| 838 | }; |
| 839 | struct drm_rect dst = { |
| 840 | /* integer pixels */ |
| 841 | .x1 = crtc_x, |
| 842 | .x2 = crtc_x + crtc_w, |
| 843 | .y1 = crtc_y, |
| 844 | .y2 = crtc_y + crtc_h, |
| 845 | }; |
| 846 | const struct drm_rect clip = { |
Ville Syrjälä | 03c5b25 | 2013-10-01 18:02:11 +0300 | [diff] [blame] | 847 | .x2 = intel_crtc->active ? intel_crtc->config.pipe_src_w : 0, |
| 848 | .y2 = intel_crtc->active ? intel_crtc->config.pipe_src_h : 0, |
Ville Syrjälä | 1731693 | 2013-04-24 18:52:38 +0300 | [diff] [blame] | 849 | }; |
Ville Syrjälä | 098ebd6 | 2013-10-01 18:02:15 +0300 | [diff] [blame] | 850 | const struct { |
| 851 | int crtc_x, crtc_y; |
| 852 | unsigned int crtc_w, crtc_h; |
| 853 | uint32_t src_x, src_y, src_w, src_h; |
| 854 | } orig = { |
| 855 | .crtc_x = crtc_x, |
| 856 | .crtc_y = crtc_y, |
| 857 | .crtc_w = crtc_w, |
| 858 | .crtc_h = crtc_h, |
| 859 | .src_x = src_x, |
| 860 | .src_y = src_y, |
| 861 | .src_w = src_w, |
| 862 | .src_h = src_h, |
| 863 | }; |
Jesse Barnes | 5e1bac2 | 2013-03-26 09:25:43 -0700 | [diff] [blame] | 864 | |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 865 | /* Don't modify another pipe's plane */ |
Ville Syrjälä | 1731693 | 2013-04-24 18:52:38 +0300 | [diff] [blame] | 866 | if (intel_plane->pipe != intel_crtc->pipe) { |
| 867 | DRM_DEBUG_KMS("Wrong plane <-> crtc mapping\n"); |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 868 | return -EINVAL; |
Ville Syrjälä | 1731693 | 2013-04-24 18:52:38 +0300 | [diff] [blame] | 869 | } |
| 870 | |
| 871 | /* FIXME check all gen limits */ |
| 872 | if (fb->width < 3 || fb->height < 3 || fb->pitches[0] > 16384) { |
| 873 | DRM_DEBUG_KMS("Unsuitable framebuffer for plane\n"); |
| 874 | return -EINVAL; |
| 875 | } |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 876 | |
Damien Lespiau | 94c6419 | 2012-10-29 15:14:51 +0000 | [diff] [blame] | 877 | /* Sprite planes can be linear or x-tiled surfaces */ |
| 878 | switch (obj->tiling_mode) { |
| 879 | case I915_TILING_NONE: |
| 880 | case I915_TILING_X: |
| 881 | break; |
| 882 | default: |
Ville Syrjälä | 1731693 | 2013-04-24 18:52:38 +0300 | [diff] [blame] | 883 | DRM_DEBUG_KMS("Unsupported tiling mode\n"); |
Damien Lespiau | 94c6419 | 2012-10-29 15:14:51 +0000 | [diff] [blame] | 884 | return -EINVAL; |
| 885 | } |
| 886 | |
Ville Syrjälä | 3c3686c | 2013-04-24 18:52:39 +0300 | [diff] [blame] | 887 | /* |
| 888 | * FIXME the following code does a bunch of fuzzy adjustments to the |
| 889 | * coordinates and sizes. We probably need some way to decide whether |
| 890 | * more strict checking should be done instead. |
| 891 | */ |
Ville Syrjälä | 1731693 | 2013-04-24 18:52:38 +0300 | [diff] [blame] | 892 | max_scale = intel_plane->max_downscale << 16; |
| 893 | min_scale = intel_plane->can_scale ? 1 : (1 << 16); |
| 894 | |
Ville Syrjälä | 3c3686c | 2013-04-24 18:52:39 +0300 | [diff] [blame] | 895 | hscale = drm_rect_calc_hscale_relaxed(&src, &dst, min_scale, max_scale); |
| 896 | BUG_ON(hscale < 0); |
Ville Syrjälä | 1731693 | 2013-04-24 18:52:38 +0300 | [diff] [blame] | 897 | |
Ville Syrjälä | 3c3686c | 2013-04-24 18:52:39 +0300 | [diff] [blame] | 898 | vscale = drm_rect_calc_vscale_relaxed(&src, &dst, min_scale, max_scale); |
| 899 | BUG_ON(vscale < 0); |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 900 | |
Ville Syrjälä | 1731693 | 2013-04-24 18:52:38 +0300 | [diff] [blame] | 901 | visible = drm_rect_clip_scaled(&src, &dst, &clip, hscale, vscale); |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 902 | |
Ville Syrjälä | 1731693 | 2013-04-24 18:52:38 +0300 | [diff] [blame] | 903 | crtc_x = dst.x1; |
| 904 | crtc_y = dst.y1; |
| 905 | crtc_w = drm_rect_width(&dst); |
| 906 | crtc_h = drm_rect_height(&dst); |
Damien Lespiau | 2d354c3 | 2012-10-22 18:19:27 +0100 | [diff] [blame] | 907 | |
Ville Syrjälä | 1731693 | 2013-04-24 18:52:38 +0300 | [diff] [blame] | 908 | if (visible) { |
Ville Syrjälä | 3c3686c | 2013-04-24 18:52:39 +0300 | [diff] [blame] | 909 | /* check again in case clipping clamped the results */ |
| 910 | hscale = drm_rect_calc_hscale(&src, &dst, min_scale, max_scale); |
| 911 | if (hscale < 0) { |
| 912 | DRM_DEBUG_KMS("Horizontal scaling factor out of limits\n"); |
| 913 | drm_rect_debug_print(&src, true); |
| 914 | drm_rect_debug_print(&dst, false); |
| 915 | |
| 916 | return hscale; |
| 917 | } |
| 918 | |
| 919 | vscale = drm_rect_calc_vscale(&src, &dst, min_scale, max_scale); |
| 920 | if (vscale < 0) { |
| 921 | DRM_DEBUG_KMS("Vertical scaling factor out of limits\n"); |
| 922 | drm_rect_debug_print(&src, true); |
| 923 | drm_rect_debug_print(&dst, false); |
| 924 | |
| 925 | return vscale; |
| 926 | } |
| 927 | |
Ville Syrjälä | 1731693 | 2013-04-24 18:52:38 +0300 | [diff] [blame] | 928 | /* Make the source viewport size an exact multiple of the scaling factors. */ |
| 929 | drm_rect_adjust_size(&src, |
| 930 | drm_rect_width(&dst) * hscale - drm_rect_width(&src), |
| 931 | drm_rect_height(&dst) * vscale - drm_rect_height(&src)); |
| 932 | |
| 933 | /* sanity check to make sure the src viewport wasn't enlarged */ |
| 934 | WARN_ON(src.x1 < (int) src_x || |
| 935 | src.y1 < (int) src_y || |
| 936 | src.x2 > (int) (src_x + src_w) || |
| 937 | src.y2 > (int) (src_y + src_h)); |
| 938 | |
| 939 | /* |
| 940 | * Hardware doesn't handle subpixel coordinates. |
| 941 | * Adjust to (macro)pixel boundary, but be careful not to |
| 942 | * increase the source viewport size, because that could |
| 943 | * push the downscaling factor out of bounds. |
Ville Syrjälä | 1731693 | 2013-04-24 18:52:38 +0300 | [diff] [blame] | 944 | */ |
| 945 | src_x = src.x1 >> 16; |
| 946 | src_w = drm_rect_width(&src) >> 16; |
| 947 | src_y = src.y1 >> 16; |
| 948 | src_h = drm_rect_height(&src) >> 16; |
| 949 | |
| 950 | if (format_is_yuv(fb->pixel_format)) { |
| 951 | src_x &= ~1; |
| 952 | src_w &= ~1; |
| 953 | |
| 954 | /* |
| 955 | * Must keep src and dst the |
| 956 | * same if we can't scale. |
| 957 | */ |
| 958 | if (!intel_plane->can_scale) |
| 959 | crtc_w &= ~1; |
| 960 | |
| 961 | if (crtc_w == 0) |
| 962 | visible = false; |
| 963 | } |
| 964 | } |
| 965 | |
| 966 | /* Check size restrictions when scaling */ |
| 967 | if (visible && (src_w != crtc_w || src_h != crtc_h)) { |
| 968 | unsigned int width_bytes; |
| 969 | |
| 970 | WARN_ON(!intel_plane->can_scale); |
| 971 | |
| 972 | /* FIXME interlacing min height is 6 */ |
| 973 | |
| 974 | if (crtc_w < 3 || crtc_h < 3) |
| 975 | visible = false; |
| 976 | |
| 977 | if (src_w < 3 || src_h < 3) |
| 978 | visible = false; |
| 979 | |
| 980 | width_bytes = ((src_x * pixel_size) & 63) + src_w * pixel_size; |
| 981 | |
| 982 | if (src_w > 2048 || src_h > 2048 || |
| 983 | width_bytes > 4096 || fb->pitches[0] > 4096) { |
| 984 | DRM_DEBUG_KMS("Source dimensions exceed hardware limits\n"); |
| 985 | return -EINVAL; |
| 986 | } |
| 987 | } |
| 988 | |
| 989 | dst.x1 = crtc_x; |
| 990 | dst.x2 = crtc_x + crtc_w; |
| 991 | dst.y1 = crtc_y; |
| 992 | dst.y2 = crtc_y + crtc_h; |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 993 | |
| 994 | /* |
| 995 | * If the sprite is completely covering the primary plane, |
| 996 | * we can disable the primary and save power. |
| 997 | */ |
Ville Syrjälä | 5b633d6 | 2014-04-29 13:35:47 +0300 | [diff] [blame] | 998 | primary_enabled = !drm_rect_equals(&dst, &clip) || colorkey_enabled(intel_plane); |
| 999 | WARN_ON(!primary_enabled && !visible && intel_crtc->active); |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 1000 | |
| 1001 | mutex_lock(&dev->struct_mutex); |
| 1002 | |
Chris Wilson | 693db18 | 2013-03-05 14:52:39 +0000 | [diff] [blame] | 1003 | /* Note that this will apply the VT-d workaround for scanouts, |
| 1004 | * which is more restrictive than required for sprites. (The |
| 1005 | * primary plane requires 256KiB alignment with 64 PTE padding, |
| 1006 | * the sprite planes only require 128KiB alignment and 32 PTE padding. |
| 1007 | */ |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 1008 | ret = intel_pin_and_fence_fb_obj(dev, obj, NULL); |
Ville Syrjälä | 82284b6 | 2013-10-01 18:02:12 +0300 | [diff] [blame] | 1009 | |
Daniel Vetter | a071fa0 | 2014-06-18 23:28:09 +0200 | [diff] [blame] | 1010 | i915_gem_track_fb(old_obj, obj, |
| 1011 | INTEL_FRONTBUFFER_SPRITE(pipe)); |
Ville Syrjälä | 82284b6 | 2013-10-01 18:02:12 +0300 | [diff] [blame] | 1012 | mutex_unlock(&dev->struct_mutex); |
| 1013 | |
Jesse Barnes | 00c2064b | 2012-01-13 15:48:39 -0800 | [diff] [blame] | 1014 | if (ret) |
Ville Syrjälä | 82284b6 | 2013-10-01 18:02:12 +0300 | [diff] [blame] | 1015 | return ret; |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 1016 | |
Ville Syrjälä | 098ebd6 | 2013-10-01 18:02:15 +0300 | [diff] [blame] | 1017 | intel_plane->crtc_x = orig.crtc_x; |
| 1018 | intel_plane->crtc_y = orig.crtc_y; |
| 1019 | intel_plane->crtc_w = orig.crtc_w; |
| 1020 | intel_plane->crtc_h = orig.crtc_h; |
| 1021 | intel_plane->src_x = orig.src_x; |
| 1022 | intel_plane->src_y = orig.src_y; |
| 1023 | intel_plane->src_w = orig.src_w; |
| 1024 | intel_plane->src_h = orig.src_h; |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 1025 | intel_plane->obj = obj; |
| 1026 | |
Ville Syrjälä | 03c5b25 | 2013-10-01 18:02:11 +0300 | [diff] [blame] | 1027 | if (intel_crtc->active) { |
Ville Syrjälä | 5b633d6 | 2014-04-29 13:35:47 +0300 | [diff] [blame] | 1028 | bool primary_was_enabled = intel_crtc->primary_enabled; |
| 1029 | |
| 1030 | intel_crtc->primary_enabled = primary_enabled; |
| 1031 | |
Ville Syrjälä | 46a55d3 | 2014-05-21 14:04:46 +0300 | [diff] [blame] | 1032 | if (primary_was_enabled != primary_enabled) |
| 1033 | intel_crtc_wait_for_pending_flips(crtc); |
| 1034 | |
Ville Syrjälä | 5b633d6 | 2014-04-29 13:35:47 +0300 | [diff] [blame] | 1035 | if (primary_was_enabled && !primary_enabled) |
| 1036 | intel_pre_disable_primary(crtc); |
Jesse Barnes | 175bd42 | 2011-12-13 13:19:39 -0800 | [diff] [blame] | 1037 | |
Ville Syrjälä | 03c5b25 | 2013-10-01 18:02:11 +0300 | [diff] [blame] | 1038 | if (visible) |
| 1039 | intel_plane->update_plane(plane, crtc, fb, obj, |
| 1040 | crtc_x, crtc_y, crtc_w, crtc_h, |
| 1041 | src_x, src_y, src_w, src_h); |
| 1042 | else |
| 1043 | intel_plane->disable_plane(plane, crtc); |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 1044 | |
Daniel Vetter | f99d706 | 2014-06-19 16:01:59 +0200 | [diff] [blame] | 1045 | intel_frontbuffer_flip(dev, INTEL_FRONTBUFFER_SPRITE(pipe)); |
| 1046 | |
Ville Syrjälä | 5b633d6 | 2014-04-29 13:35:47 +0300 | [diff] [blame] | 1047 | if (!primary_was_enabled && primary_enabled) |
| 1048 | intel_post_enable_primary(crtc); |
Ville Syrjälä | 03c5b25 | 2013-10-01 18:02:11 +0300 | [diff] [blame] | 1049 | } |
Jesse Barnes | 175bd42 | 2011-12-13 13:19:39 -0800 | [diff] [blame] | 1050 | |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 1051 | /* Unpin old obj after new one is active to avoid ugliness */ |
| 1052 | if (old_obj) { |
| 1053 | /* |
| 1054 | * It's fairly common to simply update the position of |
| 1055 | * an existing object. In that case, we don't need to |
| 1056 | * wait for vblank to avoid ugliness, we only need to |
| 1057 | * do the pin & ref bookkeeping. |
| 1058 | */ |
Ville Syrjälä | 82284b6 | 2013-10-01 18:02:12 +0300 | [diff] [blame] | 1059 | if (old_obj != obj && intel_crtc->active) |
Ville Syrjälä | 2afd9ef | 2013-10-01 18:02:14 +0300 | [diff] [blame] | 1060 | intel_wait_for_vblank(dev, intel_crtc->pipe); |
Ville Syrjälä | 82284b6 | 2013-10-01 18:02:12 +0300 | [diff] [blame] | 1061 | |
| 1062 | mutex_lock(&dev->struct_mutex); |
Chris Wilson | 1690e1e | 2011-12-14 13:57:08 +0100 | [diff] [blame] | 1063 | intel_unpin_fb_obj(old_obj); |
Ville Syrjälä | 82284b6 | 2013-10-01 18:02:12 +0300 | [diff] [blame] | 1064 | mutex_unlock(&dev->struct_mutex); |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 1065 | } |
| 1066 | |
Ville Syrjälä | 82284b6 | 2013-10-01 18:02:12 +0300 | [diff] [blame] | 1067 | return 0; |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 1068 | } |
| 1069 | |
| 1070 | static int |
| 1071 | intel_disable_plane(struct drm_plane *plane) |
| 1072 | { |
| 1073 | struct drm_device *dev = plane->dev; |
| 1074 | struct intel_plane *intel_plane = to_intel_plane(plane); |
Ville Syrjälä | 03c5b25 | 2013-10-01 18:02:11 +0300 | [diff] [blame] | 1075 | struct intel_crtc *intel_crtc; |
Daniel Vetter | a071fa0 | 2014-06-18 23:28:09 +0200 | [diff] [blame] | 1076 | enum pipe pipe; |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 1077 | |
Ville Syrjälä | 88a94a5 | 2013-08-07 13:30:23 +0300 | [diff] [blame] | 1078 | if (!plane->fb) |
| 1079 | return 0; |
| 1080 | |
| 1081 | if (WARN_ON(!plane->crtc)) |
| 1082 | return -EINVAL; |
| 1083 | |
Ville Syrjälä | 03c5b25 | 2013-10-01 18:02:11 +0300 | [diff] [blame] | 1084 | intel_crtc = to_intel_crtc(plane->crtc); |
Daniel Vetter | a071fa0 | 2014-06-18 23:28:09 +0200 | [diff] [blame] | 1085 | pipe = intel_crtc->pipe; |
Ville Syrjälä | 03c5b25 | 2013-10-01 18:02:11 +0300 | [diff] [blame] | 1086 | |
| 1087 | if (intel_crtc->active) { |
Ville Syrjälä | 5b633d6 | 2014-04-29 13:35:47 +0300 | [diff] [blame] | 1088 | bool primary_was_enabled = intel_crtc->primary_enabled; |
| 1089 | |
| 1090 | intel_crtc->primary_enabled = true; |
| 1091 | |
Ville Syrjälä | 03c5b25 | 2013-10-01 18:02:11 +0300 | [diff] [blame] | 1092 | intel_plane->disable_plane(plane, plane->crtc); |
Ville Syrjälä | 5b633d6 | 2014-04-29 13:35:47 +0300 | [diff] [blame] | 1093 | |
| 1094 | if (!primary_was_enabled && intel_crtc->primary_enabled) |
| 1095 | intel_post_enable_primary(plane->crtc); |
Ville Syrjälä | 03c5b25 | 2013-10-01 18:02:11 +0300 | [diff] [blame] | 1096 | } |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 1097 | |
Ville Syrjälä | 5f3fb46 | 2013-10-01 18:02:13 +0300 | [diff] [blame] | 1098 | if (intel_plane->obj) { |
| 1099 | if (intel_crtc->active) |
| 1100 | intel_wait_for_vblank(dev, intel_plane->pipe); |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 1101 | |
Ville Syrjälä | 5f3fb46 | 2013-10-01 18:02:13 +0300 | [diff] [blame] | 1102 | mutex_lock(&dev->struct_mutex); |
| 1103 | intel_unpin_fb_obj(intel_plane->obj); |
Daniel Vetter | a071fa0 | 2014-06-18 23:28:09 +0200 | [diff] [blame] | 1104 | i915_gem_track_fb(intel_plane->obj, NULL, |
| 1105 | INTEL_FRONTBUFFER_SPRITE(pipe)); |
Ville Syrjälä | 5f3fb46 | 2013-10-01 18:02:13 +0300 | [diff] [blame] | 1106 | mutex_unlock(&dev->struct_mutex); |
Ville Syrjälä | c626d31 | 2013-03-27 17:49:13 +0200 | [diff] [blame] | 1107 | |
Ville Syrjälä | 5f3fb46 | 2013-10-01 18:02:13 +0300 | [diff] [blame] | 1108 | intel_plane->obj = NULL; |
| 1109 | } |
Ville Syrjälä | 82284b6 | 2013-10-01 18:02:12 +0300 | [diff] [blame] | 1110 | |
Ville Syrjälä | 5f3fb46 | 2013-10-01 18:02:13 +0300 | [diff] [blame] | 1111 | return 0; |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 1112 | } |
| 1113 | |
| 1114 | static void intel_destroy_plane(struct drm_plane *plane) |
| 1115 | { |
| 1116 | struct intel_plane *intel_plane = to_intel_plane(plane); |
| 1117 | intel_disable_plane(plane); |
| 1118 | drm_plane_cleanup(plane); |
| 1119 | kfree(intel_plane); |
| 1120 | } |
| 1121 | |
Jesse Barnes | 8ea3086 | 2012-01-03 08:05:39 -0800 | [diff] [blame] | 1122 | int intel_sprite_set_colorkey(struct drm_device *dev, void *data, |
| 1123 | struct drm_file *file_priv) |
| 1124 | { |
| 1125 | struct drm_intel_sprite_colorkey *set = data; |
Jesse Barnes | 8ea3086 | 2012-01-03 08:05:39 -0800 | [diff] [blame] | 1126 | struct drm_plane *plane; |
| 1127 | struct intel_plane *intel_plane; |
| 1128 | int ret = 0; |
| 1129 | |
Daniel Vetter | 1cff8f6 | 2012-04-24 09:55:08 +0200 | [diff] [blame] | 1130 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
| 1131 | return -ENODEV; |
Jesse Barnes | 8ea3086 | 2012-01-03 08:05:39 -0800 | [diff] [blame] | 1132 | |
| 1133 | /* Make sure we don't try to enable both src & dest simultaneously */ |
| 1134 | if ((set->flags & (I915_SET_COLORKEY_DESTINATION | I915_SET_COLORKEY_SOURCE)) == (I915_SET_COLORKEY_DESTINATION | I915_SET_COLORKEY_SOURCE)) |
| 1135 | return -EINVAL; |
| 1136 | |
Daniel Vetter | a0e99e6 | 2012-12-02 01:05:46 +0100 | [diff] [blame] | 1137 | drm_modeset_lock_all(dev); |
Jesse Barnes | 8ea3086 | 2012-01-03 08:05:39 -0800 | [diff] [blame] | 1138 | |
Rob Clark | 7707e65 | 2014-07-17 23:30:04 -0400 | [diff] [blame^] | 1139 | plane = drm_plane_find(dev, set->plane_id); |
| 1140 | if (!plane) { |
Ville Syrjälä | 3f2c205 | 2013-10-17 13:35:03 +0300 | [diff] [blame] | 1141 | ret = -ENOENT; |
Jesse Barnes | 8ea3086 | 2012-01-03 08:05:39 -0800 | [diff] [blame] | 1142 | goto out_unlock; |
| 1143 | } |
| 1144 | |
Jesse Barnes | 8ea3086 | 2012-01-03 08:05:39 -0800 | [diff] [blame] | 1145 | intel_plane = to_intel_plane(plane); |
| 1146 | ret = intel_plane->update_colorkey(plane, set); |
| 1147 | |
| 1148 | out_unlock: |
Daniel Vetter | a0e99e6 | 2012-12-02 01:05:46 +0100 | [diff] [blame] | 1149 | drm_modeset_unlock_all(dev); |
Jesse Barnes | 8ea3086 | 2012-01-03 08:05:39 -0800 | [diff] [blame] | 1150 | return ret; |
| 1151 | } |
| 1152 | |
| 1153 | int intel_sprite_get_colorkey(struct drm_device *dev, void *data, |
| 1154 | struct drm_file *file_priv) |
| 1155 | { |
| 1156 | struct drm_intel_sprite_colorkey *get = data; |
Jesse Barnes | 8ea3086 | 2012-01-03 08:05:39 -0800 | [diff] [blame] | 1157 | struct drm_plane *plane; |
| 1158 | struct intel_plane *intel_plane; |
| 1159 | int ret = 0; |
| 1160 | |
Daniel Vetter | 1cff8f6 | 2012-04-24 09:55:08 +0200 | [diff] [blame] | 1161 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
| 1162 | return -ENODEV; |
Jesse Barnes | 8ea3086 | 2012-01-03 08:05:39 -0800 | [diff] [blame] | 1163 | |
Daniel Vetter | a0e99e6 | 2012-12-02 01:05:46 +0100 | [diff] [blame] | 1164 | drm_modeset_lock_all(dev); |
Jesse Barnes | 8ea3086 | 2012-01-03 08:05:39 -0800 | [diff] [blame] | 1165 | |
Rob Clark | 7707e65 | 2014-07-17 23:30:04 -0400 | [diff] [blame^] | 1166 | plane = drm_plane_find(dev, get->plane_id); |
| 1167 | if (!plane) { |
Ville Syrjälä | 3f2c205 | 2013-10-17 13:35:03 +0300 | [diff] [blame] | 1168 | ret = -ENOENT; |
Jesse Barnes | 8ea3086 | 2012-01-03 08:05:39 -0800 | [diff] [blame] | 1169 | goto out_unlock; |
| 1170 | } |
| 1171 | |
Jesse Barnes | 8ea3086 | 2012-01-03 08:05:39 -0800 | [diff] [blame] | 1172 | intel_plane = to_intel_plane(plane); |
| 1173 | intel_plane->get_colorkey(plane, get); |
| 1174 | |
| 1175 | out_unlock: |
Daniel Vetter | a0e99e6 | 2012-12-02 01:05:46 +0100 | [diff] [blame] | 1176 | drm_modeset_unlock_all(dev); |
Jesse Barnes | 8ea3086 | 2012-01-03 08:05:39 -0800 | [diff] [blame] | 1177 | return ret; |
| 1178 | } |
| 1179 | |
Jesse Barnes | 5e1bac2 | 2013-03-26 09:25:43 -0700 | [diff] [blame] | 1180 | void intel_plane_restore(struct drm_plane *plane) |
| 1181 | { |
| 1182 | struct intel_plane *intel_plane = to_intel_plane(plane); |
| 1183 | |
| 1184 | if (!plane->crtc || !plane->fb) |
| 1185 | return; |
| 1186 | |
| 1187 | intel_update_plane(plane, plane->crtc, plane->fb, |
| 1188 | intel_plane->crtc_x, intel_plane->crtc_y, |
| 1189 | intel_plane->crtc_w, intel_plane->crtc_h, |
| 1190 | intel_plane->src_x, intel_plane->src_y, |
| 1191 | intel_plane->src_w, intel_plane->src_h); |
| 1192 | } |
| 1193 | |
Ville Syrjälä | bb53d4a | 2013-06-04 13:49:04 +0300 | [diff] [blame] | 1194 | void intel_plane_disable(struct drm_plane *plane) |
| 1195 | { |
| 1196 | if (!plane->crtc || !plane->fb) |
| 1197 | return; |
| 1198 | |
| 1199 | intel_disable_plane(plane); |
| 1200 | } |
| 1201 | |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 1202 | static const struct drm_plane_funcs intel_plane_funcs = { |
| 1203 | .update_plane = intel_update_plane, |
| 1204 | .disable_plane = intel_disable_plane, |
| 1205 | .destroy = intel_destroy_plane, |
| 1206 | }; |
| 1207 | |
Chris Wilson | d1686ae | 2012-04-10 11:41:49 +0100 | [diff] [blame] | 1208 | static uint32_t ilk_plane_formats[] = { |
| 1209 | DRM_FORMAT_XRGB8888, |
| 1210 | DRM_FORMAT_YUYV, |
| 1211 | DRM_FORMAT_YVYU, |
| 1212 | DRM_FORMAT_UYVY, |
| 1213 | DRM_FORMAT_VYUY, |
| 1214 | }; |
| 1215 | |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 1216 | static uint32_t snb_plane_formats[] = { |
| 1217 | DRM_FORMAT_XBGR8888, |
| 1218 | DRM_FORMAT_XRGB8888, |
| 1219 | DRM_FORMAT_YUYV, |
| 1220 | DRM_FORMAT_YVYU, |
| 1221 | DRM_FORMAT_UYVY, |
| 1222 | DRM_FORMAT_VYUY, |
| 1223 | }; |
| 1224 | |
Jesse Barnes | 7f1f385 | 2013-04-02 11:22:20 -0700 | [diff] [blame] | 1225 | static uint32_t vlv_plane_formats[] = { |
| 1226 | DRM_FORMAT_RGB565, |
| 1227 | DRM_FORMAT_ABGR8888, |
| 1228 | DRM_FORMAT_ARGB8888, |
| 1229 | DRM_FORMAT_XBGR8888, |
| 1230 | DRM_FORMAT_XRGB8888, |
| 1231 | DRM_FORMAT_XBGR2101010, |
| 1232 | DRM_FORMAT_ABGR2101010, |
| 1233 | DRM_FORMAT_YUYV, |
| 1234 | DRM_FORMAT_YVYU, |
| 1235 | DRM_FORMAT_UYVY, |
| 1236 | DRM_FORMAT_VYUY, |
| 1237 | }; |
| 1238 | |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 1239 | int |
Jesse Barnes | 7f1f385 | 2013-04-02 11:22:20 -0700 | [diff] [blame] | 1240 | intel_plane_init(struct drm_device *dev, enum pipe pipe, int plane) |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 1241 | { |
| 1242 | struct intel_plane *intel_plane; |
| 1243 | unsigned long possible_crtcs; |
Chris Wilson | d1686ae | 2012-04-10 11:41:49 +0100 | [diff] [blame] | 1244 | const uint32_t *plane_formats; |
| 1245 | int num_plane_formats; |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 1246 | int ret; |
| 1247 | |
Chris Wilson | d1686ae | 2012-04-10 11:41:49 +0100 | [diff] [blame] | 1248 | if (INTEL_INFO(dev)->gen < 5) |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 1249 | return -ENODEV; |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 1250 | |
Daniel Vetter | b14c567 | 2013-09-19 12:18:32 +0200 | [diff] [blame] | 1251 | intel_plane = kzalloc(sizeof(*intel_plane), GFP_KERNEL); |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 1252 | if (!intel_plane) |
| 1253 | return -ENOMEM; |
| 1254 | |
Chris Wilson | d1686ae | 2012-04-10 11:41:49 +0100 | [diff] [blame] | 1255 | switch (INTEL_INFO(dev)->gen) { |
| 1256 | case 5: |
| 1257 | case 6: |
Damien Lespiau | 2d354c3 | 2012-10-22 18:19:27 +0100 | [diff] [blame] | 1258 | intel_plane->can_scale = true; |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 1259 | intel_plane->max_downscale = 16; |
Chris Wilson | d1686ae | 2012-04-10 11:41:49 +0100 | [diff] [blame] | 1260 | intel_plane->update_plane = ilk_update_plane; |
| 1261 | intel_plane->disable_plane = ilk_disable_plane; |
| 1262 | intel_plane->update_colorkey = ilk_update_colorkey; |
| 1263 | intel_plane->get_colorkey = ilk_get_colorkey; |
| 1264 | |
| 1265 | if (IS_GEN6(dev)) { |
| 1266 | plane_formats = snb_plane_formats; |
| 1267 | num_plane_formats = ARRAY_SIZE(snb_plane_formats); |
| 1268 | } else { |
| 1269 | plane_formats = ilk_plane_formats; |
| 1270 | num_plane_formats = ARRAY_SIZE(ilk_plane_formats); |
| 1271 | } |
| 1272 | break; |
| 1273 | |
| 1274 | case 7: |
Ben Widawsky | 4e0bbc3 | 2013-11-02 21:07:07 -0700 | [diff] [blame] | 1275 | case 8: |
Damien Lespiau | d49f709 | 2013-04-25 15:15:00 +0100 | [diff] [blame] | 1276 | if (IS_IVYBRIDGE(dev)) { |
Damien Lespiau | 2d354c3 | 2012-10-22 18:19:27 +0100 | [diff] [blame] | 1277 | intel_plane->can_scale = true; |
Damien Lespiau | d49f709 | 2013-04-25 15:15:00 +0100 | [diff] [blame] | 1278 | intel_plane->max_downscale = 2; |
| 1279 | } else { |
| 1280 | intel_plane->can_scale = false; |
| 1281 | intel_plane->max_downscale = 1; |
| 1282 | } |
Chris Wilson | d1686ae | 2012-04-10 11:41:49 +0100 | [diff] [blame] | 1283 | |
Jesse Barnes | 7f1f385 | 2013-04-02 11:22:20 -0700 | [diff] [blame] | 1284 | if (IS_VALLEYVIEW(dev)) { |
Jesse Barnes | 7f1f385 | 2013-04-02 11:22:20 -0700 | [diff] [blame] | 1285 | intel_plane->update_plane = vlv_update_plane; |
| 1286 | intel_plane->disable_plane = vlv_disable_plane; |
| 1287 | intel_plane->update_colorkey = vlv_update_colorkey; |
| 1288 | intel_plane->get_colorkey = vlv_get_colorkey; |
| 1289 | |
| 1290 | plane_formats = vlv_plane_formats; |
| 1291 | num_plane_formats = ARRAY_SIZE(vlv_plane_formats); |
| 1292 | } else { |
Jesse Barnes | 7f1f385 | 2013-04-02 11:22:20 -0700 | [diff] [blame] | 1293 | intel_plane->update_plane = ivb_update_plane; |
| 1294 | intel_plane->disable_plane = ivb_disable_plane; |
| 1295 | intel_plane->update_colorkey = ivb_update_colorkey; |
| 1296 | intel_plane->get_colorkey = ivb_get_colorkey; |
| 1297 | |
| 1298 | plane_formats = snb_plane_formats; |
| 1299 | num_plane_formats = ARRAY_SIZE(snb_plane_formats); |
| 1300 | } |
Chris Wilson | d1686ae | 2012-04-10 11:41:49 +0100 | [diff] [blame] | 1301 | break; |
| 1302 | |
| 1303 | default: |
Jesper Juhl | a8b0bba | 2012-06-27 00:55:37 +0200 | [diff] [blame] | 1304 | kfree(intel_plane); |
Chris Wilson | d1686ae | 2012-04-10 11:41:49 +0100 | [diff] [blame] | 1305 | return -ENODEV; |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 1306 | } |
| 1307 | |
| 1308 | intel_plane->pipe = pipe; |
Jesse Barnes | 7f1f385 | 2013-04-02 11:22:20 -0700 | [diff] [blame] | 1309 | intel_plane->plane = plane; |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 1310 | possible_crtcs = (1 << pipe); |
| 1311 | ret = drm_plane_init(dev, &intel_plane->base, possible_crtcs, |
Chris Wilson | d1686ae | 2012-04-10 11:41:49 +0100 | [diff] [blame] | 1312 | &intel_plane_funcs, |
| 1313 | plane_formats, num_plane_formats, |
| 1314 | false); |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 1315 | if (ret) |
| 1316 | kfree(intel_plane); |
| 1317 | |
| 1318 | return ret; |
| 1319 | } |