blob: 6d4e1ea4219f6d6aa62ef8c7a2d65e7b48f6203c [file] [log] [blame]
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001/*
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 Howells760285e2012-10-02 18:01:07 +010032#include <drm/drmP.h>
33#include <drm/drm_crtc.h>
34#include <drm/drm_fourcc.h>
Ville Syrjälä17316932013-04-24 18:52:38 +030035#include <drm/drm_rect.h>
Matt Roperea2c67b2014-12-23 10:41:52 -080036#include <drm/drm_plane_helper.h>
Jesse Barnesb840d907f2011-12-13 13:19:38 -080037#include "intel_drv.h"
David Howells760285e2012-10-02 18:01:07 +010038#include <drm/i915_drm.h>
Jesse Barnesb840d907f2011-12-13 13:19:38 -080039#include "i915_drv.h"
40
Ville Syrjälä6ca2aeb2014-10-20 19:47:53 +030041static bool
42format_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ä8d7849d2014-04-29 13:35:46 +030055static 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 Oliveira26ff2762014-10-28 15:10:12 +020064/**
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 Oliveira9362c7c2014-10-28 15:10:14 +020080bool intel_pipe_update_start(struct intel_crtc *crtc, uint32_t *start_vbl_count)
Ville Syrjälä8d7849d2014-04-29 13:35:46 +030081{
82 struct drm_device *dev = crtc->base.dev;
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +020083 const struct drm_display_mode *mode = &crtc->config->base.adjusted_mode;
Ville Syrjälä8d7849d2014-04-29 13:35:46 +030084 enum pipe pipe = crtc->pipe;
85 long timeout = msecs_to_jiffies_timeout(1);
86 int scanline, min, max, vblank_start;
Ville Syrjälä210871b2014-05-22 19:00:50 +030087 wait_queue_head_t *wq = drm_crtc_vblank_waitqueue(&crtc->base);
Ville Syrjälä8d7849d2014-04-29 13:35:46 +030088 DEFINE_WAIT(wait);
89
Ville Syrjälä8d7849d2014-04-29 13:35:46 +030090 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 Vetter1e3feef2015-02-13 21:03:45 +0100101 if (WARN_ON(drm_crtc_vblank_get(&crtc->base)))
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300102 return false;
103
104 local_irq_disable();
105
Ville Syrjälä25ef2842014-04-29 13:35:48 +0300106 trace_i915_pipe_update_start(crtc, min, max);
107
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300108 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ä210871b2014-05-22 19:00:50 +0300114 prepare_to_wait(wq, &wait, TASK_UNINTERRUPTIBLE);
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300115
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ä210871b2014-05-22 19:00:50 +0300133 finish_wait(wq, &wait);
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300134
Daniel Vetter1e3feef2015-02-13 21:03:45 +0100135 drm_crtc_vblank_put(&crtc->base);
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300136
137 *start_vbl_count = dev->driver->get_vblank_counter(dev, pipe);
138
Ville Syrjälä25ef2842014-04-29 13:35:48 +0300139 trace_i915_pipe_update_vblank_evaded(crtc, min, max, *start_vbl_count);
140
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300141 return true;
142}
143
Ander Conselvan de Oliveira26ff2762014-10-28 15:10:12 +0200144/**
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 Oliveira9362c7c2014-10-28 15:10:14 +0200153void intel_pipe_update_end(struct intel_crtc *crtc, u32 start_vbl_count)
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300154{
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ä25ef2842014-04-29 13:35:48 +0300159 trace_i915_pipe_update_end(crtc, end_vbl_count);
160
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300161 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ä5b633d62014-04-29 13:35:47 +0300168static 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 Barnesb840d907f2011-12-13 13:19:38 -0800179static void
Damien Lespiaudc2a41b2013-12-04 00:49:41 +0000180skl_update_plane(struct drm_plane *drm_plane, struct drm_crtc *crtc,
181 struct drm_framebuffer *fb,
Ville Syrjäläbdd75542015-03-19 17:57:11 +0200182 int crtc_x, int crtc_y,
Damien Lespiaudc2a41b2013-12-04 00:49:41 +0000183 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äbdd75542015-03-19 17:57:11 +0200190 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
Damien Lespiaudc2a41b2013-12-04 00:49:41 +0000191 const int pipe = intel_plane->pipe;
192 const int plane = intel_plane->plane + 1;
Sonika Jindal3b7a5112015-04-10 14:37:29 +0530193 u32 plane_ctl, stride_div, stride;
Damien Lespiaudc2a41b2013-12-04 00:49:41 +0000194 int pixel_size = drm_format_plane_cpp(fb->pixel_format, 0);
Ville Syrjälä47ecbb22015-03-19 21:18:57 +0200195 const struct drm_intel_sprite_colorkey *key = &intel_plane->ckey;
Tvrtko Ursulin121920f2015-03-23 11:10:37 +0000196 unsigned long surf_addr;
Sonika Jindal3b7a5112015-04-10 14:37:29 +0530197 u32 tile_height, plane_offset, plane_size;
198 unsigned int rotation;
199 int x_offset, y_offset;
Damien Lespiaudc2a41b2013-12-04 00:49:41 +0000200
Ville Syrjälä48fe4692015-03-19 17:57:13 +0200201 plane_ctl = PLANE_CTL_ENABLE |
202 PLANE_CTL_PIPE_CSC_ENABLE;
Damien Lespiaudc2a41b2013-12-04 00:49:41 +0000203
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 Ursulin66ebf562015-02-10 17:16:13 +0000244 switch (fb->modifier[0]) {
245 case DRM_FORMAT_MOD_NONE:
Damien Lespiaudc2a41b2013-12-04 00:49:41 +0000246 break;
Tvrtko Ursulin66ebf562015-02-10 17:16:13 +0000247 case I915_FORMAT_MOD_X_TILED:
Damien Lespiaudc2a41b2013-12-04 00:49:41 +0000248 plane_ctl |= PLANE_CTL_TILED_X;
Damien Lespiaub3218032015-02-27 11:15:18 +0000249 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 Lespiaudc2a41b2013-12-04 00:49:41 +0000255 break;
256 default:
Damien Lespiaub3218032015-02-27 11:15:18 +0000257 MISSING_CASE(fb->modifier[0]);
Damien Lespiaudc2a41b2013-12-04 00:49:41 +0000258 }
Damien Lespiaub3218032015-02-27 11:15:18 +0000259
Sonika Jindal3b7a5112015-04-10 14:37:29 +0530260 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 Jindal1447dde2014-10-04 10:53:31 +0100267 plane_ctl |= PLANE_CTL_ROTATE_180;
Sonika Jindal3b7a5112015-04-10 14:37:29 +0530268 break;
269
270 case BIT(DRM_ROTATE_270):
271 plane_ctl |= PLANE_CTL_ROTATE_270;
272 break;
273 }
Damien Lespiaudc2a41b2013-12-04 00:49:41 +0000274
Damien Lespiaudc2a41b2013-12-04 00:49:41 +0000275 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 Lespiaub3218032015-02-27 11:15:18 +0000279 stride_div = intel_fb_stride_alignment(dev, fb->modifier[0],
280 fb->pixel_format);
281
Damien Lespiaudc2a41b2013-12-04 00:49:41 +0000282 /* Sizes are 0 based */
283 src_w--;
284 src_h--;
285 crtc_w--;
286 crtc_h--;
287
Ville Syrjälä47ecbb22015-03-19 21:18:57 +0200288 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 Ursulin121920f2015-03-23 11:10:37 +0000299 surf_addr = intel_plane_obj_offset(intel_plane, obj);
300
Sonika Jindal3b7a5112015-04-10 14:37:29 +0530301 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 Lespiaudc2a41b2013-12-04 00:49:41 +0000319 I915_WRITE(PLANE_POS(pipe, plane), (crtc_y << 16) | crtc_x);
Sonika Jindal3b7a5112015-04-10 14:37:29 +0530320 I915_WRITE(PLANE_SIZE(pipe, plane), plane_size);
Damien Lespiaudc2a41b2013-12-04 00:49:41 +0000321 I915_WRITE(PLANE_CTL(pipe, plane), plane_ctl);
Tvrtko Ursulin121920f2015-03-23 11:10:37 +0000322 I915_WRITE(PLANE_SURF(pipe, plane), surf_addr);
Damien Lespiaudc2a41b2013-12-04 00:49:41 +0000323 POSTING_READ(PLANE_SURF(pipe, plane));
324}
325
326static void
327skl_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ä48fe4692015-03-19 17:57:13 +0200335 I915_WRITE(PLANE_CTL(pipe, plane), 0);
Damien Lespiaudc2a41b2013-12-04 00:49:41 +0000336
337 /* Activate double buffered register update */
Ville Syrjälä2ddc1da2015-03-19 17:57:14 +0200338 I915_WRITE(PLANE_SURF(pipe, plane), 0);
339 POSTING_READ(PLANE_SURF(pipe, plane));
Damien Lespiaudc2a41b2013-12-04 00:49:41 +0000340
341 intel_update_sprite_watermarks(drm_plane, crtc, 0, 0, 0, false, false);
342}
343
Damien Lespiaudc2a41b2013-12-04 00:49:41 +0000344static void
Ville Syrjälä6ca2aeb2014-10-20 19:47:53 +0300345chv_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
383static void
Ville Syrjäläb39d53f2013-08-06 22:24:09 +0300384vlv_update_plane(struct drm_plane *dplane, struct drm_crtc *crtc,
385 struct drm_framebuffer *fb,
Ville Syrjäläbdd75542015-03-19 17:57:11 +0200386 int crtc_x, int crtc_y,
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700387 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ä8d7849d2014-04-29 13:35:46 +0300394 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Ville Syrjäläbdd75542015-03-19 17:57:11 +0200395 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700396 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ä47ecbb22015-03-19 21:18:57 +0200401 const struct drm_intel_sprite_colorkey *key = &intel_plane->ckey;
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700402
Ville Syrjälä48fe4692015-03-19 17:57:13 +0200403 sprctl = SP_ENABLE;
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700404
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ä4ea67bc2013-11-18 18:32:38 -0800448 /*
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 Barnes7f1f3852013-04-02 11:22:20 -0700454 if (obj->tiling_mode != I915_TILING_NONE)
455 sprctl |= SP_TILED;
456
Damien Lespiaued57cb82014-07-15 09:21:24 +0200457 intel_update_sprite_watermarks(dplane, crtc, src_w, src_h,
458 pixel_size, true,
Ville Syrjälä67ca28f2013-07-05 11:57:14 +0300459 src_w != crtc_w || src_h != crtc_h);
460
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700461 /* Sizes are 0 based */
462 src_w--;
463 src_h--;
464 crtc_w--;
465 crtc_h--;
466
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700467 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 Roper8e7d6882015-01-21 16:35:41 -0800474 if (dplane->state->rotation == BIT(DRM_ROTATE_180)) {
Ville Syrjälä76eebda2014-08-05 11:26:52 +0530475 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ä5b633d62014-04-29 13:35:47 +0300482 intel_update_primary_plane(intel_crtc);
483
Ville Syrjälä47ecbb22015-03-19 21:18:57 +0200484 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ä6ca2aeb2014-10-20 19:47:53 +0300493 if (IS_CHERRYVIEW(dev) && pipe == PIPE_B)
494 chv_update_csc(intel_plane, fb->pixel_format);
495
Ville Syrjäläca6ad022014-01-17 20:09:03 +0200496 I915_WRITE(SPSTRIDE(pipe, plane), fb->pitches[0]);
497 I915_WRITE(SPPOS(pipe, plane), (crtc_y << 16) | crtc_x);
498
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700499 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äc14b0482014-10-16 20:52:34 +0300504 I915_WRITE(SPCONSTALPHA(pipe, plane), 0);
505
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700506 I915_WRITE(SPSIZE(pipe, plane), (crtc_h << 16) | crtc_w);
507 I915_WRITE(SPCNTR(pipe, plane), sprctl);
Daniel Vetter85ba7b72014-01-24 10:31:44 +0100508 I915_WRITE(SPSURF(pipe, plane), i915_gem_obj_ggtt_offset(obj) +
509 sprsurf_offset);
Ville Syrjälä5b633d62014-04-29 13:35:47 +0300510
511 intel_flush_primary_plane(dev_priv, intel_crtc->plane);
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700512}
513
514static void
Ville Syrjäläb39d53f2013-08-06 22:24:09 +0300515vlv_disable_plane(struct drm_plane *dplane, struct drm_crtc *crtc)
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700516{
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ä8d7849d2014-04-29 13:35:46 +0300520 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700521 int pipe = intel_plane->pipe;
522 int plane = intel_plane->plane;
523
Ville Syrjälä5b633d62014-04-29 13:35:47 +0300524 intel_update_primary_plane(intel_crtc);
525
Ville Syrjälä48fe4692015-03-19 17:57:13 +0200526 I915_WRITE(SPCNTR(pipe, plane), 0);
527
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700528 /* Activate double buffered register update */
Daniel Vetter85ba7b72014-01-24 10:31:44 +0100529 I915_WRITE(SPSURF(pipe, plane), 0);
Ville Syrjälä5b633d62014-04-29 13:35:47 +0300530
531 intel_flush_primary_plane(dev_priv, intel_crtc->plane);
Ville Syrjäläa95fd8c2013-08-06 22:24:12 +0300532
Damien Lespiaued57cb82014-07-15 09:21:24 +0200533 intel_update_sprite_watermarks(dplane, crtc, 0, 0, 0, false, false);
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700534}
535
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700536
537static void
Ville Syrjäläb39d53f2013-08-06 22:24:09 +0300538ivb_update_plane(struct drm_plane *plane, struct drm_crtc *crtc,
539 struct drm_framebuffer *fb,
Ville Syrjäläbdd75542015-03-19 17:57:11 +0200540 int crtc_x, int crtc_y,
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800541 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ä8d7849d2014-04-29 13:35:46 +0300548 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Ville Syrjäläbdd75542015-03-19 17:57:11 +0200549 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
Ville Syrjälä47ecbb22015-03-19 21:18:57 +0200550 enum pipe pipe = intel_plane->pipe;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800551 u32 sprctl, sprscale = 0;
Damien Lespiau5a35e992012-10-26 18:20:12 +0100552 unsigned long sprsurf_offset, linear_offset;
Ville Syrjälä2bd3c3c2012-10-31 17:50:20 +0200553 int pixel_size = drm_format_plane_cpp(fb->pixel_format, 0);
Ville Syrjälä47ecbb22015-03-19 21:18:57 +0200554 const struct drm_intel_sprite_colorkey *key = &intel_plane->ckey;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800555
Ville Syrjälä48fe4692015-03-19 17:57:13 +0200556 sprctl = SPRITE_ENABLE;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800557
558 switch (fb->pixel_format) {
559 case DRM_FORMAT_XBGR8888:
Vijay Purushothaman5ee36912012-08-23 12:08:57 +0530560 sprctl |= SPRITE_FORMAT_RGBX888 | SPRITE_RGB_ORDER_RGBX;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800561 break;
562 case DRM_FORMAT_XRGB8888:
Vijay Purushothaman5ee36912012-08-23 12:08:57 +0530563 sprctl |= SPRITE_FORMAT_RGBX888;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800564 break;
565 case DRM_FORMAT_YUYV:
566 sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_YUYV;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800567 break;
568 case DRM_FORMAT_YVYU:
569 sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_YVYU;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800570 break;
571 case DRM_FORMAT_UYVY:
572 sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_UYVY;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800573 break;
574 case DRM_FORMAT_VYUY:
575 sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_VYUY;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800576 break;
577 default:
Ville Syrjälä28d491d2012-10-31 17:50:21 +0200578 BUG();
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800579 }
580
Ville Syrjälä4ea67bc2013-11-18 18:32:38 -0800581 /*
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 Barnesb840d907f2011-12-13 13:19:38 -0800587 if (obj->tiling_mode != I915_TILING_NONE)
588 sprctl |= SPRITE_TILED;
589
Ville Syrjäläb42c6002013-11-03 13:47:27 +0200590 if (IS_HASWELL(dev) || IS_BROADWELL(dev))
Paulo Zanoni1f5d76d2013-08-23 19:51:28 -0300591 sprctl &= ~SPRITE_TRICKLE_FEED_DISABLE;
592 else
593 sprctl |= SPRITE_TRICKLE_FEED_DISABLE;
594
Ville Syrjälä6bbfa1c2013-11-02 21:07:39 -0700595 if (IS_HASWELL(dev) || IS_BROADWELL(dev))
Ville Syrjälä86d3efc2013-01-18 19:11:38 +0200596 sprctl |= SPRITE_PIPE_CSC_ENABLE;
597
Damien Lespiaued57cb82014-07-15 09:21:24 +0200598 intel_update_sprite_watermarks(plane, crtc, src_w, src_h, pixel_size,
599 true,
Ville Syrjälä67ca28f2013-07-05 11:57:14 +0300600 src_w != crtc_w || src_h != crtc_h);
601
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800602 /* Sizes are 0 based */
603 src_w--;
604 src_h--;
605 crtc_w--;
606 crtc_h--;
607
Ville Syrjälä8553c182013-12-05 15:51:39 +0200608 if (crtc_w != src_w || crtc_h != src_h)
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800609 sprscale = SPRITE_SCALE_ENABLE | (src_w << 16) | src_h;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800610
Chris Wilsonca320ac2012-12-19 12:14:22 +0000611 linear_offset = y * fb->pitches[0] + x * pixel_size;
Damien Lespiau5a35e992012-10-26 18:20:12 +0100612 sprsurf_offset =
Chris Wilsonbc752862013-02-21 20:04:31 +0000613 intel_gen4_compute_page_offset(&x, &y, obj->tiling_mode,
614 pixel_size, fb->pitches[0]);
Damien Lespiau5a35e992012-10-26 18:20:12 +0100615 linear_offset -= sprsurf_offset;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800616
Matt Roper8e7d6882015-01-21 16:35:41 -0800617 if (plane->state->rotation == BIT(DRM_ROTATE_180)) {
Ville Syrjälä76eebda2014-08-05 11:26:52 +0530618 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ä5b633d62014-04-29 13:35:47 +0300629 intel_update_primary_plane(intel_crtc);
630
Ville Syrjälä47ecbb22015-03-19 21:18:57 +0200631 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äca6ad022014-01-17 20:09:03 +0200642 I915_WRITE(SPRSTRIDE(pipe), fb->pitches[0]);
643 I915_WRITE(SPRPOS(pipe), (crtc_y << 16) | crtc_x);
644
Damien Lespiau5a35e992012-10-26 18:20:12 +0100645 /* HSW consolidates SPRTILEOFF and SPRLINOFF into a single SPROFFSET
646 * register */
Paulo Zanonib3dc6852013-11-02 21:07:33 -0700647 if (IS_HASWELL(dev) || IS_BROADWELL(dev))
Damien Lespiau5a35e992012-10-26 18:20:12 +0100648 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 Lespiauc54173a2012-10-26 18:20:11 +0100653
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800654 I915_WRITE(SPRSIZE(pipe), (crtc_h << 16) | crtc_w);
Damien Lespiau2d354c32012-10-22 18:19:27 +0100655 if (intel_plane->can_scale)
656 I915_WRITE(SPRSCALE(pipe), sprscale);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800657 I915_WRITE(SPRCTL(pipe), sprctl);
Daniel Vetter85ba7b72014-01-24 10:31:44 +0100658 I915_WRITE(SPRSURF(pipe),
659 i915_gem_obj_ggtt_offset(obj) + sprsurf_offset);
Ville Syrjälä5b633d62014-04-29 13:35:47 +0300660
661 intel_flush_primary_plane(dev_priv, intel_crtc->plane);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800662}
663
664static void
Ville Syrjäläb39d53f2013-08-06 22:24:09 +0300665ivb_disable_plane(struct drm_plane *plane, struct drm_crtc *crtc)
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800666{
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ä8d7849d2014-04-29 13:35:46 +0300670 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800671 int pipe = intel_plane->pipe;
672
Ville Syrjälä5b633d62014-04-29 13:35:47 +0300673 intel_update_primary_plane(intel_crtc);
674
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800675 I915_WRITE(SPRCTL(pipe), I915_READ(SPRCTL(pipe)) & ~SPRITE_ENABLE);
676 /* Can't leave the scaler enabled... */
Damien Lespiau2d354c32012-10-22 18:19:27 +0100677 if (intel_plane->can_scale)
678 I915_WRITE(SPRSCALE(pipe), 0);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800679 /* Activate double buffered register update */
Daniel Vetter85ba7b72014-01-24 10:31:44 +0100680 I915_WRITE(SPRSURF(pipe), 0);
Ville Syrjälä5b633d62014-04-29 13:35:47 +0300681
682 intel_flush_primary_plane(dev_priv, intel_crtc->plane);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800683}
684
685static void
Ville Syrjäläb39d53f2013-08-06 22:24:09 +0300686ilk_update_plane(struct drm_plane *plane, struct drm_crtc *crtc,
687 struct drm_framebuffer *fb,
Ville Syrjäläbdd75542015-03-19 17:57:11 +0200688 int crtc_x, int crtc_y,
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800689 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ä8d7849d2014-04-29 13:35:46 +0300696 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Ville Syrjäläbdd75542015-03-19 17:57:11 +0200697 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
Ville Syrjälä2bd3c3c2012-10-31 17:50:20 +0200698 int pipe = intel_plane->pipe;
Damien Lespiau5a35e992012-10-26 18:20:12 +0100699 unsigned long dvssurf_offset, linear_offset;
Chris Wilson8aaa81a2012-04-14 22:14:26 +0100700 u32 dvscntr, dvsscale;
Ville Syrjälä2bd3c3c2012-10-31 17:50:20 +0200701 int pixel_size = drm_format_plane_cpp(fb->pixel_format, 0);
Ville Syrjälä47ecbb22015-03-19 21:18:57 +0200702 const struct drm_intel_sprite_colorkey *key = &intel_plane->ckey;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800703
Ville Syrjälä48fe4692015-03-19 17:57:13 +0200704 dvscntr = DVS_ENABLE;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800705
706 switch (fb->pixel_format) {
707 case DRM_FORMAT_XBGR8888:
Jesse Barnesab2f9df2012-02-27 12:40:10 -0800708 dvscntr |= DVS_FORMAT_RGBX888 | DVS_RGB_ORDER_XBGR;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800709 break;
710 case DRM_FORMAT_XRGB8888:
Jesse Barnesab2f9df2012-02-27 12:40:10 -0800711 dvscntr |= DVS_FORMAT_RGBX888;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800712 break;
713 case DRM_FORMAT_YUYV:
714 dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_YUYV;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800715 break;
716 case DRM_FORMAT_YVYU:
717 dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_YVYU;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800718 break;
719 case DRM_FORMAT_UYVY:
720 dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_UYVY;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800721 break;
722 case DRM_FORMAT_VYUY:
723 dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_VYUY;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800724 break;
725 default:
Ville Syrjälä28d491d2012-10-31 17:50:21 +0200726 BUG();
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800727 }
728
Ville Syrjälä4ea67bc2013-11-18 18:32:38 -0800729 /*
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 Barnesb840d907f2011-12-13 13:19:38 -0800735 if (obj->tiling_mode != I915_TILING_NONE)
736 dvscntr |= DVS_TILED;
737
Chris Wilsond1686ae2012-04-10 11:41:49 +0100738 if (IS_GEN6(dev))
739 dvscntr |= DVS_TRICKLE_FEED_DISABLE; /* must disable */
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800740
Damien Lespiaued57cb82014-07-15 09:21:24 +0200741 intel_update_sprite_watermarks(plane, crtc, src_w, src_h,
742 pixel_size, true,
Ville Syrjälä67ca28f2013-07-05 11:57:14 +0300743 src_w != crtc_w || src_h != crtc_h);
744
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800745 /* Sizes are 0 based */
746 src_w--;
747 src_h--;
748 crtc_w--;
749 crtc_h--;
750
Chris Wilson8aaa81a2012-04-14 22:14:26 +0100751 dvsscale = 0;
Ville Syrjälä8368f012013-12-05 15:51:31 +0200752 if (crtc_w != src_w || crtc_h != src_h)
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800753 dvsscale = DVS_SCALE_ENABLE | (src_w << 16) | src_h;
754
Chris Wilsonca320ac2012-12-19 12:14:22 +0000755 linear_offset = y * fb->pitches[0] + x * pixel_size;
Damien Lespiau5a35e992012-10-26 18:20:12 +0100756 dvssurf_offset =
Chris Wilsonbc752862013-02-21 20:04:31 +0000757 intel_gen4_compute_page_offset(&x, &y, obj->tiling_mode,
758 pixel_size, fb->pitches[0]);
Damien Lespiau5a35e992012-10-26 18:20:12 +0100759 linear_offset -= dvssurf_offset;
760
Matt Roper8e7d6882015-01-21 16:35:41 -0800761 if (plane->state->rotation == BIT(DRM_ROTATE_180)) {
Ville Syrjälä76eebda2014-08-05 11:26:52 +0530762 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ä5b633d62014-04-29 13:35:47 +0300769 intel_update_primary_plane(intel_crtc);
770
Ville Syrjälä47ecbb22015-03-19 21:18:57 +0200771 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äca6ad022014-01-17 20:09:03 +0200782 I915_WRITE(DVSSTRIDE(pipe), fb->pitches[0]);
783 I915_WRITE(DVSPOS(pipe), (crtc_y << 16) | crtc_x);
784
Damien Lespiau5a35e992012-10-26 18:20:12 +0100785 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 Barnesb840d907f2011-12-13 13:19:38 -0800790 I915_WRITE(DVSSIZE(pipe), (crtc_h << 16) | crtc_w);
791 I915_WRITE(DVSSCALE(pipe), dvsscale);
792 I915_WRITE(DVSCNTR(pipe), dvscntr);
Daniel Vetter85ba7b72014-01-24 10:31:44 +0100793 I915_WRITE(DVSSURF(pipe),
794 i915_gem_obj_ggtt_offset(obj) + dvssurf_offset);
Ville Syrjälä5b633d62014-04-29 13:35:47 +0300795
796 intel_flush_primary_plane(dev_priv, intel_crtc->plane);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800797}
798
799static void
Ville Syrjäläb39d53f2013-08-06 22:24:09 +0300800ilk_disable_plane(struct drm_plane *plane, struct drm_crtc *crtc)
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800801{
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ä8d7849d2014-04-29 13:35:46 +0300805 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800806 int pipe = intel_plane->pipe;
807
Ville Syrjälä5b633d62014-04-29 13:35:47 +0300808 intel_update_primary_plane(intel_crtc);
809
Ville Syrjälä48fe4692015-03-19 17:57:13 +0200810 I915_WRITE(DVSCNTR(pipe), 0);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800811 /* Disable the scaler */
812 I915_WRITE(DVSSCALE(pipe), 0);
Ville Syrjälä48fe4692015-03-19 17:57:13 +0200813
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800814 /* Flush double buffered register updates */
Daniel Vetter85ba7b72014-01-24 10:31:44 +0100815 I915_WRITE(DVSSURF(pipe), 0);
Ville Syrjälä5b633d62014-04-29 13:35:47 +0300816
817 intel_flush_primary_plane(dev_priv, intel_crtc->plane);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800818}
819
Matt Roper32b7eee2014-12-24 07:59:06 -0800820/**
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 */
830void
Ville Syrjälä5b633d62014-04-29 13:35:47 +0300831intel_post_enable_primary(struct drm_crtc *crtc)
Jesse Barnes175bd422011-12-13 13:19:39 -0800832{
833 struct drm_device *dev = crtc->dev;
Jesse Barnes175bd422011-12-13 13:19:39 -0800834 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Ville Syrjäläabae50e2013-10-01 18:02:16 +0300835
Ville Syrjälä20bc86732013-10-01 18:02:17 +0300836 /*
Ville Syrjälä33c3b0d2014-06-24 13:59:28 +0300837 * 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ä20bc86732013-10-01 18:02:17 +0300845 * 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äcea165c2014-04-15 21:41:35 +0300850 hsw_enable_ips(intel_crtc);
Ville Syrjälä20bc86732013-10-01 18:02:17 +0300851
Ville Syrjälä82284b62013-10-01 18:02:12 +0300852 mutex_lock(&dev->struct_mutex);
Rodrigo Vivi7ff0ebc2014-12-08 14:09:10 -0200853 intel_fbc_update(dev);
Ville Syrjälä82284b62013-10-01 18:02:12 +0300854 mutex_unlock(&dev->struct_mutex);
Jesse Barnes175bd422011-12-13 13:19:39 -0800855}
856
Matt Roper32b7eee2014-12-24 07:59:06 -0800857/**
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 */
867void
Ville Syrjälä5b633d62014-04-29 13:35:47 +0300868intel_pre_disable_primary(struct drm_crtc *crtc)
Jesse Barnes175bd422011-12-13 13:19:39 -0800869{
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ä82284b62013-10-01 18:02:12 +0300873
874 mutex_lock(&dev->struct_mutex);
Paulo Zanonie35fef22015-02-09 14:46:29 -0200875 if (dev_priv->fbc.crtc == intel_crtc)
Rodrigo Vivi7ff0ebc2014-12-08 14:09:10 -0200876 intel_fbc_disable(dev);
Ville Syrjälä82284b62013-10-01 18:02:12 +0300877 mutex_unlock(&dev->struct_mutex);
Ville Syrjäläabae50e2013-10-01 18:02:16 +0300878
Ville Syrjälä20bc86732013-10-01 18:02:17 +0300879 /*
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 Barnes175bd422011-12-13 13:19:39 -0800886}
887
Ville Syrjäläefb31d12013-12-05 15:51:40 +0200888static bool colorkey_enabled(struct intel_plane *intel_plane)
889{
Ville Syrjälä47ecbb22015-03-19 21:18:57 +0200890 return intel_plane->ckey.flags != I915_SET_COLORKEY_NONE;
Ville Syrjäläefb31d12013-12-05 15:51:40 +0200891}
892
Jesse Barnes8ea30862012-01-03 08:05:39 -0800893static int
Gustavo Padovan96d61a72014-09-05 17:04:47 -0300894intel_check_sprite_plane(struct drm_plane *plane,
895 struct intel_plane_state *state)
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800896{
Matt Roper2b875c22014-12-01 15:40:13 -0800897 struct intel_crtc *intel_crtc = to_intel_crtc(state->base.crtc);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800898 struct intel_plane *intel_plane = to_intel_plane(plane);
Matt Roper2b875c22014-12-01 15:40:13 -0800899 struct drm_framebuffer *fb = state->base.fb;
Gustavo Padovan96d61a72014-09-05 17:04:47 -0300900 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 Padovan96d61a72014-09-05 17:04:47 -0300905 const struct drm_rect *clip = &state->clip;
Ville Syrjälä17316932013-04-24 18:52:38 +0300906 int hscale, vscale;
907 int max_scale, min_scale;
Matt Ropercf4c7c12014-12-04 10:27:42 -0800908 int pixel_size;
909
Matt Roperea2c67b2014-12-23 10:41:52 -0800910 intel_crtc = intel_crtc ? intel_crtc : to_intel_crtc(plane->crtc);
911
Matt Ropercf4c7c12014-12-04 10:27:42 -0800912 if (!fb) {
913 state->visible = false;
Matt Roper32b7eee2014-12-24 07:59:06 -0800914 goto finish;
Matt Ropercf4c7c12014-12-04 10:27:42 -0800915 }
Jesse Barnes5e1bac22013-03-26 09:25:43 -0700916
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800917 /* Don't modify another pipe's plane */
Ville Syrjälä17316932013-04-24 18:52:38 +0300918 if (intel_plane->pipe != intel_crtc->pipe) {
919 DRM_DEBUG_KMS("Wrong plane <-> crtc mapping\n");
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800920 return -EINVAL;
Ville Syrjälä17316932013-04-24 18:52:38 +0300921 }
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 Barnesb840d907f2011-12-13 13:19:38 -0800928
Ville Syrjälä3c3686c2013-04-24 18:52:39 +0300929 /*
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ä17316932013-04-24 18:52:38 +0300934 max_scale = intel_plane->max_downscale << 16;
935 min_scale = intel_plane->can_scale ? 1 : (1 << 16);
936
Gustavo Padovan96d61a72014-09-05 17:04:47 -0300937 drm_rect_rotate(src, fb->width << 16, fb->height << 16,
Matt Roper8e7d6882015-01-21 16:35:41 -0800938 state->base.rotation);
Ville Syrjälä76eebda2014-08-05 11:26:52 +0530939
Gustavo Padovan96d61a72014-09-05 17:04:47 -0300940 hscale = drm_rect_calc_hscale_relaxed(src, dst, min_scale, max_scale);
Ville Syrjälä3c3686c2013-04-24 18:52:39 +0300941 BUG_ON(hscale < 0);
Ville Syrjälä17316932013-04-24 18:52:38 +0300942
Gustavo Padovan96d61a72014-09-05 17:04:47 -0300943 vscale = drm_rect_calc_vscale_relaxed(src, dst, min_scale, max_scale);
Ville Syrjälä3c3686c2013-04-24 18:52:39 +0300944 BUG_ON(vscale < 0);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800945
Gustavo Padovan96d61a72014-09-05 17:04:47 -0300946 state->visible = drm_rect_clip_scaled(src, dst, clip, hscale, vscale);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800947
Gustavo Padovan96d61a72014-09-05 17:04:47 -0300948 crtc_x = dst->x1;
949 crtc_y = dst->y1;
950 crtc_w = drm_rect_width(dst);
951 crtc_h = drm_rect_height(dst);
Damien Lespiau2d354c32012-10-22 18:19:27 +0100952
Gustavo Padovan96d61a72014-09-05 17:04:47 -0300953 if (state->visible) {
Ville Syrjälä3c3686c2013-04-24 18:52:39 +0300954 /* check again in case clipping clamped the results */
Gustavo Padovan96d61a72014-09-05 17:04:47 -0300955 hscale = drm_rect_calc_hscale(src, dst, min_scale, max_scale);
Ville Syrjälä3c3686c2013-04-24 18:52:39 +0300956 if (hscale < 0) {
957 DRM_DEBUG_KMS("Horizontal scaling factor out of limits\n");
Gustavo Padovan96d61a72014-09-05 17:04:47 -0300958 drm_rect_debug_print(src, true);
959 drm_rect_debug_print(dst, false);
Ville Syrjälä3c3686c2013-04-24 18:52:39 +0300960
961 return hscale;
962 }
963
Gustavo Padovan96d61a72014-09-05 17:04:47 -0300964 vscale = drm_rect_calc_vscale(src, dst, min_scale, max_scale);
Ville Syrjälä3c3686c2013-04-24 18:52:39 +0300965 if (vscale < 0) {
966 DRM_DEBUG_KMS("Vertical scaling factor out of limits\n");
Gustavo Padovan96d61a72014-09-05 17:04:47 -0300967 drm_rect_debug_print(src, true);
968 drm_rect_debug_print(dst, false);
Ville Syrjälä3c3686c2013-04-24 18:52:39 +0300969
970 return vscale;
971 }
972
Ville Syrjälä17316932013-04-24 18:52:38 +0300973 /* Make the source viewport size an exact multiple of the scaling factors. */
Gustavo Padovan96d61a72014-09-05 17:04:47 -0300974 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ä17316932013-04-24 18:52:38 +0300977
Gustavo Padovan96d61a72014-09-05 17:04:47 -0300978 drm_rect_rotate_inv(src, fb->width << 16, fb->height << 16,
Matt Roper8e7d6882015-01-21 16:35:41 -0800979 state->base.rotation);
Ville Syrjälä76eebda2014-08-05 11:26:52 +0530980
Ville Syrjälä17316932013-04-24 18:52:38 +0300981 /* sanity check to make sure the src viewport wasn't enlarged */
Matt Roperea2c67b2014-12-23 10:41:52 -0800982 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ä17316932013-04-24 18:52:38 +0300986
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ä17316932013-04-24 18:52:38 +0300992 */
Gustavo Padovan96d61a72014-09-05 17:04:47 -0300993 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ä17316932013-04-24 18:52:38 +0300997
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 Padovan96d61a72014-09-05 17:04:47 -03001010 state->visible = false;
Ville Syrjälä17316932013-04-24 18:52:38 +03001011 }
1012 }
1013
1014 /* Check size restrictions when scaling */
Gustavo Padovan96d61a72014-09-05 17:04:47 -03001015 if (state->visible && (src_w != crtc_w || src_h != crtc_h)) {
Ville Syrjälä17316932013-04-24 18:52:38 +03001016 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 Padovan96d61a72014-09-05 17:04:47 -03001023 state->visible = false;
Ville Syrjälä17316932013-04-24 18:52:38 +03001024
1025 if (src_w < 3 || src_h < 3)
Gustavo Padovan96d61a72014-09-05 17:04:47 -03001026 state->visible = false;
Ville Syrjälä17316932013-04-24 18:52:38 +03001027
Matt Ropercf4c7c12014-12-04 10:27:42 -08001028 pixel_size = drm_format_plane_cpp(fb->pixel_format, 0);
Gustavo Padovan96d61a72014-09-05 17:04:47 -03001029 width_bytes = ((src_x * pixel_size) & 63) +
1030 src_w * pixel_size;
Ville Syrjälä17316932013-04-24 18:52:38 +03001031
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 Padovan96d61a72014-09-05 17:04:47 -03001039 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 Roper32b7eee2014-12-24 07:59:06 -08001051finish:
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 Ursulin0fda6562015-02-27 15:12:35 +00001072
Tvrtko Ursulin1fc0a8f2015-03-23 11:10:38 +00001073 if (intel_wm_need_update(plane, &state->base))
Tvrtko Ursulin0fda6562015-02-27 15:12:35 +00001074 intel_crtc->atomic.update_wm = true;
Matt Roper08fd59f2015-03-18 15:04:47 -07001075
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 Roper32b7eee2014-12-24 07:59:06 -08001085 }
1086
Gustavo Padovan96d61a72014-09-05 17:04:47 -03001087 return 0;
1088}
1089
Gustavo Padovan34aa50a2014-10-24 14:51:32 +01001090static void
1091intel_commit_sprite_plane(struct drm_plane *plane,
1092 struct intel_plane_state *state)
1093{
Matt Roper2b875c22014-12-01 15:40:13 -08001094 struct drm_crtc *crtc = state->base.crtc;
Matt Roperea2c67b2014-12-23 10:41:52 -08001095 struct intel_crtc *intel_crtc;
Gustavo Padovan34aa50a2014-10-24 14:51:32 +01001096 struct intel_plane *intel_plane = to_intel_plane(plane);
Matt Roper2b875c22014-12-01 15:40:13 -08001097 struct drm_framebuffer *fb = state->base.fb;
Gustavo Padovan34aa50a2014-10-24 14:51:32 +01001098 int crtc_x, crtc_y;
1099 unsigned int crtc_w, crtc_h;
1100 uint32_t src_x, src_y, src_w, src_h;
Gustavo Padovan34aa50a2014-10-24 14:51:32 +01001101
Matt Roperea2c67b2014-12-23 10:41:52 -08001102 crtc = crtc ? crtc : plane->crtc;
1103 intel_crtc = to_intel_crtc(crtc);
1104
Ville Syrjäläbdd75542015-03-19 17:57:11 +02001105 plane->fb = fb;
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001106
Ville Syrjälä03c5b252013-10-01 18:02:11 +03001107 if (intel_crtc->active) {
Matt Roper32b7eee2014-12-24 07:59:06 -08001108 intel_crtc->primary_enabled = !state->hides_primary;
Jesse Barnes175bd422011-12-13 13:19:39 -08001109
Gustavo Padovan96d61a72014-09-05 17:04:47 -03001110 if (state->visible) {
1111 crtc_x = state->dst.x1;
Gustavo Padovane259f172014-09-11 17:42:15 -03001112 crtc_y = state->dst.y1;
Gustavo Padovan96d61a72014-09-05 17:04:47 -03001113 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äbdd75542015-03-19 17:57:11 +02001119 intel_plane->update_plane(plane, crtc, fb,
Ville Syrjälä03c5b252013-10-01 18:02:11 +03001120 crtc_x, crtc_y, crtc_w, crtc_h,
1121 src_x, src_y, src_w, src_h);
Gustavo Padovan96d61a72014-09-05 17:04:47 -03001122 } else {
Ville Syrjälä03c5b252013-10-01 18:02:11 +03001123 intel_plane->disable_plane(plane, crtc);
Gustavo Padovan96d61a72014-09-05 17:04:47 -03001124 }
Ville Syrjälä03c5b252013-10-01 18:02:11 +03001125 }
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001126}
1127
Jesse Barnes8ea30862012-01-03 08:05:39 -08001128int 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 Barnes8ea30862012-01-03 08:05:39 -08001132 struct drm_plane *plane;
1133 struct intel_plane *intel_plane;
1134 int ret = 0;
1135
Jesse Barnes8ea30862012-01-03 08:05:39 -08001136 /* 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ä47ecbb22015-03-19 21:18:57 +02001140 if (IS_VALLEYVIEW(dev) &&
1141 set->flags & I915_SET_COLORKEY_DESTINATION)
1142 return -EINVAL;
1143
Daniel Vettera0e99e62012-12-02 01:05:46 +01001144 drm_modeset_lock_all(dev);
Jesse Barnes8ea30862012-01-03 08:05:39 -08001145
Rob Clark7707e652014-07-17 23:30:04 -04001146 plane = drm_plane_find(dev, set->plane_id);
1147 if (!plane) {
Ville Syrjälä3f2c2052013-10-17 13:35:03 +03001148 ret = -ENOENT;
Jesse Barnes8ea30862012-01-03 08:05:39 -08001149 goto out_unlock;
1150 }
1151
Jesse Barnes8ea30862012-01-03 08:05:39 -08001152 intel_plane = to_intel_plane(plane);
Ville Syrjälä47ecbb22015-03-19 21:18:57 +02001153 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 Barnes8ea30862012-01-03 08:05:39 -08001162
1163out_unlock:
Daniel Vettera0e99e62012-12-02 01:05:46 +01001164 drm_modeset_unlock_all(dev);
Jesse Barnes8ea30862012-01-03 08:05:39 -08001165 return ret;
1166}
1167
Ville Syrjäläe57465f2014-08-05 11:26:53 +05301168int intel_plane_restore(struct drm_plane *plane)
Jesse Barnes5e1bac22013-03-26 09:25:43 -07001169{
Ville Syrjälä6e721fb2015-03-10 13:15:23 +02001170 if (!plane->crtc || !plane->state->fb)
Ville Syrjäläe57465f2014-08-05 11:26:53 +05301171 return 0;
Jesse Barnes5e1bac22013-03-26 09:25:43 -07001172
Matt Roper70a101f2015-04-08 18:56:53 -07001173 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 Barnes5e1bac22013-03-26 09:25:43 -07001178}
1179
Chris Wilsond1686ae2012-04-10 11:41:49 +01001180static 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 Barnesb840d907f2011-12-13 13:19:38 -08001188static 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 Barnes7f1f3852013-04-02 11:22:20 -07001197static 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 Lespiaudc2a41b2013-12-04 00:49:41 +00001211static 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 Barnesb840d907f2011-12-13 13:19:38 -08001223int
Jesse Barnes7f1f3852013-04-02 11:22:20 -07001224intel_plane_init(struct drm_device *dev, enum pipe pipe, int plane)
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001225{
1226 struct intel_plane *intel_plane;
Matt Roper8e7d6882015-01-21 16:35:41 -08001227 struct intel_plane_state *state;
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001228 unsigned long possible_crtcs;
Chris Wilsond1686ae2012-04-10 11:41:49 +01001229 const uint32_t *plane_formats;
1230 int num_plane_formats;
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001231 int ret;
1232
Chris Wilsond1686ae2012-04-10 11:41:49 +01001233 if (INTEL_INFO(dev)->gen < 5)
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001234 return -ENODEV;
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001235
Daniel Vetterb14c5672013-09-19 12:18:32 +02001236 intel_plane = kzalloc(sizeof(*intel_plane), GFP_KERNEL);
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001237 if (!intel_plane)
1238 return -ENOMEM;
1239
Matt Roper8e7d6882015-01-21 16:35:41 -08001240 state = intel_create_plane_state(&intel_plane->base);
1241 if (!state) {
Matt Roperea2c67b2014-12-23 10:41:52 -08001242 kfree(intel_plane);
1243 return -ENOMEM;
1244 }
Matt Roper8e7d6882015-01-21 16:35:41 -08001245 intel_plane->base.state = &state->base;
Matt Roperea2c67b2014-12-23 10:41:52 -08001246
Chris Wilsond1686ae2012-04-10 11:41:49 +01001247 switch (INTEL_INFO(dev)->gen) {
1248 case 5:
1249 case 6:
Damien Lespiau2d354c32012-10-22 18:19:27 +01001250 intel_plane->can_scale = true;
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001251 intel_plane->max_downscale = 16;
Chris Wilsond1686ae2012-04-10 11:41:49 +01001252 intel_plane->update_plane = ilk_update_plane;
1253 intel_plane->disable_plane = ilk_disable_plane;
Chris Wilsond1686ae2012-04-10 11:41:49 +01001254
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 Widawsky4e0bbc32013-11-02 21:07:07 -07001265 case 8:
Damien Lespiaud49f7092013-04-25 15:15:00 +01001266 if (IS_IVYBRIDGE(dev)) {
Damien Lespiau2d354c32012-10-22 18:19:27 +01001267 intel_plane->can_scale = true;
Damien Lespiaud49f7092013-04-25 15:15:00 +01001268 intel_plane->max_downscale = 2;
1269 } else {
1270 intel_plane->can_scale = false;
1271 intel_plane->max_downscale = 1;
1272 }
Chris Wilsond1686ae2012-04-10 11:41:49 +01001273
Jesse Barnes7f1f3852013-04-02 11:22:20 -07001274 if (IS_VALLEYVIEW(dev)) {
Jesse Barnes7f1f3852013-04-02 11:22:20 -07001275 intel_plane->update_plane = vlv_update_plane;
1276 intel_plane->disable_plane = vlv_disable_plane;
Jesse Barnes7f1f3852013-04-02 11:22:20 -07001277
1278 plane_formats = vlv_plane_formats;
1279 num_plane_formats = ARRAY_SIZE(vlv_plane_formats);
1280 } else {
Jesse Barnes7f1f3852013-04-02 11:22:20 -07001281 intel_plane->update_plane = ivb_update_plane;
1282 intel_plane->disable_plane = ivb_disable_plane;
Jesse Barnes7f1f3852013-04-02 11:22:20 -07001283
1284 plane_formats = snb_plane_formats;
1285 num_plane_formats = ARRAY_SIZE(snb_plane_formats);
1286 }
Chris Wilsond1686ae2012-04-10 11:41:49 +01001287 break;
Damien Lespiaudc2a41b2013-12-04 00:49:41 +00001288 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;
Chandra Konduru549e2bf2015-04-07 15:28:38 -07001297 state->scaler_id = -1;
Chris Wilsond1686ae2012-04-10 11:41:49 +01001298
Damien Lespiaudc2a41b2013-12-04 00:49:41 +00001299 plane_formats = skl_plane_formats;
1300 num_plane_formats = ARRAY_SIZE(skl_plane_formats);
1301 break;
Chris Wilsond1686ae2012-04-10 11:41:49 +01001302 default:
Jesper Juhla8b0bba2012-06-27 00:55:37 +02001303 kfree(intel_plane);
Chris Wilsond1686ae2012-04-10 11:41:49 +01001304 return -ENODEV;
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001305 }
1306
1307 intel_plane->pipe = pipe;
Jesse Barnes7f1f3852013-04-02 11:22:20 -07001308 intel_plane->plane = plane;
Matt Roperc59cb172014-12-01 15:40:16 -08001309 intel_plane->check_plane = intel_check_sprite_plane;
1310 intel_plane->commit_plane = intel_commit_sprite_plane;
Chandra Konduru08e221f2015-04-07 15:28:37 -07001311 intel_plane->ckey.flags = I915_SET_COLORKEY_NONE;
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001312 possible_crtcs = (1 << pipe);
Derek Foreman8fe8a3f2014-09-03 10:38:20 -03001313 ret = drm_universal_plane_init(dev, &intel_plane->base, possible_crtcs,
Matt Roper65a3fea2015-01-21 16:35:42 -08001314 &intel_plane_funcs,
Derek Foreman8fe8a3f2014-09-03 10:38:20 -03001315 plane_formats, num_plane_formats,
1316 DRM_PLANE_TYPE_OVERLAY);
Ville Syrjälä7ed6eee2014-08-05 11:26:55 +05301317 if (ret) {
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001318 kfree(intel_plane);
Ville Syrjälä7ed6eee2014-08-05 11:26:55 +05301319 goto out;
1320 }
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001321
Sonika Jindal3b7a5112015-04-10 14:37:29 +05301322 intel_create_rotation_property(dev, intel_plane);
Ville Syrjälä7ed6eee2014-08-05 11:26:55 +05301323
Matt Roperea2c67b2014-12-23 10:41:52 -08001324 drm_plane_helper_add(&intel_plane->base, &intel_plane_helper_funcs);
1325
Ville Syrjälä7ed6eee2014-08-05 11:26:55 +05301326 out:
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001327 return ret;
1328}