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