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