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