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; |
Ville Syrjälä | 210871b | 2014-05-22 19:00:50 +0300 | [diff] [blame] | 56 | wait_queue_head_t *wq = drm_crtc_vblank_waitqueue(&crtc->base); |
Ville Syrjälä | 8d7849d | 2014-04-29 13:35:46 +0300 | [diff] [blame] | 57 | DEFINE_WAIT(wait); |
| 58 | |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 59 | WARN_ON(!drm_modeset_is_locked(&crtc->base.mutex)); |
Ville Syrjälä | 8d7849d | 2014-04-29 13:35:46 +0300 | [diff] [blame] | 60 | |
| 61 | vblank_start = mode->crtc_vblank_start; |
| 62 | if (mode->flags & DRM_MODE_FLAG_INTERLACE) |
| 63 | vblank_start = DIV_ROUND_UP(vblank_start, 2); |
| 64 | |
| 65 | /* FIXME needs to be calibrated sensibly */ |
| 66 | min = vblank_start - usecs_to_scanlines(mode, 100); |
| 67 | max = vblank_start - 1; |
| 68 | |
| 69 | if (min <= 0 || max <= 0) |
| 70 | return false; |
| 71 | |
| 72 | if (WARN_ON(drm_vblank_get(dev, pipe))) |
| 73 | return false; |
| 74 | |
| 75 | local_irq_disable(); |
| 76 | |
Ville Syrjälä | 25ef284 | 2014-04-29 13:35:48 +0300 | [diff] [blame] | 77 | trace_i915_pipe_update_start(crtc, min, max); |
| 78 | |
Ville Syrjälä | 8d7849d | 2014-04-29 13:35:46 +0300 | [diff] [blame] | 79 | for (;;) { |
| 80 | /* |
| 81 | * prepare_to_wait() has a memory barrier, which guarantees |
| 82 | * other CPUs can see the task state update by the time we |
| 83 | * read the scanline. |
| 84 | */ |
Ville Syrjälä | 210871b | 2014-05-22 19:00:50 +0300 | [diff] [blame] | 85 | prepare_to_wait(wq, &wait, TASK_UNINTERRUPTIBLE); |
Ville Syrjälä | 8d7849d | 2014-04-29 13:35:46 +0300 | [diff] [blame] | 86 | |
| 87 | scanline = intel_get_crtc_scanline(crtc); |
| 88 | if (scanline < min || scanline > max) |
| 89 | break; |
| 90 | |
| 91 | if (timeout <= 0) { |
| 92 | DRM_ERROR("Potential atomic update failure on pipe %c\n", |
| 93 | pipe_name(crtc->pipe)); |
| 94 | break; |
| 95 | } |
| 96 | |
| 97 | local_irq_enable(); |
| 98 | |
| 99 | timeout = schedule_timeout(timeout); |
| 100 | |
| 101 | local_irq_disable(); |
| 102 | } |
| 103 | |
Ville Syrjälä | 210871b | 2014-05-22 19:00:50 +0300 | [diff] [blame] | 104 | finish_wait(wq, &wait); |
Ville Syrjälä | 8d7849d | 2014-04-29 13:35:46 +0300 | [diff] [blame] | 105 | |
| 106 | drm_vblank_put(dev, pipe); |
| 107 | |
| 108 | *start_vbl_count = dev->driver->get_vblank_counter(dev, pipe); |
| 109 | |
Ville Syrjälä | 25ef284 | 2014-04-29 13:35:48 +0300 | [diff] [blame] | 110 | trace_i915_pipe_update_vblank_evaded(crtc, min, max, *start_vbl_count); |
| 111 | |
Ville Syrjälä | 8d7849d | 2014-04-29 13:35:46 +0300 | [diff] [blame] | 112 | return true; |
| 113 | } |
| 114 | |
| 115 | static void intel_pipe_update_end(struct intel_crtc *crtc, u32 start_vbl_count) |
| 116 | { |
| 117 | struct drm_device *dev = crtc->base.dev; |
| 118 | enum pipe pipe = crtc->pipe; |
| 119 | u32 end_vbl_count = dev->driver->get_vblank_counter(dev, pipe); |
| 120 | |
Ville Syrjälä | 25ef284 | 2014-04-29 13:35:48 +0300 | [diff] [blame] | 121 | trace_i915_pipe_update_end(crtc, end_vbl_count); |
| 122 | |
Ville Syrjälä | 8d7849d | 2014-04-29 13:35:46 +0300 | [diff] [blame] | 123 | local_irq_enable(); |
| 124 | |
| 125 | if (start_vbl_count != end_vbl_count) |
| 126 | DRM_ERROR("Atomic update failure on pipe %c (start=%u end=%u)\n", |
| 127 | pipe_name(pipe), start_vbl_count, end_vbl_count); |
| 128 | } |
| 129 | |
Ville Syrjälä | 5b633d6 | 2014-04-29 13:35:47 +0300 | [diff] [blame] | 130 | static void intel_update_primary_plane(struct intel_crtc *crtc) |
| 131 | { |
| 132 | struct drm_i915_private *dev_priv = crtc->base.dev->dev_private; |
| 133 | int reg = DSPCNTR(crtc->plane); |
| 134 | |
| 135 | if (crtc->primary_enabled) |
| 136 | I915_WRITE(reg, I915_READ(reg) | DISPLAY_PLANE_ENABLE); |
| 137 | else |
| 138 | I915_WRITE(reg, I915_READ(reg) & ~DISPLAY_PLANE_ENABLE); |
| 139 | } |
| 140 | |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 141 | static void |
Damien Lespiau | dc2a41b | 2013-12-04 00:49:41 +0000 | [diff] [blame] | 142 | skl_update_plane(struct drm_plane *drm_plane, struct drm_crtc *crtc, |
| 143 | struct drm_framebuffer *fb, |
| 144 | struct drm_i915_gem_object *obj, int crtc_x, int crtc_y, |
| 145 | unsigned int crtc_w, unsigned int crtc_h, |
| 146 | uint32_t x, uint32_t y, |
| 147 | uint32_t src_w, uint32_t src_h) |
| 148 | { |
| 149 | struct drm_device *dev = drm_plane->dev; |
| 150 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 151 | struct intel_plane *intel_plane = to_intel_plane(drm_plane); |
| 152 | const int pipe = intel_plane->pipe; |
| 153 | const int plane = intel_plane->plane + 1; |
| 154 | u32 plane_ctl, stride; |
| 155 | int pixel_size = drm_format_plane_cpp(fb->pixel_format, 0); |
| 156 | |
| 157 | plane_ctl = I915_READ(PLANE_CTL(pipe, plane)); |
| 158 | |
| 159 | /* Mask out pixel format bits in case we change it */ |
| 160 | plane_ctl &= ~PLANE_CTL_FORMAT_MASK; |
| 161 | plane_ctl &= ~PLANE_CTL_ORDER_RGBX; |
| 162 | plane_ctl &= ~PLANE_CTL_YUV422_ORDER_MASK; |
| 163 | plane_ctl &= ~PLANE_CTL_TILED_MASK; |
| 164 | plane_ctl &= ~PLANE_CTL_ALPHA_MASK; |
Sonika Jindal | 1447dde | 2014-10-04 10:53:31 +0100 | [diff] [blame] | 165 | plane_ctl &= ~PLANE_CTL_ROTATE_MASK; |
Damien Lespiau | dc2a41b | 2013-12-04 00:49:41 +0000 | [diff] [blame] | 166 | |
| 167 | /* Trickle feed has to be enabled */ |
| 168 | plane_ctl &= ~PLANE_CTL_TRICKLE_FEED_DISABLE; |
| 169 | |
| 170 | switch (fb->pixel_format) { |
| 171 | case DRM_FORMAT_RGB565: |
| 172 | plane_ctl |= PLANE_CTL_FORMAT_RGB_565; |
| 173 | break; |
| 174 | case DRM_FORMAT_XBGR8888: |
| 175 | plane_ctl |= PLANE_CTL_FORMAT_XRGB_8888 | PLANE_CTL_ORDER_RGBX; |
| 176 | break; |
| 177 | case DRM_FORMAT_XRGB8888: |
| 178 | plane_ctl |= PLANE_CTL_FORMAT_XRGB_8888; |
| 179 | break; |
| 180 | /* |
| 181 | * XXX: For ARBG/ABGR formats we default to expecting scanout buffers |
| 182 | * to be already pre-multiplied. We need to add a knob (or a different |
| 183 | * DRM_FORMAT) for user-space to configure that. |
| 184 | */ |
| 185 | case DRM_FORMAT_ABGR8888: |
| 186 | plane_ctl |= PLANE_CTL_FORMAT_XRGB_8888 | |
| 187 | PLANE_CTL_ORDER_RGBX | |
| 188 | PLANE_CTL_ALPHA_SW_PREMULTIPLY; |
| 189 | break; |
| 190 | case DRM_FORMAT_ARGB8888: |
| 191 | plane_ctl |= PLANE_CTL_FORMAT_XRGB_8888 | |
| 192 | PLANE_CTL_ALPHA_SW_PREMULTIPLY; |
| 193 | break; |
| 194 | case DRM_FORMAT_YUYV: |
| 195 | plane_ctl |= PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YUYV; |
| 196 | break; |
| 197 | case DRM_FORMAT_YVYU: |
| 198 | plane_ctl |= PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YVYU; |
| 199 | break; |
| 200 | case DRM_FORMAT_UYVY: |
| 201 | plane_ctl |= PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_UYVY; |
| 202 | break; |
| 203 | case DRM_FORMAT_VYUY: |
| 204 | plane_ctl |= PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_VYUY; |
| 205 | break; |
| 206 | default: |
| 207 | BUG(); |
| 208 | } |
| 209 | |
| 210 | switch (obj->tiling_mode) { |
| 211 | case I915_TILING_NONE: |
| 212 | stride = fb->pitches[0] >> 6; |
| 213 | break; |
| 214 | case I915_TILING_X: |
| 215 | plane_ctl |= PLANE_CTL_TILED_X; |
| 216 | stride = fb->pitches[0] >> 9; |
| 217 | break; |
| 218 | default: |
| 219 | BUG(); |
| 220 | } |
Sonika Jindal | 1447dde | 2014-10-04 10:53:31 +0100 | [diff] [blame] | 221 | if (intel_plane->rotation == BIT(DRM_ROTATE_180)) |
| 222 | plane_ctl |= PLANE_CTL_ROTATE_180; |
Damien Lespiau | dc2a41b | 2013-12-04 00:49:41 +0000 | [diff] [blame] | 223 | |
| 224 | plane_ctl |= PLANE_CTL_ENABLE; |
| 225 | plane_ctl |= PLANE_CTL_PIPE_CSC_ENABLE; |
| 226 | |
| 227 | intel_update_sprite_watermarks(drm_plane, crtc, src_w, src_h, |
| 228 | pixel_size, true, |
| 229 | src_w != crtc_w || src_h != crtc_h); |
| 230 | |
| 231 | /* Sizes are 0 based */ |
| 232 | src_w--; |
| 233 | src_h--; |
| 234 | crtc_w--; |
| 235 | crtc_h--; |
| 236 | |
| 237 | I915_WRITE(PLANE_OFFSET(pipe, plane), (y << 16) | x); |
| 238 | I915_WRITE(PLANE_STRIDE(pipe, plane), stride); |
| 239 | I915_WRITE(PLANE_POS(pipe, plane), (crtc_y << 16) | crtc_x); |
| 240 | I915_WRITE(PLANE_SIZE(pipe, plane), (crtc_h << 16) | crtc_w); |
| 241 | I915_WRITE(PLANE_CTL(pipe, plane), plane_ctl); |
| 242 | I915_WRITE(PLANE_SURF(pipe, plane), i915_gem_obj_ggtt_offset(obj)); |
| 243 | POSTING_READ(PLANE_SURF(pipe, plane)); |
| 244 | } |
| 245 | |
| 246 | static void |
| 247 | skl_disable_plane(struct drm_plane *drm_plane, struct drm_crtc *crtc) |
| 248 | { |
| 249 | struct drm_device *dev = drm_plane->dev; |
| 250 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 251 | struct intel_plane *intel_plane = to_intel_plane(drm_plane); |
| 252 | const int pipe = intel_plane->pipe; |
| 253 | const int plane = intel_plane->plane + 1; |
| 254 | |
| 255 | I915_WRITE(PLANE_CTL(pipe, plane), |
| 256 | I915_READ(PLANE_CTL(pipe, plane)) & ~PLANE_CTL_ENABLE); |
| 257 | |
| 258 | /* Activate double buffered register update */ |
| 259 | I915_WRITE(PLANE_CTL(pipe, plane), 0); |
| 260 | POSTING_READ(PLANE_CTL(pipe, plane)); |
| 261 | |
| 262 | intel_update_sprite_watermarks(drm_plane, crtc, 0, 0, 0, false, false); |
| 263 | } |
| 264 | |
| 265 | static int |
| 266 | skl_update_colorkey(struct drm_plane *drm_plane, |
| 267 | struct drm_intel_sprite_colorkey *key) |
| 268 | { |
| 269 | struct drm_device *dev = drm_plane->dev; |
| 270 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 271 | struct intel_plane *intel_plane = to_intel_plane(drm_plane); |
| 272 | const int pipe = intel_plane->pipe; |
| 273 | const int plane = intel_plane->plane; |
| 274 | u32 plane_ctl; |
| 275 | |
| 276 | I915_WRITE(PLANE_KEYVAL(pipe, plane), key->min_value); |
| 277 | I915_WRITE(PLANE_KEYMAX(pipe, plane), key->max_value); |
| 278 | I915_WRITE(PLANE_KEYMSK(pipe, plane), key->channel_mask); |
| 279 | |
| 280 | plane_ctl = I915_READ(PLANE_CTL(pipe, plane)); |
| 281 | plane_ctl &= ~PLANE_CTL_KEY_ENABLE_MASK; |
| 282 | if (key->flags & I915_SET_COLORKEY_DESTINATION) |
| 283 | plane_ctl |= PLANE_CTL_KEY_ENABLE_DESTINATION; |
| 284 | else if (key->flags & I915_SET_COLORKEY_SOURCE) |
| 285 | plane_ctl |= PLANE_CTL_KEY_ENABLE_SOURCE; |
| 286 | I915_WRITE(PLANE_CTL(pipe, plane), plane_ctl); |
| 287 | |
| 288 | POSTING_READ(PLANE_CTL(pipe, plane)); |
| 289 | |
| 290 | return 0; |
| 291 | } |
| 292 | |
| 293 | static void |
| 294 | skl_get_colorkey(struct drm_plane *drm_plane, |
| 295 | struct drm_intel_sprite_colorkey *key) |
| 296 | { |
| 297 | struct drm_device *dev = drm_plane->dev; |
| 298 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 299 | struct intel_plane *intel_plane = to_intel_plane(drm_plane); |
| 300 | const int pipe = intel_plane->pipe; |
| 301 | const int plane = intel_plane->plane; |
| 302 | u32 plane_ctl; |
| 303 | |
| 304 | key->min_value = I915_READ(PLANE_KEYVAL(pipe, plane)); |
| 305 | key->max_value = I915_READ(PLANE_KEYMAX(pipe, plane)); |
| 306 | key->channel_mask = I915_READ(PLANE_KEYMSK(pipe, plane)); |
| 307 | |
| 308 | plane_ctl = I915_READ(PLANE_CTL(pipe, plane)); |
| 309 | |
| 310 | switch (plane_ctl & PLANE_CTL_KEY_ENABLE_MASK) { |
| 311 | case PLANE_CTL_KEY_ENABLE_DESTINATION: |
| 312 | key->flags = I915_SET_COLORKEY_DESTINATION; |
| 313 | break; |
| 314 | case PLANE_CTL_KEY_ENABLE_SOURCE: |
| 315 | key->flags = I915_SET_COLORKEY_SOURCE; |
| 316 | break; |
| 317 | default: |
| 318 | key->flags = I915_SET_COLORKEY_NONE; |
| 319 | } |
| 320 | } |
| 321 | |
| 322 | static void |
Ville Syrjälä | b39d53f | 2013-08-06 22:24:09 +0300 | [diff] [blame] | 323 | vlv_update_plane(struct drm_plane *dplane, struct drm_crtc *crtc, |
| 324 | struct drm_framebuffer *fb, |
Jesse Barnes | 7f1f385 | 2013-04-02 11:22:20 -0700 | [diff] [blame] | 325 | struct drm_i915_gem_object *obj, int crtc_x, int crtc_y, |
| 326 | unsigned int crtc_w, unsigned int crtc_h, |
| 327 | uint32_t x, uint32_t y, |
| 328 | uint32_t src_w, uint32_t src_h) |
| 329 | { |
| 330 | struct drm_device *dev = dplane->dev; |
| 331 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 332 | struct intel_plane *intel_plane = to_intel_plane(dplane); |
Ville Syrjälä | 8d7849d | 2014-04-29 13:35:46 +0300 | [diff] [blame] | 333 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Jesse Barnes | 7f1f385 | 2013-04-02 11:22:20 -0700 | [diff] [blame] | 334 | int pipe = intel_plane->pipe; |
| 335 | int plane = intel_plane->plane; |
| 336 | u32 sprctl; |
| 337 | unsigned long sprsurf_offset, linear_offset; |
| 338 | int pixel_size = drm_format_plane_cpp(fb->pixel_format, 0); |
Ville Syrjälä | 8d7849d | 2014-04-29 13:35:46 +0300 | [diff] [blame] | 339 | u32 start_vbl_count; |
| 340 | bool atomic_update; |
Jesse Barnes | 7f1f385 | 2013-04-02 11:22:20 -0700 | [diff] [blame] | 341 | |
| 342 | sprctl = I915_READ(SPCNTR(pipe, plane)); |
| 343 | |
| 344 | /* Mask out pixel format bits in case we change it */ |
| 345 | sprctl &= ~SP_PIXFORMAT_MASK; |
| 346 | sprctl &= ~SP_YUV_BYTE_ORDER_MASK; |
| 347 | sprctl &= ~SP_TILED; |
Ville Syrjälä | 76eebda | 2014-08-05 11:26:52 +0530 | [diff] [blame] | 348 | sprctl &= ~SP_ROTATE_180; |
Jesse Barnes | 7f1f385 | 2013-04-02 11:22:20 -0700 | [diff] [blame] | 349 | |
| 350 | switch (fb->pixel_format) { |
| 351 | case DRM_FORMAT_YUYV: |
| 352 | sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_YUYV; |
| 353 | break; |
| 354 | case DRM_FORMAT_YVYU: |
| 355 | sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_YVYU; |
| 356 | break; |
| 357 | case DRM_FORMAT_UYVY: |
| 358 | sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_UYVY; |
| 359 | break; |
| 360 | case DRM_FORMAT_VYUY: |
| 361 | sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_VYUY; |
| 362 | break; |
| 363 | case DRM_FORMAT_RGB565: |
| 364 | sprctl |= SP_FORMAT_BGR565; |
| 365 | break; |
| 366 | case DRM_FORMAT_XRGB8888: |
| 367 | sprctl |= SP_FORMAT_BGRX8888; |
| 368 | break; |
| 369 | case DRM_FORMAT_ARGB8888: |
| 370 | sprctl |= SP_FORMAT_BGRA8888; |
| 371 | break; |
| 372 | case DRM_FORMAT_XBGR2101010: |
| 373 | sprctl |= SP_FORMAT_RGBX1010102; |
| 374 | break; |
| 375 | case DRM_FORMAT_ABGR2101010: |
| 376 | sprctl |= SP_FORMAT_RGBA1010102; |
| 377 | break; |
| 378 | case DRM_FORMAT_XBGR8888: |
| 379 | sprctl |= SP_FORMAT_RGBX8888; |
| 380 | break; |
| 381 | case DRM_FORMAT_ABGR8888: |
| 382 | sprctl |= SP_FORMAT_RGBA8888; |
| 383 | break; |
| 384 | default: |
| 385 | /* |
| 386 | * If we get here one of the upper layers failed to filter |
| 387 | * out the unsupported plane formats |
| 388 | */ |
| 389 | BUG(); |
| 390 | break; |
| 391 | } |
| 392 | |
Ville Syrjälä | 4ea67bc | 2013-11-18 18:32:38 -0800 | [diff] [blame] | 393 | /* |
| 394 | * Enable gamma to match primary/cursor plane behaviour. |
| 395 | * FIXME should be user controllable via propertiesa. |
| 396 | */ |
| 397 | sprctl |= SP_GAMMA_ENABLE; |
| 398 | |
Jesse Barnes | 7f1f385 | 2013-04-02 11:22:20 -0700 | [diff] [blame] | 399 | if (obj->tiling_mode != I915_TILING_NONE) |
| 400 | sprctl |= SP_TILED; |
| 401 | |
| 402 | sprctl |= SP_ENABLE; |
| 403 | |
Damien Lespiau | ed57cb8 | 2014-07-15 09:21:24 +0200 | [diff] [blame] | 404 | intel_update_sprite_watermarks(dplane, crtc, src_w, src_h, |
| 405 | pixel_size, true, |
Ville Syrjälä | 67ca28f | 2013-07-05 11:57:14 +0300 | [diff] [blame] | 406 | src_w != crtc_w || src_h != crtc_h); |
| 407 | |
Jesse Barnes | 7f1f385 | 2013-04-02 11:22:20 -0700 | [diff] [blame] | 408 | /* Sizes are 0 based */ |
| 409 | src_w--; |
| 410 | src_h--; |
| 411 | crtc_w--; |
| 412 | crtc_h--; |
| 413 | |
Jesse Barnes | 7f1f385 | 2013-04-02 11:22:20 -0700 | [diff] [blame] | 414 | linear_offset = y * fb->pitches[0] + x * pixel_size; |
| 415 | sprsurf_offset = intel_gen4_compute_page_offset(&x, &y, |
| 416 | obj->tiling_mode, |
| 417 | pixel_size, |
| 418 | fb->pitches[0]); |
| 419 | linear_offset -= sprsurf_offset; |
| 420 | |
Ville Syrjälä | 76eebda | 2014-08-05 11:26:52 +0530 | [diff] [blame] | 421 | if (intel_plane->rotation == BIT(DRM_ROTATE_180)) { |
| 422 | sprctl |= SP_ROTATE_180; |
| 423 | |
| 424 | x += src_w; |
| 425 | y += src_h; |
| 426 | linear_offset += src_h * fb->pitches[0] + src_w * pixel_size; |
| 427 | } |
| 428 | |
Ville Syrjälä | 8d7849d | 2014-04-29 13:35:46 +0300 | [diff] [blame] | 429 | atomic_update = intel_pipe_update_start(intel_crtc, &start_vbl_count); |
| 430 | |
Ville Syrjälä | 5b633d6 | 2014-04-29 13:35:47 +0300 | [diff] [blame] | 431 | intel_update_primary_plane(intel_crtc); |
| 432 | |
Ville Syrjälä | ca6ad02 | 2014-01-17 20:09:03 +0200 | [diff] [blame] | 433 | I915_WRITE(SPSTRIDE(pipe, plane), fb->pitches[0]); |
| 434 | I915_WRITE(SPPOS(pipe, plane), (crtc_y << 16) | crtc_x); |
| 435 | |
Jesse Barnes | 7f1f385 | 2013-04-02 11:22:20 -0700 | [diff] [blame] | 436 | if (obj->tiling_mode != I915_TILING_NONE) |
| 437 | I915_WRITE(SPTILEOFF(pipe, plane), (y << 16) | x); |
| 438 | else |
| 439 | I915_WRITE(SPLINOFF(pipe, plane), linear_offset); |
| 440 | |
| 441 | I915_WRITE(SPSIZE(pipe, plane), (crtc_h << 16) | crtc_w); |
| 442 | I915_WRITE(SPCNTR(pipe, plane), sprctl); |
Daniel Vetter | 85ba7b7 | 2014-01-24 10:31:44 +0100 | [diff] [blame] | 443 | I915_WRITE(SPSURF(pipe, plane), i915_gem_obj_ggtt_offset(obj) + |
| 444 | sprsurf_offset); |
Ville Syrjälä | 5b633d6 | 2014-04-29 13:35:47 +0300 | [diff] [blame] | 445 | |
| 446 | intel_flush_primary_plane(dev_priv, intel_crtc->plane); |
Ville Syrjälä | 8d7849d | 2014-04-29 13:35:46 +0300 | [diff] [blame] | 447 | |
| 448 | if (atomic_update) |
| 449 | intel_pipe_update_end(intel_crtc, start_vbl_count); |
Jesse Barnes | 7f1f385 | 2013-04-02 11:22:20 -0700 | [diff] [blame] | 450 | } |
| 451 | |
| 452 | static void |
Ville Syrjälä | b39d53f | 2013-08-06 22:24:09 +0300 | [diff] [blame] | 453 | vlv_disable_plane(struct drm_plane *dplane, struct drm_crtc *crtc) |
Jesse Barnes | 7f1f385 | 2013-04-02 11:22:20 -0700 | [diff] [blame] | 454 | { |
| 455 | struct drm_device *dev = dplane->dev; |
| 456 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 457 | struct intel_plane *intel_plane = to_intel_plane(dplane); |
Ville Syrjälä | 8d7849d | 2014-04-29 13:35:46 +0300 | [diff] [blame] | 458 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Jesse Barnes | 7f1f385 | 2013-04-02 11:22:20 -0700 | [diff] [blame] | 459 | int pipe = intel_plane->pipe; |
| 460 | int plane = intel_plane->plane; |
Ville Syrjälä | 8d7849d | 2014-04-29 13:35:46 +0300 | [diff] [blame] | 461 | u32 start_vbl_count; |
| 462 | bool atomic_update; |
| 463 | |
| 464 | atomic_update = intel_pipe_update_start(intel_crtc, &start_vbl_count); |
Jesse Barnes | 7f1f385 | 2013-04-02 11:22:20 -0700 | [diff] [blame] | 465 | |
Ville Syrjälä | 5b633d6 | 2014-04-29 13:35:47 +0300 | [diff] [blame] | 466 | intel_update_primary_plane(intel_crtc); |
| 467 | |
Jesse Barnes | 7f1f385 | 2013-04-02 11:22:20 -0700 | [diff] [blame] | 468 | I915_WRITE(SPCNTR(pipe, plane), I915_READ(SPCNTR(pipe, plane)) & |
| 469 | ~SP_ENABLE); |
| 470 | /* Activate double buffered register update */ |
Daniel Vetter | 85ba7b7 | 2014-01-24 10:31:44 +0100 | [diff] [blame] | 471 | I915_WRITE(SPSURF(pipe, plane), 0); |
Ville Syrjälä | 5b633d6 | 2014-04-29 13:35:47 +0300 | [diff] [blame] | 472 | |
| 473 | intel_flush_primary_plane(dev_priv, intel_crtc->plane); |
Ville Syrjälä | a95fd8c | 2013-08-06 22:24:12 +0300 | [diff] [blame] | 474 | |
Ville Syrjälä | 8d7849d | 2014-04-29 13:35:46 +0300 | [diff] [blame] | 475 | if (atomic_update) |
| 476 | intel_pipe_update_end(intel_crtc, start_vbl_count); |
| 477 | |
Damien Lespiau | ed57cb8 | 2014-07-15 09:21:24 +0200 | [diff] [blame] | 478 | intel_update_sprite_watermarks(dplane, crtc, 0, 0, 0, false, false); |
Jesse Barnes | 7f1f385 | 2013-04-02 11:22:20 -0700 | [diff] [blame] | 479 | } |
| 480 | |
| 481 | static int |
| 482 | vlv_update_colorkey(struct drm_plane *dplane, |
| 483 | struct drm_intel_sprite_colorkey *key) |
| 484 | { |
| 485 | struct drm_device *dev = dplane->dev; |
| 486 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 487 | struct intel_plane *intel_plane = to_intel_plane(dplane); |
| 488 | int pipe = intel_plane->pipe; |
| 489 | int plane = intel_plane->plane; |
| 490 | u32 sprctl; |
| 491 | |
| 492 | if (key->flags & I915_SET_COLORKEY_DESTINATION) |
| 493 | return -EINVAL; |
| 494 | |
| 495 | I915_WRITE(SPKEYMINVAL(pipe, plane), key->min_value); |
| 496 | I915_WRITE(SPKEYMAXVAL(pipe, plane), key->max_value); |
| 497 | I915_WRITE(SPKEYMSK(pipe, plane), key->channel_mask); |
| 498 | |
| 499 | sprctl = I915_READ(SPCNTR(pipe, plane)); |
| 500 | sprctl &= ~SP_SOURCE_KEY; |
| 501 | if (key->flags & I915_SET_COLORKEY_SOURCE) |
| 502 | sprctl |= SP_SOURCE_KEY; |
| 503 | I915_WRITE(SPCNTR(pipe, plane), sprctl); |
| 504 | |
| 505 | POSTING_READ(SPKEYMSK(pipe, plane)); |
| 506 | |
| 507 | return 0; |
| 508 | } |
| 509 | |
| 510 | static void |
| 511 | vlv_get_colorkey(struct drm_plane *dplane, |
| 512 | struct drm_intel_sprite_colorkey *key) |
| 513 | { |
| 514 | struct drm_device *dev = dplane->dev; |
| 515 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 516 | struct intel_plane *intel_plane = to_intel_plane(dplane); |
| 517 | int pipe = intel_plane->pipe; |
| 518 | int plane = intel_plane->plane; |
| 519 | u32 sprctl; |
| 520 | |
| 521 | key->min_value = I915_READ(SPKEYMINVAL(pipe, plane)); |
| 522 | key->max_value = I915_READ(SPKEYMAXVAL(pipe, plane)); |
| 523 | key->channel_mask = I915_READ(SPKEYMSK(pipe, plane)); |
| 524 | |
| 525 | sprctl = I915_READ(SPCNTR(pipe, plane)); |
| 526 | if (sprctl & SP_SOURCE_KEY) |
| 527 | key->flags = I915_SET_COLORKEY_SOURCE; |
| 528 | else |
| 529 | key->flags = I915_SET_COLORKEY_NONE; |
| 530 | } |
| 531 | |
| 532 | static void |
Ville Syrjälä | b39d53f | 2013-08-06 22:24:09 +0300 | [diff] [blame] | 533 | ivb_update_plane(struct drm_plane *plane, struct drm_crtc *crtc, |
| 534 | struct drm_framebuffer *fb, |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 535 | struct drm_i915_gem_object *obj, int crtc_x, int crtc_y, |
| 536 | unsigned int crtc_w, unsigned int crtc_h, |
| 537 | uint32_t x, uint32_t y, |
| 538 | uint32_t src_w, uint32_t src_h) |
| 539 | { |
| 540 | struct drm_device *dev = plane->dev; |
| 541 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 542 | struct intel_plane *intel_plane = to_intel_plane(plane); |
Ville Syrjälä | 8d7849d | 2014-04-29 13:35:46 +0300 | [diff] [blame] | 543 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 544 | int pipe = intel_plane->pipe; |
| 545 | u32 sprctl, sprscale = 0; |
Damien Lespiau | 5a35e99 | 2012-10-26 18:20:12 +0100 | [diff] [blame] | 546 | unsigned long sprsurf_offset, linear_offset; |
Ville Syrjälä | 2bd3c3c | 2012-10-31 17:50:20 +0200 | [diff] [blame] | 547 | int pixel_size = drm_format_plane_cpp(fb->pixel_format, 0); |
Ville Syrjälä | 8d7849d | 2014-04-29 13:35:46 +0300 | [diff] [blame] | 548 | u32 start_vbl_count; |
| 549 | bool atomic_update; |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 550 | |
| 551 | sprctl = I915_READ(SPRCTL(pipe)); |
| 552 | |
| 553 | /* Mask out pixel format bits in case we change it */ |
| 554 | sprctl &= ~SPRITE_PIXFORMAT_MASK; |
| 555 | sprctl &= ~SPRITE_RGB_ORDER_RGBX; |
| 556 | sprctl &= ~SPRITE_YUV_BYTE_ORDER_MASK; |
Jesse Barnes | e86fe0d | 2012-06-26 13:10:11 -0700 | [diff] [blame] | 557 | sprctl &= ~SPRITE_TILED; |
Ville Syrjälä | 76eebda | 2014-08-05 11:26:52 +0530 | [diff] [blame] | 558 | sprctl &= ~SPRITE_ROTATE_180; |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 559 | |
| 560 | switch (fb->pixel_format) { |
| 561 | case DRM_FORMAT_XBGR8888: |
Vijay Purushothaman | 5ee3691 | 2012-08-23 12:08:57 +0530 | [diff] [blame] | 562 | sprctl |= SPRITE_FORMAT_RGBX888 | SPRITE_RGB_ORDER_RGBX; |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 563 | break; |
| 564 | case DRM_FORMAT_XRGB8888: |
Vijay Purushothaman | 5ee3691 | 2012-08-23 12:08:57 +0530 | [diff] [blame] | 565 | sprctl |= SPRITE_FORMAT_RGBX888; |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 566 | break; |
| 567 | case DRM_FORMAT_YUYV: |
| 568 | sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_YUYV; |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 569 | break; |
| 570 | case DRM_FORMAT_YVYU: |
| 571 | sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_YVYU; |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 572 | break; |
| 573 | case DRM_FORMAT_UYVY: |
| 574 | sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_UYVY; |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 575 | break; |
| 576 | case DRM_FORMAT_VYUY: |
| 577 | sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_VYUY; |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 578 | break; |
| 579 | default: |
Ville Syrjälä | 28d491d | 2012-10-31 17:50:21 +0200 | [diff] [blame] | 580 | BUG(); |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 581 | } |
| 582 | |
Ville Syrjälä | 4ea67bc | 2013-11-18 18:32:38 -0800 | [diff] [blame] | 583 | /* |
| 584 | * Enable gamma to match primary/cursor plane behaviour. |
| 585 | * FIXME should be user controllable via propertiesa. |
| 586 | */ |
| 587 | sprctl |= SPRITE_GAMMA_ENABLE; |
| 588 | |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 589 | if (obj->tiling_mode != I915_TILING_NONE) |
| 590 | sprctl |= SPRITE_TILED; |
| 591 | |
Ville Syrjälä | b42c600 | 2013-11-03 13:47:27 +0200 | [diff] [blame] | 592 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
Paulo Zanoni | 1f5d76d | 2013-08-23 19:51:28 -0300 | [diff] [blame] | 593 | sprctl &= ~SPRITE_TRICKLE_FEED_DISABLE; |
| 594 | else |
| 595 | sprctl |= SPRITE_TRICKLE_FEED_DISABLE; |
| 596 | |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 597 | sprctl |= SPRITE_ENABLE; |
| 598 | |
Ville Syrjälä | 6bbfa1c | 2013-11-02 21:07:39 -0700 | [diff] [blame] | 599 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
Ville Syrjälä | 86d3efc | 2013-01-18 19:11:38 +0200 | [diff] [blame] | 600 | sprctl |= SPRITE_PIPE_CSC_ENABLE; |
| 601 | |
Damien Lespiau | ed57cb8 | 2014-07-15 09:21:24 +0200 | [diff] [blame] | 602 | intel_update_sprite_watermarks(plane, crtc, src_w, src_h, pixel_size, |
| 603 | true, |
Ville Syrjälä | 67ca28f | 2013-07-05 11:57:14 +0300 | [diff] [blame] | 604 | src_w != crtc_w || src_h != crtc_h); |
| 605 | |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 606 | /* Sizes are 0 based */ |
| 607 | src_w--; |
| 608 | src_h--; |
| 609 | crtc_w--; |
| 610 | crtc_h--; |
| 611 | |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 612 | if (crtc_w != src_w || crtc_h != src_h) |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 613 | sprscale = SPRITE_SCALE_ENABLE | (src_w << 16) | src_h; |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 614 | |
Chris Wilson | ca320ac | 2012-12-19 12:14:22 +0000 | [diff] [blame] | 615 | linear_offset = y * fb->pitches[0] + x * pixel_size; |
Damien Lespiau | 5a35e99 | 2012-10-26 18:20:12 +0100 | [diff] [blame] | 616 | sprsurf_offset = |
Chris Wilson | bc75286 | 2013-02-21 20:04:31 +0000 | [diff] [blame] | 617 | intel_gen4_compute_page_offset(&x, &y, obj->tiling_mode, |
| 618 | pixel_size, fb->pitches[0]); |
Damien Lespiau | 5a35e99 | 2012-10-26 18:20:12 +0100 | [diff] [blame] | 619 | linear_offset -= sprsurf_offset; |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 620 | |
Ville Syrjälä | 76eebda | 2014-08-05 11:26:52 +0530 | [diff] [blame] | 621 | if (intel_plane->rotation == BIT(DRM_ROTATE_180)) { |
| 622 | sprctl |= SPRITE_ROTATE_180; |
| 623 | |
| 624 | /* HSW and BDW does this automagically in hardware */ |
| 625 | if (!IS_HASWELL(dev) && !IS_BROADWELL(dev)) { |
| 626 | x += src_w; |
| 627 | y += src_h; |
| 628 | linear_offset += src_h * fb->pitches[0] + |
| 629 | src_w * pixel_size; |
| 630 | } |
| 631 | } |
| 632 | |
Ville Syrjälä | 8d7849d | 2014-04-29 13:35:46 +0300 | [diff] [blame] | 633 | atomic_update = intel_pipe_update_start(intel_crtc, &start_vbl_count); |
| 634 | |
Ville Syrjälä | 5b633d6 | 2014-04-29 13:35:47 +0300 | [diff] [blame] | 635 | intel_update_primary_plane(intel_crtc); |
| 636 | |
Ville Syrjälä | ca6ad02 | 2014-01-17 20:09:03 +0200 | [diff] [blame] | 637 | I915_WRITE(SPRSTRIDE(pipe), fb->pitches[0]); |
| 638 | I915_WRITE(SPRPOS(pipe), (crtc_y << 16) | crtc_x); |
| 639 | |
Damien Lespiau | 5a35e99 | 2012-10-26 18:20:12 +0100 | [diff] [blame] | 640 | /* HSW consolidates SPRTILEOFF and SPRLINOFF into a single SPROFFSET |
| 641 | * register */ |
Paulo Zanoni | b3dc685 | 2013-11-02 21:07:33 -0700 | [diff] [blame] | 642 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
Damien Lespiau | 5a35e99 | 2012-10-26 18:20:12 +0100 | [diff] [blame] | 643 | I915_WRITE(SPROFFSET(pipe), (y << 16) | x); |
| 644 | else if (obj->tiling_mode != I915_TILING_NONE) |
| 645 | I915_WRITE(SPRTILEOFF(pipe), (y << 16) | x); |
| 646 | else |
| 647 | I915_WRITE(SPRLINOFF(pipe), linear_offset); |
Damien Lespiau | c54173a | 2012-10-26 18:20:11 +0100 | [diff] [blame] | 648 | |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 649 | I915_WRITE(SPRSIZE(pipe), (crtc_h << 16) | crtc_w); |
Damien Lespiau | 2d354c3 | 2012-10-22 18:19:27 +0100 | [diff] [blame] | 650 | if (intel_plane->can_scale) |
| 651 | I915_WRITE(SPRSCALE(pipe), sprscale); |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 652 | I915_WRITE(SPRCTL(pipe), sprctl); |
Daniel Vetter | 85ba7b7 | 2014-01-24 10:31:44 +0100 | [diff] [blame] | 653 | I915_WRITE(SPRSURF(pipe), |
| 654 | i915_gem_obj_ggtt_offset(obj) + sprsurf_offset); |
Ville Syrjälä | 5b633d6 | 2014-04-29 13:35:47 +0300 | [diff] [blame] | 655 | |
| 656 | intel_flush_primary_plane(dev_priv, intel_crtc->plane); |
Ville Syrjälä | 8d7849d | 2014-04-29 13:35:46 +0300 | [diff] [blame] | 657 | |
| 658 | if (atomic_update) |
| 659 | intel_pipe_update_end(intel_crtc, start_vbl_count); |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 660 | } |
| 661 | |
| 662 | static void |
Ville Syrjälä | b39d53f | 2013-08-06 22:24:09 +0300 | [diff] [blame] | 663 | ivb_disable_plane(struct drm_plane *plane, struct drm_crtc *crtc) |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 664 | { |
| 665 | struct drm_device *dev = plane->dev; |
| 666 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 667 | struct intel_plane *intel_plane = to_intel_plane(plane); |
Ville Syrjälä | 8d7849d | 2014-04-29 13:35:46 +0300 | [diff] [blame] | 668 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 669 | int pipe = intel_plane->pipe; |
Ville Syrjälä | 8d7849d | 2014-04-29 13:35:46 +0300 | [diff] [blame] | 670 | u32 start_vbl_count; |
| 671 | bool atomic_update; |
| 672 | |
| 673 | atomic_update = intel_pipe_update_start(intel_crtc, &start_vbl_count); |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 674 | |
Ville Syrjälä | 5b633d6 | 2014-04-29 13:35:47 +0300 | [diff] [blame] | 675 | intel_update_primary_plane(intel_crtc); |
| 676 | |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 677 | I915_WRITE(SPRCTL(pipe), I915_READ(SPRCTL(pipe)) & ~SPRITE_ENABLE); |
| 678 | /* Can't leave the scaler enabled... */ |
Damien Lespiau | 2d354c3 | 2012-10-22 18:19:27 +0100 | [diff] [blame] | 679 | if (intel_plane->can_scale) |
| 680 | I915_WRITE(SPRSCALE(pipe), 0); |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 681 | /* Activate double buffered register update */ |
Daniel Vetter | 85ba7b7 | 2014-01-24 10:31:44 +0100 | [diff] [blame] | 682 | I915_WRITE(SPRSURF(pipe), 0); |
Ville Syrjälä | 5b633d6 | 2014-04-29 13:35:47 +0300 | [diff] [blame] | 683 | |
| 684 | intel_flush_primary_plane(dev_priv, intel_crtc->plane); |
Chris Wilson | 828ed3e | 2012-04-18 17:12:26 +0100 | [diff] [blame] | 685 | |
Ville Syrjälä | 8d7849d | 2014-04-29 13:35:46 +0300 | [diff] [blame] | 686 | if (atomic_update) |
| 687 | intel_pipe_update_end(intel_crtc, start_vbl_count); |
| 688 | |
Ville Syrjälä | 1bd09ec | 2013-12-05 15:51:41 +0200 | [diff] [blame] | 689 | /* |
| 690 | * Avoid underruns when disabling the sprite. |
| 691 | * FIXME remove once watermark updates are done properly. |
| 692 | */ |
| 693 | intel_wait_for_vblank(dev, pipe); |
| 694 | |
Damien Lespiau | ed57cb8 | 2014-07-15 09:21:24 +0200 | [diff] [blame] | 695 | intel_update_sprite_watermarks(plane, crtc, 0, 0, 0, false, false); |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 696 | } |
| 697 | |
Jesse Barnes | 8ea3086 | 2012-01-03 08:05:39 -0800 | [diff] [blame] | 698 | static int |
| 699 | ivb_update_colorkey(struct drm_plane *plane, |
| 700 | struct drm_intel_sprite_colorkey *key) |
| 701 | { |
| 702 | struct drm_device *dev = plane->dev; |
| 703 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 704 | struct intel_plane *intel_plane; |
| 705 | u32 sprctl; |
| 706 | int ret = 0; |
| 707 | |
| 708 | intel_plane = to_intel_plane(plane); |
| 709 | |
| 710 | I915_WRITE(SPRKEYVAL(intel_plane->pipe), key->min_value); |
| 711 | I915_WRITE(SPRKEYMAX(intel_plane->pipe), key->max_value); |
| 712 | I915_WRITE(SPRKEYMSK(intel_plane->pipe), key->channel_mask); |
| 713 | |
| 714 | sprctl = I915_READ(SPRCTL(intel_plane->pipe)); |
| 715 | sprctl &= ~(SPRITE_SOURCE_KEY | SPRITE_DEST_KEY); |
| 716 | if (key->flags & I915_SET_COLORKEY_DESTINATION) |
| 717 | sprctl |= SPRITE_DEST_KEY; |
| 718 | else if (key->flags & I915_SET_COLORKEY_SOURCE) |
| 719 | sprctl |= SPRITE_SOURCE_KEY; |
| 720 | I915_WRITE(SPRCTL(intel_plane->pipe), sprctl); |
| 721 | |
| 722 | POSTING_READ(SPRKEYMSK(intel_plane->pipe)); |
| 723 | |
| 724 | return ret; |
| 725 | } |
| 726 | |
| 727 | static void |
| 728 | ivb_get_colorkey(struct drm_plane *plane, struct drm_intel_sprite_colorkey *key) |
| 729 | { |
| 730 | struct drm_device *dev = plane->dev; |
| 731 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 732 | struct intel_plane *intel_plane; |
| 733 | u32 sprctl; |
| 734 | |
| 735 | intel_plane = to_intel_plane(plane); |
| 736 | |
| 737 | key->min_value = I915_READ(SPRKEYVAL(intel_plane->pipe)); |
| 738 | key->max_value = I915_READ(SPRKEYMAX(intel_plane->pipe)); |
| 739 | key->channel_mask = I915_READ(SPRKEYMSK(intel_plane->pipe)); |
| 740 | key->flags = 0; |
| 741 | |
| 742 | sprctl = I915_READ(SPRCTL(intel_plane->pipe)); |
| 743 | |
| 744 | if (sprctl & SPRITE_DEST_KEY) |
| 745 | key->flags = I915_SET_COLORKEY_DESTINATION; |
| 746 | else if (sprctl & SPRITE_SOURCE_KEY) |
| 747 | key->flags = I915_SET_COLORKEY_SOURCE; |
| 748 | else |
| 749 | key->flags = I915_SET_COLORKEY_NONE; |
| 750 | } |
| 751 | |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 752 | static void |
Ville Syrjälä | b39d53f | 2013-08-06 22:24:09 +0300 | [diff] [blame] | 753 | ilk_update_plane(struct drm_plane *plane, struct drm_crtc *crtc, |
| 754 | struct drm_framebuffer *fb, |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 755 | struct drm_i915_gem_object *obj, int crtc_x, int crtc_y, |
| 756 | unsigned int crtc_w, unsigned int crtc_h, |
| 757 | uint32_t x, uint32_t y, |
| 758 | uint32_t src_w, uint32_t src_h) |
| 759 | { |
| 760 | struct drm_device *dev = plane->dev; |
| 761 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 762 | struct intel_plane *intel_plane = to_intel_plane(plane); |
Ville Syrjälä | 8d7849d | 2014-04-29 13:35:46 +0300 | [diff] [blame] | 763 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ville Syrjälä | 2bd3c3c | 2012-10-31 17:50:20 +0200 | [diff] [blame] | 764 | int pipe = intel_plane->pipe; |
Damien Lespiau | 5a35e99 | 2012-10-26 18:20:12 +0100 | [diff] [blame] | 765 | unsigned long dvssurf_offset, linear_offset; |
Chris Wilson | 8aaa81a | 2012-04-14 22:14:26 +0100 | [diff] [blame] | 766 | u32 dvscntr, dvsscale; |
Ville Syrjälä | 2bd3c3c | 2012-10-31 17:50:20 +0200 | [diff] [blame] | 767 | int pixel_size = drm_format_plane_cpp(fb->pixel_format, 0); |
Ville Syrjälä | 8d7849d | 2014-04-29 13:35:46 +0300 | [diff] [blame] | 768 | u32 start_vbl_count; |
| 769 | bool atomic_update; |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 770 | |
| 771 | dvscntr = I915_READ(DVSCNTR(pipe)); |
| 772 | |
| 773 | /* Mask out pixel format bits in case we change it */ |
| 774 | dvscntr &= ~DVS_PIXFORMAT_MASK; |
Jesse Barnes | ab2f9df | 2012-02-27 12:40:10 -0800 | [diff] [blame] | 775 | dvscntr &= ~DVS_RGB_ORDER_XBGR; |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 776 | dvscntr &= ~DVS_YUV_BYTE_ORDER_MASK; |
Ander Conselvan de Oliveira | 7962652 | 2012-07-13 15:50:33 +0300 | [diff] [blame] | 777 | dvscntr &= ~DVS_TILED; |
Ville Syrjälä | 76eebda | 2014-08-05 11:26:52 +0530 | [diff] [blame] | 778 | dvscntr &= ~DVS_ROTATE_180; |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 779 | |
| 780 | switch (fb->pixel_format) { |
| 781 | case DRM_FORMAT_XBGR8888: |
Jesse Barnes | ab2f9df | 2012-02-27 12:40:10 -0800 | [diff] [blame] | 782 | dvscntr |= DVS_FORMAT_RGBX888 | DVS_RGB_ORDER_XBGR; |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 783 | break; |
| 784 | case DRM_FORMAT_XRGB8888: |
Jesse Barnes | ab2f9df | 2012-02-27 12:40:10 -0800 | [diff] [blame] | 785 | dvscntr |= DVS_FORMAT_RGBX888; |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 786 | break; |
| 787 | case DRM_FORMAT_YUYV: |
| 788 | dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_YUYV; |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 789 | break; |
| 790 | case DRM_FORMAT_YVYU: |
| 791 | dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_YVYU; |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 792 | break; |
| 793 | case DRM_FORMAT_UYVY: |
| 794 | dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_UYVY; |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 795 | break; |
| 796 | case DRM_FORMAT_VYUY: |
| 797 | dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_VYUY; |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 798 | break; |
| 799 | default: |
Ville Syrjälä | 28d491d | 2012-10-31 17:50:21 +0200 | [diff] [blame] | 800 | BUG(); |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 801 | } |
| 802 | |
Ville Syrjälä | 4ea67bc | 2013-11-18 18:32:38 -0800 | [diff] [blame] | 803 | /* |
| 804 | * Enable gamma to match primary/cursor plane behaviour. |
| 805 | * FIXME should be user controllable via propertiesa. |
| 806 | */ |
| 807 | dvscntr |= DVS_GAMMA_ENABLE; |
| 808 | |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 809 | if (obj->tiling_mode != I915_TILING_NONE) |
| 810 | dvscntr |= DVS_TILED; |
| 811 | |
Chris Wilson | d1686ae | 2012-04-10 11:41:49 +0100 | [diff] [blame] | 812 | if (IS_GEN6(dev)) |
| 813 | dvscntr |= DVS_TRICKLE_FEED_DISABLE; /* must disable */ |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 814 | dvscntr |= DVS_ENABLE; |
| 815 | |
Damien Lespiau | ed57cb8 | 2014-07-15 09:21:24 +0200 | [diff] [blame] | 816 | intel_update_sprite_watermarks(plane, crtc, src_w, src_h, |
| 817 | pixel_size, true, |
Ville Syrjälä | 67ca28f | 2013-07-05 11:57:14 +0300 | [diff] [blame] | 818 | src_w != crtc_w || src_h != crtc_h); |
| 819 | |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 820 | /* Sizes are 0 based */ |
| 821 | src_w--; |
| 822 | src_h--; |
| 823 | crtc_w--; |
| 824 | crtc_h--; |
| 825 | |
Chris Wilson | 8aaa81a | 2012-04-14 22:14:26 +0100 | [diff] [blame] | 826 | dvsscale = 0; |
Ville Syrjälä | 8368f01 | 2013-12-05 15:51:31 +0200 | [diff] [blame] | 827 | if (crtc_w != src_w || crtc_h != src_h) |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 828 | dvsscale = DVS_SCALE_ENABLE | (src_w << 16) | src_h; |
| 829 | |
Chris Wilson | ca320ac | 2012-12-19 12:14:22 +0000 | [diff] [blame] | 830 | linear_offset = y * fb->pitches[0] + x * pixel_size; |
Damien Lespiau | 5a35e99 | 2012-10-26 18:20:12 +0100 | [diff] [blame] | 831 | dvssurf_offset = |
Chris Wilson | bc75286 | 2013-02-21 20:04:31 +0000 | [diff] [blame] | 832 | intel_gen4_compute_page_offset(&x, &y, obj->tiling_mode, |
| 833 | pixel_size, fb->pitches[0]); |
Damien Lespiau | 5a35e99 | 2012-10-26 18:20:12 +0100 | [diff] [blame] | 834 | linear_offset -= dvssurf_offset; |
| 835 | |
Ville Syrjälä | 76eebda | 2014-08-05 11:26:52 +0530 | [diff] [blame] | 836 | if (intel_plane->rotation == BIT(DRM_ROTATE_180)) { |
| 837 | dvscntr |= DVS_ROTATE_180; |
| 838 | |
| 839 | x += src_w; |
| 840 | y += src_h; |
| 841 | linear_offset += src_h * fb->pitches[0] + src_w * pixel_size; |
| 842 | } |
| 843 | |
Ville Syrjälä | 8d7849d | 2014-04-29 13:35:46 +0300 | [diff] [blame] | 844 | atomic_update = intel_pipe_update_start(intel_crtc, &start_vbl_count); |
| 845 | |
Ville Syrjälä | 5b633d6 | 2014-04-29 13:35:47 +0300 | [diff] [blame] | 846 | intel_update_primary_plane(intel_crtc); |
| 847 | |
Ville Syrjälä | ca6ad02 | 2014-01-17 20:09:03 +0200 | [diff] [blame] | 848 | I915_WRITE(DVSSTRIDE(pipe), fb->pitches[0]); |
| 849 | I915_WRITE(DVSPOS(pipe), (crtc_y << 16) | crtc_x); |
| 850 | |
Damien Lespiau | 5a35e99 | 2012-10-26 18:20:12 +0100 | [diff] [blame] | 851 | if (obj->tiling_mode != I915_TILING_NONE) |
| 852 | I915_WRITE(DVSTILEOFF(pipe), (y << 16) | x); |
| 853 | else |
| 854 | I915_WRITE(DVSLINOFF(pipe), linear_offset); |
| 855 | |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 856 | I915_WRITE(DVSSIZE(pipe), (crtc_h << 16) | crtc_w); |
| 857 | I915_WRITE(DVSSCALE(pipe), dvsscale); |
| 858 | I915_WRITE(DVSCNTR(pipe), dvscntr); |
Daniel Vetter | 85ba7b7 | 2014-01-24 10:31:44 +0100 | [diff] [blame] | 859 | I915_WRITE(DVSSURF(pipe), |
| 860 | i915_gem_obj_ggtt_offset(obj) + dvssurf_offset); |
Ville Syrjälä | 5b633d6 | 2014-04-29 13:35:47 +0300 | [diff] [blame] | 861 | |
| 862 | intel_flush_primary_plane(dev_priv, intel_crtc->plane); |
Ville Syrjälä | 8d7849d | 2014-04-29 13:35:46 +0300 | [diff] [blame] | 863 | |
| 864 | if (atomic_update) |
| 865 | intel_pipe_update_end(intel_crtc, start_vbl_count); |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 866 | } |
| 867 | |
| 868 | static void |
Ville Syrjälä | b39d53f | 2013-08-06 22:24:09 +0300 | [diff] [blame] | 869 | ilk_disable_plane(struct drm_plane *plane, struct drm_crtc *crtc) |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 870 | { |
| 871 | struct drm_device *dev = plane->dev; |
| 872 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 873 | struct intel_plane *intel_plane = to_intel_plane(plane); |
Ville Syrjälä | 8d7849d | 2014-04-29 13:35:46 +0300 | [diff] [blame] | 874 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 875 | int pipe = intel_plane->pipe; |
Ville Syrjälä | 8d7849d | 2014-04-29 13:35:46 +0300 | [diff] [blame] | 876 | u32 start_vbl_count; |
| 877 | bool atomic_update; |
| 878 | |
| 879 | atomic_update = intel_pipe_update_start(intel_crtc, &start_vbl_count); |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 880 | |
Ville Syrjälä | 5b633d6 | 2014-04-29 13:35:47 +0300 | [diff] [blame] | 881 | intel_update_primary_plane(intel_crtc); |
| 882 | |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 883 | I915_WRITE(DVSCNTR(pipe), I915_READ(DVSCNTR(pipe)) & ~DVS_ENABLE); |
| 884 | /* Disable the scaler */ |
| 885 | I915_WRITE(DVSSCALE(pipe), 0); |
| 886 | /* Flush double buffered register updates */ |
Daniel Vetter | 85ba7b7 | 2014-01-24 10:31:44 +0100 | [diff] [blame] | 887 | I915_WRITE(DVSSURF(pipe), 0); |
Ville Syrjälä | 5b633d6 | 2014-04-29 13:35:47 +0300 | [diff] [blame] | 888 | |
| 889 | intel_flush_primary_plane(dev_priv, intel_crtc->plane); |
Ville Syrjälä | a95fd8c | 2013-08-06 22:24:12 +0300 | [diff] [blame] | 890 | |
Ville Syrjälä | 8d7849d | 2014-04-29 13:35:46 +0300 | [diff] [blame] | 891 | if (atomic_update) |
| 892 | intel_pipe_update_end(intel_crtc, start_vbl_count); |
| 893 | |
Ville Syrjälä | 1bd09ec | 2013-12-05 15:51:41 +0200 | [diff] [blame] | 894 | /* |
| 895 | * Avoid underruns when disabling the sprite. |
| 896 | * FIXME remove once watermark updates are done properly. |
| 897 | */ |
| 898 | intel_wait_for_vblank(dev, pipe); |
| 899 | |
Damien Lespiau | ed57cb8 | 2014-07-15 09:21:24 +0200 | [diff] [blame] | 900 | intel_update_sprite_watermarks(plane, crtc, 0, 0, 0, false, false); |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 901 | } |
| 902 | |
Jesse Barnes | 175bd42 | 2011-12-13 13:19:39 -0800 | [diff] [blame] | 903 | static void |
Ville Syrjälä | 5b633d6 | 2014-04-29 13:35:47 +0300 | [diff] [blame] | 904 | intel_post_enable_primary(struct drm_crtc *crtc) |
Jesse Barnes | 175bd42 | 2011-12-13 13:19:39 -0800 | [diff] [blame] | 905 | { |
| 906 | struct drm_device *dev = crtc->dev; |
Jesse Barnes | 175bd42 | 2011-12-13 13:19:39 -0800 | [diff] [blame] | 907 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ville Syrjälä | abae50e | 2013-10-01 18:02:16 +0300 | [diff] [blame] | 908 | |
Ville Syrjälä | 20bc8673 | 2013-10-01 18:02:17 +0300 | [diff] [blame] | 909 | /* |
Ville Syrjälä | 33c3b0d | 2014-06-24 13:59:28 +0300 | [diff] [blame] | 910 | * BDW signals flip done immediately if the plane |
| 911 | * is disabled, even if the plane enable is already |
| 912 | * armed to occur at the next vblank :( |
| 913 | */ |
| 914 | if (IS_BROADWELL(dev)) |
| 915 | intel_wait_for_vblank(dev, intel_crtc->pipe); |
| 916 | |
| 917 | /* |
Ville Syrjälä | 20bc8673 | 2013-10-01 18:02:17 +0300 | [diff] [blame] | 918 | * FIXME IPS should be fine as long as one plane is |
| 919 | * enabled, but in practice it seems to have problems |
| 920 | * when going from primary only to sprite only and vice |
| 921 | * versa. |
| 922 | */ |
Ville Syrjälä | cea165c | 2014-04-15 21:41:35 +0300 | [diff] [blame] | 923 | hsw_enable_ips(intel_crtc); |
Ville Syrjälä | 20bc8673 | 2013-10-01 18:02:17 +0300 | [diff] [blame] | 924 | |
Ville Syrjälä | 82284b6 | 2013-10-01 18:02:12 +0300 | [diff] [blame] | 925 | mutex_lock(&dev->struct_mutex); |
Chris Wilson | 93314b5 | 2012-06-13 17:36:55 +0100 | [diff] [blame] | 926 | intel_update_fbc(dev); |
Ville Syrjälä | 82284b6 | 2013-10-01 18:02:12 +0300 | [diff] [blame] | 927 | mutex_unlock(&dev->struct_mutex); |
Jesse Barnes | 175bd42 | 2011-12-13 13:19:39 -0800 | [diff] [blame] | 928 | } |
| 929 | |
| 930 | static void |
Ville Syrjälä | 5b633d6 | 2014-04-29 13:35:47 +0300 | [diff] [blame] | 931 | intel_pre_disable_primary(struct drm_crtc *crtc) |
Jesse Barnes | 175bd42 | 2011-12-13 13:19:39 -0800 | [diff] [blame] | 932 | { |
| 933 | struct drm_device *dev = crtc->dev; |
| 934 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 935 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ville Syrjälä | 82284b6 | 2013-10-01 18:02:12 +0300 | [diff] [blame] | 936 | |
| 937 | mutex_lock(&dev->struct_mutex); |
Ville Syrjälä | abae50e | 2013-10-01 18:02:16 +0300 | [diff] [blame] | 938 | if (dev_priv->fbc.plane == intel_crtc->plane) |
| 939 | intel_disable_fbc(dev); |
Ville Syrjälä | 82284b6 | 2013-10-01 18:02:12 +0300 | [diff] [blame] | 940 | mutex_unlock(&dev->struct_mutex); |
Ville Syrjälä | abae50e | 2013-10-01 18:02:16 +0300 | [diff] [blame] | 941 | |
Ville Syrjälä | 20bc8673 | 2013-10-01 18:02:17 +0300 | [diff] [blame] | 942 | /* |
| 943 | * FIXME IPS should be fine as long as one plane is |
| 944 | * enabled, but in practice it seems to have problems |
| 945 | * when going from primary only to sprite only and vice |
| 946 | * versa. |
| 947 | */ |
| 948 | hsw_disable_ips(intel_crtc); |
Jesse Barnes | 175bd42 | 2011-12-13 13:19:39 -0800 | [diff] [blame] | 949 | } |
| 950 | |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 951 | static int |
Chris Wilson | d1686ae | 2012-04-10 11:41:49 +0100 | [diff] [blame] | 952 | ilk_update_colorkey(struct drm_plane *plane, |
Jesse Barnes | 8ea3086 | 2012-01-03 08:05:39 -0800 | [diff] [blame] | 953 | struct drm_intel_sprite_colorkey *key) |
| 954 | { |
| 955 | struct drm_device *dev = plane->dev; |
| 956 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 957 | struct intel_plane *intel_plane; |
| 958 | u32 dvscntr; |
| 959 | int ret = 0; |
| 960 | |
| 961 | intel_plane = to_intel_plane(plane); |
| 962 | |
| 963 | I915_WRITE(DVSKEYVAL(intel_plane->pipe), key->min_value); |
| 964 | I915_WRITE(DVSKEYMAX(intel_plane->pipe), key->max_value); |
| 965 | I915_WRITE(DVSKEYMSK(intel_plane->pipe), key->channel_mask); |
| 966 | |
| 967 | dvscntr = I915_READ(DVSCNTR(intel_plane->pipe)); |
| 968 | dvscntr &= ~(DVS_SOURCE_KEY | DVS_DEST_KEY); |
| 969 | if (key->flags & I915_SET_COLORKEY_DESTINATION) |
| 970 | dvscntr |= DVS_DEST_KEY; |
| 971 | else if (key->flags & I915_SET_COLORKEY_SOURCE) |
| 972 | dvscntr |= DVS_SOURCE_KEY; |
| 973 | I915_WRITE(DVSCNTR(intel_plane->pipe), dvscntr); |
| 974 | |
| 975 | POSTING_READ(DVSKEYMSK(intel_plane->pipe)); |
| 976 | |
| 977 | return ret; |
| 978 | } |
| 979 | |
| 980 | static void |
Chris Wilson | d1686ae | 2012-04-10 11:41:49 +0100 | [diff] [blame] | 981 | 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] | 982 | { |
| 983 | struct drm_device *dev = plane->dev; |
| 984 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 985 | struct intel_plane *intel_plane; |
| 986 | u32 dvscntr; |
| 987 | |
| 988 | intel_plane = to_intel_plane(plane); |
| 989 | |
| 990 | key->min_value = I915_READ(DVSKEYVAL(intel_plane->pipe)); |
| 991 | key->max_value = I915_READ(DVSKEYMAX(intel_plane->pipe)); |
| 992 | key->channel_mask = I915_READ(DVSKEYMSK(intel_plane->pipe)); |
| 993 | key->flags = 0; |
| 994 | |
| 995 | dvscntr = I915_READ(DVSCNTR(intel_plane->pipe)); |
| 996 | |
| 997 | if (dvscntr & DVS_DEST_KEY) |
| 998 | key->flags = I915_SET_COLORKEY_DESTINATION; |
| 999 | else if (dvscntr & DVS_SOURCE_KEY) |
| 1000 | key->flags = I915_SET_COLORKEY_SOURCE; |
| 1001 | else |
| 1002 | key->flags = I915_SET_COLORKEY_NONE; |
| 1003 | } |
| 1004 | |
Ville Syrjälä | 1731693 | 2013-04-24 18:52:38 +0300 | [diff] [blame] | 1005 | static bool |
| 1006 | format_is_yuv(uint32_t format) |
| 1007 | { |
| 1008 | switch (format) { |
| 1009 | case DRM_FORMAT_YUYV: |
| 1010 | case DRM_FORMAT_UYVY: |
| 1011 | case DRM_FORMAT_VYUY: |
| 1012 | case DRM_FORMAT_YVYU: |
| 1013 | return true; |
| 1014 | default: |
| 1015 | return false; |
| 1016 | } |
| 1017 | } |
| 1018 | |
Ville Syrjälä | efb31d1 | 2013-12-05 15:51:40 +0200 | [diff] [blame] | 1019 | static bool colorkey_enabled(struct intel_plane *intel_plane) |
| 1020 | { |
| 1021 | struct drm_intel_sprite_colorkey key; |
| 1022 | |
| 1023 | intel_plane->get_colorkey(&intel_plane->base, &key); |
| 1024 | |
| 1025 | return key.flags != I915_SET_COLORKEY_NONE; |
| 1026 | } |
| 1027 | |
Jesse Barnes | 8ea3086 | 2012-01-03 08:05:39 -0800 | [diff] [blame] | 1028 | static int |
Gustavo Padovan | 96d61a7 | 2014-09-05 17:04:47 -0300 | [diff] [blame] | 1029 | intel_check_sprite_plane(struct drm_plane *plane, |
| 1030 | struct intel_plane_state *state) |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 1031 | { |
Gustavo Padovan | 96d61a7 | 2014-09-05 17:04:47 -0300 | [diff] [blame] | 1032 | struct intel_crtc *intel_crtc = to_intel_crtc(state->crtc); |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 1033 | struct intel_plane *intel_plane = to_intel_plane(plane); |
Gustavo Padovan | 96d61a7 | 2014-09-05 17:04:47 -0300 | [diff] [blame] | 1034 | struct drm_framebuffer *fb = state->fb; |
Gustavo Padovan | 77cde95 | 2014-10-24 14:51:33 +0100 | [diff] [blame^] | 1035 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Gustavo Padovan | 96d61a7 | 2014-09-05 17:04:47 -0300 | [diff] [blame] | 1036 | int crtc_x, crtc_y; |
| 1037 | unsigned int crtc_w, crtc_h; |
| 1038 | uint32_t src_x, src_y, src_w, src_h; |
| 1039 | struct drm_rect *src = &state->src; |
| 1040 | struct drm_rect *dst = &state->dst; |
| 1041 | struct drm_rect *orig_src = &state->orig_src; |
| 1042 | const struct drm_rect *clip = &state->clip; |
Ville Syrjälä | 1731693 | 2013-04-24 18:52:38 +0300 | [diff] [blame] | 1043 | int hscale, vscale; |
| 1044 | int max_scale, min_scale; |
| 1045 | int pixel_size = drm_format_plane_cpp(fb->pixel_format, 0); |
Jesse Barnes | 5e1bac2 | 2013-03-26 09:25:43 -0700 | [diff] [blame] | 1046 | |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 1047 | /* Don't modify another pipe's plane */ |
Ville Syrjälä | 1731693 | 2013-04-24 18:52:38 +0300 | [diff] [blame] | 1048 | if (intel_plane->pipe != intel_crtc->pipe) { |
| 1049 | DRM_DEBUG_KMS("Wrong plane <-> crtc mapping\n"); |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 1050 | return -EINVAL; |
Ville Syrjälä | 1731693 | 2013-04-24 18:52:38 +0300 | [diff] [blame] | 1051 | } |
| 1052 | |
| 1053 | /* FIXME check all gen limits */ |
| 1054 | if (fb->width < 3 || fb->height < 3 || fb->pitches[0] > 16384) { |
| 1055 | DRM_DEBUG_KMS("Unsuitable framebuffer for plane\n"); |
| 1056 | return -EINVAL; |
| 1057 | } |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 1058 | |
Damien Lespiau | 94c6419 | 2012-10-29 15:14:51 +0000 | [diff] [blame] | 1059 | /* Sprite planes can be linear or x-tiled surfaces */ |
| 1060 | switch (obj->tiling_mode) { |
| 1061 | case I915_TILING_NONE: |
| 1062 | case I915_TILING_X: |
| 1063 | break; |
| 1064 | default: |
Ville Syrjälä | 1731693 | 2013-04-24 18:52:38 +0300 | [diff] [blame] | 1065 | DRM_DEBUG_KMS("Unsupported tiling mode\n"); |
Damien Lespiau | 94c6419 | 2012-10-29 15:14:51 +0000 | [diff] [blame] | 1066 | return -EINVAL; |
| 1067 | } |
| 1068 | |
Ville Syrjälä | 3c3686c | 2013-04-24 18:52:39 +0300 | [diff] [blame] | 1069 | /* |
| 1070 | * FIXME the following code does a bunch of fuzzy adjustments to the |
| 1071 | * coordinates and sizes. We probably need some way to decide whether |
| 1072 | * more strict checking should be done instead. |
| 1073 | */ |
Ville Syrjälä | 1731693 | 2013-04-24 18:52:38 +0300 | [diff] [blame] | 1074 | max_scale = intel_plane->max_downscale << 16; |
| 1075 | min_scale = intel_plane->can_scale ? 1 : (1 << 16); |
| 1076 | |
Gustavo Padovan | 96d61a7 | 2014-09-05 17:04:47 -0300 | [diff] [blame] | 1077 | drm_rect_rotate(src, fb->width << 16, fb->height << 16, |
Ville Syrjälä | 76eebda | 2014-08-05 11:26:52 +0530 | [diff] [blame] | 1078 | intel_plane->rotation); |
| 1079 | |
Gustavo Padovan | 96d61a7 | 2014-09-05 17:04:47 -0300 | [diff] [blame] | 1080 | hscale = drm_rect_calc_hscale_relaxed(src, dst, min_scale, max_scale); |
Ville Syrjälä | 3c3686c | 2013-04-24 18:52:39 +0300 | [diff] [blame] | 1081 | BUG_ON(hscale < 0); |
Ville Syrjälä | 1731693 | 2013-04-24 18:52:38 +0300 | [diff] [blame] | 1082 | |
Gustavo Padovan | 96d61a7 | 2014-09-05 17:04:47 -0300 | [diff] [blame] | 1083 | vscale = drm_rect_calc_vscale_relaxed(src, dst, min_scale, max_scale); |
Ville Syrjälä | 3c3686c | 2013-04-24 18:52:39 +0300 | [diff] [blame] | 1084 | BUG_ON(vscale < 0); |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 1085 | |
Gustavo Padovan | 96d61a7 | 2014-09-05 17:04:47 -0300 | [diff] [blame] | 1086 | state->visible = drm_rect_clip_scaled(src, dst, clip, hscale, vscale); |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 1087 | |
Gustavo Padovan | 96d61a7 | 2014-09-05 17:04:47 -0300 | [diff] [blame] | 1088 | crtc_x = dst->x1; |
| 1089 | crtc_y = dst->y1; |
| 1090 | crtc_w = drm_rect_width(dst); |
| 1091 | crtc_h = drm_rect_height(dst); |
Damien Lespiau | 2d354c3 | 2012-10-22 18:19:27 +0100 | [diff] [blame] | 1092 | |
Gustavo Padovan | 96d61a7 | 2014-09-05 17:04:47 -0300 | [diff] [blame] | 1093 | if (state->visible) { |
Ville Syrjälä | 3c3686c | 2013-04-24 18:52:39 +0300 | [diff] [blame] | 1094 | /* check again in case clipping clamped the results */ |
Gustavo Padovan | 96d61a7 | 2014-09-05 17:04:47 -0300 | [diff] [blame] | 1095 | hscale = drm_rect_calc_hscale(src, dst, min_scale, max_scale); |
Ville Syrjälä | 3c3686c | 2013-04-24 18:52:39 +0300 | [diff] [blame] | 1096 | if (hscale < 0) { |
| 1097 | DRM_DEBUG_KMS("Horizontal scaling factor out of limits\n"); |
Gustavo Padovan | 96d61a7 | 2014-09-05 17:04:47 -0300 | [diff] [blame] | 1098 | drm_rect_debug_print(src, true); |
| 1099 | drm_rect_debug_print(dst, false); |
Ville Syrjälä | 3c3686c | 2013-04-24 18:52:39 +0300 | [diff] [blame] | 1100 | |
| 1101 | return hscale; |
| 1102 | } |
| 1103 | |
Gustavo Padovan | 96d61a7 | 2014-09-05 17:04:47 -0300 | [diff] [blame] | 1104 | vscale = drm_rect_calc_vscale(src, dst, min_scale, max_scale); |
Ville Syrjälä | 3c3686c | 2013-04-24 18:52:39 +0300 | [diff] [blame] | 1105 | if (vscale < 0) { |
| 1106 | DRM_DEBUG_KMS("Vertical scaling factor out of limits\n"); |
Gustavo Padovan | 96d61a7 | 2014-09-05 17:04:47 -0300 | [diff] [blame] | 1107 | drm_rect_debug_print(src, true); |
| 1108 | drm_rect_debug_print(dst, false); |
Ville Syrjälä | 3c3686c | 2013-04-24 18:52:39 +0300 | [diff] [blame] | 1109 | |
| 1110 | return vscale; |
| 1111 | } |
| 1112 | |
Ville Syrjälä | 1731693 | 2013-04-24 18:52:38 +0300 | [diff] [blame] | 1113 | /* Make the source viewport size an exact multiple of the scaling factors. */ |
Gustavo Padovan | 96d61a7 | 2014-09-05 17:04:47 -0300 | [diff] [blame] | 1114 | drm_rect_adjust_size(src, |
| 1115 | drm_rect_width(dst) * hscale - drm_rect_width(src), |
| 1116 | drm_rect_height(dst) * vscale - drm_rect_height(src)); |
Ville Syrjälä | 1731693 | 2013-04-24 18:52:38 +0300 | [diff] [blame] | 1117 | |
Gustavo Padovan | 96d61a7 | 2014-09-05 17:04:47 -0300 | [diff] [blame] | 1118 | drm_rect_rotate_inv(src, fb->width << 16, fb->height << 16, |
Ville Syrjälä | 76eebda | 2014-08-05 11:26:52 +0530 | [diff] [blame] | 1119 | intel_plane->rotation); |
| 1120 | |
Ville Syrjälä | 1731693 | 2013-04-24 18:52:38 +0300 | [diff] [blame] | 1121 | /* sanity check to make sure the src viewport wasn't enlarged */ |
Gustavo Padovan | 96d61a7 | 2014-09-05 17:04:47 -0300 | [diff] [blame] | 1122 | WARN_ON(src->x1 < (int) orig_src->x1 || |
| 1123 | src->y1 < (int) orig_src->y1 || |
| 1124 | src->x2 > (int) orig_src->x2 || |
| 1125 | src->y2 > (int) orig_src->y2); |
Ville Syrjälä | 1731693 | 2013-04-24 18:52:38 +0300 | [diff] [blame] | 1126 | |
| 1127 | /* |
| 1128 | * Hardware doesn't handle subpixel coordinates. |
| 1129 | * Adjust to (macro)pixel boundary, but be careful not to |
| 1130 | * increase the source viewport size, because that could |
| 1131 | * push the downscaling factor out of bounds. |
Ville Syrjälä | 1731693 | 2013-04-24 18:52:38 +0300 | [diff] [blame] | 1132 | */ |
Gustavo Padovan | 96d61a7 | 2014-09-05 17:04:47 -0300 | [diff] [blame] | 1133 | src_x = src->x1 >> 16; |
| 1134 | src_w = drm_rect_width(src) >> 16; |
| 1135 | src_y = src->y1 >> 16; |
| 1136 | src_h = drm_rect_height(src) >> 16; |
Ville Syrjälä | 1731693 | 2013-04-24 18:52:38 +0300 | [diff] [blame] | 1137 | |
| 1138 | if (format_is_yuv(fb->pixel_format)) { |
| 1139 | src_x &= ~1; |
| 1140 | src_w &= ~1; |
| 1141 | |
| 1142 | /* |
| 1143 | * Must keep src and dst the |
| 1144 | * same if we can't scale. |
| 1145 | */ |
| 1146 | if (!intel_plane->can_scale) |
| 1147 | crtc_w &= ~1; |
| 1148 | |
| 1149 | if (crtc_w == 0) |
Gustavo Padovan | 96d61a7 | 2014-09-05 17:04:47 -0300 | [diff] [blame] | 1150 | state->visible = false; |
Ville Syrjälä | 1731693 | 2013-04-24 18:52:38 +0300 | [diff] [blame] | 1151 | } |
| 1152 | } |
| 1153 | |
| 1154 | /* Check size restrictions when scaling */ |
Gustavo Padovan | 96d61a7 | 2014-09-05 17:04:47 -0300 | [diff] [blame] | 1155 | if (state->visible && (src_w != crtc_w || src_h != crtc_h)) { |
Ville Syrjälä | 1731693 | 2013-04-24 18:52:38 +0300 | [diff] [blame] | 1156 | unsigned int width_bytes; |
| 1157 | |
| 1158 | WARN_ON(!intel_plane->can_scale); |
| 1159 | |
| 1160 | /* FIXME interlacing min height is 6 */ |
| 1161 | |
| 1162 | if (crtc_w < 3 || crtc_h < 3) |
Gustavo Padovan | 96d61a7 | 2014-09-05 17:04:47 -0300 | [diff] [blame] | 1163 | state->visible = false; |
Ville Syrjälä | 1731693 | 2013-04-24 18:52:38 +0300 | [diff] [blame] | 1164 | |
| 1165 | if (src_w < 3 || src_h < 3) |
Gustavo Padovan | 96d61a7 | 2014-09-05 17:04:47 -0300 | [diff] [blame] | 1166 | state->visible = false; |
Ville Syrjälä | 1731693 | 2013-04-24 18:52:38 +0300 | [diff] [blame] | 1167 | |
Gustavo Padovan | 96d61a7 | 2014-09-05 17:04:47 -0300 | [diff] [blame] | 1168 | width_bytes = ((src_x * pixel_size) & 63) + |
| 1169 | src_w * pixel_size; |
Ville Syrjälä | 1731693 | 2013-04-24 18:52:38 +0300 | [diff] [blame] | 1170 | |
| 1171 | if (src_w > 2048 || src_h > 2048 || |
| 1172 | width_bytes > 4096 || fb->pitches[0] > 4096) { |
| 1173 | DRM_DEBUG_KMS("Source dimensions exceed hardware limits\n"); |
| 1174 | return -EINVAL; |
| 1175 | } |
| 1176 | } |
| 1177 | |
Gustavo Padovan | 96d61a7 | 2014-09-05 17:04:47 -0300 | [diff] [blame] | 1178 | if (state->visible) { |
| 1179 | src->x1 = src_x; |
| 1180 | src->x2 = src_x + src_w; |
| 1181 | src->y1 = src_y; |
| 1182 | src->y2 = src_y + src_h; |
| 1183 | } |
| 1184 | |
| 1185 | dst->x1 = crtc_x; |
| 1186 | dst->x2 = crtc_x + crtc_w; |
| 1187 | dst->y1 = crtc_y; |
| 1188 | dst->y2 = crtc_y + crtc_h; |
| 1189 | |
| 1190 | return 0; |
| 1191 | } |
| 1192 | |
| 1193 | static int |
Gustavo Padovan | 34aa50a | 2014-10-24 14:51:32 +0100 | [diff] [blame] | 1194 | intel_prepare_sprite_plane(struct drm_plane *plane, |
| 1195 | struct intel_plane_state *state) |
Gustavo Padovan | 96d61a7 | 2014-09-05 17:04:47 -0300 | [diff] [blame] | 1196 | { |
| 1197 | struct drm_device *dev = plane->dev; |
| 1198 | struct drm_crtc *crtc = state->crtc; |
| 1199 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Gustavo Padovan | 96d61a7 | 2014-09-05 17:04:47 -0300 | [diff] [blame] | 1200 | enum pipe pipe = intel_crtc->pipe; |
| 1201 | struct drm_framebuffer *fb = state->fb; |
Gustavo Padovan | 34aa50a | 2014-10-24 14:51:32 +0100 | [diff] [blame] | 1202 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
| 1203 | struct drm_i915_gem_object *old_obj = intel_fb_obj(plane->fb); |
Gustavo Padovan | 96d61a7 | 2014-09-05 17:04:47 -0300 | [diff] [blame] | 1204 | int ret; |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 1205 | |
Gustavo Padovan | 25067bf | 2014-09-10 12:03:17 -0300 | [diff] [blame] | 1206 | if (old_obj != obj) { |
| 1207 | mutex_lock(&dev->struct_mutex); |
Ville Syrjälä | 82284b6 | 2013-10-01 18:02:12 +0300 | [diff] [blame] | 1208 | |
Gustavo Padovan | 25067bf | 2014-09-10 12:03:17 -0300 | [diff] [blame] | 1209 | /* Note that this will apply the VT-d workaround for scanouts, |
| 1210 | * which is more restrictive than required for sprites. (The |
| 1211 | * primary plane requires 256KiB alignment with 64 PTE padding, |
| 1212 | * the sprite planes only require 128KiB alignment and 32 PTE |
| 1213 | * padding. |
| 1214 | */ |
| 1215 | ret = intel_pin_and_fence_fb_obj(dev, obj, NULL); |
| 1216 | if (ret == 0) |
| 1217 | i915_gem_track_fb(old_obj, obj, |
| 1218 | INTEL_FRONTBUFFER_SPRITE(pipe)); |
| 1219 | mutex_unlock(&dev->struct_mutex); |
| 1220 | if (ret) |
| 1221 | return ret; |
| 1222 | } |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 1223 | |
Gustavo Padovan | 34aa50a | 2014-10-24 14:51:32 +0100 | [diff] [blame] | 1224 | return 0; |
| 1225 | } |
| 1226 | |
| 1227 | static void |
| 1228 | intel_commit_sprite_plane(struct drm_plane *plane, |
| 1229 | struct intel_plane_state *state) |
| 1230 | { |
| 1231 | struct drm_device *dev = plane->dev; |
| 1232 | struct drm_crtc *crtc = state->crtc; |
| 1233 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 1234 | struct intel_plane *intel_plane = to_intel_plane(plane); |
| 1235 | enum pipe pipe = intel_crtc->pipe; |
| 1236 | struct drm_framebuffer *fb = state->fb; |
Gustavo Padovan | 77cde95 | 2014-10-24 14:51:33 +0100 | [diff] [blame^] | 1237 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
| 1238 | struct drm_i915_gem_object *old_obj = intel_fb_obj(plane->fb); |
Gustavo Padovan | 34aa50a | 2014-10-24 14:51:32 +0100 | [diff] [blame] | 1239 | int crtc_x, crtc_y; |
| 1240 | unsigned int crtc_w, crtc_h; |
| 1241 | uint32_t src_x, src_y, src_w, src_h; |
| 1242 | struct drm_rect *dst = &state->dst; |
| 1243 | const struct drm_rect *clip = &state->clip; |
| 1244 | bool primary_enabled; |
| 1245 | |
| 1246 | /* |
| 1247 | * If the sprite is completely covering the primary plane, |
| 1248 | * we can disable the primary and save power. |
| 1249 | */ |
| 1250 | primary_enabled = !drm_rect_equals(dst, clip) || colorkey_enabled(intel_plane); |
| 1251 | WARN_ON(!primary_enabled && !state->visible && intel_crtc->active); |
| 1252 | |
Gustavo Padovan | 96d61a7 | 2014-09-05 17:04:47 -0300 | [diff] [blame] | 1253 | intel_plane->crtc_x = state->orig_dst.x1; |
| 1254 | intel_plane->crtc_y = state->orig_dst.y1; |
| 1255 | intel_plane->crtc_w = drm_rect_width(&state->orig_dst); |
| 1256 | intel_plane->crtc_h = drm_rect_height(&state->orig_dst); |
| 1257 | intel_plane->src_x = state->orig_src.x1; |
| 1258 | intel_plane->src_y = state->orig_src.y1; |
| 1259 | intel_plane->src_w = drm_rect_width(&state->orig_src); |
| 1260 | intel_plane->src_h = drm_rect_height(&state->orig_src); |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 1261 | intel_plane->obj = obj; |
| 1262 | |
Ville Syrjälä | 03c5b25 | 2013-10-01 18:02:11 +0300 | [diff] [blame] | 1263 | if (intel_crtc->active) { |
Ville Syrjälä | 5b633d6 | 2014-04-29 13:35:47 +0300 | [diff] [blame] | 1264 | bool primary_was_enabled = intel_crtc->primary_enabled; |
| 1265 | |
| 1266 | intel_crtc->primary_enabled = primary_enabled; |
| 1267 | |
Ville Syrjälä | 46a55d3 | 2014-05-21 14:04:46 +0300 | [diff] [blame] | 1268 | if (primary_was_enabled != primary_enabled) |
| 1269 | intel_crtc_wait_for_pending_flips(crtc); |
| 1270 | |
Ville Syrjälä | 5b633d6 | 2014-04-29 13:35:47 +0300 | [diff] [blame] | 1271 | if (primary_was_enabled && !primary_enabled) |
| 1272 | intel_pre_disable_primary(crtc); |
Jesse Barnes | 175bd42 | 2011-12-13 13:19:39 -0800 | [diff] [blame] | 1273 | |
Gustavo Padovan | 96d61a7 | 2014-09-05 17:04:47 -0300 | [diff] [blame] | 1274 | if (state->visible) { |
| 1275 | crtc_x = state->dst.x1; |
Gustavo Padovan | e259f17 | 2014-09-11 17:42:15 -0300 | [diff] [blame] | 1276 | crtc_y = state->dst.y1; |
Gustavo Padovan | 96d61a7 | 2014-09-05 17:04:47 -0300 | [diff] [blame] | 1277 | crtc_w = drm_rect_width(&state->dst); |
| 1278 | crtc_h = drm_rect_height(&state->dst); |
| 1279 | src_x = state->src.x1; |
| 1280 | src_y = state->src.y1; |
| 1281 | src_w = drm_rect_width(&state->src); |
| 1282 | src_h = drm_rect_height(&state->src); |
Ville Syrjälä | 03c5b25 | 2013-10-01 18:02:11 +0300 | [diff] [blame] | 1283 | intel_plane->update_plane(plane, crtc, fb, obj, |
| 1284 | crtc_x, crtc_y, crtc_w, crtc_h, |
| 1285 | src_x, src_y, src_w, src_h); |
Gustavo Padovan | 96d61a7 | 2014-09-05 17:04:47 -0300 | [diff] [blame] | 1286 | } else { |
Ville Syrjälä | 03c5b25 | 2013-10-01 18:02:11 +0300 | [diff] [blame] | 1287 | intel_plane->disable_plane(plane, crtc); |
Gustavo Padovan | 96d61a7 | 2014-09-05 17:04:47 -0300 | [diff] [blame] | 1288 | } |
| 1289 | |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 1290 | |
Daniel Vetter | f99d706 | 2014-06-19 16:01:59 +0200 | [diff] [blame] | 1291 | intel_frontbuffer_flip(dev, INTEL_FRONTBUFFER_SPRITE(pipe)); |
| 1292 | |
Ville Syrjälä | 5b633d6 | 2014-04-29 13:35:47 +0300 | [diff] [blame] | 1293 | if (!primary_was_enabled && primary_enabled) |
| 1294 | intel_post_enable_primary(crtc); |
Ville Syrjälä | 03c5b25 | 2013-10-01 18:02:11 +0300 | [diff] [blame] | 1295 | } |
Jesse Barnes | 175bd42 | 2011-12-13 13:19:39 -0800 | [diff] [blame] | 1296 | |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 1297 | /* Unpin old obj after new one is active to avoid ugliness */ |
Gustavo Padovan | 25067bf | 2014-09-10 12:03:17 -0300 | [diff] [blame] | 1298 | if (old_obj && old_obj != obj) { |
| 1299 | |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 1300 | /* |
| 1301 | * It's fairly common to simply update the position of |
| 1302 | * an existing object. In that case, we don't need to |
| 1303 | * wait for vblank to avoid ugliness, we only need to |
| 1304 | * do the pin & ref bookkeeping. |
| 1305 | */ |
Gustavo Padovan | 25067bf | 2014-09-10 12:03:17 -0300 | [diff] [blame] | 1306 | if (intel_crtc->active) |
Ville Syrjälä | 2afd9ef | 2013-10-01 18:02:14 +0300 | [diff] [blame] | 1307 | intel_wait_for_vblank(dev, intel_crtc->pipe); |
Ville Syrjälä | 82284b6 | 2013-10-01 18:02:12 +0300 | [diff] [blame] | 1308 | |
| 1309 | mutex_lock(&dev->struct_mutex); |
Chris Wilson | 1690e1e | 2011-12-14 13:57:08 +0100 | [diff] [blame] | 1310 | intel_unpin_fb_obj(old_obj); |
Ville Syrjälä | 82284b6 | 2013-10-01 18:02:12 +0300 | [diff] [blame] | 1311 | mutex_unlock(&dev->struct_mutex); |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 1312 | } |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 1313 | } |
| 1314 | |
| 1315 | static int |
Gustavo Padovan | 96d61a7 | 2014-09-05 17:04:47 -0300 | [diff] [blame] | 1316 | intel_update_plane(struct drm_plane *plane, struct drm_crtc *crtc, |
| 1317 | struct drm_framebuffer *fb, int crtc_x, int crtc_y, |
| 1318 | unsigned int crtc_w, unsigned int crtc_h, |
| 1319 | uint32_t src_x, uint32_t src_y, |
| 1320 | uint32_t src_w, uint32_t src_h) |
| 1321 | { |
| 1322 | struct intel_plane_state state; |
| 1323 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 1324 | int ret; |
| 1325 | |
| 1326 | state.crtc = crtc; |
| 1327 | state.fb = fb; |
| 1328 | |
| 1329 | /* sample coordinates in 16.16 fixed point */ |
| 1330 | state.src.x1 = src_x; |
| 1331 | state.src.x2 = src_x + src_w; |
| 1332 | state.src.y1 = src_y; |
| 1333 | state.src.y2 = src_y + src_h; |
| 1334 | |
| 1335 | /* integer pixels */ |
| 1336 | state.dst.x1 = crtc_x; |
| 1337 | state.dst.x2 = crtc_x + crtc_w; |
| 1338 | state.dst.y1 = crtc_y; |
| 1339 | state.dst.y2 = crtc_y + crtc_h; |
| 1340 | |
| 1341 | state.clip.x1 = 0; |
| 1342 | state.clip.y1 = 0; |
| 1343 | state.clip.x2 = intel_crtc->active ? intel_crtc->config.pipe_src_w : 0; |
| 1344 | state.clip.y2 = intel_crtc->active ? intel_crtc->config.pipe_src_h : 0; |
| 1345 | state.orig_src = state.src; |
| 1346 | state.orig_dst = state.dst; |
| 1347 | |
| 1348 | ret = intel_check_sprite_plane(plane, &state); |
| 1349 | if (ret) |
| 1350 | return ret; |
| 1351 | |
Gustavo Padovan | 34aa50a | 2014-10-24 14:51:32 +0100 | [diff] [blame] | 1352 | ret = intel_prepare_sprite_plane(plane, &state); |
| 1353 | if (ret) |
| 1354 | return ret; |
| 1355 | |
| 1356 | intel_commit_sprite_plane(plane, &state); |
| 1357 | return 0; |
Gustavo Padovan | 96d61a7 | 2014-09-05 17:04:47 -0300 | [diff] [blame] | 1358 | } |
| 1359 | |
| 1360 | static int |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 1361 | intel_disable_plane(struct drm_plane *plane) |
| 1362 | { |
| 1363 | struct drm_device *dev = plane->dev; |
| 1364 | struct intel_plane *intel_plane = to_intel_plane(plane); |
Ville Syrjälä | 03c5b25 | 2013-10-01 18:02:11 +0300 | [diff] [blame] | 1365 | struct intel_crtc *intel_crtc; |
Daniel Vetter | a071fa0 | 2014-06-18 23:28:09 +0200 | [diff] [blame] | 1366 | enum pipe pipe; |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 1367 | |
Ville Syrjälä | 88a94a5 | 2013-08-07 13:30:23 +0300 | [diff] [blame] | 1368 | if (!plane->fb) |
| 1369 | return 0; |
| 1370 | |
| 1371 | if (WARN_ON(!plane->crtc)) |
| 1372 | return -EINVAL; |
| 1373 | |
Ville Syrjälä | 03c5b25 | 2013-10-01 18:02:11 +0300 | [diff] [blame] | 1374 | intel_crtc = to_intel_crtc(plane->crtc); |
Daniel Vetter | a071fa0 | 2014-06-18 23:28:09 +0200 | [diff] [blame] | 1375 | pipe = intel_crtc->pipe; |
Ville Syrjälä | 03c5b25 | 2013-10-01 18:02:11 +0300 | [diff] [blame] | 1376 | |
| 1377 | if (intel_crtc->active) { |
Ville Syrjälä | 5b633d6 | 2014-04-29 13:35:47 +0300 | [diff] [blame] | 1378 | bool primary_was_enabled = intel_crtc->primary_enabled; |
| 1379 | |
| 1380 | intel_crtc->primary_enabled = true; |
| 1381 | |
Ville Syrjälä | 03c5b25 | 2013-10-01 18:02:11 +0300 | [diff] [blame] | 1382 | intel_plane->disable_plane(plane, plane->crtc); |
Ville Syrjälä | 5b633d6 | 2014-04-29 13:35:47 +0300 | [diff] [blame] | 1383 | |
| 1384 | if (!primary_was_enabled && intel_crtc->primary_enabled) |
| 1385 | intel_post_enable_primary(plane->crtc); |
Ville Syrjälä | 03c5b25 | 2013-10-01 18:02:11 +0300 | [diff] [blame] | 1386 | } |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 1387 | |
Ville Syrjälä | 5f3fb46 | 2013-10-01 18:02:13 +0300 | [diff] [blame] | 1388 | if (intel_plane->obj) { |
| 1389 | if (intel_crtc->active) |
| 1390 | intel_wait_for_vblank(dev, intel_plane->pipe); |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 1391 | |
Ville Syrjälä | 5f3fb46 | 2013-10-01 18:02:13 +0300 | [diff] [blame] | 1392 | mutex_lock(&dev->struct_mutex); |
| 1393 | intel_unpin_fb_obj(intel_plane->obj); |
Daniel Vetter | a071fa0 | 2014-06-18 23:28:09 +0200 | [diff] [blame] | 1394 | i915_gem_track_fb(intel_plane->obj, NULL, |
| 1395 | INTEL_FRONTBUFFER_SPRITE(pipe)); |
Ville Syrjälä | 5f3fb46 | 2013-10-01 18:02:13 +0300 | [diff] [blame] | 1396 | mutex_unlock(&dev->struct_mutex); |
Ville Syrjälä | c626d31 | 2013-03-27 17:49:13 +0200 | [diff] [blame] | 1397 | |
Ville Syrjälä | 5f3fb46 | 2013-10-01 18:02:13 +0300 | [diff] [blame] | 1398 | intel_plane->obj = NULL; |
| 1399 | } |
Ville Syrjälä | 82284b6 | 2013-10-01 18:02:12 +0300 | [diff] [blame] | 1400 | |
Ville Syrjälä | 5f3fb46 | 2013-10-01 18:02:13 +0300 | [diff] [blame] | 1401 | return 0; |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 1402 | } |
| 1403 | |
| 1404 | static void intel_destroy_plane(struct drm_plane *plane) |
| 1405 | { |
| 1406 | struct intel_plane *intel_plane = to_intel_plane(plane); |
| 1407 | intel_disable_plane(plane); |
| 1408 | drm_plane_cleanup(plane); |
| 1409 | kfree(intel_plane); |
| 1410 | } |
| 1411 | |
Jesse Barnes | 8ea3086 | 2012-01-03 08:05:39 -0800 | [diff] [blame] | 1412 | int intel_sprite_set_colorkey(struct drm_device *dev, void *data, |
| 1413 | struct drm_file *file_priv) |
| 1414 | { |
| 1415 | struct drm_intel_sprite_colorkey *set = data; |
Jesse Barnes | 8ea3086 | 2012-01-03 08:05:39 -0800 | [diff] [blame] | 1416 | struct drm_plane *plane; |
| 1417 | struct intel_plane *intel_plane; |
| 1418 | int ret = 0; |
| 1419 | |
Daniel Vetter | 1cff8f6 | 2012-04-24 09:55:08 +0200 | [diff] [blame] | 1420 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
| 1421 | return -ENODEV; |
Jesse Barnes | 8ea3086 | 2012-01-03 08:05:39 -0800 | [diff] [blame] | 1422 | |
| 1423 | /* Make sure we don't try to enable both src & dest simultaneously */ |
| 1424 | if ((set->flags & (I915_SET_COLORKEY_DESTINATION | I915_SET_COLORKEY_SOURCE)) == (I915_SET_COLORKEY_DESTINATION | I915_SET_COLORKEY_SOURCE)) |
| 1425 | return -EINVAL; |
| 1426 | |
Daniel Vetter | a0e99e6 | 2012-12-02 01:05:46 +0100 | [diff] [blame] | 1427 | drm_modeset_lock_all(dev); |
Jesse Barnes | 8ea3086 | 2012-01-03 08:05:39 -0800 | [diff] [blame] | 1428 | |
Rob Clark | 7707e65 | 2014-07-17 23:30:04 -0400 | [diff] [blame] | 1429 | plane = drm_plane_find(dev, set->plane_id); |
| 1430 | if (!plane) { |
Ville Syrjälä | 3f2c205 | 2013-10-17 13:35:03 +0300 | [diff] [blame] | 1431 | ret = -ENOENT; |
Jesse Barnes | 8ea3086 | 2012-01-03 08:05:39 -0800 | [diff] [blame] | 1432 | goto out_unlock; |
| 1433 | } |
| 1434 | |
Jesse Barnes | 8ea3086 | 2012-01-03 08:05:39 -0800 | [diff] [blame] | 1435 | intel_plane = to_intel_plane(plane); |
| 1436 | ret = intel_plane->update_colorkey(plane, set); |
| 1437 | |
| 1438 | out_unlock: |
Daniel Vetter | a0e99e6 | 2012-12-02 01:05:46 +0100 | [diff] [blame] | 1439 | drm_modeset_unlock_all(dev); |
Jesse Barnes | 8ea3086 | 2012-01-03 08:05:39 -0800 | [diff] [blame] | 1440 | return ret; |
| 1441 | } |
| 1442 | |
| 1443 | int intel_sprite_get_colorkey(struct drm_device *dev, void *data, |
| 1444 | struct drm_file *file_priv) |
| 1445 | { |
| 1446 | struct drm_intel_sprite_colorkey *get = data; |
Jesse Barnes | 8ea3086 | 2012-01-03 08:05:39 -0800 | [diff] [blame] | 1447 | struct drm_plane *plane; |
| 1448 | struct intel_plane *intel_plane; |
| 1449 | int ret = 0; |
| 1450 | |
Daniel Vetter | 1cff8f6 | 2012-04-24 09:55:08 +0200 | [diff] [blame] | 1451 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
| 1452 | return -ENODEV; |
Jesse Barnes | 8ea3086 | 2012-01-03 08:05:39 -0800 | [diff] [blame] | 1453 | |
Daniel Vetter | a0e99e6 | 2012-12-02 01:05:46 +0100 | [diff] [blame] | 1454 | drm_modeset_lock_all(dev); |
Jesse Barnes | 8ea3086 | 2012-01-03 08:05:39 -0800 | [diff] [blame] | 1455 | |
Rob Clark | 7707e65 | 2014-07-17 23:30:04 -0400 | [diff] [blame] | 1456 | plane = drm_plane_find(dev, get->plane_id); |
| 1457 | if (!plane) { |
Ville Syrjälä | 3f2c205 | 2013-10-17 13:35:03 +0300 | [diff] [blame] | 1458 | ret = -ENOENT; |
Jesse Barnes | 8ea3086 | 2012-01-03 08:05:39 -0800 | [diff] [blame] | 1459 | goto out_unlock; |
| 1460 | } |
| 1461 | |
Jesse Barnes | 8ea3086 | 2012-01-03 08:05:39 -0800 | [diff] [blame] | 1462 | intel_plane = to_intel_plane(plane); |
| 1463 | intel_plane->get_colorkey(plane, get); |
| 1464 | |
| 1465 | out_unlock: |
Daniel Vetter | a0e99e6 | 2012-12-02 01:05:46 +0100 | [diff] [blame] | 1466 | drm_modeset_unlock_all(dev); |
Jesse Barnes | 8ea3086 | 2012-01-03 08:05:39 -0800 | [diff] [blame] | 1467 | return ret; |
| 1468 | } |
| 1469 | |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 1470 | int intel_plane_set_property(struct drm_plane *plane, |
| 1471 | struct drm_property *prop, |
| 1472 | uint64_t val) |
Ville Syrjälä | 7ed6eee | 2014-08-05 11:26:55 +0530 | [diff] [blame] | 1473 | { |
| 1474 | struct drm_device *dev = plane->dev; |
| 1475 | struct intel_plane *intel_plane = to_intel_plane(plane); |
| 1476 | uint64_t old_val; |
| 1477 | int ret = -ENOENT; |
| 1478 | |
| 1479 | if (prop == dev->mode_config.rotation_property) { |
| 1480 | /* exactly one rotation angle please */ |
| 1481 | if (hweight32(val & 0xf) != 1) |
| 1482 | return -EINVAL; |
| 1483 | |
Ville Syrjälä | 09dba00 | 2014-09-01 18:08:25 +0300 | [diff] [blame] | 1484 | if (intel_plane->rotation == val) |
| 1485 | return 0; |
| 1486 | |
Ville Syrjälä | 7ed6eee | 2014-08-05 11:26:55 +0530 | [diff] [blame] | 1487 | old_val = intel_plane->rotation; |
| 1488 | intel_plane->rotation = val; |
| 1489 | ret = intel_plane_restore(plane); |
| 1490 | if (ret) |
| 1491 | intel_plane->rotation = old_val; |
| 1492 | } |
| 1493 | |
| 1494 | return ret; |
| 1495 | } |
| 1496 | |
Ville Syrjälä | e57465f | 2014-08-05 11:26:53 +0530 | [diff] [blame] | 1497 | int intel_plane_restore(struct drm_plane *plane) |
Jesse Barnes | 5e1bac2 | 2013-03-26 09:25:43 -0700 | [diff] [blame] | 1498 | { |
| 1499 | struct intel_plane *intel_plane = to_intel_plane(plane); |
| 1500 | |
| 1501 | if (!plane->crtc || !plane->fb) |
Ville Syrjälä | e57465f | 2014-08-05 11:26:53 +0530 | [diff] [blame] | 1502 | return 0; |
Jesse Barnes | 5e1bac2 | 2013-03-26 09:25:43 -0700 | [diff] [blame] | 1503 | |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 1504 | return plane->funcs->update_plane(plane, plane->crtc, plane->fb, |
Ville Syrjälä | e57465f | 2014-08-05 11:26:53 +0530 | [diff] [blame] | 1505 | intel_plane->crtc_x, intel_plane->crtc_y, |
| 1506 | intel_plane->crtc_w, intel_plane->crtc_h, |
| 1507 | intel_plane->src_x, intel_plane->src_y, |
| 1508 | intel_plane->src_w, intel_plane->src_h); |
Jesse Barnes | 5e1bac2 | 2013-03-26 09:25:43 -0700 | [diff] [blame] | 1509 | } |
| 1510 | |
Ville Syrjälä | bb53d4a | 2013-06-04 13:49:04 +0300 | [diff] [blame] | 1511 | void intel_plane_disable(struct drm_plane *plane) |
| 1512 | { |
| 1513 | if (!plane->crtc || !plane->fb) |
| 1514 | return; |
| 1515 | |
| 1516 | intel_disable_plane(plane); |
| 1517 | } |
| 1518 | |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 1519 | static const struct drm_plane_funcs intel_plane_funcs = { |
| 1520 | .update_plane = intel_update_plane, |
| 1521 | .disable_plane = intel_disable_plane, |
| 1522 | .destroy = intel_destroy_plane, |
Ville Syrjälä | 7ed6eee | 2014-08-05 11:26:55 +0530 | [diff] [blame] | 1523 | .set_property = intel_plane_set_property, |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 1524 | }; |
| 1525 | |
Chris Wilson | d1686ae | 2012-04-10 11:41:49 +0100 | [diff] [blame] | 1526 | static uint32_t ilk_plane_formats[] = { |
| 1527 | DRM_FORMAT_XRGB8888, |
| 1528 | DRM_FORMAT_YUYV, |
| 1529 | DRM_FORMAT_YVYU, |
| 1530 | DRM_FORMAT_UYVY, |
| 1531 | DRM_FORMAT_VYUY, |
| 1532 | }; |
| 1533 | |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 1534 | static uint32_t snb_plane_formats[] = { |
| 1535 | DRM_FORMAT_XBGR8888, |
| 1536 | DRM_FORMAT_XRGB8888, |
| 1537 | DRM_FORMAT_YUYV, |
| 1538 | DRM_FORMAT_YVYU, |
| 1539 | DRM_FORMAT_UYVY, |
| 1540 | DRM_FORMAT_VYUY, |
| 1541 | }; |
| 1542 | |
Jesse Barnes | 7f1f385 | 2013-04-02 11:22:20 -0700 | [diff] [blame] | 1543 | static uint32_t vlv_plane_formats[] = { |
| 1544 | DRM_FORMAT_RGB565, |
| 1545 | DRM_FORMAT_ABGR8888, |
| 1546 | DRM_FORMAT_ARGB8888, |
| 1547 | DRM_FORMAT_XBGR8888, |
| 1548 | DRM_FORMAT_XRGB8888, |
| 1549 | DRM_FORMAT_XBGR2101010, |
| 1550 | DRM_FORMAT_ABGR2101010, |
| 1551 | DRM_FORMAT_YUYV, |
| 1552 | DRM_FORMAT_YVYU, |
| 1553 | DRM_FORMAT_UYVY, |
| 1554 | DRM_FORMAT_VYUY, |
| 1555 | }; |
| 1556 | |
Damien Lespiau | dc2a41b | 2013-12-04 00:49:41 +0000 | [diff] [blame] | 1557 | static uint32_t skl_plane_formats[] = { |
| 1558 | DRM_FORMAT_RGB565, |
| 1559 | DRM_FORMAT_ABGR8888, |
| 1560 | DRM_FORMAT_ARGB8888, |
| 1561 | DRM_FORMAT_XBGR8888, |
| 1562 | DRM_FORMAT_XRGB8888, |
| 1563 | DRM_FORMAT_YUYV, |
| 1564 | DRM_FORMAT_YVYU, |
| 1565 | DRM_FORMAT_UYVY, |
| 1566 | DRM_FORMAT_VYUY, |
| 1567 | }; |
| 1568 | |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 1569 | int |
Jesse Barnes | 7f1f385 | 2013-04-02 11:22:20 -0700 | [diff] [blame] | 1570 | intel_plane_init(struct drm_device *dev, enum pipe pipe, int plane) |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 1571 | { |
| 1572 | struct intel_plane *intel_plane; |
| 1573 | unsigned long possible_crtcs; |
Chris Wilson | d1686ae | 2012-04-10 11:41:49 +0100 | [diff] [blame] | 1574 | const uint32_t *plane_formats; |
| 1575 | int num_plane_formats; |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 1576 | int ret; |
| 1577 | |
Chris Wilson | d1686ae | 2012-04-10 11:41:49 +0100 | [diff] [blame] | 1578 | if (INTEL_INFO(dev)->gen < 5) |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 1579 | return -ENODEV; |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 1580 | |
Daniel Vetter | b14c567 | 2013-09-19 12:18:32 +0200 | [diff] [blame] | 1581 | intel_plane = kzalloc(sizeof(*intel_plane), GFP_KERNEL); |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 1582 | if (!intel_plane) |
| 1583 | return -ENOMEM; |
| 1584 | |
Chris Wilson | d1686ae | 2012-04-10 11:41:49 +0100 | [diff] [blame] | 1585 | switch (INTEL_INFO(dev)->gen) { |
| 1586 | case 5: |
| 1587 | case 6: |
Damien Lespiau | 2d354c3 | 2012-10-22 18:19:27 +0100 | [diff] [blame] | 1588 | intel_plane->can_scale = true; |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 1589 | intel_plane->max_downscale = 16; |
Chris Wilson | d1686ae | 2012-04-10 11:41:49 +0100 | [diff] [blame] | 1590 | intel_plane->update_plane = ilk_update_plane; |
| 1591 | intel_plane->disable_plane = ilk_disable_plane; |
| 1592 | intel_plane->update_colorkey = ilk_update_colorkey; |
| 1593 | intel_plane->get_colorkey = ilk_get_colorkey; |
| 1594 | |
| 1595 | if (IS_GEN6(dev)) { |
| 1596 | plane_formats = snb_plane_formats; |
| 1597 | num_plane_formats = ARRAY_SIZE(snb_plane_formats); |
| 1598 | } else { |
| 1599 | plane_formats = ilk_plane_formats; |
| 1600 | num_plane_formats = ARRAY_SIZE(ilk_plane_formats); |
| 1601 | } |
| 1602 | break; |
| 1603 | |
| 1604 | case 7: |
Ben Widawsky | 4e0bbc3 | 2013-11-02 21:07:07 -0700 | [diff] [blame] | 1605 | case 8: |
Damien Lespiau | d49f709 | 2013-04-25 15:15:00 +0100 | [diff] [blame] | 1606 | if (IS_IVYBRIDGE(dev)) { |
Damien Lespiau | 2d354c3 | 2012-10-22 18:19:27 +0100 | [diff] [blame] | 1607 | intel_plane->can_scale = true; |
Damien Lespiau | d49f709 | 2013-04-25 15:15:00 +0100 | [diff] [blame] | 1608 | intel_plane->max_downscale = 2; |
| 1609 | } else { |
| 1610 | intel_plane->can_scale = false; |
| 1611 | intel_plane->max_downscale = 1; |
| 1612 | } |
Chris Wilson | d1686ae | 2012-04-10 11:41:49 +0100 | [diff] [blame] | 1613 | |
Jesse Barnes | 7f1f385 | 2013-04-02 11:22:20 -0700 | [diff] [blame] | 1614 | if (IS_VALLEYVIEW(dev)) { |
Jesse Barnes | 7f1f385 | 2013-04-02 11:22:20 -0700 | [diff] [blame] | 1615 | intel_plane->update_plane = vlv_update_plane; |
| 1616 | intel_plane->disable_plane = vlv_disable_plane; |
| 1617 | intel_plane->update_colorkey = vlv_update_colorkey; |
| 1618 | intel_plane->get_colorkey = vlv_get_colorkey; |
| 1619 | |
| 1620 | plane_formats = vlv_plane_formats; |
| 1621 | num_plane_formats = ARRAY_SIZE(vlv_plane_formats); |
| 1622 | } else { |
Jesse Barnes | 7f1f385 | 2013-04-02 11:22:20 -0700 | [diff] [blame] | 1623 | intel_plane->update_plane = ivb_update_plane; |
| 1624 | intel_plane->disable_plane = ivb_disable_plane; |
| 1625 | intel_plane->update_colorkey = ivb_update_colorkey; |
| 1626 | intel_plane->get_colorkey = ivb_get_colorkey; |
| 1627 | |
| 1628 | plane_formats = snb_plane_formats; |
| 1629 | num_plane_formats = ARRAY_SIZE(snb_plane_formats); |
| 1630 | } |
Chris Wilson | d1686ae | 2012-04-10 11:41:49 +0100 | [diff] [blame] | 1631 | break; |
Damien Lespiau | dc2a41b | 2013-12-04 00:49:41 +0000 | [diff] [blame] | 1632 | case 9: |
| 1633 | /* |
| 1634 | * FIXME: Skylake planes can be scaled (with some restrictions), |
| 1635 | * but this is for another time. |
| 1636 | */ |
| 1637 | intel_plane->can_scale = false; |
| 1638 | intel_plane->max_downscale = 1; |
| 1639 | intel_plane->update_plane = skl_update_plane; |
| 1640 | intel_plane->disable_plane = skl_disable_plane; |
| 1641 | intel_plane->update_colorkey = skl_update_colorkey; |
| 1642 | intel_plane->get_colorkey = skl_get_colorkey; |
Chris Wilson | d1686ae | 2012-04-10 11:41:49 +0100 | [diff] [blame] | 1643 | |
Damien Lespiau | dc2a41b | 2013-12-04 00:49:41 +0000 | [diff] [blame] | 1644 | plane_formats = skl_plane_formats; |
| 1645 | num_plane_formats = ARRAY_SIZE(skl_plane_formats); |
| 1646 | break; |
Chris Wilson | d1686ae | 2012-04-10 11:41:49 +0100 | [diff] [blame] | 1647 | default: |
Jesper Juhl | a8b0bba | 2012-06-27 00:55:37 +0200 | [diff] [blame] | 1648 | kfree(intel_plane); |
Chris Wilson | d1686ae | 2012-04-10 11:41:49 +0100 | [diff] [blame] | 1649 | return -ENODEV; |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 1650 | } |
| 1651 | |
| 1652 | intel_plane->pipe = pipe; |
Jesse Barnes | 7f1f385 | 2013-04-02 11:22:20 -0700 | [diff] [blame] | 1653 | intel_plane->plane = plane; |
Ville Syrjälä | 76eebda | 2014-08-05 11:26:52 +0530 | [diff] [blame] | 1654 | intel_plane->rotation = BIT(DRM_ROTATE_0); |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 1655 | possible_crtcs = (1 << pipe); |
Derek Foreman | 8fe8a3f | 2014-09-03 10:38:20 -0300 | [diff] [blame] | 1656 | ret = drm_universal_plane_init(dev, &intel_plane->base, possible_crtcs, |
| 1657 | &intel_plane_funcs, |
| 1658 | plane_formats, num_plane_formats, |
| 1659 | DRM_PLANE_TYPE_OVERLAY); |
Ville Syrjälä | 7ed6eee | 2014-08-05 11:26:55 +0530 | [diff] [blame] | 1660 | if (ret) { |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 1661 | kfree(intel_plane); |
Ville Syrjälä | 7ed6eee | 2014-08-05 11:26:55 +0530 | [diff] [blame] | 1662 | goto out; |
| 1663 | } |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 1664 | |
Ville Syrjälä | 7ed6eee | 2014-08-05 11:26:55 +0530 | [diff] [blame] | 1665 | if (!dev->mode_config.rotation_property) |
| 1666 | dev->mode_config.rotation_property = |
| 1667 | drm_mode_create_rotation_property(dev, |
| 1668 | BIT(DRM_ROTATE_0) | |
| 1669 | BIT(DRM_ROTATE_180)); |
| 1670 | |
| 1671 | if (dev->mode_config.rotation_property) |
| 1672 | drm_object_attach_property(&intel_plane->base.base, |
| 1673 | dev->mode_config.rotation_property, |
| 1674 | intel_plane->rotation); |
| 1675 | |
| 1676 | out: |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 1677 | return ret; |
| 1678 | } |