blob: bf1eb158e624e23f6b82e1449b999e46913367e5 [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>
Jesse Barnesb840d907f2011-12-13 13:19:38 -080036#include "intel_drv.h"
David Howells760285e2012-10-02 18:01:07 +010037#include <drm/i915_drm.h>
Jesse Barnesb840d907f2011-12-13 13:19:38 -080038#include "i915_drv.h"
39
Ville Syrjälä6ca2aeb2014-10-20 19:47:53 +030040static bool
41format_is_yuv(uint32_t format)
42{
43 switch (format) {
44 case DRM_FORMAT_YUYV:
45 case DRM_FORMAT_UYVY:
46 case DRM_FORMAT_VYUY:
47 case DRM_FORMAT_YVYU:
48 return true;
49 default:
50 return false;
51 }
52}
53
Ville Syrjälä8d7849d2014-04-29 13:35:46 +030054static int usecs_to_scanlines(const struct drm_display_mode *mode, int usecs)
55{
56 /* paranoia */
57 if (!mode->crtc_htotal)
58 return 1;
59
60 return DIV_ROUND_UP(usecs * mode->crtc_clock, 1000 * mode->crtc_htotal);
61}
62
63static bool intel_pipe_update_start(struct intel_crtc *crtc, uint32_t *start_vbl_count)
64{
65 struct drm_device *dev = crtc->base.dev;
66 const struct drm_display_mode *mode = &crtc->config.adjusted_mode;
67 enum pipe pipe = crtc->pipe;
68 long timeout = msecs_to_jiffies_timeout(1);
69 int scanline, min, max, vblank_start;
Ville Syrjälä210871b2014-05-22 19:00:50 +030070 wait_queue_head_t *wq = drm_crtc_vblank_waitqueue(&crtc->base);
Ville Syrjälä8d7849d2014-04-29 13:35:46 +030071 DEFINE_WAIT(wait);
72
Rob Clark51fd3712013-11-19 12:10:12 -050073 WARN_ON(!drm_modeset_is_locked(&crtc->base.mutex));
Ville Syrjälä8d7849d2014-04-29 13:35:46 +030074
75 vblank_start = mode->crtc_vblank_start;
76 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
77 vblank_start = DIV_ROUND_UP(vblank_start, 2);
78
79 /* FIXME needs to be calibrated sensibly */
80 min = vblank_start - usecs_to_scanlines(mode, 100);
81 max = vblank_start - 1;
82
83 if (min <= 0 || max <= 0)
84 return false;
85
86 if (WARN_ON(drm_vblank_get(dev, pipe)))
87 return false;
88
89 local_irq_disable();
90
Ville Syrjälä25ef2842014-04-29 13:35:48 +030091 trace_i915_pipe_update_start(crtc, min, max);
92
Ville Syrjälä8d7849d2014-04-29 13:35:46 +030093 for (;;) {
94 /*
95 * prepare_to_wait() has a memory barrier, which guarantees
96 * other CPUs can see the task state update by the time we
97 * read the scanline.
98 */
Ville Syrjälä210871b2014-05-22 19:00:50 +030099 prepare_to_wait(wq, &wait, TASK_UNINTERRUPTIBLE);
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300100
101 scanline = intel_get_crtc_scanline(crtc);
102 if (scanline < min || scanline > max)
103 break;
104
105 if (timeout <= 0) {
106 DRM_ERROR("Potential atomic update failure on pipe %c\n",
107 pipe_name(crtc->pipe));
108 break;
109 }
110
111 local_irq_enable();
112
113 timeout = schedule_timeout(timeout);
114
115 local_irq_disable();
116 }
117
Ville Syrjälä210871b2014-05-22 19:00:50 +0300118 finish_wait(wq, &wait);
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300119
120 drm_vblank_put(dev, pipe);
121
122 *start_vbl_count = dev->driver->get_vblank_counter(dev, pipe);
123
Ville Syrjälä25ef2842014-04-29 13:35:48 +0300124 trace_i915_pipe_update_vblank_evaded(crtc, min, max, *start_vbl_count);
125
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300126 return true;
127}
128
129static void intel_pipe_update_end(struct intel_crtc *crtc, u32 start_vbl_count)
130{
131 struct drm_device *dev = crtc->base.dev;
132 enum pipe pipe = crtc->pipe;
133 u32 end_vbl_count = dev->driver->get_vblank_counter(dev, pipe);
134
Ville Syrjälä25ef2842014-04-29 13:35:48 +0300135 trace_i915_pipe_update_end(crtc, end_vbl_count);
136
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300137 local_irq_enable();
138
139 if (start_vbl_count != end_vbl_count)
140 DRM_ERROR("Atomic update failure on pipe %c (start=%u end=%u)\n",
141 pipe_name(pipe), start_vbl_count, end_vbl_count);
142}
143
Ville Syrjälä5b633d62014-04-29 13:35:47 +0300144static void intel_update_primary_plane(struct intel_crtc *crtc)
145{
146 struct drm_i915_private *dev_priv = crtc->base.dev->dev_private;
147 int reg = DSPCNTR(crtc->plane);
148
149 if (crtc->primary_enabled)
150 I915_WRITE(reg, I915_READ(reg) | DISPLAY_PLANE_ENABLE);
151 else
152 I915_WRITE(reg, I915_READ(reg) & ~DISPLAY_PLANE_ENABLE);
153}
154
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800155static void
Damien Lespiaudc2a41b2013-12-04 00:49:41 +0000156skl_update_plane(struct drm_plane *drm_plane, struct drm_crtc *crtc,
157 struct drm_framebuffer *fb,
158 struct drm_i915_gem_object *obj, int crtc_x, int crtc_y,
159 unsigned int crtc_w, unsigned int crtc_h,
160 uint32_t x, uint32_t y,
161 uint32_t src_w, uint32_t src_h)
162{
163 struct drm_device *dev = drm_plane->dev;
164 struct drm_i915_private *dev_priv = dev->dev_private;
165 struct intel_plane *intel_plane = to_intel_plane(drm_plane);
166 const int pipe = intel_plane->pipe;
167 const int plane = intel_plane->plane + 1;
168 u32 plane_ctl, stride;
169 int pixel_size = drm_format_plane_cpp(fb->pixel_format, 0);
170
171 plane_ctl = I915_READ(PLANE_CTL(pipe, plane));
172
173 /* Mask out pixel format bits in case we change it */
174 plane_ctl &= ~PLANE_CTL_FORMAT_MASK;
175 plane_ctl &= ~PLANE_CTL_ORDER_RGBX;
176 plane_ctl &= ~PLANE_CTL_YUV422_ORDER_MASK;
177 plane_ctl &= ~PLANE_CTL_TILED_MASK;
178 plane_ctl &= ~PLANE_CTL_ALPHA_MASK;
Sonika Jindal1447dde2014-10-04 10:53:31 +0100179 plane_ctl &= ~PLANE_CTL_ROTATE_MASK;
Damien Lespiaudc2a41b2013-12-04 00:49:41 +0000180
181 /* Trickle feed has to be enabled */
182 plane_ctl &= ~PLANE_CTL_TRICKLE_FEED_DISABLE;
183
184 switch (fb->pixel_format) {
185 case DRM_FORMAT_RGB565:
186 plane_ctl |= PLANE_CTL_FORMAT_RGB_565;
187 break;
188 case DRM_FORMAT_XBGR8888:
189 plane_ctl |= PLANE_CTL_FORMAT_XRGB_8888 | PLANE_CTL_ORDER_RGBX;
190 break;
191 case DRM_FORMAT_XRGB8888:
192 plane_ctl |= PLANE_CTL_FORMAT_XRGB_8888;
193 break;
194 /*
195 * XXX: For ARBG/ABGR formats we default to expecting scanout buffers
196 * to be already pre-multiplied. We need to add a knob (or a different
197 * DRM_FORMAT) for user-space to configure that.
198 */
199 case DRM_FORMAT_ABGR8888:
200 plane_ctl |= PLANE_CTL_FORMAT_XRGB_8888 |
201 PLANE_CTL_ORDER_RGBX |
202 PLANE_CTL_ALPHA_SW_PREMULTIPLY;
203 break;
204 case DRM_FORMAT_ARGB8888:
205 plane_ctl |= PLANE_CTL_FORMAT_XRGB_8888 |
206 PLANE_CTL_ALPHA_SW_PREMULTIPLY;
207 break;
208 case DRM_FORMAT_YUYV:
209 plane_ctl |= PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YUYV;
210 break;
211 case DRM_FORMAT_YVYU:
212 plane_ctl |= PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YVYU;
213 break;
214 case DRM_FORMAT_UYVY:
215 plane_ctl |= PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_UYVY;
216 break;
217 case DRM_FORMAT_VYUY:
218 plane_ctl |= PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_VYUY;
219 break;
220 default:
221 BUG();
222 }
223
224 switch (obj->tiling_mode) {
225 case I915_TILING_NONE:
226 stride = fb->pitches[0] >> 6;
227 break;
228 case I915_TILING_X:
229 plane_ctl |= PLANE_CTL_TILED_X;
230 stride = fb->pitches[0] >> 9;
231 break;
232 default:
233 BUG();
234 }
Sonika Jindal1447dde2014-10-04 10:53:31 +0100235 if (intel_plane->rotation == BIT(DRM_ROTATE_180))
236 plane_ctl |= PLANE_CTL_ROTATE_180;
Damien Lespiaudc2a41b2013-12-04 00:49:41 +0000237
238 plane_ctl |= PLANE_CTL_ENABLE;
239 plane_ctl |= PLANE_CTL_PIPE_CSC_ENABLE;
240
241 intel_update_sprite_watermarks(drm_plane, crtc, src_w, src_h,
242 pixel_size, true,
243 src_w != crtc_w || src_h != crtc_h);
244
245 /* Sizes are 0 based */
246 src_w--;
247 src_h--;
248 crtc_w--;
249 crtc_h--;
250
251 I915_WRITE(PLANE_OFFSET(pipe, plane), (y << 16) | x);
252 I915_WRITE(PLANE_STRIDE(pipe, plane), stride);
253 I915_WRITE(PLANE_POS(pipe, plane), (crtc_y << 16) | crtc_x);
254 I915_WRITE(PLANE_SIZE(pipe, plane), (crtc_h << 16) | crtc_w);
255 I915_WRITE(PLANE_CTL(pipe, plane), plane_ctl);
256 I915_WRITE(PLANE_SURF(pipe, plane), i915_gem_obj_ggtt_offset(obj));
257 POSTING_READ(PLANE_SURF(pipe, plane));
258}
259
260static void
261skl_disable_plane(struct drm_plane *drm_plane, struct drm_crtc *crtc)
262{
263 struct drm_device *dev = drm_plane->dev;
264 struct drm_i915_private *dev_priv = dev->dev_private;
265 struct intel_plane *intel_plane = to_intel_plane(drm_plane);
266 const int pipe = intel_plane->pipe;
267 const int plane = intel_plane->plane + 1;
268
269 I915_WRITE(PLANE_CTL(pipe, plane),
270 I915_READ(PLANE_CTL(pipe, plane)) & ~PLANE_CTL_ENABLE);
271
272 /* Activate double buffered register update */
273 I915_WRITE(PLANE_CTL(pipe, plane), 0);
274 POSTING_READ(PLANE_CTL(pipe, plane));
275
276 intel_update_sprite_watermarks(drm_plane, crtc, 0, 0, 0, false, false);
277}
278
279static int
280skl_update_colorkey(struct drm_plane *drm_plane,
281 struct drm_intel_sprite_colorkey *key)
282{
283 struct drm_device *dev = drm_plane->dev;
284 struct drm_i915_private *dev_priv = dev->dev_private;
285 struct intel_plane *intel_plane = to_intel_plane(drm_plane);
286 const int pipe = intel_plane->pipe;
287 const int plane = intel_plane->plane;
288 u32 plane_ctl;
289
290 I915_WRITE(PLANE_KEYVAL(pipe, plane), key->min_value);
291 I915_WRITE(PLANE_KEYMAX(pipe, plane), key->max_value);
292 I915_WRITE(PLANE_KEYMSK(pipe, plane), key->channel_mask);
293
294 plane_ctl = I915_READ(PLANE_CTL(pipe, plane));
295 plane_ctl &= ~PLANE_CTL_KEY_ENABLE_MASK;
296 if (key->flags & I915_SET_COLORKEY_DESTINATION)
297 plane_ctl |= PLANE_CTL_KEY_ENABLE_DESTINATION;
298 else if (key->flags & I915_SET_COLORKEY_SOURCE)
299 plane_ctl |= PLANE_CTL_KEY_ENABLE_SOURCE;
300 I915_WRITE(PLANE_CTL(pipe, plane), plane_ctl);
301
302 POSTING_READ(PLANE_CTL(pipe, plane));
303
304 return 0;
305}
306
307static void
308skl_get_colorkey(struct drm_plane *drm_plane,
309 struct drm_intel_sprite_colorkey *key)
310{
311 struct drm_device *dev = drm_plane->dev;
312 struct drm_i915_private *dev_priv = dev->dev_private;
313 struct intel_plane *intel_plane = to_intel_plane(drm_plane);
314 const int pipe = intel_plane->pipe;
315 const int plane = intel_plane->plane;
316 u32 plane_ctl;
317
318 key->min_value = I915_READ(PLANE_KEYVAL(pipe, plane));
319 key->max_value = I915_READ(PLANE_KEYMAX(pipe, plane));
320 key->channel_mask = I915_READ(PLANE_KEYMSK(pipe, plane));
321
322 plane_ctl = I915_READ(PLANE_CTL(pipe, plane));
323
324 switch (plane_ctl & PLANE_CTL_KEY_ENABLE_MASK) {
325 case PLANE_CTL_KEY_ENABLE_DESTINATION:
326 key->flags = I915_SET_COLORKEY_DESTINATION;
327 break;
328 case PLANE_CTL_KEY_ENABLE_SOURCE:
329 key->flags = I915_SET_COLORKEY_SOURCE;
330 break;
331 default:
332 key->flags = I915_SET_COLORKEY_NONE;
333 }
334}
335
336static void
Ville Syrjälä6ca2aeb2014-10-20 19:47:53 +0300337chv_update_csc(struct intel_plane *intel_plane, uint32_t format)
338{
339 struct drm_i915_private *dev_priv = intel_plane->base.dev->dev_private;
340 int plane = intel_plane->plane;
341
342 /* Seems RGB data bypasses the CSC always */
343 if (!format_is_yuv(format))
344 return;
345
346 /*
347 * BT.601 limited range YCbCr -> full range RGB
348 *
349 * |r| | 6537 4769 0| |cr |
350 * |g| = |-3330 4769 -1605| x |y-64|
351 * |b| | 0 4769 8263| |cb |
352 *
353 * Cb and Cr apparently come in as signed already, so no
354 * need for any offset. For Y we need to remove the offset.
355 */
356 I915_WRITE(SPCSCYGOFF(plane), SPCSC_OOFF(0) | SPCSC_IOFF(-64));
357 I915_WRITE(SPCSCCBOFF(plane), SPCSC_OOFF(0) | SPCSC_IOFF(0));
358 I915_WRITE(SPCSCCROFF(plane), SPCSC_OOFF(0) | SPCSC_IOFF(0));
359
360 I915_WRITE(SPCSCC01(plane), SPCSC_C1(4769) | SPCSC_C0(6537));
361 I915_WRITE(SPCSCC23(plane), SPCSC_C1(-3330) | SPCSC_C0(0));
362 I915_WRITE(SPCSCC45(plane), SPCSC_C1(-1605) | SPCSC_C0(4769));
363 I915_WRITE(SPCSCC67(plane), SPCSC_C1(4769) | SPCSC_C0(0));
364 I915_WRITE(SPCSCC8(plane), SPCSC_C0(8263));
365
366 I915_WRITE(SPCSCYGICLAMP(plane), SPCSC_IMAX(940) | SPCSC_IMIN(64));
367 I915_WRITE(SPCSCCBICLAMP(plane), SPCSC_IMAX(448) | SPCSC_IMIN(-448));
368 I915_WRITE(SPCSCCRICLAMP(plane), SPCSC_IMAX(448) | SPCSC_IMIN(-448));
369
370 I915_WRITE(SPCSCYGOCLAMP(plane), SPCSC_OMAX(1023) | SPCSC_OMIN(0));
371 I915_WRITE(SPCSCCBOCLAMP(plane), SPCSC_OMAX(1023) | SPCSC_OMIN(0));
372 I915_WRITE(SPCSCCROCLAMP(plane), SPCSC_OMAX(1023) | SPCSC_OMIN(0));
373}
374
375static void
Ville Syrjäläb39d53f2013-08-06 22:24:09 +0300376vlv_update_plane(struct drm_plane *dplane, struct drm_crtc *crtc,
377 struct drm_framebuffer *fb,
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700378 struct drm_i915_gem_object *obj, int crtc_x, int crtc_y,
379 unsigned int crtc_w, unsigned int crtc_h,
380 uint32_t x, uint32_t y,
381 uint32_t src_w, uint32_t src_h)
382{
383 struct drm_device *dev = dplane->dev;
384 struct drm_i915_private *dev_priv = dev->dev_private;
385 struct intel_plane *intel_plane = to_intel_plane(dplane);
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300386 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700387 int pipe = intel_plane->pipe;
388 int plane = intel_plane->plane;
389 u32 sprctl;
390 unsigned long sprsurf_offset, linear_offset;
391 int pixel_size = drm_format_plane_cpp(fb->pixel_format, 0);
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300392 u32 start_vbl_count;
393 bool atomic_update;
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700394
395 sprctl = I915_READ(SPCNTR(pipe, plane));
396
397 /* Mask out pixel format bits in case we change it */
398 sprctl &= ~SP_PIXFORMAT_MASK;
399 sprctl &= ~SP_YUV_BYTE_ORDER_MASK;
400 sprctl &= ~SP_TILED;
Ville Syrjälä76eebda2014-08-05 11:26:52 +0530401 sprctl &= ~SP_ROTATE_180;
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700402
403 switch (fb->pixel_format) {
404 case DRM_FORMAT_YUYV:
405 sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_YUYV;
406 break;
407 case DRM_FORMAT_YVYU:
408 sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_YVYU;
409 break;
410 case DRM_FORMAT_UYVY:
411 sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_UYVY;
412 break;
413 case DRM_FORMAT_VYUY:
414 sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_VYUY;
415 break;
416 case DRM_FORMAT_RGB565:
417 sprctl |= SP_FORMAT_BGR565;
418 break;
419 case DRM_FORMAT_XRGB8888:
420 sprctl |= SP_FORMAT_BGRX8888;
421 break;
422 case DRM_FORMAT_ARGB8888:
423 sprctl |= SP_FORMAT_BGRA8888;
424 break;
425 case DRM_FORMAT_XBGR2101010:
426 sprctl |= SP_FORMAT_RGBX1010102;
427 break;
428 case DRM_FORMAT_ABGR2101010:
429 sprctl |= SP_FORMAT_RGBA1010102;
430 break;
431 case DRM_FORMAT_XBGR8888:
432 sprctl |= SP_FORMAT_RGBX8888;
433 break;
434 case DRM_FORMAT_ABGR8888:
435 sprctl |= SP_FORMAT_RGBA8888;
436 break;
437 default:
438 /*
439 * If we get here one of the upper layers failed to filter
440 * out the unsupported plane formats
441 */
442 BUG();
443 break;
444 }
445
Ville Syrjälä4ea67bc2013-11-18 18:32:38 -0800446 /*
447 * Enable gamma to match primary/cursor plane behaviour.
448 * FIXME should be user controllable via propertiesa.
449 */
450 sprctl |= SP_GAMMA_ENABLE;
451
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700452 if (obj->tiling_mode != I915_TILING_NONE)
453 sprctl |= SP_TILED;
454
455 sprctl |= SP_ENABLE;
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
Ville Syrjälä76eebda2014-08-05 11:26:52 +0530474 if (intel_plane->rotation == BIT(DRM_ROTATE_180)) {
475 sprctl |= SP_ROTATE_180;
476
477 x += src_w;
478 y += src_h;
479 linear_offset += src_h * fb->pitches[0] + src_w * pixel_size;
480 }
481
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300482 atomic_update = intel_pipe_update_start(intel_crtc, &start_vbl_count);
483
Ville Syrjälä5b633d62014-04-29 13:35:47 +0300484 intel_update_primary_plane(intel_crtc);
485
Ville Syrjälä6ca2aeb2014-10-20 19:47:53 +0300486 if (IS_CHERRYVIEW(dev) && pipe == PIPE_B)
487 chv_update_csc(intel_plane, fb->pixel_format);
488
Ville Syrjäläca6ad022014-01-17 20:09:03 +0200489 I915_WRITE(SPSTRIDE(pipe, plane), fb->pitches[0]);
490 I915_WRITE(SPPOS(pipe, plane), (crtc_y << 16) | crtc_x);
491
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700492 if (obj->tiling_mode != I915_TILING_NONE)
493 I915_WRITE(SPTILEOFF(pipe, plane), (y << 16) | x);
494 else
495 I915_WRITE(SPLINOFF(pipe, plane), linear_offset);
496
Ville Syrjäläc14b0482014-10-16 20:52:34 +0300497 I915_WRITE(SPCONSTALPHA(pipe, plane), 0);
498
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700499 I915_WRITE(SPSIZE(pipe, plane), (crtc_h << 16) | crtc_w);
500 I915_WRITE(SPCNTR(pipe, plane), sprctl);
Daniel Vetter85ba7b72014-01-24 10:31:44 +0100501 I915_WRITE(SPSURF(pipe, plane), i915_gem_obj_ggtt_offset(obj) +
502 sprsurf_offset);
Ville Syrjälä5b633d62014-04-29 13:35:47 +0300503
504 intel_flush_primary_plane(dev_priv, intel_crtc->plane);
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300505
506 if (atomic_update)
507 intel_pipe_update_end(intel_crtc, start_vbl_count);
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700508}
509
510static void
Ville Syrjäläb39d53f2013-08-06 22:24:09 +0300511vlv_disable_plane(struct drm_plane *dplane, struct drm_crtc *crtc)
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700512{
513 struct drm_device *dev = dplane->dev;
514 struct drm_i915_private *dev_priv = dev->dev_private;
515 struct intel_plane *intel_plane = to_intel_plane(dplane);
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300516 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700517 int pipe = intel_plane->pipe;
518 int plane = intel_plane->plane;
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300519 u32 start_vbl_count;
520 bool atomic_update;
521
522 atomic_update = intel_pipe_update_start(intel_crtc, &start_vbl_count);
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700523
Ville Syrjälä5b633d62014-04-29 13:35:47 +0300524 intel_update_primary_plane(intel_crtc);
525
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700526 I915_WRITE(SPCNTR(pipe, plane), I915_READ(SPCNTR(pipe, plane)) &
527 ~SP_ENABLE);
528 /* 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
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300533 if (atomic_update)
534 intel_pipe_update_end(intel_crtc, start_vbl_count);
535
Damien Lespiaued57cb82014-07-15 09:21:24 +0200536 intel_update_sprite_watermarks(dplane, crtc, 0, 0, 0, false, false);
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700537}
538
539static int
540vlv_update_colorkey(struct drm_plane *dplane,
541 struct drm_intel_sprite_colorkey *key)
542{
543 struct drm_device *dev = dplane->dev;
544 struct drm_i915_private *dev_priv = dev->dev_private;
545 struct intel_plane *intel_plane = to_intel_plane(dplane);
546 int pipe = intel_plane->pipe;
547 int plane = intel_plane->plane;
548 u32 sprctl;
549
550 if (key->flags & I915_SET_COLORKEY_DESTINATION)
551 return -EINVAL;
552
553 I915_WRITE(SPKEYMINVAL(pipe, plane), key->min_value);
554 I915_WRITE(SPKEYMAXVAL(pipe, plane), key->max_value);
555 I915_WRITE(SPKEYMSK(pipe, plane), key->channel_mask);
556
557 sprctl = I915_READ(SPCNTR(pipe, plane));
558 sprctl &= ~SP_SOURCE_KEY;
559 if (key->flags & I915_SET_COLORKEY_SOURCE)
560 sprctl |= SP_SOURCE_KEY;
561 I915_WRITE(SPCNTR(pipe, plane), sprctl);
562
563 POSTING_READ(SPKEYMSK(pipe, plane));
564
565 return 0;
566}
567
568static void
569vlv_get_colorkey(struct drm_plane *dplane,
570 struct drm_intel_sprite_colorkey *key)
571{
572 struct drm_device *dev = dplane->dev;
573 struct drm_i915_private *dev_priv = dev->dev_private;
574 struct intel_plane *intel_plane = to_intel_plane(dplane);
575 int pipe = intel_plane->pipe;
576 int plane = intel_plane->plane;
577 u32 sprctl;
578
579 key->min_value = I915_READ(SPKEYMINVAL(pipe, plane));
580 key->max_value = I915_READ(SPKEYMAXVAL(pipe, plane));
581 key->channel_mask = I915_READ(SPKEYMSK(pipe, plane));
582
583 sprctl = I915_READ(SPCNTR(pipe, plane));
584 if (sprctl & SP_SOURCE_KEY)
585 key->flags = I915_SET_COLORKEY_SOURCE;
586 else
587 key->flags = I915_SET_COLORKEY_NONE;
588}
589
590static void
Ville Syrjäläb39d53f2013-08-06 22:24:09 +0300591ivb_update_plane(struct drm_plane *plane, struct drm_crtc *crtc,
592 struct drm_framebuffer *fb,
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800593 struct drm_i915_gem_object *obj, int crtc_x, int crtc_y,
594 unsigned int crtc_w, unsigned int crtc_h,
595 uint32_t x, uint32_t y,
596 uint32_t src_w, uint32_t src_h)
597{
598 struct drm_device *dev = plane->dev;
599 struct drm_i915_private *dev_priv = dev->dev_private;
600 struct intel_plane *intel_plane = to_intel_plane(plane);
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300601 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800602 int pipe = intel_plane->pipe;
603 u32 sprctl, sprscale = 0;
Damien Lespiau5a35e992012-10-26 18:20:12 +0100604 unsigned long sprsurf_offset, linear_offset;
Ville Syrjälä2bd3c3c2012-10-31 17:50:20 +0200605 int pixel_size = drm_format_plane_cpp(fb->pixel_format, 0);
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300606 u32 start_vbl_count;
607 bool atomic_update;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800608
609 sprctl = I915_READ(SPRCTL(pipe));
610
611 /* Mask out pixel format bits in case we change it */
612 sprctl &= ~SPRITE_PIXFORMAT_MASK;
613 sprctl &= ~SPRITE_RGB_ORDER_RGBX;
614 sprctl &= ~SPRITE_YUV_BYTE_ORDER_MASK;
Jesse Barnese86fe0d2012-06-26 13:10:11 -0700615 sprctl &= ~SPRITE_TILED;
Ville Syrjälä76eebda2014-08-05 11:26:52 +0530616 sprctl &= ~SPRITE_ROTATE_180;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800617
618 switch (fb->pixel_format) {
619 case DRM_FORMAT_XBGR8888:
Vijay Purushothaman5ee36912012-08-23 12:08:57 +0530620 sprctl |= SPRITE_FORMAT_RGBX888 | SPRITE_RGB_ORDER_RGBX;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800621 break;
622 case DRM_FORMAT_XRGB8888:
Vijay Purushothaman5ee36912012-08-23 12:08:57 +0530623 sprctl |= SPRITE_FORMAT_RGBX888;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800624 break;
625 case DRM_FORMAT_YUYV:
626 sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_YUYV;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800627 break;
628 case DRM_FORMAT_YVYU:
629 sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_YVYU;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800630 break;
631 case DRM_FORMAT_UYVY:
632 sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_UYVY;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800633 break;
634 case DRM_FORMAT_VYUY:
635 sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_VYUY;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800636 break;
637 default:
Ville Syrjälä28d491d2012-10-31 17:50:21 +0200638 BUG();
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800639 }
640
Ville Syrjälä4ea67bc2013-11-18 18:32:38 -0800641 /*
642 * Enable gamma to match primary/cursor plane behaviour.
643 * FIXME should be user controllable via propertiesa.
644 */
645 sprctl |= SPRITE_GAMMA_ENABLE;
646
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800647 if (obj->tiling_mode != I915_TILING_NONE)
648 sprctl |= SPRITE_TILED;
649
Ville Syrjäläb42c6002013-11-03 13:47:27 +0200650 if (IS_HASWELL(dev) || IS_BROADWELL(dev))
Paulo Zanoni1f5d76d2013-08-23 19:51:28 -0300651 sprctl &= ~SPRITE_TRICKLE_FEED_DISABLE;
652 else
653 sprctl |= SPRITE_TRICKLE_FEED_DISABLE;
654
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800655 sprctl |= SPRITE_ENABLE;
656
Ville Syrjälä6bbfa1c2013-11-02 21:07:39 -0700657 if (IS_HASWELL(dev) || IS_BROADWELL(dev))
Ville Syrjälä86d3efc2013-01-18 19:11:38 +0200658 sprctl |= SPRITE_PIPE_CSC_ENABLE;
659
Damien Lespiaued57cb82014-07-15 09:21:24 +0200660 intel_update_sprite_watermarks(plane, crtc, src_w, src_h, pixel_size,
661 true,
Ville Syrjälä67ca28f2013-07-05 11:57:14 +0300662 src_w != crtc_w || src_h != crtc_h);
663
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800664 /* Sizes are 0 based */
665 src_w--;
666 src_h--;
667 crtc_w--;
668 crtc_h--;
669
Ville Syrjälä8553c182013-12-05 15:51:39 +0200670 if (crtc_w != src_w || crtc_h != src_h)
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800671 sprscale = SPRITE_SCALE_ENABLE | (src_w << 16) | src_h;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800672
Chris Wilsonca320ac2012-12-19 12:14:22 +0000673 linear_offset = y * fb->pitches[0] + x * pixel_size;
Damien Lespiau5a35e992012-10-26 18:20:12 +0100674 sprsurf_offset =
Chris Wilsonbc752862013-02-21 20:04:31 +0000675 intel_gen4_compute_page_offset(&x, &y, obj->tiling_mode,
676 pixel_size, fb->pitches[0]);
Damien Lespiau5a35e992012-10-26 18:20:12 +0100677 linear_offset -= sprsurf_offset;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800678
Ville Syrjälä76eebda2014-08-05 11:26:52 +0530679 if (intel_plane->rotation == BIT(DRM_ROTATE_180)) {
680 sprctl |= SPRITE_ROTATE_180;
681
682 /* HSW and BDW does this automagically in hardware */
683 if (!IS_HASWELL(dev) && !IS_BROADWELL(dev)) {
684 x += src_w;
685 y += src_h;
686 linear_offset += src_h * fb->pitches[0] +
687 src_w * pixel_size;
688 }
689 }
690
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300691 atomic_update = intel_pipe_update_start(intel_crtc, &start_vbl_count);
692
Ville Syrjälä5b633d62014-04-29 13:35:47 +0300693 intel_update_primary_plane(intel_crtc);
694
Ville Syrjäläca6ad022014-01-17 20:09:03 +0200695 I915_WRITE(SPRSTRIDE(pipe), fb->pitches[0]);
696 I915_WRITE(SPRPOS(pipe), (crtc_y << 16) | crtc_x);
697
Damien Lespiau5a35e992012-10-26 18:20:12 +0100698 /* HSW consolidates SPRTILEOFF and SPRLINOFF into a single SPROFFSET
699 * register */
Paulo Zanonib3dc6852013-11-02 21:07:33 -0700700 if (IS_HASWELL(dev) || IS_BROADWELL(dev))
Damien Lespiau5a35e992012-10-26 18:20:12 +0100701 I915_WRITE(SPROFFSET(pipe), (y << 16) | x);
702 else if (obj->tiling_mode != I915_TILING_NONE)
703 I915_WRITE(SPRTILEOFF(pipe), (y << 16) | x);
704 else
705 I915_WRITE(SPRLINOFF(pipe), linear_offset);
Damien Lespiauc54173a2012-10-26 18:20:11 +0100706
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800707 I915_WRITE(SPRSIZE(pipe), (crtc_h << 16) | crtc_w);
Damien Lespiau2d354c32012-10-22 18:19:27 +0100708 if (intel_plane->can_scale)
709 I915_WRITE(SPRSCALE(pipe), sprscale);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800710 I915_WRITE(SPRCTL(pipe), sprctl);
Daniel Vetter85ba7b72014-01-24 10:31:44 +0100711 I915_WRITE(SPRSURF(pipe),
712 i915_gem_obj_ggtt_offset(obj) + sprsurf_offset);
Ville Syrjälä5b633d62014-04-29 13:35:47 +0300713
714 intel_flush_primary_plane(dev_priv, intel_crtc->plane);
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300715
716 if (atomic_update)
717 intel_pipe_update_end(intel_crtc, start_vbl_count);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800718}
719
720static void
Ville Syrjäläb39d53f2013-08-06 22:24:09 +0300721ivb_disable_plane(struct drm_plane *plane, struct drm_crtc *crtc)
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800722{
723 struct drm_device *dev = plane->dev;
724 struct drm_i915_private *dev_priv = dev->dev_private;
725 struct intel_plane *intel_plane = to_intel_plane(plane);
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300726 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800727 int pipe = intel_plane->pipe;
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300728 u32 start_vbl_count;
729 bool atomic_update;
730
731 atomic_update = intel_pipe_update_start(intel_crtc, &start_vbl_count);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800732
Ville Syrjälä5b633d62014-04-29 13:35:47 +0300733 intel_update_primary_plane(intel_crtc);
734
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800735 I915_WRITE(SPRCTL(pipe), I915_READ(SPRCTL(pipe)) & ~SPRITE_ENABLE);
736 /* Can't leave the scaler enabled... */
Damien Lespiau2d354c32012-10-22 18:19:27 +0100737 if (intel_plane->can_scale)
738 I915_WRITE(SPRSCALE(pipe), 0);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800739 /* Activate double buffered register update */
Daniel Vetter85ba7b72014-01-24 10:31:44 +0100740 I915_WRITE(SPRSURF(pipe), 0);
Ville Syrjälä5b633d62014-04-29 13:35:47 +0300741
742 intel_flush_primary_plane(dev_priv, intel_crtc->plane);
Chris Wilson828ed3e2012-04-18 17:12:26 +0100743
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300744 if (atomic_update)
745 intel_pipe_update_end(intel_crtc, start_vbl_count);
746
Ville Syrjälä1bd09ec2013-12-05 15:51:41 +0200747 /*
748 * Avoid underruns when disabling the sprite.
749 * FIXME remove once watermark updates are done properly.
750 */
751 intel_wait_for_vblank(dev, pipe);
752
Damien Lespiaued57cb82014-07-15 09:21:24 +0200753 intel_update_sprite_watermarks(plane, crtc, 0, 0, 0, false, false);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800754}
755
Jesse Barnes8ea30862012-01-03 08:05:39 -0800756static int
757ivb_update_colorkey(struct drm_plane *plane,
758 struct drm_intel_sprite_colorkey *key)
759{
760 struct drm_device *dev = plane->dev;
761 struct drm_i915_private *dev_priv = dev->dev_private;
762 struct intel_plane *intel_plane;
763 u32 sprctl;
764 int ret = 0;
765
766 intel_plane = to_intel_plane(plane);
767
768 I915_WRITE(SPRKEYVAL(intel_plane->pipe), key->min_value);
769 I915_WRITE(SPRKEYMAX(intel_plane->pipe), key->max_value);
770 I915_WRITE(SPRKEYMSK(intel_plane->pipe), key->channel_mask);
771
772 sprctl = I915_READ(SPRCTL(intel_plane->pipe));
773 sprctl &= ~(SPRITE_SOURCE_KEY | SPRITE_DEST_KEY);
774 if (key->flags & I915_SET_COLORKEY_DESTINATION)
775 sprctl |= SPRITE_DEST_KEY;
776 else if (key->flags & I915_SET_COLORKEY_SOURCE)
777 sprctl |= SPRITE_SOURCE_KEY;
778 I915_WRITE(SPRCTL(intel_plane->pipe), sprctl);
779
780 POSTING_READ(SPRKEYMSK(intel_plane->pipe));
781
782 return ret;
783}
784
785static void
786ivb_get_colorkey(struct drm_plane *plane, struct drm_intel_sprite_colorkey *key)
787{
788 struct drm_device *dev = plane->dev;
789 struct drm_i915_private *dev_priv = dev->dev_private;
790 struct intel_plane *intel_plane;
791 u32 sprctl;
792
793 intel_plane = to_intel_plane(plane);
794
795 key->min_value = I915_READ(SPRKEYVAL(intel_plane->pipe));
796 key->max_value = I915_READ(SPRKEYMAX(intel_plane->pipe));
797 key->channel_mask = I915_READ(SPRKEYMSK(intel_plane->pipe));
798 key->flags = 0;
799
800 sprctl = I915_READ(SPRCTL(intel_plane->pipe));
801
802 if (sprctl & SPRITE_DEST_KEY)
803 key->flags = I915_SET_COLORKEY_DESTINATION;
804 else if (sprctl & SPRITE_SOURCE_KEY)
805 key->flags = I915_SET_COLORKEY_SOURCE;
806 else
807 key->flags = I915_SET_COLORKEY_NONE;
808}
809
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800810static void
Ville Syrjäläb39d53f2013-08-06 22:24:09 +0300811ilk_update_plane(struct drm_plane *plane, struct drm_crtc *crtc,
812 struct drm_framebuffer *fb,
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800813 struct drm_i915_gem_object *obj, int crtc_x, int crtc_y,
814 unsigned int crtc_w, unsigned int crtc_h,
815 uint32_t x, uint32_t y,
816 uint32_t src_w, uint32_t src_h)
817{
818 struct drm_device *dev = plane->dev;
819 struct drm_i915_private *dev_priv = dev->dev_private;
820 struct intel_plane *intel_plane = to_intel_plane(plane);
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300821 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Ville Syrjälä2bd3c3c2012-10-31 17:50:20 +0200822 int pipe = intel_plane->pipe;
Damien Lespiau5a35e992012-10-26 18:20:12 +0100823 unsigned long dvssurf_offset, linear_offset;
Chris Wilson8aaa81a2012-04-14 22:14:26 +0100824 u32 dvscntr, dvsscale;
Ville Syrjälä2bd3c3c2012-10-31 17:50:20 +0200825 int pixel_size = drm_format_plane_cpp(fb->pixel_format, 0);
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300826 u32 start_vbl_count;
827 bool atomic_update;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800828
829 dvscntr = I915_READ(DVSCNTR(pipe));
830
831 /* Mask out pixel format bits in case we change it */
832 dvscntr &= ~DVS_PIXFORMAT_MASK;
Jesse Barnesab2f9df2012-02-27 12:40:10 -0800833 dvscntr &= ~DVS_RGB_ORDER_XBGR;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800834 dvscntr &= ~DVS_YUV_BYTE_ORDER_MASK;
Ander Conselvan de Oliveira79626522012-07-13 15:50:33 +0300835 dvscntr &= ~DVS_TILED;
Ville Syrjälä76eebda2014-08-05 11:26:52 +0530836 dvscntr &= ~DVS_ROTATE_180;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800837
838 switch (fb->pixel_format) {
839 case DRM_FORMAT_XBGR8888:
Jesse Barnesab2f9df2012-02-27 12:40:10 -0800840 dvscntr |= DVS_FORMAT_RGBX888 | DVS_RGB_ORDER_XBGR;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800841 break;
842 case DRM_FORMAT_XRGB8888:
Jesse Barnesab2f9df2012-02-27 12:40:10 -0800843 dvscntr |= DVS_FORMAT_RGBX888;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800844 break;
845 case DRM_FORMAT_YUYV:
846 dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_YUYV;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800847 break;
848 case DRM_FORMAT_YVYU:
849 dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_YVYU;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800850 break;
851 case DRM_FORMAT_UYVY:
852 dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_UYVY;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800853 break;
854 case DRM_FORMAT_VYUY:
855 dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_VYUY;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800856 break;
857 default:
Ville Syrjälä28d491d2012-10-31 17:50:21 +0200858 BUG();
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800859 }
860
Ville Syrjälä4ea67bc2013-11-18 18:32:38 -0800861 /*
862 * Enable gamma to match primary/cursor plane behaviour.
863 * FIXME should be user controllable via propertiesa.
864 */
865 dvscntr |= DVS_GAMMA_ENABLE;
866
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800867 if (obj->tiling_mode != I915_TILING_NONE)
868 dvscntr |= DVS_TILED;
869
Chris Wilsond1686ae2012-04-10 11:41:49 +0100870 if (IS_GEN6(dev))
871 dvscntr |= DVS_TRICKLE_FEED_DISABLE; /* must disable */
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800872 dvscntr |= DVS_ENABLE;
873
Damien Lespiaued57cb82014-07-15 09:21:24 +0200874 intel_update_sprite_watermarks(plane, crtc, src_w, src_h,
875 pixel_size, true,
Ville Syrjälä67ca28f2013-07-05 11:57:14 +0300876 src_w != crtc_w || src_h != crtc_h);
877
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800878 /* Sizes are 0 based */
879 src_w--;
880 src_h--;
881 crtc_w--;
882 crtc_h--;
883
Chris Wilson8aaa81a2012-04-14 22:14:26 +0100884 dvsscale = 0;
Ville Syrjälä8368f012013-12-05 15:51:31 +0200885 if (crtc_w != src_w || crtc_h != src_h)
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800886 dvsscale = DVS_SCALE_ENABLE | (src_w << 16) | src_h;
887
Chris Wilsonca320ac2012-12-19 12:14:22 +0000888 linear_offset = y * fb->pitches[0] + x * pixel_size;
Damien Lespiau5a35e992012-10-26 18:20:12 +0100889 dvssurf_offset =
Chris Wilsonbc752862013-02-21 20:04:31 +0000890 intel_gen4_compute_page_offset(&x, &y, obj->tiling_mode,
891 pixel_size, fb->pitches[0]);
Damien Lespiau5a35e992012-10-26 18:20:12 +0100892 linear_offset -= dvssurf_offset;
893
Ville Syrjälä76eebda2014-08-05 11:26:52 +0530894 if (intel_plane->rotation == BIT(DRM_ROTATE_180)) {
895 dvscntr |= DVS_ROTATE_180;
896
897 x += src_w;
898 y += src_h;
899 linear_offset += src_h * fb->pitches[0] + src_w * pixel_size;
900 }
901
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300902 atomic_update = intel_pipe_update_start(intel_crtc, &start_vbl_count);
903
Ville Syrjälä5b633d62014-04-29 13:35:47 +0300904 intel_update_primary_plane(intel_crtc);
905
Ville Syrjäläca6ad022014-01-17 20:09:03 +0200906 I915_WRITE(DVSSTRIDE(pipe), fb->pitches[0]);
907 I915_WRITE(DVSPOS(pipe), (crtc_y << 16) | crtc_x);
908
Damien Lespiau5a35e992012-10-26 18:20:12 +0100909 if (obj->tiling_mode != I915_TILING_NONE)
910 I915_WRITE(DVSTILEOFF(pipe), (y << 16) | x);
911 else
912 I915_WRITE(DVSLINOFF(pipe), linear_offset);
913
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800914 I915_WRITE(DVSSIZE(pipe), (crtc_h << 16) | crtc_w);
915 I915_WRITE(DVSSCALE(pipe), dvsscale);
916 I915_WRITE(DVSCNTR(pipe), dvscntr);
Daniel Vetter85ba7b72014-01-24 10:31:44 +0100917 I915_WRITE(DVSSURF(pipe),
918 i915_gem_obj_ggtt_offset(obj) + dvssurf_offset);
Ville Syrjälä5b633d62014-04-29 13:35:47 +0300919
920 intel_flush_primary_plane(dev_priv, intel_crtc->plane);
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300921
922 if (atomic_update)
923 intel_pipe_update_end(intel_crtc, start_vbl_count);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800924}
925
926static void
Ville Syrjäläb39d53f2013-08-06 22:24:09 +0300927ilk_disable_plane(struct drm_plane *plane, struct drm_crtc *crtc)
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800928{
929 struct drm_device *dev = plane->dev;
930 struct drm_i915_private *dev_priv = dev->dev_private;
931 struct intel_plane *intel_plane = to_intel_plane(plane);
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300932 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800933 int pipe = intel_plane->pipe;
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300934 u32 start_vbl_count;
935 bool atomic_update;
936
937 atomic_update = intel_pipe_update_start(intel_crtc, &start_vbl_count);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800938
Ville Syrjälä5b633d62014-04-29 13:35:47 +0300939 intel_update_primary_plane(intel_crtc);
940
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800941 I915_WRITE(DVSCNTR(pipe), I915_READ(DVSCNTR(pipe)) & ~DVS_ENABLE);
942 /* Disable the scaler */
943 I915_WRITE(DVSSCALE(pipe), 0);
944 /* Flush double buffered register updates */
Daniel Vetter85ba7b72014-01-24 10:31:44 +0100945 I915_WRITE(DVSSURF(pipe), 0);
Ville Syrjälä5b633d62014-04-29 13:35:47 +0300946
947 intel_flush_primary_plane(dev_priv, intel_crtc->plane);
Ville Syrjäläa95fd8c2013-08-06 22:24:12 +0300948
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300949 if (atomic_update)
950 intel_pipe_update_end(intel_crtc, start_vbl_count);
951
Ville Syrjälä1bd09ec2013-12-05 15:51:41 +0200952 /*
953 * Avoid underruns when disabling the sprite.
954 * FIXME remove once watermark updates are done properly.
955 */
956 intel_wait_for_vblank(dev, pipe);
957
Damien Lespiaued57cb82014-07-15 09:21:24 +0200958 intel_update_sprite_watermarks(plane, crtc, 0, 0, 0, false, false);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800959}
960
Jesse Barnes175bd422011-12-13 13:19:39 -0800961static void
Ville Syrjälä5b633d62014-04-29 13:35:47 +0300962intel_post_enable_primary(struct drm_crtc *crtc)
Jesse Barnes175bd422011-12-13 13:19:39 -0800963{
964 struct drm_device *dev = crtc->dev;
Jesse Barnes175bd422011-12-13 13:19:39 -0800965 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Ville Syrjäläabae50e2013-10-01 18:02:16 +0300966
Ville Syrjälä20bc86732013-10-01 18:02:17 +0300967 /*
Ville Syrjälä33c3b0d2014-06-24 13:59:28 +0300968 * BDW signals flip done immediately if the plane
969 * is disabled, even if the plane enable is already
970 * armed to occur at the next vblank :(
971 */
972 if (IS_BROADWELL(dev))
973 intel_wait_for_vblank(dev, intel_crtc->pipe);
974
975 /*
Ville Syrjälä20bc86732013-10-01 18:02:17 +0300976 * FIXME IPS should be fine as long as one plane is
977 * enabled, but in practice it seems to have problems
978 * when going from primary only to sprite only and vice
979 * versa.
980 */
Ville Syrjäläcea165c2014-04-15 21:41:35 +0300981 hsw_enable_ips(intel_crtc);
Ville Syrjälä20bc86732013-10-01 18:02:17 +0300982
Ville Syrjälä82284b62013-10-01 18:02:12 +0300983 mutex_lock(&dev->struct_mutex);
Chris Wilson93314b52012-06-13 17:36:55 +0100984 intel_update_fbc(dev);
Ville Syrjälä82284b62013-10-01 18:02:12 +0300985 mutex_unlock(&dev->struct_mutex);
Jesse Barnes175bd422011-12-13 13:19:39 -0800986}
987
988static void
Ville Syrjälä5b633d62014-04-29 13:35:47 +0300989intel_pre_disable_primary(struct drm_crtc *crtc)
Jesse Barnes175bd422011-12-13 13:19:39 -0800990{
991 struct drm_device *dev = crtc->dev;
992 struct drm_i915_private *dev_priv = dev->dev_private;
993 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Ville Syrjälä82284b62013-10-01 18:02:12 +0300994
995 mutex_lock(&dev->struct_mutex);
Ville Syrjäläabae50e2013-10-01 18:02:16 +0300996 if (dev_priv->fbc.plane == intel_crtc->plane)
997 intel_disable_fbc(dev);
Ville Syrjälä82284b62013-10-01 18:02:12 +0300998 mutex_unlock(&dev->struct_mutex);
Ville Syrjäläabae50e2013-10-01 18:02:16 +0300999
Ville Syrjälä20bc86732013-10-01 18:02:17 +03001000 /*
1001 * FIXME IPS should be fine as long as one plane is
1002 * enabled, but in practice it seems to have problems
1003 * when going from primary only to sprite only and vice
1004 * versa.
1005 */
1006 hsw_disable_ips(intel_crtc);
Jesse Barnes175bd422011-12-13 13:19:39 -08001007}
1008
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001009static int
Chris Wilsond1686ae2012-04-10 11:41:49 +01001010ilk_update_colorkey(struct drm_plane *plane,
Jesse Barnes8ea30862012-01-03 08:05:39 -08001011 struct drm_intel_sprite_colorkey *key)
1012{
1013 struct drm_device *dev = plane->dev;
1014 struct drm_i915_private *dev_priv = dev->dev_private;
1015 struct intel_plane *intel_plane;
1016 u32 dvscntr;
1017 int ret = 0;
1018
1019 intel_plane = to_intel_plane(plane);
1020
1021 I915_WRITE(DVSKEYVAL(intel_plane->pipe), key->min_value);
1022 I915_WRITE(DVSKEYMAX(intel_plane->pipe), key->max_value);
1023 I915_WRITE(DVSKEYMSK(intel_plane->pipe), key->channel_mask);
1024
1025 dvscntr = I915_READ(DVSCNTR(intel_plane->pipe));
1026 dvscntr &= ~(DVS_SOURCE_KEY | DVS_DEST_KEY);
1027 if (key->flags & I915_SET_COLORKEY_DESTINATION)
1028 dvscntr |= DVS_DEST_KEY;
1029 else if (key->flags & I915_SET_COLORKEY_SOURCE)
1030 dvscntr |= DVS_SOURCE_KEY;
1031 I915_WRITE(DVSCNTR(intel_plane->pipe), dvscntr);
1032
1033 POSTING_READ(DVSKEYMSK(intel_plane->pipe));
1034
1035 return ret;
1036}
1037
1038static void
Chris Wilsond1686ae2012-04-10 11:41:49 +01001039ilk_get_colorkey(struct drm_plane *plane, struct drm_intel_sprite_colorkey *key)
Jesse Barnes8ea30862012-01-03 08:05:39 -08001040{
1041 struct drm_device *dev = plane->dev;
1042 struct drm_i915_private *dev_priv = dev->dev_private;
1043 struct intel_plane *intel_plane;
1044 u32 dvscntr;
1045
1046 intel_plane = to_intel_plane(plane);
1047
1048 key->min_value = I915_READ(DVSKEYVAL(intel_plane->pipe));
1049 key->max_value = I915_READ(DVSKEYMAX(intel_plane->pipe));
1050 key->channel_mask = I915_READ(DVSKEYMSK(intel_plane->pipe));
1051 key->flags = 0;
1052
1053 dvscntr = I915_READ(DVSCNTR(intel_plane->pipe));
1054
1055 if (dvscntr & DVS_DEST_KEY)
1056 key->flags = I915_SET_COLORKEY_DESTINATION;
1057 else if (dvscntr & DVS_SOURCE_KEY)
1058 key->flags = I915_SET_COLORKEY_SOURCE;
1059 else
1060 key->flags = I915_SET_COLORKEY_NONE;
1061}
1062
Ville Syrjäläefb31d12013-12-05 15:51:40 +02001063static bool colorkey_enabled(struct intel_plane *intel_plane)
1064{
1065 struct drm_intel_sprite_colorkey key;
1066
1067 intel_plane->get_colorkey(&intel_plane->base, &key);
1068
1069 return key.flags != I915_SET_COLORKEY_NONE;
1070}
1071
Jesse Barnes8ea30862012-01-03 08:05:39 -08001072static int
Gustavo Padovan96d61a72014-09-05 17:04:47 -03001073intel_check_sprite_plane(struct drm_plane *plane,
1074 struct intel_plane_state *state)
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001075{
Gustavo Padovan96d61a72014-09-05 17:04:47 -03001076 struct intel_crtc *intel_crtc = to_intel_crtc(state->crtc);
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001077 struct intel_plane *intel_plane = to_intel_plane(plane);
Gustavo Padovan96d61a72014-09-05 17:04:47 -03001078 struct drm_framebuffer *fb = state->fb;
Gustavo Padovan77cde952014-10-24 14:51:33 +01001079 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
Gustavo Padovan96d61a72014-09-05 17:04:47 -03001080 int crtc_x, crtc_y;
1081 unsigned int crtc_w, crtc_h;
1082 uint32_t src_x, src_y, src_w, src_h;
1083 struct drm_rect *src = &state->src;
1084 struct drm_rect *dst = &state->dst;
1085 struct drm_rect *orig_src = &state->orig_src;
1086 const struct drm_rect *clip = &state->clip;
Ville Syrjälä17316932013-04-24 18:52:38 +03001087 int hscale, vscale;
1088 int max_scale, min_scale;
1089 int pixel_size = drm_format_plane_cpp(fb->pixel_format, 0);
Jesse Barnes5e1bac22013-03-26 09:25:43 -07001090
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001091 /* Don't modify another pipe's plane */
Ville Syrjälä17316932013-04-24 18:52:38 +03001092 if (intel_plane->pipe != intel_crtc->pipe) {
1093 DRM_DEBUG_KMS("Wrong plane <-> crtc mapping\n");
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001094 return -EINVAL;
Ville Syrjälä17316932013-04-24 18:52:38 +03001095 }
1096
1097 /* FIXME check all gen limits */
1098 if (fb->width < 3 || fb->height < 3 || fb->pitches[0] > 16384) {
1099 DRM_DEBUG_KMS("Unsuitable framebuffer for plane\n");
1100 return -EINVAL;
1101 }
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001102
Damien Lespiau94c64192012-10-29 15:14:51 +00001103 /* Sprite planes can be linear or x-tiled surfaces */
1104 switch (obj->tiling_mode) {
1105 case I915_TILING_NONE:
1106 case I915_TILING_X:
1107 break;
1108 default:
Ville Syrjälä17316932013-04-24 18:52:38 +03001109 DRM_DEBUG_KMS("Unsupported tiling mode\n");
Damien Lespiau94c64192012-10-29 15:14:51 +00001110 return -EINVAL;
1111 }
1112
Ville Syrjälä3c3686c2013-04-24 18:52:39 +03001113 /*
1114 * FIXME the following code does a bunch of fuzzy adjustments to the
1115 * coordinates and sizes. We probably need some way to decide whether
1116 * more strict checking should be done instead.
1117 */
Ville Syrjälä17316932013-04-24 18:52:38 +03001118 max_scale = intel_plane->max_downscale << 16;
1119 min_scale = intel_plane->can_scale ? 1 : (1 << 16);
1120
Gustavo Padovan96d61a72014-09-05 17:04:47 -03001121 drm_rect_rotate(src, fb->width << 16, fb->height << 16,
Ville Syrjälä76eebda2014-08-05 11:26:52 +05301122 intel_plane->rotation);
1123
Gustavo Padovan96d61a72014-09-05 17:04:47 -03001124 hscale = drm_rect_calc_hscale_relaxed(src, dst, min_scale, max_scale);
Ville Syrjälä3c3686c2013-04-24 18:52:39 +03001125 BUG_ON(hscale < 0);
Ville Syrjälä17316932013-04-24 18:52:38 +03001126
Gustavo Padovan96d61a72014-09-05 17:04:47 -03001127 vscale = drm_rect_calc_vscale_relaxed(src, dst, min_scale, max_scale);
Ville Syrjälä3c3686c2013-04-24 18:52:39 +03001128 BUG_ON(vscale < 0);
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001129
Gustavo Padovan96d61a72014-09-05 17:04:47 -03001130 state->visible = drm_rect_clip_scaled(src, dst, clip, hscale, vscale);
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001131
Gustavo Padovan96d61a72014-09-05 17:04:47 -03001132 crtc_x = dst->x1;
1133 crtc_y = dst->y1;
1134 crtc_w = drm_rect_width(dst);
1135 crtc_h = drm_rect_height(dst);
Damien Lespiau2d354c32012-10-22 18:19:27 +01001136
Gustavo Padovan96d61a72014-09-05 17:04:47 -03001137 if (state->visible) {
Ville Syrjälä3c3686c2013-04-24 18:52:39 +03001138 /* check again in case clipping clamped the results */
Gustavo Padovan96d61a72014-09-05 17:04:47 -03001139 hscale = drm_rect_calc_hscale(src, dst, min_scale, max_scale);
Ville Syrjälä3c3686c2013-04-24 18:52:39 +03001140 if (hscale < 0) {
1141 DRM_DEBUG_KMS("Horizontal scaling factor out of limits\n");
Gustavo Padovan96d61a72014-09-05 17:04:47 -03001142 drm_rect_debug_print(src, true);
1143 drm_rect_debug_print(dst, false);
Ville Syrjälä3c3686c2013-04-24 18:52:39 +03001144
1145 return hscale;
1146 }
1147
Gustavo Padovan96d61a72014-09-05 17:04:47 -03001148 vscale = drm_rect_calc_vscale(src, dst, min_scale, max_scale);
Ville Syrjälä3c3686c2013-04-24 18:52:39 +03001149 if (vscale < 0) {
1150 DRM_DEBUG_KMS("Vertical scaling factor out of limits\n");
Gustavo Padovan96d61a72014-09-05 17:04:47 -03001151 drm_rect_debug_print(src, true);
1152 drm_rect_debug_print(dst, false);
Ville Syrjälä3c3686c2013-04-24 18:52:39 +03001153
1154 return vscale;
1155 }
1156
Ville Syrjälä17316932013-04-24 18:52:38 +03001157 /* Make the source viewport size an exact multiple of the scaling factors. */
Gustavo Padovan96d61a72014-09-05 17:04:47 -03001158 drm_rect_adjust_size(src,
1159 drm_rect_width(dst) * hscale - drm_rect_width(src),
1160 drm_rect_height(dst) * vscale - drm_rect_height(src));
Ville Syrjälä17316932013-04-24 18:52:38 +03001161
Gustavo Padovan96d61a72014-09-05 17:04:47 -03001162 drm_rect_rotate_inv(src, fb->width << 16, fb->height << 16,
Ville Syrjälä76eebda2014-08-05 11:26:52 +05301163 intel_plane->rotation);
1164
Ville Syrjälä17316932013-04-24 18:52:38 +03001165 /* sanity check to make sure the src viewport wasn't enlarged */
Gustavo Padovan96d61a72014-09-05 17:04:47 -03001166 WARN_ON(src->x1 < (int) orig_src->x1 ||
1167 src->y1 < (int) orig_src->y1 ||
1168 src->x2 > (int) orig_src->x2 ||
1169 src->y2 > (int) orig_src->y2);
Ville Syrjälä17316932013-04-24 18:52:38 +03001170
1171 /*
1172 * Hardware doesn't handle subpixel coordinates.
1173 * Adjust to (macro)pixel boundary, but be careful not to
1174 * increase the source viewport size, because that could
1175 * push the downscaling factor out of bounds.
Ville Syrjälä17316932013-04-24 18:52:38 +03001176 */
Gustavo Padovan96d61a72014-09-05 17:04:47 -03001177 src_x = src->x1 >> 16;
1178 src_w = drm_rect_width(src) >> 16;
1179 src_y = src->y1 >> 16;
1180 src_h = drm_rect_height(src) >> 16;
Ville Syrjälä17316932013-04-24 18:52:38 +03001181
1182 if (format_is_yuv(fb->pixel_format)) {
1183 src_x &= ~1;
1184 src_w &= ~1;
1185
1186 /*
1187 * Must keep src and dst the
1188 * same if we can't scale.
1189 */
1190 if (!intel_plane->can_scale)
1191 crtc_w &= ~1;
1192
1193 if (crtc_w == 0)
Gustavo Padovan96d61a72014-09-05 17:04:47 -03001194 state->visible = false;
Ville Syrjälä17316932013-04-24 18:52:38 +03001195 }
1196 }
1197
1198 /* Check size restrictions when scaling */
Gustavo Padovan96d61a72014-09-05 17:04:47 -03001199 if (state->visible && (src_w != crtc_w || src_h != crtc_h)) {
Ville Syrjälä17316932013-04-24 18:52:38 +03001200 unsigned int width_bytes;
1201
1202 WARN_ON(!intel_plane->can_scale);
1203
1204 /* FIXME interlacing min height is 6 */
1205
1206 if (crtc_w < 3 || crtc_h < 3)
Gustavo Padovan96d61a72014-09-05 17:04:47 -03001207 state->visible = false;
Ville Syrjälä17316932013-04-24 18:52:38 +03001208
1209 if (src_w < 3 || src_h < 3)
Gustavo Padovan96d61a72014-09-05 17:04:47 -03001210 state->visible = false;
Ville Syrjälä17316932013-04-24 18:52:38 +03001211
Gustavo Padovan96d61a72014-09-05 17:04:47 -03001212 width_bytes = ((src_x * pixel_size) & 63) +
1213 src_w * pixel_size;
Ville Syrjälä17316932013-04-24 18:52:38 +03001214
1215 if (src_w > 2048 || src_h > 2048 ||
1216 width_bytes > 4096 || fb->pitches[0] > 4096) {
1217 DRM_DEBUG_KMS("Source dimensions exceed hardware limits\n");
1218 return -EINVAL;
1219 }
1220 }
1221
Gustavo Padovan96d61a72014-09-05 17:04:47 -03001222 if (state->visible) {
1223 src->x1 = src_x;
1224 src->x2 = src_x + src_w;
1225 src->y1 = src_y;
1226 src->y2 = src_y + src_h;
1227 }
1228
1229 dst->x1 = crtc_x;
1230 dst->x2 = crtc_x + crtc_w;
1231 dst->y1 = crtc_y;
1232 dst->y2 = crtc_y + crtc_h;
1233
1234 return 0;
1235}
1236
1237static int
Gustavo Padovan34aa50a2014-10-24 14:51:32 +01001238intel_prepare_sprite_plane(struct drm_plane *plane,
1239 struct intel_plane_state *state)
Gustavo Padovan96d61a72014-09-05 17:04:47 -03001240{
1241 struct drm_device *dev = plane->dev;
1242 struct drm_crtc *crtc = state->crtc;
1243 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Gustavo Padovan96d61a72014-09-05 17:04:47 -03001244 enum pipe pipe = intel_crtc->pipe;
1245 struct drm_framebuffer *fb = state->fb;
Gustavo Padovan34aa50a2014-10-24 14:51:32 +01001246 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
1247 struct drm_i915_gem_object *old_obj = intel_fb_obj(plane->fb);
Gustavo Padovan96d61a72014-09-05 17:04:47 -03001248 int ret;
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001249
Gustavo Padovan25067bf2014-09-10 12:03:17 -03001250 if (old_obj != obj) {
1251 mutex_lock(&dev->struct_mutex);
Ville Syrjälä82284b62013-10-01 18:02:12 +03001252
Gustavo Padovan25067bf2014-09-10 12:03:17 -03001253 /* Note that this will apply the VT-d workaround for scanouts,
1254 * which is more restrictive than required for sprites. (The
1255 * primary plane requires 256KiB alignment with 64 PTE padding,
1256 * the sprite planes only require 128KiB alignment and 32 PTE
1257 * padding.
1258 */
1259 ret = intel_pin_and_fence_fb_obj(dev, obj, NULL);
1260 if (ret == 0)
1261 i915_gem_track_fb(old_obj, obj,
1262 INTEL_FRONTBUFFER_SPRITE(pipe));
1263 mutex_unlock(&dev->struct_mutex);
1264 if (ret)
1265 return ret;
1266 }
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001267
Gustavo Padovan34aa50a2014-10-24 14:51:32 +01001268 return 0;
1269}
1270
1271static void
1272intel_commit_sprite_plane(struct drm_plane *plane,
1273 struct intel_plane_state *state)
1274{
1275 struct drm_device *dev = plane->dev;
1276 struct drm_crtc *crtc = state->crtc;
1277 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
1278 struct intel_plane *intel_plane = to_intel_plane(plane);
1279 enum pipe pipe = intel_crtc->pipe;
1280 struct drm_framebuffer *fb = state->fb;
Gustavo Padovan77cde952014-10-24 14:51:33 +01001281 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
1282 struct drm_i915_gem_object *old_obj = intel_fb_obj(plane->fb);
Gustavo Padovan34aa50a2014-10-24 14:51:32 +01001283 int crtc_x, crtc_y;
1284 unsigned int crtc_w, crtc_h;
1285 uint32_t src_x, src_y, src_w, src_h;
1286 struct drm_rect *dst = &state->dst;
1287 const struct drm_rect *clip = &state->clip;
1288 bool primary_enabled;
1289
1290 /*
1291 * If the sprite is completely covering the primary plane,
1292 * we can disable the primary and save power.
1293 */
1294 primary_enabled = !drm_rect_equals(dst, clip) || colorkey_enabled(intel_plane);
1295 WARN_ON(!primary_enabled && !state->visible && intel_crtc->active);
1296
Gustavo Padovan96d61a72014-09-05 17:04:47 -03001297 intel_plane->crtc_x = state->orig_dst.x1;
1298 intel_plane->crtc_y = state->orig_dst.y1;
1299 intel_plane->crtc_w = drm_rect_width(&state->orig_dst);
1300 intel_plane->crtc_h = drm_rect_height(&state->orig_dst);
1301 intel_plane->src_x = state->orig_src.x1;
1302 intel_plane->src_y = state->orig_src.y1;
1303 intel_plane->src_w = drm_rect_width(&state->orig_src);
1304 intel_plane->src_h = drm_rect_height(&state->orig_src);
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001305 intel_plane->obj = obj;
1306
Ville Syrjälä03c5b252013-10-01 18:02:11 +03001307 if (intel_crtc->active) {
Ville Syrjälä5b633d62014-04-29 13:35:47 +03001308 bool primary_was_enabled = intel_crtc->primary_enabled;
1309
1310 intel_crtc->primary_enabled = primary_enabled;
1311
Ville Syrjälä46a55d32014-05-21 14:04:46 +03001312 if (primary_was_enabled != primary_enabled)
1313 intel_crtc_wait_for_pending_flips(crtc);
1314
Ville Syrjälä5b633d62014-04-29 13:35:47 +03001315 if (primary_was_enabled && !primary_enabled)
1316 intel_pre_disable_primary(crtc);
Jesse Barnes175bd422011-12-13 13:19:39 -08001317
Gustavo Padovan96d61a72014-09-05 17:04:47 -03001318 if (state->visible) {
1319 crtc_x = state->dst.x1;
Gustavo Padovane259f172014-09-11 17:42:15 -03001320 crtc_y = state->dst.y1;
Gustavo Padovan96d61a72014-09-05 17:04:47 -03001321 crtc_w = drm_rect_width(&state->dst);
1322 crtc_h = drm_rect_height(&state->dst);
1323 src_x = state->src.x1;
1324 src_y = state->src.y1;
1325 src_w = drm_rect_width(&state->src);
1326 src_h = drm_rect_height(&state->src);
Ville Syrjälä03c5b252013-10-01 18:02:11 +03001327 intel_plane->update_plane(plane, crtc, fb, obj,
1328 crtc_x, crtc_y, crtc_w, crtc_h,
1329 src_x, src_y, src_w, src_h);
Gustavo Padovan96d61a72014-09-05 17:04:47 -03001330 } else {
Ville Syrjälä03c5b252013-10-01 18:02:11 +03001331 intel_plane->disable_plane(plane, crtc);
Gustavo Padovan96d61a72014-09-05 17:04:47 -03001332 }
1333
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001334
Daniel Vetterf99d7062014-06-19 16:01:59 +02001335 intel_frontbuffer_flip(dev, INTEL_FRONTBUFFER_SPRITE(pipe));
1336
Ville Syrjälä5b633d62014-04-29 13:35:47 +03001337 if (!primary_was_enabled && primary_enabled)
1338 intel_post_enable_primary(crtc);
Ville Syrjälä03c5b252013-10-01 18:02:11 +03001339 }
Jesse Barnes175bd422011-12-13 13:19:39 -08001340
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001341 /* Unpin old obj after new one is active to avoid ugliness */
Gustavo Padovan25067bf2014-09-10 12:03:17 -03001342 if (old_obj && old_obj != obj) {
1343
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001344 /*
1345 * It's fairly common to simply update the position of
1346 * an existing object. In that case, we don't need to
1347 * wait for vblank to avoid ugliness, we only need to
1348 * do the pin & ref bookkeeping.
1349 */
Gustavo Padovan25067bf2014-09-10 12:03:17 -03001350 if (intel_crtc->active)
Ville Syrjälä2afd9ef2013-10-01 18:02:14 +03001351 intel_wait_for_vblank(dev, intel_crtc->pipe);
Ville Syrjälä82284b62013-10-01 18:02:12 +03001352
1353 mutex_lock(&dev->struct_mutex);
Chris Wilson1690e1e2011-12-14 13:57:08 +01001354 intel_unpin_fb_obj(old_obj);
Ville Syrjälä82284b62013-10-01 18:02:12 +03001355 mutex_unlock(&dev->struct_mutex);
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001356 }
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001357}
1358
1359static int
Gustavo Padovan96d61a72014-09-05 17:04:47 -03001360intel_update_plane(struct drm_plane *plane, struct drm_crtc *crtc,
1361 struct drm_framebuffer *fb, int crtc_x, int crtc_y,
1362 unsigned int crtc_w, unsigned int crtc_h,
1363 uint32_t src_x, uint32_t src_y,
1364 uint32_t src_w, uint32_t src_h)
1365{
1366 struct intel_plane_state state;
1367 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
1368 int ret;
1369
1370 state.crtc = crtc;
1371 state.fb = fb;
1372
1373 /* sample coordinates in 16.16 fixed point */
1374 state.src.x1 = src_x;
1375 state.src.x2 = src_x + src_w;
1376 state.src.y1 = src_y;
1377 state.src.y2 = src_y + src_h;
1378
1379 /* integer pixels */
1380 state.dst.x1 = crtc_x;
1381 state.dst.x2 = crtc_x + crtc_w;
1382 state.dst.y1 = crtc_y;
1383 state.dst.y2 = crtc_y + crtc_h;
1384
1385 state.clip.x1 = 0;
1386 state.clip.y1 = 0;
1387 state.clip.x2 = intel_crtc->active ? intel_crtc->config.pipe_src_w : 0;
1388 state.clip.y2 = intel_crtc->active ? intel_crtc->config.pipe_src_h : 0;
1389 state.orig_src = state.src;
1390 state.orig_dst = state.dst;
1391
1392 ret = intel_check_sprite_plane(plane, &state);
1393 if (ret)
1394 return ret;
1395
Gustavo Padovan34aa50a2014-10-24 14:51:32 +01001396 ret = intel_prepare_sprite_plane(plane, &state);
1397 if (ret)
1398 return ret;
1399
1400 intel_commit_sprite_plane(plane, &state);
1401 return 0;
Gustavo Padovan96d61a72014-09-05 17:04:47 -03001402}
1403
1404static int
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001405intel_disable_plane(struct drm_plane *plane)
1406{
1407 struct drm_device *dev = plane->dev;
1408 struct intel_plane *intel_plane = to_intel_plane(plane);
Ville Syrjälä03c5b252013-10-01 18:02:11 +03001409 struct intel_crtc *intel_crtc;
Daniel Vettera071fa02014-06-18 23:28:09 +02001410 enum pipe pipe;
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001411
Ville Syrjälä88a94a52013-08-07 13:30:23 +03001412 if (!plane->fb)
1413 return 0;
1414
1415 if (WARN_ON(!plane->crtc))
1416 return -EINVAL;
1417
Ville Syrjälä03c5b252013-10-01 18:02:11 +03001418 intel_crtc = to_intel_crtc(plane->crtc);
Daniel Vettera071fa02014-06-18 23:28:09 +02001419 pipe = intel_crtc->pipe;
Ville Syrjälä03c5b252013-10-01 18:02:11 +03001420
1421 if (intel_crtc->active) {
Ville Syrjälä5b633d62014-04-29 13:35:47 +03001422 bool primary_was_enabled = intel_crtc->primary_enabled;
1423
1424 intel_crtc->primary_enabled = true;
1425
Ville Syrjälä03c5b252013-10-01 18:02:11 +03001426 intel_plane->disable_plane(plane, plane->crtc);
Ville Syrjälä5b633d62014-04-29 13:35:47 +03001427
1428 if (!primary_was_enabled && intel_crtc->primary_enabled)
1429 intel_post_enable_primary(plane->crtc);
Ville Syrjälä03c5b252013-10-01 18:02:11 +03001430 }
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001431
Ville Syrjälä5f3fb462013-10-01 18:02:13 +03001432 if (intel_plane->obj) {
1433 if (intel_crtc->active)
1434 intel_wait_for_vblank(dev, intel_plane->pipe);
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001435
Ville Syrjälä5f3fb462013-10-01 18:02:13 +03001436 mutex_lock(&dev->struct_mutex);
1437 intel_unpin_fb_obj(intel_plane->obj);
Daniel Vettera071fa02014-06-18 23:28:09 +02001438 i915_gem_track_fb(intel_plane->obj, NULL,
1439 INTEL_FRONTBUFFER_SPRITE(pipe));
Ville Syrjälä5f3fb462013-10-01 18:02:13 +03001440 mutex_unlock(&dev->struct_mutex);
Ville Syrjäläc626d312013-03-27 17:49:13 +02001441
Ville Syrjälä5f3fb462013-10-01 18:02:13 +03001442 intel_plane->obj = NULL;
1443 }
Ville Syrjälä82284b62013-10-01 18:02:12 +03001444
Ville Syrjälä5f3fb462013-10-01 18:02:13 +03001445 return 0;
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001446}
1447
1448static void intel_destroy_plane(struct drm_plane *plane)
1449{
1450 struct intel_plane *intel_plane = to_intel_plane(plane);
1451 intel_disable_plane(plane);
1452 drm_plane_cleanup(plane);
1453 kfree(intel_plane);
1454}
1455
Jesse Barnes8ea30862012-01-03 08:05:39 -08001456int intel_sprite_set_colorkey(struct drm_device *dev, void *data,
1457 struct drm_file *file_priv)
1458{
1459 struct drm_intel_sprite_colorkey *set = data;
Jesse Barnes8ea30862012-01-03 08:05:39 -08001460 struct drm_plane *plane;
1461 struct intel_plane *intel_plane;
1462 int ret = 0;
1463
Daniel Vetter1cff8f62012-04-24 09:55:08 +02001464 if (!drm_core_check_feature(dev, DRIVER_MODESET))
1465 return -ENODEV;
Jesse Barnes8ea30862012-01-03 08:05:39 -08001466
1467 /* Make sure we don't try to enable both src & dest simultaneously */
1468 if ((set->flags & (I915_SET_COLORKEY_DESTINATION | I915_SET_COLORKEY_SOURCE)) == (I915_SET_COLORKEY_DESTINATION | I915_SET_COLORKEY_SOURCE))
1469 return -EINVAL;
1470
Daniel Vettera0e99e62012-12-02 01:05:46 +01001471 drm_modeset_lock_all(dev);
Jesse Barnes8ea30862012-01-03 08:05:39 -08001472
Rob Clark7707e652014-07-17 23:30:04 -04001473 plane = drm_plane_find(dev, set->plane_id);
1474 if (!plane) {
Ville Syrjälä3f2c2052013-10-17 13:35:03 +03001475 ret = -ENOENT;
Jesse Barnes8ea30862012-01-03 08:05:39 -08001476 goto out_unlock;
1477 }
1478
Jesse Barnes8ea30862012-01-03 08:05:39 -08001479 intel_plane = to_intel_plane(plane);
1480 ret = intel_plane->update_colorkey(plane, set);
1481
1482out_unlock:
Daniel Vettera0e99e62012-12-02 01:05:46 +01001483 drm_modeset_unlock_all(dev);
Jesse Barnes8ea30862012-01-03 08:05:39 -08001484 return ret;
1485}
1486
1487int intel_sprite_get_colorkey(struct drm_device *dev, void *data,
1488 struct drm_file *file_priv)
1489{
1490 struct drm_intel_sprite_colorkey *get = data;
Jesse Barnes8ea30862012-01-03 08:05:39 -08001491 struct drm_plane *plane;
1492 struct intel_plane *intel_plane;
1493 int ret = 0;
1494
Daniel Vetter1cff8f62012-04-24 09:55:08 +02001495 if (!drm_core_check_feature(dev, DRIVER_MODESET))
1496 return -ENODEV;
Jesse Barnes8ea30862012-01-03 08:05:39 -08001497
Daniel Vettera0e99e62012-12-02 01:05:46 +01001498 drm_modeset_lock_all(dev);
Jesse Barnes8ea30862012-01-03 08:05:39 -08001499
Rob Clark7707e652014-07-17 23:30:04 -04001500 plane = drm_plane_find(dev, get->plane_id);
1501 if (!plane) {
Ville Syrjälä3f2c2052013-10-17 13:35:03 +03001502 ret = -ENOENT;
Jesse Barnes8ea30862012-01-03 08:05:39 -08001503 goto out_unlock;
1504 }
1505
Jesse Barnes8ea30862012-01-03 08:05:39 -08001506 intel_plane = to_intel_plane(plane);
1507 intel_plane->get_colorkey(plane, get);
1508
1509out_unlock:
Daniel Vettera0e99e62012-12-02 01:05:46 +01001510 drm_modeset_unlock_all(dev);
Jesse Barnes8ea30862012-01-03 08:05:39 -08001511 return ret;
1512}
1513
Sonika Jindal48404c12014-08-22 14:06:04 +05301514int intel_plane_set_property(struct drm_plane *plane,
1515 struct drm_property *prop,
1516 uint64_t val)
Ville Syrjälä7ed6eee2014-08-05 11:26:55 +05301517{
1518 struct drm_device *dev = plane->dev;
1519 struct intel_plane *intel_plane = to_intel_plane(plane);
1520 uint64_t old_val;
1521 int ret = -ENOENT;
1522
1523 if (prop == dev->mode_config.rotation_property) {
1524 /* exactly one rotation angle please */
1525 if (hweight32(val & 0xf) != 1)
1526 return -EINVAL;
1527
Ville Syrjälä09dba002014-09-01 18:08:25 +03001528 if (intel_plane->rotation == val)
1529 return 0;
1530
Ville Syrjälä7ed6eee2014-08-05 11:26:55 +05301531 old_val = intel_plane->rotation;
1532 intel_plane->rotation = val;
1533 ret = intel_plane_restore(plane);
1534 if (ret)
1535 intel_plane->rotation = old_val;
1536 }
1537
1538 return ret;
1539}
1540
Ville Syrjäläe57465f2014-08-05 11:26:53 +05301541int intel_plane_restore(struct drm_plane *plane)
Jesse Barnes5e1bac22013-03-26 09:25:43 -07001542{
1543 struct intel_plane *intel_plane = to_intel_plane(plane);
1544
1545 if (!plane->crtc || !plane->fb)
Ville Syrjäläe57465f2014-08-05 11:26:53 +05301546 return 0;
Jesse Barnes5e1bac22013-03-26 09:25:43 -07001547
Sonika Jindal48404c12014-08-22 14:06:04 +05301548 return plane->funcs->update_plane(plane, plane->crtc, plane->fb,
Ville Syrjäläe57465f2014-08-05 11:26:53 +05301549 intel_plane->crtc_x, intel_plane->crtc_y,
1550 intel_plane->crtc_w, intel_plane->crtc_h,
1551 intel_plane->src_x, intel_plane->src_y,
1552 intel_plane->src_w, intel_plane->src_h);
Jesse Barnes5e1bac22013-03-26 09:25:43 -07001553}
1554
Ville Syrjäläbb53d4a2013-06-04 13:49:04 +03001555void intel_plane_disable(struct drm_plane *plane)
1556{
1557 if (!plane->crtc || !plane->fb)
1558 return;
1559
1560 intel_disable_plane(plane);
1561}
1562
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001563static const struct drm_plane_funcs intel_plane_funcs = {
1564 .update_plane = intel_update_plane,
1565 .disable_plane = intel_disable_plane,
1566 .destroy = intel_destroy_plane,
Ville Syrjälä7ed6eee2014-08-05 11:26:55 +05301567 .set_property = intel_plane_set_property,
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001568};
1569
Chris Wilsond1686ae2012-04-10 11:41:49 +01001570static uint32_t ilk_plane_formats[] = {
1571 DRM_FORMAT_XRGB8888,
1572 DRM_FORMAT_YUYV,
1573 DRM_FORMAT_YVYU,
1574 DRM_FORMAT_UYVY,
1575 DRM_FORMAT_VYUY,
1576};
1577
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001578static uint32_t snb_plane_formats[] = {
1579 DRM_FORMAT_XBGR8888,
1580 DRM_FORMAT_XRGB8888,
1581 DRM_FORMAT_YUYV,
1582 DRM_FORMAT_YVYU,
1583 DRM_FORMAT_UYVY,
1584 DRM_FORMAT_VYUY,
1585};
1586
Jesse Barnes7f1f3852013-04-02 11:22:20 -07001587static uint32_t vlv_plane_formats[] = {
1588 DRM_FORMAT_RGB565,
1589 DRM_FORMAT_ABGR8888,
1590 DRM_FORMAT_ARGB8888,
1591 DRM_FORMAT_XBGR8888,
1592 DRM_FORMAT_XRGB8888,
1593 DRM_FORMAT_XBGR2101010,
1594 DRM_FORMAT_ABGR2101010,
1595 DRM_FORMAT_YUYV,
1596 DRM_FORMAT_YVYU,
1597 DRM_FORMAT_UYVY,
1598 DRM_FORMAT_VYUY,
1599};
1600
Damien Lespiaudc2a41b2013-12-04 00:49:41 +00001601static uint32_t skl_plane_formats[] = {
1602 DRM_FORMAT_RGB565,
1603 DRM_FORMAT_ABGR8888,
1604 DRM_FORMAT_ARGB8888,
1605 DRM_FORMAT_XBGR8888,
1606 DRM_FORMAT_XRGB8888,
1607 DRM_FORMAT_YUYV,
1608 DRM_FORMAT_YVYU,
1609 DRM_FORMAT_UYVY,
1610 DRM_FORMAT_VYUY,
1611};
1612
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001613int
Jesse Barnes7f1f3852013-04-02 11:22:20 -07001614intel_plane_init(struct drm_device *dev, enum pipe pipe, int plane)
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001615{
1616 struct intel_plane *intel_plane;
1617 unsigned long possible_crtcs;
Chris Wilsond1686ae2012-04-10 11:41:49 +01001618 const uint32_t *plane_formats;
1619 int num_plane_formats;
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001620 int ret;
1621
Chris Wilsond1686ae2012-04-10 11:41:49 +01001622 if (INTEL_INFO(dev)->gen < 5)
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001623 return -ENODEV;
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001624
Daniel Vetterb14c5672013-09-19 12:18:32 +02001625 intel_plane = kzalloc(sizeof(*intel_plane), GFP_KERNEL);
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001626 if (!intel_plane)
1627 return -ENOMEM;
1628
Chris Wilsond1686ae2012-04-10 11:41:49 +01001629 switch (INTEL_INFO(dev)->gen) {
1630 case 5:
1631 case 6:
Damien Lespiau2d354c32012-10-22 18:19:27 +01001632 intel_plane->can_scale = true;
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001633 intel_plane->max_downscale = 16;
Chris Wilsond1686ae2012-04-10 11:41:49 +01001634 intel_plane->update_plane = ilk_update_plane;
1635 intel_plane->disable_plane = ilk_disable_plane;
1636 intel_plane->update_colorkey = ilk_update_colorkey;
1637 intel_plane->get_colorkey = ilk_get_colorkey;
1638
1639 if (IS_GEN6(dev)) {
1640 plane_formats = snb_plane_formats;
1641 num_plane_formats = ARRAY_SIZE(snb_plane_formats);
1642 } else {
1643 plane_formats = ilk_plane_formats;
1644 num_plane_formats = ARRAY_SIZE(ilk_plane_formats);
1645 }
1646 break;
1647
1648 case 7:
Ben Widawsky4e0bbc32013-11-02 21:07:07 -07001649 case 8:
Damien Lespiaud49f7092013-04-25 15:15:00 +01001650 if (IS_IVYBRIDGE(dev)) {
Damien Lespiau2d354c32012-10-22 18:19:27 +01001651 intel_plane->can_scale = true;
Damien Lespiaud49f7092013-04-25 15:15:00 +01001652 intel_plane->max_downscale = 2;
1653 } else {
1654 intel_plane->can_scale = false;
1655 intel_plane->max_downscale = 1;
1656 }
Chris Wilsond1686ae2012-04-10 11:41:49 +01001657
Jesse Barnes7f1f3852013-04-02 11:22:20 -07001658 if (IS_VALLEYVIEW(dev)) {
Jesse Barnes7f1f3852013-04-02 11:22:20 -07001659 intel_plane->update_plane = vlv_update_plane;
1660 intel_plane->disable_plane = vlv_disable_plane;
1661 intel_plane->update_colorkey = vlv_update_colorkey;
1662 intel_plane->get_colorkey = vlv_get_colorkey;
1663
1664 plane_formats = vlv_plane_formats;
1665 num_plane_formats = ARRAY_SIZE(vlv_plane_formats);
1666 } else {
Jesse Barnes7f1f3852013-04-02 11:22:20 -07001667 intel_plane->update_plane = ivb_update_plane;
1668 intel_plane->disable_plane = ivb_disable_plane;
1669 intel_plane->update_colorkey = ivb_update_colorkey;
1670 intel_plane->get_colorkey = ivb_get_colorkey;
1671
1672 plane_formats = snb_plane_formats;
1673 num_plane_formats = ARRAY_SIZE(snb_plane_formats);
1674 }
Chris Wilsond1686ae2012-04-10 11:41:49 +01001675 break;
Damien Lespiaudc2a41b2013-12-04 00:49:41 +00001676 case 9:
1677 /*
1678 * FIXME: Skylake planes can be scaled (with some restrictions),
1679 * but this is for another time.
1680 */
1681 intel_plane->can_scale = false;
1682 intel_plane->max_downscale = 1;
1683 intel_plane->update_plane = skl_update_plane;
1684 intel_plane->disable_plane = skl_disable_plane;
1685 intel_plane->update_colorkey = skl_update_colorkey;
1686 intel_plane->get_colorkey = skl_get_colorkey;
Chris Wilsond1686ae2012-04-10 11:41:49 +01001687
Damien Lespiaudc2a41b2013-12-04 00:49:41 +00001688 plane_formats = skl_plane_formats;
1689 num_plane_formats = ARRAY_SIZE(skl_plane_formats);
1690 break;
Chris Wilsond1686ae2012-04-10 11:41:49 +01001691 default:
Jesper Juhla8b0bba2012-06-27 00:55:37 +02001692 kfree(intel_plane);
Chris Wilsond1686ae2012-04-10 11:41:49 +01001693 return -ENODEV;
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001694 }
1695
1696 intel_plane->pipe = pipe;
Jesse Barnes7f1f3852013-04-02 11:22:20 -07001697 intel_plane->plane = plane;
Ville Syrjälä76eebda2014-08-05 11:26:52 +05301698 intel_plane->rotation = BIT(DRM_ROTATE_0);
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001699 possible_crtcs = (1 << pipe);
Derek Foreman8fe8a3f2014-09-03 10:38:20 -03001700 ret = drm_universal_plane_init(dev, &intel_plane->base, possible_crtcs,
1701 &intel_plane_funcs,
1702 plane_formats, num_plane_formats,
1703 DRM_PLANE_TYPE_OVERLAY);
Ville Syrjälä7ed6eee2014-08-05 11:26:55 +05301704 if (ret) {
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001705 kfree(intel_plane);
Ville Syrjälä7ed6eee2014-08-05 11:26:55 +05301706 goto out;
1707 }
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001708
Ville Syrjälä7ed6eee2014-08-05 11:26:55 +05301709 if (!dev->mode_config.rotation_property)
1710 dev->mode_config.rotation_property =
1711 drm_mode_create_rotation_property(dev,
1712 BIT(DRM_ROTATE_0) |
1713 BIT(DRM_ROTATE_180));
1714
1715 if (dev->mode_config.rotation_property)
1716 drm_object_attach_property(&intel_plane->base.base,
1717 dev->mode_config.rotation_property,
1718 intel_plane->rotation);
1719
1720 out:
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001721 return ret;
1722}