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