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