blob: d34a5696ffb616560c7f963bc54ee69a94dffa5f [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ä8d7849d2014-04-29 13:35:46 +030040static int usecs_to_scanlines(const struct drm_display_mode *mode, int usecs)
41{
42 /* paranoia */
43 if (!mode->crtc_htotal)
44 return 1;
45
46 return DIV_ROUND_UP(usecs * mode->crtc_clock, 1000 * mode->crtc_htotal);
47}
48
49static bool intel_pipe_update_start(struct intel_crtc *crtc, uint32_t *start_vbl_count)
50{
51 struct drm_device *dev = crtc->base.dev;
52 const struct drm_display_mode *mode = &crtc->config.adjusted_mode;
53 enum pipe pipe = crtc->pipe;
54 long timeout = msecs_to_jiffies_timeout(1);
55 int scanline, min, max, vblank_start;
Ville Syrjälä210871b2014-05-22 19:00:50 +030056 wait_queue_head_t *wq = drm_crtc_vblank_waitqueue(&crtc->base);
Ville Syrjälä8d7849d2014-04-29 13:35:46 +030057 DEFINE_WAIT(wait);
58
Rob Clark51fd3712013-11-19 12:10:12 -050059 WARN_ON(!drm_modeset_is_locked(&crtc->base.mutex));
Ville Syrjälä8d7849d2014-04-29 13:35:46 +030060
61 vblank_start = mode->crtc_vblank_start;
62 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
63 vblank_start = DIV_ROUND_UP(vblank_start, 2);
64
65 /* FIXME needs to be calibrated sensibly */
66 min = vblank_start - usecs_to_scanlines(mode, 100);
67 max = vblank_start - 1;
68
69 if (min <= 0 || max <= 0)
70 return false;
71
72 if (WARN_ON(drm_vblank_get(dev, pipe)))
73 return false;
74
75 local_irq_disable();
76
Ville Syrjälä25ef2842014-04-29 13:35:48 +030077 trace_i915_pipe_update_start(crtc, min, max);
78
Ville Syrjälä8d7849d2014-04-29 13:35:46 +030079 for (;;) {
80 /*
81 * prepare_to_wait() has a memory barrier, which guarantees
82 * other CPUs can see the task state update by the time we
83 * read the scanline.
84 */
Ville Syrjälä210871b2014-05-22 19:00:50 +030085 prepare_to_wait(wq, &wait, TASK_UNINTERRUPTIBLE);
Ville Syrjälä8d7849d2014-04-29 13:35:46 +030086
87 scanline = intel_get_crtc_scanline(crtc);
88 if (scanline < min || scanline > max)
89 break;
90
91 if (timeout <= 0) {
92 DRM_ERROR("Potential atomic update failure on pipe %c\n",
93 pipe_name(crtc->pipe));
94 break;
95 }
96
97 local_irq_enable();
98
99 timeout = schedule_timeout(timeout);
100
101 local_irq_disable();
102 }
103
Ville Syrjälä210871b2014-05-22 19:00:50 +0300104 finish_wait(wq, &wait);
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300105
106 drm_vblank_put(dev, pipe);
107
108 *start_vbl_count = dev->driver->get_vblank_counter(dev, pipe);
109
Ville Syrjälä25ef2842014-04-29 13:35:48 +0300110 trace_i915_pipe_update_vblank_evaded(crtc, min, max, *start_vbl_count);
111
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300112 return true;
113}
114
115static void intel_pipe_update_end(struct intel_crtc *crtc, u32 start_vbl_count)
116{
117 struct drm_device *dev = crtc->base.dev;
118 enum pipe pipe = crtc->pipe;
119 u32 end_vbl_count = dev->driver->get_vblank_counter(dev, pipe);
120
Ville Syrjälä25ef2842014-04-29 13:35:48 +0300121 trace_i915_pipe_update_end(crtc, end_vbl_count);
122
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300123 local_irq_enable();
124
125 if (start_vbl_count != end_vbl_count)
126 DRM_ERROR("Atomic update failure on pipe %c (start=%u end=%u)\n",
127 pipe_name(pipe), start_vbl_count, end_vbl_count);
128}
129
Ville Syrjälä5b633d62014-04-29 13:35:47 +0300130static void intel_update_primary_plane(struct intel_crtc *crtc)
131{
132 struct drm_i915_private *dev_priv = crtc->base.dev->dev_private;
133 int reg = DSPCNTR(crtc->plane);
134
135 if (crtc->primary_enabled)
136 I915_WRITE(reg, I915_READ(reg) | DISPLAY_PLANE_ENABLE);
137 else
138 I915_WRITE(reg, I915_READ(reg) & ~DISPLAY_PLANE_ENABLE);
139}
140
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800141static void
Ville Syrjäläb39d53f2013-08-06 22:24:09 +0300142vlv_update_plane(struct drm_plane *dplane, struct drm_crtc *crtc,
143 struct drm_framebuffer *fb,
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700144 struct drm_i915_gem_object *obj, int crtc_x, int crtc_y,
145 unsigned int crtc_w, unsigned int crtc_h,
146 uint32_t x, uint32_t y,
147 uint32_t src_w, uint32_t src_h)
148{
149 struct drm_device *dev = dplane->dev;
150 struct drm_i915_private *dev_priv = dev->dev_private;
151 struct intel_plane *intel_plane = to_intel_plane(dplane);
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300152 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700153 int pipe = intel_plane->pipe;
154 int plane = intel_plane->plane;
155 u32 sprctl;
156 unsigned long sprsurf_offset, linear_offset;
157 int pixel_size = drm_format_plane_cpp(fb->pixel_format, 0);
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300158 u32 start_vbl_count;
159 bool atomic_update;
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700160
161 sprctl = I915_READ(SPCNTR(pipe, plane));
162
163 /* Mask out pixel format bits in case we change it */
164 sprctl &= ~SP_PIXFORMAT_MASK;
165 sprctl &= ~SP_YUV_BYTE_ORDER_MASK;
166 sprctl &= ~SP_TILED;
167
168 switch (fb->pixel_format) {
169 case DRM_FORMAT_YUYV:
170 sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_YUYV;
171 break;
172 case DRM_FORMAT_YVYU:
173 sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_YVYU;
174 break;
175 case DRM_FORMAT_UYVY:
176 sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_UYVY;
177 break;
178 case DRM_FORMAT_VYUY:
179 sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_VYUY;
180 break;
181 case DRM_FORMAT_RGB565:
182 sprctl |= SP_FORMAT_BGR565;
183 break;
184 case DRM_FORMAT_XRGB8888:
185 sprctl |= SP_FORMAT_BGRX8888;
186 break;
187 case DRM_FORMAT_ARGB8888:
188 sprctl |= SP_FORMAT_BGRA8888;
189 break;
190 case DRM_FORMAT_XBGR2101010:
191 sprctl |= SP_FORMAT_RGBX1010102;
192 break;
193 case DRM_FORMAT_ABGR2101010:
194 sprctl |= SP_FORMAT_RGBA1010102;
195 break;
196 case DRM_FORMAT_XBGR8888:
197 sprctl |= SP_FORMAT_RGBX8888;
198 break;
199 case DRM_FORMAT_ABGR8888:
200 sprctl |= SP_FORMAT_RGBA8888;
201 break;
202 default:
203 /*
204 * If we get here one of the upper layers failed to filter
205 * out the unsupported plane formats
206 */
207 BUG();
208 break;
209 }
210
Ville Syrjälä4ea67bc2013-11-18 18:32:38 -0800211 /*
212 * Enable gamma to match primary/cursor plane behaviour.
213 * FIXME should be user controllable via propertiesa.
214 */
215 sprctl |= SP_GAMMA_ENABLE;
216
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700217 if (obj->tiling_mode != I915_TILING_NONE)
218 sprctl |= SP_TILED;
219
220 sprctl |= SP_ENABLE;
221
Damien Lespiaued57cb82014-07-15 09:21:24 +0200222 intel_update_sprite_watermarks(dplane, crtc, src_w, src_h,
223 pixel_size, true,
Ville Syrjälä67ca28f2013-07-05 11:57:14 +0300224 src_w != crtc_w || src_h != crtc_h);
225
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700226 /* Sizes are 0 based */
227 src_w--;
228 src_h--;
229 crtc_w--;
230 crtc_h--;
231
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700232 linear_offset = y * fb->pitches[0] + x * pixel_size;
233 sprsurf_offset = intel_gen4_compute_page_offset(&x, &y,
234 obj->tiling_mode,
235 pixel_size,
236 fb->pitches[0]);
237 linear_offset -= sprsurf_offset;
238
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300239 atomic_update = intel_pipe_update_start(intel_crtc, &start_vbl_count);
240
Ville Syrjälä5b633d62014-04-29 13:35:47 +0300241 intel_update_primary_plane(intel_crtc);
242
Ville Syrjäläca6ad022014-01-17 20:09:03 +0200243 I915_WRITE(SPSTRIDE(pipe, plane), fb->pitches[0]);
244 I915_WRITE(SPPOS(pipe, plane), (crtc_y << 16) | crtc_x);
245
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700246 if (obj->tiling_mode != I915_TILING_NONE)
247 I915_WRITE(SPTILEOFF(pipe, plane), (y << 16) | x);
248 else
249 I915_WRITE(SPLINOFF(pipe, plane), linear_offset);
250
251 I915_WRITE(SPSIZE(pipe, plane), (crtc_h << 16) | crtc_w);
252 I915_WRITE(SPCNTR(pipe, plane), sprctl);
Daniel Vetter85ba7b72014-01-24 10:31:44 +0100253 I915_WRITE(SPSURF(pipe, plane), i915_gem_obj_ggtt_offset(obj) +
254 sprsurf_offset);
Ville Syrjälä5b633d62014-04-29 13:35:47 +0300255
256 intel_flush_primary_plane(dev_priv, intel_crtc->plane);
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300257
258 if (atomic_update)
259 intel_pipe_update_end(intel_crtc, start_vbl_count);
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700260}
261
262static void
Ville Syrjäläb39d53f2013-08-06 22:24:09 +0300263vlv_disable_plane(struct drm_plane *dplane, struct drm_crtc *crtc)
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700264{
265 struct drm_device *dev = dplane->dev;
266 struct drm_i915_private *dev_priv = dev->dev_private;
267 struct intel_plane *intel_plane = to_intel_plane(dplane);
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300268 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700269 int pipe = intel_plane->pipe;
270 int plane = intel_plane->plane;
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300271 u32 start_vbl_count;
272 bool atomic_update;
273
274 atomic_update = intel_pipe_update_start(intel_crtc, &start_vbl_count);
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700275
Ville Syrjälä5b633d62014-04-29 13:35:47 +0300276 intel_update_primary_plane(intel_crtc);
277
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700278 I915_WRITE(SPCNTR(pipe, plane), I915_READ(SPCNTR(pipe, plane)) &
279 ~SP_ENABLE);
280 /* Activate double buffered register update */
Daniel Vetter85ba7b72014-01-24 10:31:44 +0100281 I915_WRITE(SPSURF(pipe, plane), 0);
Ville Syrjälä5b633d62014-04-29 13:35:47 +0300282
283 intel_flush_primary_plane(dev_priv, intel_crtc->plane);
Ville Syrjäläa95fd8c2013-08-06 22:24:12 +0300284
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300285 if (atomic_update)
286 intel_pipe_update_end(intel_crtc, start_vbl_count);
287
Damien Lespiaued57cb82014-07-15 09:21:24 +0200288 intel_update_sprite_watermarks(dplane, crtc, 0, 0, 0, false, false);
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700289}
290
291static int
292vlv_update_colorkey(struct drm_plane *dplane,
293 struct drm_intel_sprite_colorkey *key)
294{
295 struct drm_device *dev = dplane->dev;
296 struct drm_i915_private *dev_priv = dev->dev_private;
297 struct intel_plane *intel_plane = to_intel_plane(dplane);
298 int pipe = intel_plane->pipe;
299 int plane = intel_plane->plane;
300 u32 sprctl;
301
302 if (key->flags & I915_SET_COLORKEY_DESTINATION)
303 return -EINVAL;
304
305 I915_WRITE(SPKEYMINVAL(pipe, plane), key->min_value);
306 I915_WRITE(SPKEYMAXVAL(pipe, plane), key->max_value);
307 I915_WRITE(SPKEYMSK(pipe, plane), key->channel_mask);
308
309 sprctl = I915_READ(SPCNTR(pipe, plane));
310 sprctl &= ~SP_SOURCE_KEY;
311 if (key->flags & I915_SET_COLORKEY_SOURCE)
312 sprctl |= SP_SOURCE_KEY;
313 I915_WRITE(SPCNTR(pipe, plane), sprctl);
314
315 POSTING_READ(SPKEYMSK(pipe, plane));
316
317 return 0;
318}
319
320static void
321vlv_get_colorkey(struct drm_plane *dplane,
322 struct drm_intel_sprite_colorkey *key)
323{
324 struct drm_device *dev = dplane->dev;
325 struct drm_i915_private *dev_priv = dev->dev_private;
326 struct intel_plane *intel_plane = to_intel_plane(dplane);
327 int pipe = intel_plane->pipe;
328 int plane = intel_plane->plane;
329 u32 sprctl;
330
331 key->min_value = I915_READ(SPKEYMINVAL(pipe, plane));
332 key->max_value = I915_READ(SPKEYMAXVAL(pipe, plane));
333 key->channel_mask = I915_READ(SPKEYMSK(pipe, plane));
334
335 sprctl = I915_READ(SPCNTR(pipe, plane));
336 if (sprctl & SP_SOURCE_KEY)
337 key->flags = I915_SET_COLORKEY_SOURCE;
338 else
339 key->flags = I915_SET_COLORKEY_NONE;
340}
341
342static void
Ville Syrjäläb39d53f2013-08-06 22:24:09 +0300343ivb_update_plane(struct drm_plane *plane, struct drm_crtc *crtc,
344 struct drm_framebuffer *fb,
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800345 struct drm_i915_gem_object *obj, int crtc_x, int crtc_y,
346 unsigned int crtc_w, unsigned int crtc_h,
347 uint32_t x, uint32_t y,
348 uint32_t src_w, uint32_t src_h)
349{
350 struct drm_device *dev = plane->dev;
351 struct drm_i915_private *dev_priv = dev->dev_private;
352 struct intel_plane *intel_plane = to_intel_plane(plane);
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300353 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800354 int pipe = intel_plane->pipe;
355 u32 sprctl, sprscale = 0;
Damien Lespiau5a35e992012-10-26 18:20:12 +0100356 unsigned long sprsurf_offset, linear_offset;
Ville Syrjälä2bd3c3c2012-10-31 17:50:20 +0200357 int pixel_size = drm_format_plane_cpp(fb->pixel_format, 0);
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300358 u32 start_vbl_count;
359 bool atomic_update;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800360
361 sprctl = I915_READ(SPRCTL(pipe));
362
363 /* Mask out pixel format bits in case we change it */
364 sprctl &= ~SPRITE_PIXFORMAT_MASK;
365 sprctl &= ~SPRITE_RGB_ORDER_RGBX;
366 sprctl &= ~SPRITE_YUV_BYTE_ORDER_MASK;
Jesse Barnese86fe0d2012-06-26 13:10:11 -0700367 sprctl &= ~SPRITE_TILED;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800368
369 switch (fb->pixel_format) {
370 case DRM_FORMAT_XBGR8888:
Vijay Purushothaman5ee36912012-08-23 12:08:57 +0530371 sprctl |= SPRITE_FORMAT_RGBX888 | SPRITE_RGB_ORDER_RGBX;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800372 break;
373 case DRM_FORMAT_XRGB8888:
Vijay Purushothaman5ee36912012-08-23 12:08:57 +0530374 sprctl |= SPRITE_FORMAT_RGBX888;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800375 break;
376 case DRM_FORMAT_YUYV:
377 sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_YUYV;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800378 break;
379 case DRM_FORMAT_YVYU:
380 sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_YVYU;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800381 break;
382 case DRM_FORMAT_UYVY:
383 sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_UYVY;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800384 break;
385 case DRM_FORMAT_VYUY:
386 sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_VYUY;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800387 break;
388 default:
Ville Syrjälä28d491d2012-10-31 17:50:21 +0200389 BUG();
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800390 }
391
Ville Syrjälä4ea67bc2013-11-18 18:32:38 -0800392 /*
393 * Enable gamma to match primary/cursor plane behaviour.
394 * FIXME should be user controllable via propertiesa.
395 */
396 sprctl |= SPRITE_GAMMA_ENABLE;
397
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800398 if (obj->tiling_mode != I915_TILING_NONE)
399 sprctl |= SPRITE_TILED;
400
Ville Syrjäläb42c6002013-11-03 13:47:27 +0200401 if (IS_HASWELL(dev) || IS_BROADWELL(dev))
Paulo Zanoni1f5d76d2013-08-23 19:51:28 -0300402 sprctl &= ~SPRITE_TRICKLE_FEED_DISABLE;
403 else
404 sprctl |= SPRITE_TRICKLE_FEED_DISABLE;
405
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800406 sprctl |= SPRITE_ENABLE;
407
Ville Syrjälä6bbfa1c2013-11-02 21:07:39 -0700408 if (IS_HASWELL(dev) || IS_BROADWELL(dev))
Ville Syrjälä86d3efc2013-01-18 19:11:38 +0200409 sprctl |= SPRITE_PIPE_CSC_ENABLE;
410
Damien Lespiaued57cb82014-07-15 09:21:24 +0200411 intel_update_sprite_watermarks(plane, crtc, src_w, src_h, pixel_size,
412 true,
Ville Syrjälä67ca28f2013-07-05 11:57:14 +0300413 src_w != crtc_w || src_h != crtc_h);
414
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800415 /* Sizes are 0 based */
416 src_w--;
417 src_h--;
418 crtc_w--;
419 crtc_h--;
420
Ville Syrjälä8553c182013-12-05 15:51:39 +0200421 if (crtc_w != src_w || crtc_h != src_h)
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800422 sprscale = SPRITE_SCALE_ENABLE | (src_w << 16) | src_h;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800423
Chris Wilsonca320ac2012-12-19 12:14:22 +0000424 linear_offset = y * fb->pitches[0] + x * pixel_size;
Damien Lespiau5a35e992012-10-26 18:20:12 +0100425 sprsurf_offset =
Chris Wilsonbc752862013-02-21 20:04:31 +0000426 intel_gen4_compute_page_offset(&x, &y, obj->tiling_mode,
427 pixel_size, fb->pitches[0]);
Damien Lespiau5a35e992012-10-26 18:20:12 +0100428 linear_offset -= sprsurf_offset;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800429
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300430 atomic_update = intel_pipe_update_start(intel_crtc, &start_vbl_count);
431
Ville Syrjälä5b633d62014-04-29 13:35:47 +0300432 intel_update_primary_plane(intel_crtc);
433
Ville Syrjäläca6ad022014-01-17 20:09:03 +0200434 I915_WRITE(SPRSTRIDE(pipe), fb->pitches[0]);
435 I915_WRITE(SPRPOS(pipe), (crtc_y << 16) | crtc_x);
436
Damien Lespiau5a35e992012-10-26 18:20:12 +0100437 /* HSW consolidates SPRTILEOFF and SPRLINOFF into a single SPROFFSET
438 * register */
Paulo Zanonib3dc6852013-11-02 21:07:33 -0700439 if (IS_HASWELL(dev) || IS_BROADWELL(dev))
Damien Lespiau5a35e992012-10-26 18:20:12 +0100440 I915_WRITE(SPROFFSET(pipe), (y << 16) | x);
441 else if (obj->tiling_mode != I915_TILING_NONE)
442 I915_WRITE(SPRTILEOFF(pipe), (y << 16) | x);
443 else
444 I915_WRITE(SPRLINOFF(pipe), linear_offset);
Damien Lespiauc54173a2012-10-26 18:20:11 +0100445
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800446 I915_WRITE(SPRSIZE(pipe), (crtc_h << 16) | crtc_w);
Damien Lespiau2d354c32012-10-22 18:19:27 +0100447 if (intel_plane->can_scale)
448 I915_WRITE(SPRSCALE(pipe), sprscale);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800449 I915_WRITE(SPRCTL(pipe), sprctl);
Daniel Vetter85ba7b72014-01-24 10:31:44 +0100450 I915_WRITE(SPRSURF(pipe),
451 i915_gem_obj_ggtt_offset(obj) + sprsurf_offset);
Ville Syrjälä5b633d62014-04-29 13:35:47 +0300452
453 intel_flush_primary_plane(dev_priv, intel_crtc->plane);
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300454
455 if (atomic_update)
456 intel_pipe_update_end(intel_crtc, start_vbl_count);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800457}
458
459static void
Ville Syrjäläb39d53f2013-08-06 22:24:09 +0300460ivb_disable_plane(struct drm_plane *plane, struct drm_crtc *crtc)
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800461{
462 struct drm_device *dev = plane->dev;
463 struct drm_i915_private *dev_priv = dev->dev_private;
464 struct intel_plane *intel_plane = to_intel_plane(plane);
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300465 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800466 int pipe = intel_plane->pipe;
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300467 u32 start_vbl_count;
468 bool atomic_update;
469
470 atomic_update = intel_pipe_update_start(intel_crtc, &start_vbl_count);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800471
Ville Syrjälä5b633d62014-04-29 13:35:47 +0300472 intel_update_primary_plane(intel_crtc);
473
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800474 I915_WRITE(SPRCTL(pipe), I915_READ(SPRCTL(pipe)) & ~SPRITE_ENABLE);
475 /* Can't leave the scaler enabled... */
Damien Lespiau2d354c32012-10-22 18:19:27 +0100476 if (intel_plane->can_scale)
477 I915_WRITE(SPRSCALE(pipe), 0);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800478 /* Activate double buffered register update */
Daniel Vetter85ba7b72014-01-24 10:31:44 +0100479 I915_WRITE(SPRSURF(pipe), 0);
Ville Syrjälä5b633d62014-04-29 13:35:47 +0300480
481 intel_flush_primary_plane(dev_priv, intel_crtc->plane);
Chris Wilson828ed3e2012-04-18 17:12:26 +0100482
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300483 if (atomic_update)
484 intel_pipe_update_end(intel_crtc, start_vbl_count);
485
Ville Syrjälä1bd09ec2013-12-05 15:51:41 +0200486 /*
487 * Avoid underruns when disabling the sprite.
488 * FIXME remove once watermark updates are done properly.
489 */
490 intel_wait_for_vblank(dev, pipe);
491
Damien Lespiaued57cb82014-07-15 09:21:24 +0200492 intel_update_sprite_watermarks(plane, crtc, 0, 0, 0, false, false);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800493}
494
Jesse Barnes8ea30862012-01-03 08:05:39 -0800495static int
496ivb_update_colorkey(struct drm_plane *plane,
497 struct drm_intel_sprite_colorkey *key)
498{
499 struct drm_device *dev = plane->dev;
500 struct drm_i915_private *dev_priv = dev->dev_private;
501 struct intel_plane *intel_plane;
502 u32 sprctl;
503 int ret = 0;
504
505 intel_plane = to_intel_plane(plane);
506
507 I915_WRITE(SPRKEYVAL(intel_plane->pipe), key->min_value);
508 I915_WRITE(SPRKEYMAX(intel_plane->pipe), key->max_value);
509 I915_WRITE(SPRKEYMSK(intel_plane->pipe), key->channel_mask);
510
511 sprctl = I915_READ(SPRCTL(intel_plane->pipe));
512 sprctl &= ~(SPRITE_SOURCE_KEY | SPRITE_DEST_KEY);
513 if (key->flags & I915_SET_COLORKEY_DESTINATION)
514 sprctl |= SPRITE_DEST_KEY;
515 else if (key->flags & I915_SET_COLORKEY_SOURCE)
516 sprctl |= SPRITE_SOURCE_KEY;
517 I915_WRITE(SPRCTL(intel_plane->pipe), sprctl);
518
519 POSTING_READ(SPRKEYMSK(intel_plane->pipe));
520
521 return ret;
522}
523
524static void
525ivb_get_colorkey(struct drm_plane *plane, struct drm_intel_sprite_colorkey *key)
526{
527 struct drm_device *dev = plane->dev;
528 struct drm_i915_private *dev_priv = dev->dev_private;
529 struct intel_plane *intel_plane;
530 u32 sprctl;
531
532 intel_plane = to_intel_plane(plane);
533
534 key->min_value = I915_READ(SPRKEYVAL(intel_plane->pipe));
535 key->max_value = I915_READ(SPRKEYMAX(intel_plane->pipe));
536 key->channel_mask = I915_READ(SPRKEYMSK(intel_plane->pipe));
537 key->flags = 0;
538
539 sprctl = I915_READ(SPRCTL(intel_plane->pipe));
540
541 if (sprctl & SPRITE_DEST_KEY)
542 key->flags = I915_SET_COLORKEY_DESTINATION;
543 else if (sprctl & SPRITE_SOURCE_KEY)
544 key->flags = I915_SET_COLORKEY_SOURCE;
545 else
546 key->flags = I915_SET_COLORKEY_NONE;
547}
548
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800549static void
Ville Syrjäläb39d53f2013-08-06 22:24:09 +0300550ilk_update_plane(struct drm_plane *plane, struct drm_crtc *crtc,
551 struct drm_framebuffer *fb,
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800552 struct drm_i915_gem_object *obj, int crtc_x, int crtc_y,
553 unsigned int crtc_w, unsigned int crtc_h,
554 uint32_t x, uint32_t y,
555 uint32_t src_w, uint32_t src_h)
556{
557 struct drm_device *dev = plane->dev;
558 struct drm_i915_private *dev_priv = dev->dev_private;
559 struct intel_plane *intel_plane = to_intel_plane(plane);
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300560 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Ville Syrjälä2bd3c3c2012-10-31 17:50:20 +0200561 int pipe = intel_plane->pipe;
Damien Lespiau5a35e992012-10-26 18:20:12 +0100562 unsigned long dvssurf_offset, linear_offset;
Chris Wilson8aaa81a2012-04-14 22:14:26 +0100563 u32 dvscntr, dvsscale;
Ville Syrjälä2bd3c3c2012-10-31 17:50:20 +0200564 int pixel_size = drm_format_plane_cpp(fb->pixel_format, 0);
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300565 u32 start_vbl_count;
566 bool atomic_update;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800567
568 dvscntr = I915_READ(DVSCNTR(pipe));
569
570 /* Mask out pixel format bits in case we change it */
571 dvscntr &= ~DVS_PIXFORMAT_MASK;
Jesse Barnesab2f9df2012-02-27 12:40:10 -0800572 dvscntr &= ~DVS_RGB_ORDER_XBGR;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800573 dvscntr &= ~DVS_YUV_BYTE_ORDER_MASK;
Ander Conselvan de Oliveira79626522012-07-13 15:50:33 +0300574 dvscntr &= ~DVS_TILED;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800575
576 switch (fb->pixel_format) {
577 case DRM_FORMAT_XBGR8888:
Jesse Barnesab2f9df2012-02-27 12:40:10 -0800578 dvscntr |= DVS_FORMAT_RGBX888 | DVS_RGB_ORDER_XBGR;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800579 break;
580 case DRM_FORMAT_XRGB8888:
Jesse Barnesab2f9df2012-02-27 12:40:10 -0800581 dvscntr |= DVS_FORMAT_RGBX888;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800582 break;
583 case DRM_FORMAT_YUYV:
584 dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_YUYV;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800585 break;
586 case DRM_FORMAT_YVYU:
587 dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_YVYU;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800588 break;
589 case DRM_FORMAT_UYVY:
590 dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_UYVY;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800591 break;
592 case DRM_FORMAT_VYUY:
593 dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_VYUY;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800594 break;
595 default:
Ville Syrjälä28d491d2012-10-31 17:50:21 +0200596 BUG();
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800597 }
598
Ville Syrjälä4ea67bc2013-11-18 18:32:38 -0800599 /*
600 * Enable gamma to match primary/cursor plane behaviour.
601 * FIXME should be user controllable via propertiesa.
602 */
603 dvscntr |= DVS_GAMMA_ENABLE;
604
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800605 if (obj->tiling_mode != I915_TILING_NONE)
606 dvscntr |= DVS_TILED;
607
Chris Wilsond1686ae2012-04-10 11:41:49 +0100608 if (IS_GEN6(dev))
609 dvscntr |= DVS_TRICKLE_FEED_DISABLE; /* must disable */
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800610 dvscntr |= DVS_ENABLE;
611
Damien Lespiaued57cb82014-07-15 09:21:24 +0200612 intel_update_sprite_watermarks(plane, crtc, src_w, src_h,
613 pixel_size, true,
Ville Syrjälä67ca28f2013-07-05 11:57:14 +0300614 src_w != crtc_w || src_h != crtc_h);
615
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800616 /* Sizes are 0 based */
617 src_w--;
618 src_h--;
619 crtc_w--;
620 crtc_h--;
621
Chris Wilson8aaa81a2012-04-14 22:14:26 +0100622 dvsscale = 0;
Ville Syrjälä8368f012013-12-05 15:51:31 +0200623 if (crtc_w != src_w || crtc_h != src_h)
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800624 dvsscale = DVS_SCALE_ENABLE | (src_w << 16) | src_h;
625
Chris Wilsonca320ac2012-12-19 12:14:22 +0000626 linear_offset = y * fb->pitches[0] + x * pixel_size;
Damien Lespiau5a35e992012-10-26 18:20:12 +0100627 dvssurf_offset =
Chris Wilsonbc752862013-02-21 20:04:31 +0000628 intel_gen4_compute_page_offset(&x, &y, obj->tiling_mode,
629 pixel_size, fb->pitches[0]);
Damien Lespiau5a35e992012-10-26 18:20:12 +0100630 linear_offset -= dvssurf_offset;
631
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300632 atomic_update = intel_pipe_update_start(intel_crtc, &start_vbl_count);
633
Ville Syrjälä5b633d62014-04-29 13:35:47 +0300634 intel_update_primary_plane(intel_crtc);
635
Ville Syrjäläca6ad022014-01-17 20:09:03 +0200636 I915_WRITE(DVSSTRIDE(pipe), fb->pitches[0]);
637 I915_WRITE(DVSPOS(pipe), (crtc_y << 16) | crtc_x);
638
Damien Lespiau5a35e992012-10-26 18:20:12 +0100639 if (obj->tiling_mode != I915_TILING_NONE)
640 I915_WRITE(DVSTILEOFF(pipe), (y << 16) | x);
641 else
642 I915_WRITE(DVSLINOFF(pipe), linear_offset);
643
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800644 I915_WRITE(DVSSIZE(pipe), (crtc_h << 16) | crtc_w);
645 I915_WRITE(DVSSCALE(pipe), dvsscale);
646 I915_WRITE(DVSCNTR(pipe), dvscntr);
Daniel Vetter85ba7b72014-01-24 10:31:44 +0100647 I915_WRITE(DVSSURF(pipe),
648 i915_gem_obj_ggtt_offset(obj) + dvssurf_offset);
Ville Syrjälä5b633d62014-04-29 13:35:47 +0300649
650 intel_flush_primary_plane(dev_priv, intel_crtc->plane);
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300651
652 if (atomic_update)
653 intel_pipe_update_end(intel_crtc, start_vbl_count);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800654}
655
656static void
Ville Syrjäläb39d53f2013-08-06 22:24:09 +0300657ilk_disable_plane(struct drm_plane *plane, struct drm_crtc *crtc)
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800658{
659 struct drm_device *dev = plane->dev;
660 struct drm_i915_private *dev_priv = dev->dev_private;
661 struct intel_plane *intel_plane = to_intel_plane(plane);
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300662 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800663 int pipe = intel_plane->pipe;
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300664 u32 start_vbl_count;
665 bool atomic_update;
666
667 atomic_update = intel_pipe_update_start(intel_crtc, &start_vbl_count);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800668
Ville Syrjälä5b633d62014-04-29 13:35:47 +0300669 intel_update_primary_plane(intel_crtc);
670
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800671 I915_WRITE(DVSCNTR(pipe), I915_READ(DVSCNTR(pipe)) & ~DVS_ENABLE);
672 /* Disable the scaler */
673 I915_WRITE(DVSSCALE(pipe), 0);
674 /* Flush double buffered register updates */
Daniel Vetter85ba7b72014-01-24 10:31:44 +0100675 I915_WRITE(DVSSURF(pipe), 0);
Ville Syrjälä5b633d62014-04-29 13:35:47 +0300676
677 intel_flush_primary_plane(dev_priv, intel_crtc->plane);
Ville Syrjäläa95fd8c2013-08-06 22:24:12 +0300678
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300679 if (atomic_update)
680 intel_pipe_update_end(intel_crtc, start_vbl_count);
681
Ville Syrjälä1bd09ec2013-12-05 15:51:41 +0200682 /*
683 * Avoid underruns when disabling the sprite.
684 * FIXME remove once watermark updates are done properly.
685 */
686 intel_wait_for_vblank(dev, pipe);
687
Damien Lespiaued57cb82014-07-15 09:21:24 +0200688 intel_update_sprite_watermarks(plane, crtc, 0, 0, 0, false, false);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800689}
690
Jesse Barnes175bd422011-12-13 13:19:39 -0800691static void
Ville Syrjälä5b633d62014-04-29 13:35:47 +0300692intel_post_enable_primary(struct drm_crtc *crtc)
Jesse Barnes175bd422011-12-13 13:19:39 -0800693{
694 struct drm_device *dev = crtc->dev;
Jesse Barnes175bd422011-12-13 13:19:39 -0800695 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Ville Syrjäläabae50e2013-10-01 18:02:16 +0300696
Ville Syrjälä20bc86732013-10-01 18:02:17 +0300697 /*
Ville Syrjälä33c3b0d2014-06-24 13:59:28 +0300698 * BDW signals flip done immediately if the plane
699 * is disabled, even if the plane enable is already
700 * armed to occur at the next vblank :(
701 */
702 if (IS_BROADWELL(dev))
703 intel_wait_for_vblank(dev, intel_crtc->pipe);
704
705 /*
Ville Syrjälä20bc86732013-10-01 18:02:17 +0300706 * FIXME IPS should be fine as long as one plane is
707 * enabled, but in practice it seems to have problems
708 * when going from primary only to sprite only and vice
709 * versa.
710 */
Ville Syrjäläcea165c2014-04-15 21:41:35 +0300711 hsw_enable_ips(intel_crtc);
Ville Syrjälä20bc86732013-10-01 18:02:17 +0300712
Ville Syrjälä82284b62013-10-01 18:02:12 +0300713 mutex_lock(&dev->struct_mutex);
Chris Wilson93314b52012-06-13 17:36:55 +0100714 intel_update_fbc(dev);
Ville Syrjälä82284b62013-10-01 18:02:12 +0300715 mutex_unlock(&dev->struct_mutex);
Jesse Barnes175bd422011-12-13 13:19:39 -0800716}
717
718static void
Ville Syrjälä5b633d62014-04-29 13:35:47 +0300719intel_pre_disable_primary(struct drm_crtc *crtc)
Jesse Barnes175bd422011-12-13 13:19:39 -0800720{
721 struct drm_device *dev = crtc->dev;
722 struct drm_i915_private *dev_priv = dev->dev_private;
723 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Ville Syrjälä82284b62013-10-01 18:02:12 +0300724
725 mutex_lock(&dev->struct_mutex);
Ville Syrjäläabae50e2013-10-01 18:02:16 +0300726 if (dev_priv->fbc.plane == intel_crtc->plane)
727 intel_disable_fbc(dev);
Ville Syrjälä82284b62013-10-01 18:02:12 +0300728 mutex_unlock(&dev->struct_mutex);
Ville Syrjäläabae50e2013-10-01 18:02:16 +0300729
Ville Syrjälä20bc86732013-10-01 18:02:17 +0300730 /*
731 * FIXME IPS should be fine as long as one plane is
732 * enabled, but in practice it seems to have problems
733 * when going from primary only to sprite only and vice
734 * versa.
735 */
736 hsw_disable_ips(intel_crtc);
Jesse Barnes175bd422011-12-13 13:19:39 -0800737}
738
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800739static int
Chris Wilsond1686ae2012-04-10 11:41:49 +0100740ilk_update_colorkey(struct drm_plane *plane,
Jesse Barnes8ea30862012-01-03 08:05:39 -0800741 struct drm_intel_sprite_colorkey *key)
742{
743 struct drm_device *dev = plane->dev;
744 struct drm_i915_private *dev_priv = dev->dev_private;
745 struct intel_plane *intel_plane;
746 u32 dvscntr;
747 int ret = 0;
748
749 intel_plane = to_intel_plane(plane);
750
751 I915_WRITE(DVSKEYVAL(intel_plane->pipe), key->min_value);
752 I915_WRITE(DVSKEYMAX(intel_plane->pipe), key->max_value);
753 I915_WRITE(DVSKEYMSK(intel_plane->pipe), key->channel_mask);
754
755 dvscntr = I915_READ(DVSCNTR(intel_plane->pipe));
756 dvscntr &= ~(DVS_SOURCE_KEY | DVS_DEST_KEY);
757 if (key->flags & I915_SET_COLORKEY_DESTINATION)
758 dvscntr |= DVS_DEST_KEY;
759 else if (key->flags & I915_SET_COLORKEY_SOURCE)
760 dvscntr |= DVS_SOURCE_KEY;
761 I915_WRITE(DVSCNTR(intel_plane->pipe), dvscntr);
762
763 POSTING_READ(DVSKEYMSK(intel_plane->pipe));
764
765 return ret;
766}
767
768static void
Chris Wilsond1686ae2012-04-10 11:41:49 +0100769ilk_get_colorkey(struct drm_plane *plane, struct drm_intel_sprite_colorkey *key)
Jesse Barnes8ea30862012-01-03 08:05:39 -0800770{
771 struct drm_device *dev = plane->dev;
772 struct drm_i915_private *dev_priv = dev->dev_private;
773 struct intel_plane *intel_plane;
774 u32 dvscntr;
775
776 intel_plane = to_intel_plane(plane);
777
778 key->min_value = I915_READ(DVSKEYVAL(intel_plane->pipe));
779 key->max_value = I915_READ(DVSKEYMAX(intel_plane->pipe));
780 key->channel_mask = I915_READ(DVSKEYMSK(intel_plane->pipe));
781 key->flags = 0;
782
783 dvscntr = I915_READ(DVSCNTR(intel_plane->pipe));
784
785 if (dvscntr & DVS_DEST_KEY)
786 key->flags = I915_SET_COLORKEY_DESTINATION;
787 else if (dvscntr & DVS_SOURCE_KEY)
788 key->flags = I915_SET_COLORKEY_SOURCE;
789 else
790 key->flags = I915_SET_COLORKEY_NONE;
791}
792
Ville Syrjälä17316932013-04-24 18:52:38 +0300793static bool
794format_is_yuv(uint32_t format)
795{
796 switch (format) {
797 case DRM_FORMAT_YUYV:
798 case DRM_FORMAT_UYVY:
799 case DRM_FORMAT_VYUY:
800 case DRM_FORMAT_YVYU:
801 return true;
802 default:
803 return false;
804 }
805}
806
Ville Syrjäläefb31d12013-12-05 15:51:40 +0200807static bool colorkey_enabled(struct intel_plane *intel_plane)
808{
809 struct drm_intel_sprite_colorkey key;
810
811 intel_plane->get_colorkey(&intel_plane->base, &key);
812
813 return key.flags != I915_SET_COLORKEY_NONE;
814}
815
Jesse Barnes8ea30862012-01-03 08:05:39 -0800816static int
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800817intel_update_plane(struct drm_plane *plane, struct drm_crtc *crtc,
818 struct drm_framebuffer *fb, int crtc_x, int crtc_y,
819 unsigned int crtc_w, unsigned int crtc_h,
820 uint32_t src_x, uint32_t src_y,
821 uint32_t src_w, uint32_t src_h)
822{
823 struct drm_device *dev = plane->dev;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800824 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
825 struct intel_plane *intel_plane = to_intel_plane(plane);
Daniel Vettera071fa02014-06-18 23:28:09 +0200826 enum pipe pipe = intel_crtc->pipe;
Ville Syrjälä2afd9ef2013-10-01 18:02:14 +0300827 struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
828 struct drm_i915_gem_object *obj = intel_fb->obj;
829 struct drm_i915_gem_object *old_obj = intel_plane->obj;
830 int ret;
Ville Syrjälä5b633d62014-04-29 13:35:47 +0300831 bool primary_enabled;
Ville Syrjälä17316932013-04-24 18:52:38 +0300832 bool visible;
833 int hscale, vscale;
834 int max_scale, min_scale;
835 int pixel_size = drm_format_plane_cpp(fb->pixel_format, 0);
836 struct drm_rect src = {
837 /* sample coordinates in 16.16 fixed point */
838 .x1 = src_x,
839 .x2 = src_x + src_w,
840 .y1 = src_y,
841 .y2 = src_y + src_h,
842 };
843 struct drm_rect dst = {
844 /* integer pixels */
845 .x1 = crtc_x,
846 .x2 = crtc_x + crtc_w,
847 .y1 = crtc_y,
848 .y2 = crtc_y + crtc_h,
849 };
850 const struct drm_rect clip = {
Ville Syrjälä03c5b252013-10-01 18:02:11 +0300851 .x2 = intel_crtc->active ? intel_crtc->config.pipe_src_w : 0,
852 .y2 = intel_crtc->active ? intel_crtc->config.pipe_src_h : 0,
Ville Syrjälä17316932013-04-24 18:52:38 +0300853 };
Ville Syrjälä098ebd62013-10-01 18:02:15 +0300854 const struct {
855 int crtc_x, crtc_y;
856 unsigned int crtc_w, crtc_h;
857 uint32_t src_x, src_y, src_w, src_h;
858 } orig = {
859 .crtc_x = crtc_x,
860 .crtc_y = crtc_y,
861 .crtc_w = crtc_w,
862 .crtc_h = crtc_h,
863 .src_x = src_x,
864 .src_y = src_y,
865 .src_w = src_w,
866 .src_h = src_h,
867 };
Jesse Barnes5e1bac22013-03-26 09:25:43 -0700868
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800869 /* Don't modify another pipe's plane */
Ville Syrjälä17316932013-04-24 18:52:38 +0300870 if (intel_plane->pipe != intel_crtc->pipe) {
871 DRM_DEBUG_KMS("Wrong plane <-> crtc mapping\n");
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800872 return -EINVAL;
Ville Syrjälä17316932013-04-24 18:52:38 +0300873 }
874
875 /* FIXME check all gen limits */
876 if (fb->width < 3 || fb->height < 3 || fb->pitches[0] > 16384) {
877 DRM_DEBUG_KMS("Unsuitable framebuffer for plane\n");
878 return -EINVAL;
879 }
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800880
Damien Lespiau94c64192012-10-29 15:14:51 +0000881 /* Sprite planes can be linear or x-tiled surfaces */
882 switch (obj->tiling_mode) {
883 case I915_TILING_NONE:
884 case I915_TILING_X:
885 break;
886 default:
Ville Syrjälä17316932013-04-24 18:52:38 +0300887 DRM_DEBUG_KMS("Unsupported tiling mode\n");
Damien Lespiau94c64192012-10-29 15:14:51 +0000888 return -EINVAL;
889 }
890
Ville Syrjälä3c3686c2013-04-24 18:52:39 +0300891 /*
892 * FIXME the following code does a bunch of fuzzy adjustments to the
893 * coordinates and sizes. We probably need some way to decide whether
894 * more strict checking should be done instead.
895 */
Ville Syrjälä17316932013-04-24 18:52:38 +0300896 max_scale = intel_plane->max_downscale << 16;
897 min_scale = intel_plane->can_scale ? 1 : (1 << 16);
898
Ville Syrjälä3c3686c2013-04-24 18:52:39 +0300899 hscale = drm_rect_calc_hscale_relaxed(&src, &dst, min_scale, max_scale);
900 BUG_ON(hscale < 0);
Ville Syrjälä17316932013-04-24 18:52:38 +0300901
Ville Syrjälä3c3686c2013-04-24 18:52:39 +0300902 vscale = drm_rect_calc_vscale_relaxed(&src, &dst, min_scale, max_scale);
903 BUG_ON(vscale < 0);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800904
Ville Syrjälä17316932013-04-24 18:52:38 +0300905 visible = drm_rect_clip_scaled(&src, &dst, &clip, hscale, vscale);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800906
Ville Syrjälä17316932013-04-24 18:52:38 +0300907 crtc_x = dst.x1;
908 crtc_y = dst.y1;
909 crtc_w = drm_rect_width(&dst);
910 crtc_h = drm_rect_height(&dst);
Damien Lespiau2d354c32012-10-22 18:19:27 +0100911
Ville Syrjälä17316932013-04-24 18:52:38 +0300912 if (visible) {
Ville Syrjälä3c3686c2013-04-24 18:52:39 +0300913 /* check again in case clipping clamped the results */
914 hscale = drm_rect_calc_hscale(&src, &dst, min_scale, max_scale);
915 if (hscale < 0) {
916 DRM_DEBUG_KMS("Horizontal scaling factor out of limits\n");
917 drm_rect_debug_print(&src, true);
918 drm_rect_debug_print(&dst, false);
919
920 return hscale;
921 }
922
923 vscale = drm_rect_calc_vscale(&src, &dst, min_scale, max_scale);
924 if (vscale < 0) {
925 DRM_DEBUG_KMS("Vertical scaling factor out of limits\n");
926 drm_rect_debug_print(&src, true);
927 drm_rect_debug_print(&dst, false);
928
929 return vscale;
930 }
931
Ville Syrjälä17316932013-04-24 18:52:38 +0300932 /* Make the source viewport size an exact multiple of the scaling factors. */
933 drm_rect_adjust_size(&src,
934 drm_rect_width(&dst) * hscale - drm_rect_width(&src),
935 drm_rect_height(&dst) * vscale - drm_rect_height(&src));
936
937 /* sanity check to make sure the src viewport wasn't enlarged */
938 WARN_ON(src.x1 < (int) src_x ||
939 src.y1 < (int) src_y ||
940 src.x2 > (int) (src_x + src_w) ||
941 src.y2 > (int) (src_y + src_h));
942
943 /*
944 * Hardware doesn't handle subpixel coordinates.
945 * Adjust to (macro)pixel boundary, but be careful not to
946 * increase the source viewport size, because that could
947 * push the downscaling factor out of bounds.
Ville Syrjälä17316932013-04-24 18:52:38 +0300948 */
949 src_x = src.x1 >> 16;
950 src_w = drm_rect_width(&src) >> 16;
951 src_y = src.y1 >> 16;
952 src_h = drm_rect_height(&src) >> 16;
953
954 if (format_is_yuv(fb->pixel_format)) {
955 src_x &= ~1;
956 src_w &= ~1;
957
958 /*
959 * Must keep src and dst the
960 * same if we can't scale.
961 */
962 if (!intel_plane->can_scale)
963 crtc_w &= ~1;
964
965 if (crtc_w == 0)
966 visible = false;
967 }
968 }
969
970 /* Check size restrictions when scaling */
971 if (visible && (src_w != crtc_w || src_h != crtc_h)) {
972 unsigned int width_bytes;
973
974 WARN_ON(!intel_plane->can_scale);
975
976 /* FIXME interlacing min height is 6 */
977
978 if (crtc_w < 3 || crtc_h < 3)
979 visible = false;
980
981 if (src_w < 3 || src_h < 3)
982 visible = false;
983
984 width_bytes = ((src_x * pixel_size) & 63) + src_w * pixel_size;
985
986 if (src_w > 2048 || src_h > 2048 ||
987 width_bytes > 4096 || fb->pitches[0] > 4096) {
988 DRM_DEBUG_KMS("Source dimensions exceed hardware limits\n");
989 return -EINVAL;
990 }
991 }
992
993 dst.x1 = crtc_x;
994 dst.x2 = crtc_x + crtc_w;
995 dst.y1 = crtc_y;
996 dst.y2 = crtc_y + crtc_h;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800997
998 /*
999 * If the sprite is completely covering the primary plane,
1000 * we can disable the primary and save power.
1001 */
Ville Syrjälä5b633d62014-04-29 13:35:47 +03001002 primary_enabled = !drm_rect_equals(&dst, &clip) || colorkey_enabled(intel_plane);
1003 WARN_ON(!primary_enabled && !visible && intel_crtc->active);
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001004
1005 mutex_lock(&dev->struct_mutex);
1006
Chris Wilson693db182013-03-05 14:52:39 +00001007 /* Note that this will apply the VT-d workaround for scanouts,
1008 * which is more restrictive than required for sprites. (The
1009 * primary plane requires 256KiB alignment with 64 PTE padding,
1010 * the sprite planes only require 128KiB alignment and 32 PTE padding.
1011 */
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001012 ret = intel_pin_and_fence_fb_obj(dev, obj, NULL);
Ville Syrjälä82284b62013-10-01 18:02:12 +03001013
Daniel Vettera071fa02014-06-18 23:28:09 +02001014 i915_gem_track_fb(old_obj, obj,
1015 INTEL_FRONTBUFFER_SPRITE(pipe));
Ville Syrjälä82284b62013-10-01 18:02:12 +03001016 mutex_unlock(&dev->struct_mutex);
1017
Jesse Barnes00c2064b2012-01-13 15:48:39 -08001018 if (ret)
Ville Syrjälä82284b62013-10-01 18:02:12 +03001019 return ret;
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001020
Ville Syrjälä098ebd62013-10-01 18:02:15 +03001021 intel_plane->crtc_x = orig.crtc_x;
1022 intel_plane->crtc_y = orig.crtc_y;
1023 intel_plane->crtc_w = orig.crtc_w;
1024 intel_plane->crtc_h = orig.crtc_h;
1025 intel_plane->src_x = orig.src_x;
1026 intel_plane->src_y = orig.src_y;
1027 intel_plane->src_w = orig.src_w;
1028 intel_plane->src_h = orig.src_h;
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001029 intel_plane->obj = obj;
1030
Ville Syrjälä03c5b252013-10-01 18:02:11 +03001031 if (intel_crtc->active) {
Ville Syrjälä5b633d62014-04-29 13:35:47 +03001032 bool primary_was_enabled = intel_crtc->primary_enabled;
1033
1034 intel_crtc->primary_enabled = primary_enabled;
1035
Ville Syrjälä46a55d32014-05-21 14:04:46 +03001036 if (primary_was_enabled != primary_enabled)
1037 intel_crtc_wait_for_pending_flips(crtc);
1038
Ville Syrjälä5b633d62014-04-29 13:35:47 +03001039 if (primary_was_enabled && !primary_enabled)
1040 intel_pre_disable_primary(crtc);
Jesse Barnes175bd422011-12-13 13:19:39 -08001041
Ville Syrjälä03c5b252013-10-01 18:02:11 +03001042 if (visible)
1043 intel_plane->update_plane(plane, crtc, fb, obj,
1044 crtc_x, crtc_y, crtc_w, crtc_h,
1045 src_x, src_y, src_w, src_h);
1046 else
1047 intel_plane->disable_plane(plane, crtc);
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001048
Daniel Vetterf99d7062014-06-19 16:01:59 +02001049 intel_frontbuffer_flip(dev, INTEL_FRONTBUFFER_SPRITE(pipe));
1050
Ville Syrjälä5b633d62014-04-29 13:35:47 +03001051 if (!primary_was_enabled && primary_enabled)
1052 intel_post_enable_primary(crtc);
Ville Syrjälä03c5b252013-10-01 18:02:11 +03001053 }
Jesse Barnes175bd422011-12-13 13:19:39 -08001054
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001055 /* Unpin old obj after new one is active to avoid ugliness */
1056 if (old_obj) {
1057 /*
1058 * It's fairly common to simply update the position of
1059 * an existing object. In that case, we don't need to
1060 * wait for vblank to avoid ugliness, we only need to
1061 * do the pin & ref bookkeeping.
1062 */
Ville Syrjälä82284b62013-10-01 18:02:12 +03001063 if (old_obj != obj && intel_crtc->active)
Ville Syrjälä2afd9ef2013-10-01 18:02:14 +03001064 intel_wait_for_vblank(dev, intel_crtc->pipe);
Ville Syrjälä82284b62013-10-01 18:02:12 +03001065
1066 mutex_lock(&dev->struct_mutex);
Chris Wilson1690e1e2011-12-14 13:57:08 +01001067 intel_unpin_fb_obj(old_obj);
Ville Syrjälä82284b62013-10-01 18:02:12 +03001068 mutex_unlock(&dev->struct_mutex);
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001069 }
1070
Ville Syrjälä82284b62013-10-01 18:02:12 +03001071 return 0;
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001072}
1073
1074static int
1075intel_disable_plane(struct drm_plane *plane)
1076{
1077 struct drm_device *dev = plane->dev;
1078 struct intel_plane *intel_plane = to_intel_plane(plane);
Ville Syrjälä03c5b252013-10-01 18:02:11 +03001079 struct intel_crtc *intel_crtc;
Daniel Vettera071fa02014-06-18 23:28:09 +02001080 enum pipe pipe;
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001081
Ville Syrjälä88a94a52013-08-07 13:30:23 +03001082 if (!plane->fb)
1083 return 0;
1084
1085 if (WARN_ON(!plane->crtc))
1086 return -EINVAL;
1087
Ville Syrjälä03c5b252013-10-01 18:02:11 +03001088 intel_crtc = to_intel_crtc(plane->crtc);
Daniel Vettera071fa02014-06-18 23:28:09 +02001089 pipe = intel_crtc->pipe;
Ville Syrjälä03c5b252013-10-01 18:02:11 +03001090
1091 if (intel_crtc->active) {
Ville Syrjälä5b633d62014-04-29 13:35:47 +03001092 bool primary_was_enabled = intel_crtc->primary_enabled;
1093
1094 intel_crtc->primary_enabled = true;
1095
Ville Syrjälä03c5b252013-10-01 18:02:11 +03001096 intel_plane->disable_plane(plane, plane->crtc);
Ville Syrjälä5b633d62014-04-29 13:35:47 +03001097
1098 if (!primary_was_enabled && intel_crtc->primary_enabled)
1099 intel_post_enable_primary(plane->crtc);
Ville Syrjälä03c5b252013-10-01 18:02:11 +03001100 }
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001101
Ville Syrjälä5f3fb462013-10-01 18:02:13 +03001102 if (intel_plane->obj) {
1103 if (intel_crtc->active)
1104 intel_wait_for_vblank(dev, intel_plane->pipe);
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001105
Ville Syrjälä5f3fb462013-10-01 18:02:13 +03001106 mutex_lock(&dev->struct_mutex);
1107 intel_unpin_fb_obj(intel_plane->obj);
Daniel Vettera071fa02014-06-18 23:28:09 +02001108 i915_gem_track_fb(intel_plane->obj, NULL,
1109 INTEL_FRONTBUFFER_SPRITE(pipe));
Ville Syrjälä5f3fb462013-10-01 18:02:13 +03001110 mutex_unlock(&dev->struct_mutex);
Ville Syrjäläc626d312013-03-27 17:49:13 +02001111
Ville Syrjälä5f3fb462013-10-01 18:02:13 +03001112 intel_plane->obj = NULL;
1113 }
Ville Syrjälä82284b62013-10-01 18:02:12 +03001114
Ville Syrjälä5f3fb462013-10-01 18:02:13 +03001115 return 0;
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001116}
1117
1118static void intel_destroy_plane(struct drm_plane *plane)
1119{
1120 struct intel_plane *intel_plane = to_intel_plane(plane);
1121 intel_disable_plane(plane);
1122 drm_plane_cleanup(plane);
1123 kfree(intel_plane);
1124}
1125
Jesse Barnes8ea30862012-01-03 08:05:39 -08001126int intel_sprite_set_colorkey(struct drm_device *dev, void *data,
1127 struct drm_file *file_priv)
1128{
1129 struct drm_intel_sprite_colorkey *set = data;
Jesse Barnes8ea30862012-01-03 08:05:39 -08001130 struct drm_plane *plane;
1131 struct intel_plane *intel_plane;
1132 int ret = 0;
1133
Daniel Vetter1cff8f62012-04-24 09:55:08 +02001134 if (!drm_core_check_feature(dev, DRIVER_MODESET))
1135 return -ENODEV;
Jesse Barnes8ea30862012-01-03 08:05:39 -08001136
1137 /* Make sure we don't try to enable both src & dest simultaneously */
1138 if ((set->flags & (I915_SET_COLORKEY_DESTINATION | I915_SET_COLORKEY_SOURCE)) == (I915_SET_COLORKEY_DESTINATION | I915_SET_COLORKEY_SOURCE))
1139 return -EINVAL;
1140
Daniel Vettera0e99e62012-12-02 01:05:46 +01001141 drm_modeset_lock_all(dev);
Jesse Barnes8ea30862012-01-03 08:05:39 -08001142
Rob Clark7707e652014-07-17 23:30:04 -04001143 plane = drm_plane_find(dev, set->plane_id);
1144 if (!plane) {
Ville Syrjälä3f2c2052013-10-17 13:35:03 +03001145 ret = -ENOENT;
Jesse Barnes8ea30862012-01-03 08:05:39 -08001146 goto out_unlock;
1147 }
1148
Jesse Barnes8ea30862012-01-03 08:05:39 -08001149 intel_plane = to_intel_plane(plane);
1150 ret = intel_plane->update_colorkey(plane, set);
1151
1152out_unlock:
Daniel Vettera0e99e62012-12-02 01:05:46 +01001153 drm_modeset_unlock_all(dev);
Jesse Barnes8ea30862012-01-03 08:05:39 -08001154 return ret;
1155}
1156
1157int intel_sprite_get_colorkey(struct drm_device *dev, void *data,
1158 struct drm_file *file_priv)
1159{
1160 struct drm_intel_sprite_colorkey *get = data;
Jesse Barnes8ea30862012-01-03 08:05:39 -08001161 struct drm_plane *plane;
1162 struct intel_plane *intel_plane;
1163 int ret = 0;
1164
Daniel Vetter1cff8f62012-04-24 09:55:08 +02001165 if (!drm_core_check_feature(dev, DRIVER_MODESET))
1166 return -ENODEV;
Jesse Barnes8ea30862012-01-03 08:05:39 -08001167
Daniel Vettera0e99e62012-12-02 01:05:46 +01001168 drm_modeset_lock_all(dev);
Jesse Barnes8ea30862012-01-03 08:05:39 -08001169
Rob Clark7707e652014-07-17 23:30:04 -04001170 plane = drm_plane_find(dev, get->plane_id);
1171 if (!plane) {
Ville Syrjälä3f2c2052013-10-17 13:35:03 +03001172 ret = -ENOENT;
Jesse Barnes8ea30862012-01-03 08:05:39 -08001173 goto out_unlock;
1174 }
1175
Jesse Barnes8ea30862012-01-03 08:05:39 -08001176 intel_plane = to_intel_plane(plane);
1177 intel_plane->get_colorkey(plane, get);
1178
1179out_unlock:
Daniel Vettera0e99e62012-12-02 01:05:46 +01001180 drm_modeset_unlock_all(dev);
Jesse Barnes8ea30862012-01-03 08:05:39 -08001181 return ret;
1182}
1183
Jesse Barnes5e1bac22013-03-26 09:25:43 -07001184void intel_plane_restore(struct drm_plane *plane)
1185{
1186 struct intel_plane *intel_plane = to_intel_plane(plane);
1187
1188 if (!plane->crtc || !plane->fb)
1189 return;
1190
1191 intel_update_plane(plane, plane->crtc, plane->fb,
1192 intel_plane->crtc_x, intel_plane->crtc_y,
1193 intel_plane->crtc_w, intel_plane->crtc_h,
1194 intel_plane->src_x, intel_plane->src_y,
1195 intel_plane->src_w, intel_plane->src_h);
1196}
1197
Ville Syrjäläbb53d4a2013-06-04 13:49:04 +03001198void intel_plane_disable(struct drm_plane *plane)
1199{
1200 if (!plane->crtc || !plane->fb)
1201 return;
1202
1203 intel_disable_plane(plane);
1204}
1205
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001206static const struct drm_plane_funcs intel_plane_funcs = {
1207 .update_plane = intel_update_plane,
1208 .disable_plane = intel_disable_plane,
1209 .destroy = intel_destroy_plane,
1210};
1211
Chris Wilsond1686ae2012-04-10 11:41:49 +01001212static uint32_t ilk_plane_formats[] = {
1213 DRM_FORMAT_XRGB8888,
1214 DRM_FORMAT_YUYV,
1215 DRM_FORMAT_YVYU,
1216 DRM_FORMAT_UYVY,
1217 DRM_FORMAT_VYUY,
1218};
1219
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001220static uint32_t snb_plane_formats[] = {
1221 DRM_FORMAT_XBGR8888,
1222 DRM_FORMAT_XRGB8888,
1223 DRM_FORMAT_YUYV,
1224 DRM_FORMAT_YVYU,
1225 DRM_FORMAT_UYVY,
1226 DRM_FORMAT_VYUY,
1227};
1228
Jesse Barnes7f1f3852013-04-02 11:22:20 -07001229static uint32_t vlv_plane_formats[] = {
1230 DRM_FORMAT_RGB565,
1231 DRM_FORMAT_ABGR8888,
1232 DRM_FORMAT_ARGB8888,
1233 DRM_FORMAT_XBGR8888,
1234 DRM_FORMAT_XRGB8888,
1235 DRM_FORMAT_XBGR2101010,
1236 DRM_FORMAT_ABGR2101010,
1237 DRM_FORMAT_YUYV,
1238 DRM_FORMAT_YVYU,
1239 DRM_FORMAT_UYVY,
1240 DRM_FORMAT_VYUY,
1241};
1242
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001243int
Jesse Barnes7f1f3852013-04-02 11:22:20 -07001244intel_plane_init(struct drm_device *dev, enum pipe pipe, int plane)
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001245{
1246 struct intel_plane *intel_plane;
1247 unsigned long possible_crtcs;
Chris Wilsond1686ae2012-04-10 11:41:49 +01001248 const uint32_t *plane_formats;
1249 int num_plane_formats;
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001250 int ret;
1251
Chris Wilsond1686ae2012-04-10 11:41:49 +01001252 if (INTEL_INFO(dev)->gen < 5)
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001253 return -ENODEV;
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001254
Daniel Vetterb14c5672013-09-19 12:18:32 +02001255 intel_plane = kzalloc(sizeof(*intel_plane), GFP_KERNEL);
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001256 if (!intel_plane)
1257 return -ENOMEM;
1258
Chris Wilsond1686ae2012-04-10 11:41:49 +01001259 switch (INTEL_INFO(dev)->gen) {
1260 case 5:
1261 case 6:
Damien Lespiau2d354c32012-10-22 18:19:27 +01001262 intel_plane->can_scale = true;
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001263 intel_plane->max_downscale = 16;
Chris Wilsond1686ae2012-04-10 11:41:49 +01001264 intel_plane->update_plane = ilk_update_plane;
1265 intel_plane->disable_plane = ilk_disable_plane;
1266 intel_plane->update_colorkey = ilk_update_colorkey;
1267 intel_plane->get_colorkey = ilk_get_colorkey;
1268
1269 if (IS_GEN6(dev)) {
1270 plane_formats = snb_plane_formats;
1271 num_plane_formats = ARRAY_SIZE(snb_plane_formats);
1272 } else {
1273 plane_formats = ilk_plane_formats;
1274 num_plane_formats = ARRAY_SIZE(ilk_plane_formats);
1275 }
1276 break;
1277
1278 case 7:
Ben Widawsky4e0bbc32013-11-02 21:07:07 -07001279 case 8:
Damien Lespiaud49f7092013-04-25 15:15:00 +01001280 if (IS_IVYBRIDGE(dev)) {
Damien Lespiau2d354c32012-10-22 18:19:27 +01001281 intel_plane->can_scale = true;
Damien Lespiaud49f7092013-04-25 15:15:00 +01001282 intel_plane->max_downscale = 2;
1283 } else {
1284 intel_plane->can_scale = false;
1285 intel_plane->max_downscale = 1;
1286 }
Chris Wilsond1686ae2012-04-10 11:41:49 +01001287
Jesse Barnes7f1f3852013-04-02 11:22:20 -07001288 if (IS_VALLEYVIEW(dev)) {
Jesse Barnes7f1f3852013-04-02 11:22:20 -07001289 intel_plane->update_plane = vlv_update_plane;
1290 intel_plane->disable_plane = vlv_disable_plane;
1291 intel_plane->update_colorkey = vlv_update_colorkey;
1292 intel_plane->get_colorkey = vlv_get_colorkey;
1293
1294 plane_formats = vlv_plane_formats;
1295 num_plane_formats = ARRAY_SIZE(vlv_plane_formats);
1296 } else {
Jesse Barnes7f1f3852013-04-02 11:22:20 -07001297 intel_plane->update_plane = ivb_update_plane;
1298 intel_plane->disable_plane = ivb_disable_plane;
1299 intel_plane->update_colorkey = ivb_update_colorkey;
1300 intel_plane->get_colorkey = ivb_get_colorkey;
1301
1302 plane_formats = snb_plane_formats;
1303 num_plane_formats = ARRAY_SIZE(snb_plane_formats);
1304 }
Chris Wilsond1686ae2012-04-10 11:41:49 +01001305 break;
1306
1307 default:
Jesper Juhla8b0bba2012-06-27 00:55:37 +02001308 kfree(intel_plane);
Chris Wilsond1686ae2012-04-10 11:41:49 +01001309 return -ENODEV;
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001310 }
1311
1312 intel_plane->pipe = pipe;
Jesse Barnes7f1f3852013-04-02 11:22:20 -07001313 intel_plane->plane = plane;
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001314 possible_crtcs = (1 << pipe);
1315 ret = drm_plane_init(dev, &intel_plane->base, possible_crtcs,
Chris Wilsond1686ae2012-04-10 11:41:49 +01001316 &intel_plane_funcs,
1317 plane_formats, num_plane_formats,
1318 false);
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001319 if (ret)
1320 kfree(intel_plane);
1321
1322 return ret;
1323}