blob: 6192e586de5d55c6deb635857f7b99ce23709dad [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;
56 DEFINE_WAIT(wait);
57
58 WARN_ON(!mutex_is_locked(&crtc->base.mutex));
59
60 vblank_start = mode->crtc_vblank_start;
61 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
62 vblank_start = DIV_ROUND_UP(vblank_start, 2);
63
64 /* FIXME needs to be calibrated sensibly */
65 min = vblank_start - usecs_to_scanlines(mode, 100);
66 max = vblank_start - 1;
67
68 if (min <= 0 || max <= 0)
69 return false;
70
71 if (WARN_ON(drm_vblank_get(dev, pipe)))
72 return false;
73
74 local_irq_disable();
75
76 for (;;) {
77 /*
78 * prepare_to_wait() has a memory barrier, which guarantees
79 * other CPUs can see the task state update by the time we
80 * read the scanline.
81 */
82 prepare_to_wait(&crtc->vbl_wait, &wait, TASK_UNINTERRUPTIBLE);
83
84 scanline = intel_get_crtc_scanline(crtc);
85 if (scanline < min || scanline > max)
86 break;
87
88 if (timeout <= 0) {
89 DRM_ERROR("Potential atomic update failure on pipe %c\n",
90 pipe_name(crtc->pipe));
91 break;
92 }
93
94 local_irq_enable();
95
96 timeout = schedule_timeout(timeout);
97
98 local_irq_disable();
99 }
100
101 finish_wait(&crtc->vbl_wait, &wait);
102
103 drm_vblank_put(dev, pipe);
104
105 *start_vbl_count = dev->driver->get_vblank_counter(dev, pipe);
106
107 return true;
108}
109
110static void intel_pipe_update_end(struct intel_crtc *crtc, u32 start_vbl_count)
111{
112 struct drm_device *dev = crtc->base.dev;
113 enum pipe pipe = crtc->pipe;
114 u32 end_vbl_count = dev->driver->get_vblank_counter(dev, pipe);
115
116 local_irq_enable();
117
118 if (start_vbl_count != end_vbl_count)
119 DRM_ERROR("Atomic update failure on pipe %c (start=%u end=%u)\n",
120 pipe_name(pipe), start_vbl_count, end_vbl_count);
121}
122
Ville Syrjälä5b633d62014-04-29 13:35:47 +0300123static void intel_update_primary_plane(struct intel_crtc *crtc)
124{
125 struct drm_i915_private *dev_priv = crtc->base.dev->dev_private;
126 int reg = DSPCNTR(crtc->plane);
127
128 if (crtc->primary_enabled)
129 I915_WRITE(reg, I915_READ(reg) | DISPLAY_PLANE_ENABLE);
130 else
131 I915_WRITE(reg, I915_READ(reg) & ~DISPLAY_PLANE_ENABLE);
132}
133
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800134static void
Ville Syrjäläb39d53f2013-08-06 22:24:09 +0300135vlv_update_plane(struct drm_plane *dplane, struct drm_crtc *crtc,
136 struct drm_framebuffer *fb,
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700137 struct drm_i915_gem_object *obj, int crtc_x, int crtc_y,
138 unsigned int crtc_w, unsigned int crtc_h,
139 uint32_t x, uint32_t y,
140 uint32_t src_w, uint32_t src_h)
141{
142 struct drm_device *dev = dplane->dev;
143 struct drm_i915_private *dev_priv = dev->dev_private;
144 struct intel_plane *intel_plane = to_intel_plane(dplane);
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300145 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700146 int pipe = intel_plane->pipe;
147 int plane = intel_plane->plane;
148 u32 sprctl;
149 unsigned long sprsurf_offset, linear_offset;
150 int pixel_size = drm_format_plane_cpp(fb->pixel_format, 0);
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300151 u32 start_vbl_count;
152 bool atomic_update;
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700153
154 sprctl = I915_READ(SPCNTR(pipe, plane));
155
156 /* Mask out pixel format bits in case we change it */
157 sprctl &= ~SP_PIXFORMAT_MASK;
158 sprctl &= ~SP_YUV_BYTE_ORDER_MASK;
159 sprctl &= ~SP_TILED;
160
161 switch (fb->pixel_format) {
162 case DRM_FORMAT_YUYV:
163 sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_YUYV;
164 break;
165 case DRM_FORMAT_YVYU:
166 sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_YVYU;
167 break;
168 case DRM_FORMAT_UYVY:
169 sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_UYVY;
170 break;
171 case DRM_FORMAT_VYUY:
172 sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_VYUY;
173 break;
174 case DRM_FORMAT_RGB565:
175 sprctl |= SP_FORMAT_BGR565;
176 break;
177 case DRM_FORMAT_XRGB8888:
178 sprctl |= SP_FORMAT_BGRX8888;
179 break;
180 case DRM_FORMAT_ARGB8888:
181 sprctl |= SP_FORMAT_BGRA8888;
182 break;
183 case DRM_FORMAT_XBGR2101010:
184 sprctl |= SP_FORMAT_RGBX1010102;
185 break;
186 case DRM_FORMAT_ABGR2101010:
187 sprctl |= SP_FORMAT_RGBA1010102;
188 break;
189 case DRM_FORMAT_XBGR8888:
190 sprctl |= SP_FORMAT_RGBX8888;
191 break;
192 case DRM_FORMAT_ABGR8888:
193 sprctl |= SP_FORMAT_RGBA8888;
194 break;
195 default:
196 /*
197 * If we get here one of the upper layers failed to filter
198 * out the unsupported plane formats
199 */
200 BUG();
201 break;
202 }
203
Ville Syrjälä4ea67bc2013-11-18 18:32:38 -0800204 /*
205 * Enable gamma to match primary/cursor plane behaviour.
206 * FIXME should be user controllable via propertiesa.
207 */
208 sprctl |= SP_GAMMA_ENABLE;
209
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700210 if (obj->tiling_mode != I915_TILING_NONE)
211 sprctl |= SP_TILED;
212
213 sprctl |= SP_ENABLE;
214
Ville Syrjäläadf3d352013-08-06 22:24:11 +0300215 intel_update_sprite_watermarks(dplane, crtc, src_w, pixel_size, true,
Ville Syrjälä67ca28f2013-07-05 11:57:14 +0300216 src_w != crtc_w || src_h != crtc_h);
217
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700218 /* Sizes are 0 based */
219 src_w--;
220 src_h--;
221 crtc_w--;
222 crtc_h--;
223
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700224 linear_offset = y * fb->pitches[0] + x * pixel_size;
225 sprsurf_offset = intel_gen4_compute_page_offset(&x, &y,
226 obj->tiling_mode,
227 pixel_size,
228 fb->pitches[0]);
229 linear_offset -= sprsurf_offset;
230
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300231 atomic_update = intel_pipe_update_start(intel_crtc, &start_vbl_count);
232
Ville Syrjälä5b633d62014-04-29 13:35:47 +0300233 intel_update_primary_plane(intel_crtc);
234
Ville Syrjäläca6ad022014-01-17 20:09:03 +0200235 I915_WRITE(SPSTRIDE(pipe, plane), fb->pitches[0]);
236 I915_WRITE(SPPOS(pipe, plane), (crtc_y << 16) | crtc_x);
237
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700238 if (obj->tiling_mode != I915_TILING_NONE)
239 I915_WRITE(SPTILEOFF(pipe, plane), (y << 16) | x);
240 else
241 I915_WRITE(SPLINOFF(pipe, plane), linear_offset);
242
243 I915_WRITE(SPSIZE(pipe, plane), (crtc_h << 16) | crtc_w);
244 I915_WRITE(SPCNTR(pipe, plane), sprctl);
Daniel Vetter85ba7b72014-01-24 10:31:44 +0100245 I915_WRITE(SPSURF(pipe, plane), i915_gem_obj_ggtt_offset(obj) +
246 sprsurf_offset);
Ville Syrjälä5b633d62014-04-29 13:35:47 +0300247
248 intel_flush_primary_plane(dev_priv, intel_crtc->plane);
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300249
250 if (atomic_update)
251 intel_pipe_update_end(intel_crtc, start_vbl_count);
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700252}
253
254static void
Ville Syrjäläb39d53f2013-08-06 22:24:09 +0300255vlv_disable_plane(struct drm_plane *dplane, struct drm_crtc *crtc)
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700256{
257 struct drm_device *dev = dplane->dev;
258 struct drm_i915_private *dev_priv = dev->dev_private;
259 struct intel_plane *intel_plane = to_intel_plane(dplane);
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300260 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700261 int pipe = intel_plane->pipe;
262 int plane = intel_plane->plane;
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300263 u32 start_vbl_count;
264 bool atomic_update;
265
266 atomic_update = intel_pipe_update_start(intel_crtc, &start_vbl_count);
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700267
Ville Syrjälä5b633d62014-04-29 13:35:47 +0300268 intel_update_primary_plane(intel_crtc);
269
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700270 I915_WRITE(SPCNTR(pipe, plane), I915_READ(SPCNTR(pipe, plane)) &
271 ~SP_ENABLE);
272 /* Activate double buffered register update */
Daniel Vetter85ba7b72014-01-24 10:31:44 +0100273 I915_WRITE(SPSURF(pipe, plane), 0);
Ville Syrjälä5b633d62014-04-29 13:35:47 +0300274
275 intel_flush_primary_plane(dev_priv, intel_crtc->plane);
Ville Syrjäläa95fd8c2013-08-06 22:24:12 +0300276
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300277 if (atomic_update)
278 intel_pipe_update_end(intel_crtc, start_vbl_count);
279
Ville Syrjäläa95fd8c2013-08-06 22:24:12 +0300280 intel_update_sprite_watermarks(dplane, crtc, 0, 0, false, false);
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700281}
282
283static int
284vlv_update_colorkey(struct drm_plane *dplane,
285 struct drm_intel_sprite_colorkey *key)
286{
287 struct drm_device *dev = dplane->dev;
288 struct drm_i915_private *dev_priv = dev->dev_private;
289 struct intel_plane *intel_plane = to_intel_plane(dplane);
290 int pipe = intel_plane->pipe;
291 int plane = intel_plane->plane;
292 u32 sprctl;
293
294 if (key->flags & I915_SET_COLORKEY_DESTINATION)
295 return -EINVAL;
296
297 I915_WRITE(SPKEYMINVAL(pipe, plane), key->min_value);
298 I915_WRITE(SPKEYMAXVAL(pipe, plane), key->max_value);
299 I915_WRITE(SPKEYMSK(pipe, plane), key->channel_mask);
300
301 sprctl = I915_READ(SPCNTR(pipe, plane));
302 sprctl &= ~SP_SOURCE_KEY;
303 if (key->flags & I915_SET_COLORKEY_SOURCE)
304 sprctl |= SP_SOURCE_KEY;
305 I915_WRITE(SPCNTR(pipe, plane), sprctl);
306
307 POSTING_READ(SPKEYMSK(pipe, plane));
308
309 return 0;
310}
311
312static void
313vlv_get_colorkey(struct drm_plane *dplane,
314 struct drm_intel_sprite_colorkey *key)
315{
316 struct drm_device *dev = dplane->dev;
317 struct drm_i915_private *dev_priv = dev->dev_private;
318 struct intel_plane *intel_plane = to_intel_plane(dplane);
319 int pipe = intel_plane->pipe;
320 int plane = intel_plane->plane;
321 u32 sprctl;
322
323 key->min_value = I915_READ(SPKEYMINVAL(pipe, plane));
324 key->max_value = I915_READ(SPKEYMAXVAL(pipe, plane));
325 key->channel_mask = I915_READ(SPKEYMSK(pipe, plane));
326
327 sprctl = I915_READ(SPCNTR(pipe, plane));
328 if (sprctl & SP_SOURCE_KEY)
329 key->flags = I915_SET_COLORKEY_SOURCE;
330 else
331 key->flags = I915_SET_COLORKEY_NONE;
332}
333
334static void
Ville Syrjäläb39d53f2013-08-06 22:24:09 +0300335ivb_update_plane(struct drm_plane *plane, struct drm_crtc *crtc,
336 struct drm_framebuffer *fb,
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800337 struct drm_i915_gem_object *obj, int crtc_x, int crtc_y,
338 unsigned int crtc_w, unsigned int crtc_h,
339 uint32_t x, uint32_t y,
340 uint32_t src_w, uint32_t src_h)
341{
342 struct drm_device *dev = plane->dev;
343 struct drm_i915_private *dev_priv = dev->dev_private;
344 struct intel_plane *intel_plane = to_intel_plane(plane);
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300345 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800346 int pipe = intel_plane->pipe;
347 u32 sprctl, sprscale = 0;
Damien Lespiau5a35e992012-10-26 18:20:12 +0100348 unsigned long sprsurf_offset, linear_offset;
Ville Syrjälä2bd3c3c2012-10-31 17:50:20 +0200349 int pixel_size = drm_format_plane_cpp(fb->pixel_format, 0);
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300350 u32 start_vbl_count;
351 bool atomic_update;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800352
353 sprctl = I915_READ(SPRCTL(pipe));
354
355 /* Mask out pixel format bits in case we change it */
356 sprctl &= ~SPRITE_PIXFORMAT_MASK;
357 sprctl &= ~SPRITE_RGB_ORDER_RGBX;
358 sprctl &= ~SPRITE_YUV_BYTE_ORDER_MASK;
Jesse Barnese86fe0d2012-06-26 13:10:11 -0700359 sprctl &= ~SPRITE_TILED;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800360
361 switch (fb->pixel_format) {
362 case DRM_FORMAT_XBGR8888:
Vijay Purushothaman5ee36912012-08-23 12:08:57 +0530363 sprctl |= SPRITE_FORMAT_RGBX888 | SPRITE_RGB_ORDER_RGBX;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800364 break;
365 case DRM_FORMAT_XRGB8888:
Vijay Purushothaman5ee36912012-08-23 12:08:57 +0530366 sprctl |= SPRITE_FORMAT_RGBX888;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800367 break;
368 case DRM_FORMAT_YUYV:
369 sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_YUYV;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800370 break;
371 case DRM_FORMAT_YVYU:
372 sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_YVYU;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800373 break;
374 case DRM_FORMAT_UYVY:
375 sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_UYVY;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800376 break;
377 case DRM_FORMAT_VYUY:
378 sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_VYUY;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800379 break;
380 default:
Ville Syrjälä28d491d2012-10-31 17:50:21 +0200381 BUG();
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800382 }
383
Ville Syrjälä4ea67bc2013-11-18 18:32:38 -0800384 /*
385 * Enable gamma to match primary/cursor plane behaviour.
386 * FIXME should be user controllable via propertiesa.
387 */
388 sprctl |= SPRITE_GAMMA_ENABLE;
389
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800390 if (obj->tiling_mode != I915_TILING_NONE)
391 sprctl |= SPRITE_TILED;
392
Ville Syrjäläb42c6002013-11-03 13:47:27 +0200393 if (IS_HASWELL(dev) || IS_BROADWELL(dev))
Paulo Zanoni1f5d76d2013-08-23 19:51:28 -0300394 sprctl &= ~SPRITE_TRICKLE_FEED_DISABLE;
395 else
396 sprctl |= SPRITE_TRICKLE_FEED_DISABLE;
397
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800398 sprctl |= SPRITE_ENABLE;
399
Ville Syrjälä6bbfa1c2013-11-02 21:07:39 -0700400 if (IS_HASWELL(dev) || IS_BROADWELL(dev))
Ville Syrjälä86d3efc2013-01-18 19:11:38 +0200401 sprctl |= SPRITE_PIPE_CSC_ENABLE;
402
Ville Syrjäläadf3d352013-08-06 22:24:11 +0300403 intel_update_sprite_watermarks(plane, crtc, src_w, pixel_size, true,
Ville Syrjälä67ca28f2013-07-05 11:57:14 +0300404 src_w != crtc_w || src_h != crtc_h);
405
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800406 /* Sizes are 0 based */
407 src_w--;
408 src_h--;
409 crtc_w--;
410 crtc_h--;
411
Ville Syrjälä8553c182013-12-05 15:51:39 +0200412 if (crtc_w != src_w || crtc_h != src_h)
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800413 sprscale = SPRITE_SCALE_ENABLE | (src_w << 16) | src_h;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800414
Chris Wilsonca320ac2012-12-19 12:14:22 +0000415 linear_offset = y * fb->pitches[0] + x * pixel_size;
Damien Lespiau5a35e992012-10-26 18:20:12 +0100416 sprsurf_offset =
Chris Wilsonbc752862013-02-21 20:04:31 +0000417 intel_gen4_compute_page_offset(&x, &y, obj->tiling_mode,
418 pixel_size, fb->pitches[0]);
Damien Lespiau5a35e992012-10-26 18:20:12 +0100419 linear_offset -= sprsurf_offset;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800420
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300421 atomic_update = intel_pipe_update_start(intel_crtc, &start_vbl_count);
422
Ville Syrjälä5b633d62014-04-29 13:35:47 +0300423 intel_update_primary_plane(intel_crtc);
424
Ville Syrjäläca6ad022014-01-17 20:09:03 +0200425 I915_WRITE(SPRSTRIDE(pipe), fb->pitches[0]);
426 I915_WRITE(SPRPOS(pipe), (crtc_y << 16) | crtc_x);
427
Damien Lespiau5a35e992012-10-26 18:20:12 +0100428 /* HSW consolidates SPRTILEOFF and SPRLINOFF into a single SPROFFSET
429 * register */
Paulo Zanonib3dc6852013-11-02 21:07:33 -0700430 if (IS_HASWELL(dev) || IS_BROADWELL(dev))
Damien Lespiau5a35e992012-10-26 18:20:12 +0100431 I915_WRITE(SPROFFSET(pipe), (y << 16) | x);
432 else if (obj->tiling_mode != I915_TILING_NONE)
433 I915_WRITE(SPRTILEOFF(pipe), (y << 16) | x);
434 else
435 I915_WRITE(SPRLINOFF(pipe), linear_offset);
Damien Lespiauc54173a2012-10-26 18:20:11 +0100436
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800437 I915_WRITE(SPRSIZE(pipe), (crtc_h << 16) | crtc_w);
Damien Lespiau2d354c32012-10-22 18:19:27 +0100438 if (intel_plane->can_scale)
439 I915_WRITE(SPRSCALE(pipe), sprscale);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800440 I915_WRITE(SPRCTL(pipe), sprctl);
Daniel Vetter85ba7b72014-01-24 10:31:44 +0100441 I915_WRITE(SPRSURF(pipe),
442 i915_gem_obj_ggtt_offset(obj) + sprsurf_offset);
Ville Syrjälä5b633d62014-04-29 13:35:47 +0300443
444 intel_flush_primary_plane(dev_priv, intel_crtc->plane);
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300445
446 if (atomic_update)
447 intel_pipe_update_end(intel_crtc, start_vbl_count);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800448}
449
450static void
Ville Syrjäläb39d53f2013-08-06 22:24:09 +0300451ivb_disable_plane(struct drm_plane *plane, struct drm_crtc *crtc)
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800452{
453 struct drm_device *dev = plane->dev;
454 struct drm_i915_private *dev_priv = dev->dev_private;
455 struct intel_plane *intel_plane = to_intel_plane(plane);
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300456 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800457 int pipe = intel_plane->pipe;
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300458 u32 start_vbl_count;
459 bool atomic_update;
460
461 atomic_update = intel_pipe_update_start(intel_crtc, &start_vbl_count);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800462
Ville Syrjälä5b633d62014-04-29 13:35:47 +0300463 intel_update_primary_plane(intel_crtc);
464
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800465 I915_WRITE(SPRCTL(pipe), I915_READ(SPRCTL(pipe)) & ~SPRITE_ENABLE);
466 /* Can't leave the scaler enabled... */
Damien Lespiau2d354c32012-10-22 18:19:27 +0100467 if (intel_plane->can_scale)
468 I915_WRITE(SPRSCALE(pipe), 0);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800469 /* Activate double buffered register update */
Daniel Vetter85ba7b72014-01-24 10:31:44 +0100470 I915_WRITE(SPRSURF(pipe), 0);
Ville Syrjälä5b633d62014-04-29 13:35:47 +0300471
472 intel_flush_primary_plane(dev_priv, intel_crtc->plane);
Chris Wilson828ed3e2012-04-18 17:12:26 +0100473
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300474 if (atomic_update)
475 intel_pipe_update_end(intel_crtc, start_vbl_count);
476
Ville Syrjälä1bd09ec2013-12-05 15:51:41 +0200477 /*
478 * Avoid underruns when disabling the sprite.
479 * FIXME remove once watermark updates are done properly.
480 */
481 intel_wait_for_vblank(dev, pipe);
482
Ville Syrjäläadf3d352013-08-06 22:24:11 +0300483 intel_update_sprite_watermarks(plane, crtc, 0, 0, false, false);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800484}
485
Jesse Barnes8ea30862012-01-03 08:05:39 -0800486static int
487ivb_update_colorkey(struct drm_plane *plane,
488 struct drm_intel_sprite_colorkey *key)
489{
490 struct drm_device *dev = plane->dev;
491 struct drm_i915_private *dev_priv = dev->dev_private;
492 struct intel_plane *intel_plane;
493 u32 sprctl;
494 int ret = 0;
495
496 intel_plane = to_intel_plane(plane);
497
498 I915_WRITE(SPRKEYVAL(intel_plane->pipe), key->min_value);
499 I915_WRITE(SPRKEYMAX(intel_plane->pipe), key->max_value);
500 I915_WRITE(SPRKEYMSK(intel_plane->pipe), key->channel_mask);
501
502 sprctl = I915_READ(SPRCTL(intel_plane->pipe));
503 sprctl &= ~(SPRITE_SOURCE_KEY | SPRITE_DEST_KEY);
504 if (key->flags & I915_SET_COLORKEY_DESTINATION)
505 sprctl |= SPRITE_DEST_KEY;
506 else if (key->flags & I915_SET_COLORKEY_SOURCE)
507 sprctl |= SPRITE_SOURCE_KEY;
508 I915_WRITE(SPRCTL(intel_plane->pipe), sprctl);
509
510 POSTING_READ(SPRKEYMSK(intel_plane->pipe));
511
512 return ret;
513}
514
515static void
516ivb_get_colorkey(struct drm_plane *plane, struct drm_intel_sprite_colorkey *key)
517{
518 struct drm_device *dev = plane->dev;
519 struct drm_i915_private *dev_priv = dev->dev_private;
520 struct intel_plane *intel_plane;
521 u32 sprctl;
522
523 intel_plane = to_intel_plane(plane);
524
525 key->min_value = I915_READ(SPRKEYVAL(intel_plane->pipe));
526 key->max_value = I915_READ(SPRKEYMAX(intel_plane->pipe));
527 key->channel_mask = I915_READ(SPRKEYMSK(intel_plane->pipe));
528 key->flags = 0;
529
530 sprctl = I915_READ(SPRCTL(intel_plane->pipe));
531
532 if (sprctl & SPRITE_DEST_KEY)
533 key->flags = I915_SET_COLORKEY_DESTINATION;
534 else if (sprctl & SPRITE_SOURCE_KEY)
535 key->flags = I915_SET_COLORKEY_SOURCE;
536 else
537 key->flags = I915_SET_COLORKEY_NONE;
538}
539
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800540static void
Ville Syrjäläb39d53f2013-08-06 22:24:09 +0300541ilk_update_plane(struct drm_plane *plane, struct drm_crtc *crtc,
542 struct drm_framebuffer *fb,
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800543 struct drm_i915_gem_object *obj, int crtc_x, int crtc_y,
544 unsigned int crtc_w, unsigned int crtc_h,
545 uint32_t x, uint32_t y,
546 uint32_t src_w, uint32_t src_h)
547{
548 struct drm_device *dev = plane->dev;
549 struct drm_i915_private *dev_priv = dev->dev_private;
550 struct intel_plane *intel_plane = to_intel_plane(plane);
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300551 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Ville Syrjälä2bd3c3c2012-10-31 17:50:20 +0200552 int pipe = intel_plane->pipe;
Damien Lespiau5a35e992012-10-26 18:20:12 +0100553 unsigned long dvssurf_offset, linear_offset;
Chris Wilson8aaa81a2012-04-14 22:14:26 +0100554 u32 dvscntr, dvsscale;
Ville Syrjälä2bd3c3c2012-10-31 17:50:20 +0200555 int pixel_size = drm_format_plane_cpp(fb->pixel_format, 0);
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300556 u32 start_vbl_count;
557 bool atomic_update;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800558
559 dvscntr = I915_READ(DVSCNTR(pipe));
560
561 /* Mask out pixel format bits in case we change it */
562 dvscntr &= ~DVS_PIXFORMAT_MASK;
Jesse Barnesab2f9df2012-02-27 12:40:10 -0800563 dvscntr &= ~DVS_RGB_ORDER_XBGR;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800564 dvscntr &= ~DVS_YUV_BYTE_ORDER_MASK;
Ander Conselvan de Oliveira79626522012-07-13 15:50:33 +0300565 dvscntr &= ~DVS_TILED;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800566
567 switch (fb->pixel_format) {
568 case DRM_FORMAT_XBGR8888:
Jesse Barnesab2f9df2012-02-27 12:40:10 -0800569 dvscntr |= DVS_FORMAT_RGBX888 | DVS_RGB_ORDER_XBGR;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800570 break;
571 case DRM_FORMAT_XRGB8888:
Jesse Barnesab2f9df2012-02-27 12:40:10 -0800572 dvscntr |= DVS_FORMAT_RGBX888;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800573 break;
574 case DRM_FORMAT_YUYV:
575 dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_YUYV;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800576 break;
577 case DRM_FORMAT_YVYU:
578 dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_YVYU;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800579 break;
580 case DRM_FORMAT_UYVY:
581 dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_UYVY;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800582 break;
583 case DRM_FORMAT_VYUY:
584 dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_VYUY;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800585 break;
586 default:
Ville Syrjälä28d491d2012-10-31 17:50:21 +0200587 BUG();
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800588 }
589
Ville Syrjälä4ea67bc2013-11-18 18:32:38 -0800590 /*
591 * Enable gamma to match primary/cursor plane behaviour.
592 * FIXME should be user controllable via propertiesa.
593 */
594 dvscntr |= DVS_GAMMA_ENABLE;
595
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800596 if (obj->tiling_mode != I915_TILING_NONE)
597 dvscntr |= DVS_TILED;
598
Chris Wilsond1686ae2012-04-10 11:41:49 +0100599 if (IS_GEN6(dev))
600 dvscntr |= DVS_TRICKLE_FEED_DISABLE; /* must disable */
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800601 dvscntr |= DVS_ENABLE;
602
Ville Syrjäläadf3d352013-08-06 22:24:11 +0300603 intel_update_sprite_watermarks(plane, crtc, src_w, pixel_size, true,
Ville Syrjälä67ca28f2013-07-05 11:57:14 +0300604 src_w != crtc_w || src_h != crtc_h);
605
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800606 /* Sizes are 0 based */
607 src_w--;
608 src_h--;
609 crtc_w--;
610 crtc_h--;
611
Chris Wilson8aaa81a2012-04-14 22:14:26 +0100612 dvsscale = 0;
Ville Syrjälä8368f012013-12-05 15:51:31 +0200613 if (crtc_w != src_w || crtc_h != src_h)
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800614 dvsscale = DVS_SCALE_ENABLE | (src_w << 16) | src_h;
615
Chris Wilsonca320ac2012-12-19 12:14:22 +0000616 linear_offset = y * fb->pitches[0] + x * pixel_size;
Damien Lespiau5a35e992012-10-26 18:20:12 +0100617 dvssurf_offset =
Chris Wilsonbc752862013-02-21 20:04:31 +0000618 intel_gen4_compute_page_offset(&x, &y, obj->tiling_mode,
619 pixel_size, fb->pitches[0]);
Damien Lespiau5a35e992012-10-26 18:20:12 +0100620 linear_offset -= dvssurf_offset;
621
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300622 atomic_update = intel_pipe_update_start(intel_crtc, &start_vbl_count);
623
Ville Syrjälä5b633d62014-04-29 13:35:47 +0300624 intel_update_primary_plane(intel_crtc);
625
Ville Syrjäläca6ad022014-01-17 20:09:03 +0200626 I915_WRITE(DVSSTRIDE(pipe), fb->pitches[0]);
627 I915_WRITE(DVSPOS(pipe), (crtc_y << 16) | crtc_x);
628
Damien Lespiau5a35e992012-10-26 18:20:12 +0100629 if (obj->tiling_mode != I915_TILING_NONE)
630 I915_WRITE(DVSTILEOFF(pipe), (y << 16) | x);
631 else
632 I915_WRITE(DVSLINOFF(pipe), linear_offset);
633
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800634 I915_WRITE(DVSSIZE(pipe), (crtc_h << 16) | crtc_w);
635 I915_WRITE(DVSSCALE(pipe), dvsscale);
636 I915_WRITE(DVSCNTR(pipe), dvscntr);
Daniel Vetter85ba7b72014-01-24 10:31:44 +0100637 I915_WRITE(DVSSURF(pipe),
638 i915_gem_obj_ggtt_offset(obj) + dvssurf_offset);
Ville Syrjälä5b633d62014-04-29 13:35:47 +0300639
640 intel_flush_primary_plane(dev_priv, intel_crtc->plane);
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300641
642 if (atomic_update)
643 intel_pipe_update_end(intel_crtc, start_vbl_count);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800644}
645
646static void
Ville Syrjäläb39d53f2013-08-06 22:24:09 +0300647ilk_disable_plane(struct drm_plane *plane, struct drm_crtc *crtc)
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800648{
649 struct drm_device *dev = plane->dev;
650 struct drm_i915_private *dev_priv = dev->dev_private;
651 struct intel_plane *intel_plane = to_intel_plane(plane);
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300652 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800653 int pipe = intel_plane->pipe;
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300654 u32 start_vbl_count;
655 bool atomic_update;
656
657 atomic_update = intel_pipe_update_start(intel_crtc, &start_vbl_count);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800658
Ville Syrjälä5b633d62014-04-29 13:35:47 +0300659 intel_update_primary_plane(intel_crtc);
660
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800661 I915_WRITE(DVSCNTR(pipe), I915_READ(DVSCNTR(pipe)) & ~DVS_ENABLE);
662 /* Disable the scaler */
663 I915_WRITE(DVSSCALE(pipe), 0);
664 /* Flush double buffered register updates */
Daniel Vetter85ba7b72014-01-24 10:31:44 +0100665 I915_WRITE(DVSSURF(pipe), 0);
Ville Syrjälä5b633d62014-04-29 13:35:47 +0300666
667 intel_flush_primary_plane(dev_priv, intel_crtc->plane);
Ville Syrjäläa95fd8c2013-08-06 22:24:12 +0300668
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300669 if (atomic_update)
670 intel_pipe_update_end(intel_crtc, start_vbl_count);
671
Ville Syrjälä1bd09ec2013-12-05 15:51:41 +0200672 /*
673 * Avoid underruns when disabling the sprite.
674 * FIXME remove once watermark updates are done properly.
675 */
676 intel_wait_for_vblank(dev, pipe);
677
Ville Syrjäläa95fd8c2013-08-06 22:24:12 +0300678 intel_update_sprite_watermarks(plane, crtc, 0, 0, false, false);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800679}
680
Jesse Barnes175bd422011-12-13 13:19:39 -0800681static void
Ville Syrjälä5b633d62014-04-29 13:35:47 +0300682intel_post_enable_primary(struct drm_crtc *crtc)
Jesse Barnes175bd422011-12-13 13:19:39 -0800683{
684 struct drm_device *dev = crtc->dev;
Jesse Barnes175bd422011-12-13 13:19:39 -0800685 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Ville Syrjäläabae50e2013-10-01 18:02:16 +0300686
Ville Syrjälä20bc86732013-10-01 18:02:17 +0300687 /*
688 * FIXME IPS should be fine as long as one plane is
689 * enabled, but in practice it seems to have problems
690 * when going from primary only to sprite only and vice
691 * versa.
692 */
693 if (intel_crtc->config.ips_enabled) {
694 intel_wait_for_vblank(dev, intel_crtc->pipe);
695 hsw_enable_ips(intel_crtc);
696 }
697
Ville Syrjälä82284b62013-10-01 18:02:12 +0300698 mutex_lock(&dev->struct_mutex);
Chris Wilson93314b52012-06-13 17:36:55 +0100699 intel_update_fbc(dev);
Ville Syrjälä82284b62013-10-01 18:02:12 +0300700 mutex_unlock(&dev->struct_mutex);
Jesse Barnes175bd422011-12-13 13:19:39 -0800701}
702
703static void
Ville Syrjälä5b633d62014-04-29 13:35:47 +0300704intel_pre_disable_primary(struct drm_crtc *crtc)
Jesse Barnes175bd422011-12-13 13:19:39 -0800705{
706 struct drm_device *dev = crtc->dev;
707 struct drm_i915_private *dev_priv = dev->dev_private;
708 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Ville Syrjälä82284b62013-10-01 18:02:12 +0300709
710 mutex_lock(&dev->struct_mutex);
Ville Syrjäläabae50e2013-10-01 18:02:16 +0300711 if (dev_priv->fbc.plane == intel_crtc->plane)
712 intel_disable_fbc(dev);
Ville Syrjälä82284b62013-10-01 18:02:12 +0300713 mutex_unlock(&dev->struct_mutex);
Ville Syrjäläabae50e2013-10-01 18:02:16 +0300714
Ville Syrjälä20bc86732013-10-01 18:02:17 +0300715 /*
716 * FIXME IPS should be fine as long as one plane is
717 * enabled, but in practice it seems to have problems
718 * when going from primary only to sprite only and vice
719 * versa.
720 */
721 hsw_disable_ips(intel_crtc);
Jesse Barnes175bd422011-12-13 13:19:39 -0800722}
723
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800724static int
Chris Wilsond1686ae2012-04-10 11:41:49 +0100725ilk_update_colorkey(struct drm_plane *plane,
Jesse Barnes8ea30862012-01-03 08:05:39 -0800726 struct drm_intel_sprite_colorkey *key)
727{
728 struct drm_device *dev = plane->dev;
729 struct drm_i915_private *dev_priv = dev->dev_private;
730 struct intel_plane *intel_plane;
731 u32 dvscntr;
732 int ret = 0;
733
734 intel_plane = to_intel_plane(plane);
735
736 I915_WRITE(DVSKEYVAL(intel_plane->pipe), key->min_value);
737 I915_WRITE(DVSKEYMAX(intel_plane->pipe), key->max_value);
738 I915_WRITE(DVSKEYMSK(intel_plane->pipe), key->channel_mask);
739
740 dvscntr = I915_READ(DVSCNTR(intel_plane->pipe));
741 dvscntr &= ~(DVS_SOURCE_KEY | DVS_DEST_KEY);
742 if (key->flags & I915_SET_COLORKEY_DESTINATION)
743 dvscntr |= DVS_DEST_KEY;
744 else if (key->flags & I915_SET_COLORKEY_SOURCE)
745 dvscntr |= DVS_SOURCE_KEY;
746 I915_WRITE(DVSCNTR(intel_plane->pipe), dvscntr);
747
748 POSTING_READ(DVSKEYMSK(intel_plane->pipe));
749
750 return ret;
751}
752
753static void
Chris Wilsond1686ae2012-04-10 11:41:49 +0100754ilk_get_colorkey(struct drm_plane *plane, struct drm_intel_sprite_colorkey *key)
Jesse Barnes8ea30862012-01-03 08:05:39 -0800755{
756 struct drm_device *dev = plane->dev;
757 struct drm_i915_private *dev_priv = dev->dev_private;
758 struct intel_plane *intel_plane;
759 u32 dvscntr;
760
761 intel_plane = to_intel_plane(plane);
762
763 key->min_value = I915_READ(DVSKEYVAL(intel_plane->pipe));
764 key->max_value = I915_READ(DVSKEYMAX(intel_plane->pipe));
765 key->channel_mask = I915_READ(DVSKEYMSK(intel_plane->pipe));
766 key->flags = 0;
767
768 dvscntr = I915_READ(DVSCNTR(intel_plane->pipe));
769
770 if (dvscntr & DVS_DEST_KEY)
771 key->flags = I915_SET_COLORKEY_DESTINATION;
772 else if (dvscntr & DVS_SOURCE_KEY)
773 key->flags = I915_SET_COLORKEY_SOURCE;
774 else
775 key->flags = I915_SET_COLORKEY_NONE;
776}
777
Ville Syrjälä17316932013-04-24 18:52:38 +0300778static bool
779format_is_yuv(uint32_t format)
780{
781 switch (format) {
782 case DRM_FORMAT_YUYV:
783 case DRM_FORMAT_UYVY:
784 case DRM_FORMAT_VYUY:
785 case DRM_FORMAT_YVYU:
786 return true;
787 default:
788 return false;
789 }
790}
791
Ville Syrjäläefb31d12013-12-05 15:51:40 +0200792static bool colorkey_enabled(struct intel_plane *intel_plane)
793{
794 struct drm_intel_sprite_colorkey key;
795
796 intel_plane->get_colorkey(&intel_plane->base, &key);
797
798 return key.flags != I915_SET_COLORKEY_NONE;
799}
800
Jesse Barnes8ea30862012-01-03 08:05:39 -0800801static int
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800802intel_update_plane(struct drm_plane *plane, struct drm_crtc *crtc,
803 struct drm_framebuffer *fb, int crtc_x, int crtc_y,
804 unsigned int crtc_w, unsigned int crtc_h,
805 uint32_t src_x, uint32_t src_y,
806 uint32_t src_w, uint32_t src_h)
807{
808 struct drm_device *dev = plane->dev;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800809 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
810 struct intel_plane *intel_plane = to_intel_plane(plane);
Ville Syrjälä2afd9ef2013-10-01 18:02:14 +0300811 struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
812 struct drm_i915_gem_object *obj = intel_fb->obj;
813 struct drm_i915_gem_object *old_obj = intel_plane->obj;
814 int ret;
Ville Syrjälä5b633d62014-04-29 13:35:47 +0300815 bool primary_enabled;
Ville Syrjälä17316932013-04-24 18:52:38 +0300816 bool visible;
817 int hscale, vscale;
818 int max_scale, min_scale;
819 int pixel_size = drm_format_plane_cpp(fb->pixel_format, 0);
820 struct drm_rect src = {
821 /* sample coordinates in 16.16 fixed point */
822 .x1 = src_x,
823 .x2 = src_x + src_w,
824 .y1 = src_y,
825 .y2 = src_y + src_h,
826 };
827 struct drm_rect dst = {
828 /* integer pixels */
829 .x1 = crtc_x,
830 .x2 = crtc_x + crtc_w,
831 .y1 = crtc_y,
832 .y2 = crtc_y + crtc_h,
833 };
834 const struct drm_rect clip = {
Ville Syrjälä03c5b252013-10-01 18:02:11 +0300835 .x2 = intel_crtc->active ? intel_crtc->config.pipe_src_w : 0,
836 .y2 = intel_crtc->active ? intel_crtc->config.pipe_src_h : 0,
Ville Syrjälä17316932013-04-24 18:52:38 +0300837 };
Ville Syrjälä098ebd62013-10-01 18:02:15 +0300838 const struct {
839 int crtc_x, crtc_y;
840 unsigned int crtc_w, crtc_h;
841 uint32_t src_x, src_y, src_w, src_h;
842 } orig = {
843 .crtc_x = crtc_x,
844 .crtc_y = crtc_y,
845 .crtc_w = crtc_w,
846 .crtc_h = crtc_h,
847 .src_x = src_x,
848 .src_y = src_y,
849 .src_w = src_w,
850 .src_h = src_h,
851 };
Jesse Barnes5e1bac22013-03-26 09:25:43 -0700852
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800853 /* Don't modify another pipe's plane */
Ville Syrjälä17316932013-04-24 18:52:38 +0300854 if (intel_plane->pipe != intel_crtc->pipe) {
855 DRM_DEBUG_KMS("Wrong plane <-> crtc mapping\n");
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800856 return -EINVAL;
Ville Syrjälä17316932013-04-24 18:52:38 +0300857 }
858
859 /* FIXME check all gen limits */
860 if (fb->width < 3 || fb->height < 3 || fb->pitches[0] > 16384) {
861 DRM_DEBUG_KMS("Unsuitable framebuffer for plane\n");
862 return -EINVAL;
863 }
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800864
Damien Lespiau94c64192012-10-29 15:14:51 +0000865 /* Sprite planes can be linear or x-tiled surfaces */
866 switch (obj->tiling_mode) {
867 case I915_TILING_NONE:
868 case I915_TILING_X:
869 break;
870 default:
Ville Syrjälä17316932013-04-24 18:52:38 +0300871 DRM_DEBUG_KMS("Unsupported tiling mode\n");
Damien Lespiau94c64192012-10-29 15:14:51 +0000872 return -EINVAL;
873 }
874
Ville Syrjälä3c3686c2013-04-24 18:52:39 +0300875 /*
876 * FIXME the following code does a bunch of fuzzy adjustments to the
877 * coordinates and sizes. We probably need some way to decide whether
878 * more strict checking should be done instead.
879 */
Ville Syrjälä17316932013-04-24 18:52:38 +0300880 max_scale = intel_plane->max_downscale << 16;
881 min_scale = intel_plane->can_scale ? 1 : (1 << 16);
882
Ville Syrjälä3c3686c2013-04-24 18:52:39 +0300883 hscale = drm_rect_calc_hscale_relaxed(&src, &dst, min_scale, max_scale);
884 BUG_ON(hscale < 0);
Ville Syrjälä17316932013-04-24 18:52:38 +0300885
Ville Syrjälä3c3686c2013-04-24 18:52:39 +0300886 vscale = drm_rect_calc_vscale_relaxed(&src, &dst, min_scale, max_scale);
887 BUG_ON(vscale < 0);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800888
Ville Syrjälä17316932013-04-24 18:52:38 +0300889 visible = drm_rect_clip_scaled(&src, &dst, &clip, hscale, vscale);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800890
Ville Syrjälä17316932013-04-24 18:52:38 +0300891 crtc_x = dst.x1;
892 crtc_y = dst.y1;
893 crtc_w = drm_rect_width(&dst);
894 crtc_h = drm_rect_height(&dst);
Damien Lespiau2d354c32012-10-22 18:19:27 +0100895
Ville Syrjälä17316932013-04-24 18:52:38 +0300896 if (visible) {
Ville Syrjälä3c3686c2013-04-24 18:52:39 +0300897 /* check again in case clipping clamped the results */
898 hscale = drm_rect_calc_hscale(&src, &dst, min_scale, max_scale);
899 if (hscale < 0) {
900 DRM_DEBUG_KMS("Horizontal scaling factor out of limits\n");
901 drm_rect_debug_print(&src, true);
902 drm_rect_debug_print(&dst, false);
903
904 return hscale;
905 }
906
907 vscale = drm_rect_calc_vscale(&src, &dst, min_scale, max_scale);
908 if (vscale < 0) {
909 DRM_DEBUG_KMS("Vertical scaling factor out of limits\n");
910 drm_rect_debug_print(&src, true);
911 drm_rect_debug_print(&dst, false);
912
913 return vscale;
914 }
915
Ville Syrjälä17316932013-04-24 18:52:38 +0300916 /* Make the source viewport size an exact multiple of the scaling factors. */
917 drm_rect_adjust_size(&src,
918 drm_rect_width(&dst) * hscale - drm_rect_width(&src),
919 drm_rect_height(&dst) * vscale - drm_rect_height(&src));
920
921 /* sanity check to make sure the src viewport wasn't enlarged */
922 WARN_ON(src.x1 < (int) src_x ||
923 src.y1 < (int) src_y ||
924 src.x2 > (int) (src_x + src_w) ||
925 src.y2 > (int) (src_y + src_h));
926
927 /*
928 * Hardware doesn't handle subpixel coordinates.
929 * Adjust to (macro)pixel boundary, but be careful not to
930 * increase the source viewport size, because that could
931 * push the downscaling factor out of bounds.
Ville Syrjälä17316932013-04-24 18:52:38 +0300932 */
933 src_x = src.x1 >> 16;
934 src_w = drm_rect_width(&src) >> 16;
935 src_y = src.y1 >> 16;
936 src_h = drm_rect_height(&src) >> 16;
937
938 if (format_is_yuv(fb->pixel_format)) {
939 src_x &= ~1;
940 src_w &= ~1;
941
942 /*
943 * Must keep src and dst the
944 * same if we can't scale.
945 */
946 if (!intel_plane->can_scale)
947 crtc_w &= ~1;
948
949 if (crtc_w == 0)
950 visible = false;
951 }
952 }
953
954 /* Check size restrictions when scaling */
955 if (visible && (src_w != crtc_w || src_h != crtc_h)) {
956 unsigned int width_bytes;
957
958 WARN_ON(!intel_plane->can_scale);
959
960 /* FIXME interlacing min height is 6 */
961
962 if (crtc_w < 3 || crtc_h < 3)
963 visible = false;
964
965 if (src_w < 3 || src_h < 3)
966 visible = false;
967
968 width_bytes = ((src_x * pixel_size) & 63) + src_w * pixel_size;
969
970 if (src_w > 2048 || src_h > 2048 ||
971 width_bytes > 4096 || fb->pitches[0] > 4096) {
972 DRM_DEBUG_KMS("Source dimensions exceed hardware limits\n");
973 return -EINVAL;
974 }
975 }
976
977 dst.x1 = crtc_x;
978 dst.x2 = crtc_x + crtc_w;
979 dst.y1 = crtc_y;
980 dst.y2 = crtc_y + crtc_h;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800981
982 /*
983 * If the sprite is completely covering the primary plane,
984 * we can disable the primary and save power.
985 */
Ville Syrjälä5b633d62014-04-29 13:35:47 +0300986 primary_enabled = !drm_rect_equals(&dst, &clip) || colorkey_enabled(intel_plane);
987 WARN_ON(!primary_enabled && !visible && intel_crtc->active);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800988
989 mutex_lock(&dev->struct_mutex);
990
Chris Wilson693db182013-03-05 14:52:39 +0000991 /* Note that this will apply the VT-d workaround for scanouts,
992 * which is more restrictive than required for sprites. (The
993 * primary plane requires 256KiB alignment with 64 PTE padding,
994 * the sprite planes only require 128KiB alignment and 32 PTE padding.
995 */
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800996 ret = intel_pin_and_fence_fb_obj(dev, obj, NULL);
Ville Syrjälä82284b62013-10-01 18:02:12 +0300997
998 mutex_unlock(&dev->struct_mutex);
999
Jesse Barnes00c2064b2012-01-13 15:48:39 -08001000 if (ret)
Ville Syrjälä82284b62013-10-01 18:02:12 +03001001 return ret;
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001002
Ville Syrjälä098ebd62013-10-01 18:02:15 +03001003 intel_plane->crtc_x = orig.crtc_x;
1004 intel_plane->crtc_y = orig.crtc_y;
1005 intel_plane->crtc_w = orig.crtc_w;
1006 intel_plane->crtc_h = orig.crtc_h;
1007 intel_plane->src_x = orig.src_x;
1008 intel_plane->src_y = orig.src_y;
1009 intel_plane->src_w = orig.src_w;
1010 intel_plane->src_h = orig.src_h;
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001011 intel_plane->obj = obj;
1012
Ville Syrjälä03c5b252013-10-01 18:02:11 +03001013 if (intel_crtc->active) {
Ville Syrjälä5b633d62014-04-29 13:35:47 +03001014 bool primary_was_enabled = intel_crtc->primary_enabled;
1015
1016 intel_crtc->primary_enabled = primary_enabled;
1017
1018 if (primary_was_enabled && !primary_enabled)
1019 intel_pre_disable_primary(crtc);
Jesse Barnes175bd422011-12-13 13:19:39 -08001020
Ville Syrjälä03c5b252013-10-01 18:02:11 +03001021 if (visible)
1022 intel_plane->update_plane(plane, crtc, fb, obj,
1023 crtc_x, crtc_y, crtc_w, crtc_h,
1024 src_x, src_y, src_w, src_h);
1025 else
1026 intel_plane->disable_plane(plane, crtc);
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001027
Ville Syrjälä5b633d62014-04-29 13:35:47 +03001028 if (!primary_was_enabled && primary_enabled)
1029 intel_post_enable_primary(crtc);
Ville Syrjälä03c5b252013-10-01 18:02:11 +03001030 }
Jesse Barnes175bd422011-12-13 13:19:39 -08001031
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001032 /* Unpin old obj after new one is active to avoid ugliness */
1033 if (old_obj) {
1034 /*
1035 * It's fairly common to simply update the position of
1036 * an existing object. In that case, we don't need to
1037 * wait for vblank to avoid ugliness, we only need to
1038 * do the pin & ref bookkeeping.
1039 */
Ville Syrjälä82284b62013-10-01 18:02:12 +03001040 if (old_obj != obj && intel_crtc->active)
Ville Syrjälä2afd9ef2013-10-01 18:02:14 +03001041 intel_wait_for_vblank(dev, intel_crtc->pipe);
Ville Syrjälä82284b62013-10-01 18:02:12 +03001042
1043 mutex_lock(&dev->struct_mutex);
Chris Wilson1690e1e2011-12-14 13:57:08 +01001044 intel_unpin_fb_obj(old_obj);
Ville Syrjälä82284b62013-10-01 18:02:12 +03001045 mutex_unlock(&dev->struct_mutex);
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001046 }
1047
Ville Syrjälä82284b62013-10-01 18:02:12 +03001048 return 0;
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001049}
1050
1051static int
1052intel_disable_plane(struct drm_plane *plane)
1053{
1054 struct drm_device *dev = plane->dev;
1055 struct intel_plane *intel_plane = to_intel_plane(plane);
Ville Syrjälä03c5b252013-10-01 18:02:11 +03001056 struct intel_crtc *intel_crtc;
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001057
Ville Syrjälä88a94a52013-08-07 13:30:23 +03001058 if (!plane->fb)
1059 return 0;
1060
1061 if (WARN_ON(!plane->crtc))
1062 return -EINVAL;
1063
Ville Syrjälä03c5b252013-10-01 18:02:11 +03001064 intel_crtc = to_intel_crtc(plane->crtc);
1065
1066 if (intel_crtc->active) {
Ville Syrjälä5b633d62014-04-29 13:35:47 +03001067 bool primary_was_enabled = intel_crtc->primary_enabled;
1068
1069 intel_crtc->primary_enabled = true;
1070
Ville Syrjälä03c5b252013-10-01 18:02:11 +03001071 intel_plane->disable_plane(plane, plane->crtc);
Ville Syrjälä5b633d62014-04-29 13:35:47 +03001072
1073 if (!primary_was_enabled && intel_crtc->primary_enabled)
1074 intel_post_enable_primary(plane->crtc);
Ville Syrjälä03c5b252013-10-01 18:02:11 +03001075 }
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001076
Ville Syrjälä5f3fb462013-10-01 18:02:13 +03001077 if (intel_plane->obj) {
1078 if (intel_crtc->active)
1079 intel_wait_for_vblank(dev, intel_plane->pipe);
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001080
Ville Syrjälä5f3fb462013-10-01 18:02:13 +03001081 mutex_lock(&dev->struct_mutex);
1082 intel_unpin_fb_obj(intel_plane->obj);
1083 mutex_unlock(&dev->struct_mutex);
Ville Syrjäläc626d312013-03-27 17:49:13 +02001084
Ville Syrjälä5f3fb462013-10-01 18:02:13 +03001085 intel_plane->obj = NULL;
1086 }
Ville Syrjälä82284b62013-10-01 18:02:12 +03001087
Ville Syrjälä5f3fb462013-10-01 18:02:13 +03001088 return 0;
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001089}
1090
1091static void intel_destroy_plane(struct drm_plane *plane)
1092{
1093 struct intel_plane *intel_plane = to_intel_plane(plane);
1094 intel_disable_plane(plane);
1095 drm_plane_cleanup(plane);
1096 kfree(intel_plane);
1097}
1098
Jesse Barnes8ea30862012-01-03 08:05:39 -08001099int intel_sprite_set_colorkey(struct drm_device *dev, void *data,
1100 struct drm_file *file_priv)
1101{
1102 struct drm_intel_sprite_colorkey *set = data;
Jesse Barnes8ea30862012-01-03 08:05:39 -08001103 struct drm_mode_object *obj;
1104 struct drm_plane *plane;
1105 struct intel_plane *intel_plane;
1106 int ret = 0;
1107
Daniel Vetter1cff8f62012-04-24 09:55:08 +02001108 if (!drm_core_check_feature(dev, DRIVER_MODESET))
1109 return -ENODEV;
Jesse Barnes8ea30862012-01-03 08:05:39 -08001110
1111 /* Make sure we don't try to enable both src & dest simultaneously */
1112 if ((set->flags & (I915_SET_COLORKEY_DESTINATION | I915_SET_COLORKEY_SOURCE)) == (I915_SET_COLORKEY_DESTINATION | I915_SET_COLORKEY_SOURCE))
1113 return -EINVAL;
1114
Daniel Vettera0e99e62012-12-02 01:05:46 +01001115 drm_modeset_lock_all(dev);
Jesse Barnes8ea30862012-01-03 08:05:39 -08001116
1117 obj = drm_mode_object_find(dev, set->plane_id, DRM_MODE_OBJECT_PLANE);
1118 if (!obj) {
Ville Syrjälä3f2c2052013-10-17 13:35:03 +03001119 ret = -ENOENT;
Jesse Barnes8ea30862012-01-03 08:05:39 -08001120 goto out_unlock;
1121 }
1122
1123 plane = obj_to_plane(obj);
1124 intel_plane = to_intel_plane(plane);
1125 ret = intel_plane->update_colorkey(plane, set);
1126
1127out_unlock:
Daniel Vettera0e99e62012-12-02 01:05:46 +01001128 drm_modeset_unlock_all(dev);
Jesse Barnes8ea30862012-01-03 08:05:39 -08001129 return ret;
1130}
1131
1132int intel_sprite_get_colorkey(struct drm_device *dev, void *data,
1133 struct drm_file *file_priv)
1134{
1135 struct drm_intel_sprite_colorkey *get = data;
Jesse Barnes8ea30862012-01-03 08:05:39 -08001136 struct drm_mode_object *obj;
1137 struct drm_plane *plane;
1138 struct intel_plane *intel_plane;
1139 int ret = 0;
1140
Daniel Vetter1cff8f62012-04-24 09:55:08 +02001141 if (!drm_core_check_feature(dev, DRIVER_MODESET))
1142 return -ENODEV;
Jesse Barnes8ea30862012-01-03 08:05:39 -08001143
Daniel Vettera0e99e62012-12-02 01:05:46 +01001144 drm_modeset_lock_all(dev);
Jesse Barnes8ea30862012-01-03 08:05:39 -08001145
1146 obj = drm_mode_object_find(dev, get->plane_id, DRM_MODE_OBJECT_PLANE);
1147 if (!obj) {
Ville Syrjälä3f2c2052013-10-17 13:35:03 +03001148 ret = -ENOENT;
Jesse Barnes8ea30862012-01-03 08:05:39 -08001149 goto out_unlock;
1150 }
1151
1152 plane = obj_to_plane(obj);
1153 intel_plane = to_intel_plane(plane);
1154 intel_plane->get_colorkey(plane, get);
1155
1156out_unlock:
Daniel Vettera0e99e62012-12-02 01:05:46 +01001157 drm_modeset_unlock_all(dev);
Jesse Barnes8ea30862012-01-03 08:05:39 -08001158 return ret;
1159}
1160
Jesse Barnes5e1bac22013-03-26 09:25:43 -07001161void intel_plane_restore(struct drm_plane *plane)
1162{
1163 struct intel_plane *intel_plane = to_intel_plane(plane);
1164
1165 if (!plane->crtc || !plane->fb)
1166 return;
1167
1168 intel_update_plane(plane, plane->crtc, plane->fb,
1169 intel_plane->crtc_x, intel_plane->crtc_y,
1170 intel_plane->crtc_w, intel_plane->crtc_h,
1171 intel_plane->src_x, intel_plane->src_y,
1172 intel_plane->src_w, intel_plane->src_h);
1173}
1174
Ville Syrjäläbb53d4a2013-06-04 13:49:04 +03001175void intel_plane_disable(struct drm_plane *plane)
1176{
1177 if (!plane->crtc || !plane->fb)
1178 return;
1179
1180 intel_disable_plane(plane);
1181}
1182
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001183static const struct drm_plane_funcs intel_plane_funcs = {
1184 .update_plane = intel_update_plane,
1185 .disable_plane = intel_disable_plane,
1186 .destroy = intel_destroy_plane,
1187};
1188
Chris Wilsond1686ae2012-04-10 11:41:49 +01001189static uint32_t ilk_plane_formats[] = {
1190 DRM_FORMAT_XRGB8888,
1191 DRM_FORMAT_YUYV,
1192 DRM_FORMAT_YVYU,
1193 DRM_FORMAT_UYVY,
1194 DRM_FORMAT_VYUY,
1195};
1196
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001197static uint32_t snb_plane_formats[] = {
1198 DRM_FORMAT_XBGR8888,
1199 DRM_FORMAT_XRGB8888,
1200 DRM_FORMAT_YUYV,
1201 DRM_FORMAT_YVYU,
1202 DRM_FORMAT_UYVY,
1203 DRM_FORMAT_VYUY,
1204};
1205
Jesse Barnes7f1f3852013-04-02 11:22:20 -07001206static uint32_t vlv_plane_formats[] = {
1207 DRM_FORMAT_RGB565,
1208 DRM_FORMAT_ABGR8888,
1209 DRM_FORMAT_ARGB8888,
1210 DRM_FORMAT_XBGR8888,
1211 DRM_FORMAT_XRGB8888,
1212 DRM_FORMAT_XBGR2101010,
1213 DRM_FORMAT_ABGR2101010,
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 -08001220int
Jesse Barnes7f1f3852013-04-02 11:22:20 -07001221intel_plane_init(struct drm_device *dev, enum pipe pipe, int plane)
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001222{
1223 struct intel_plane *intel_plane;
1224 unsigned long possible_crtcs;
Chris Wilsond1686ae2012-04-10 11:41:49 +01001225 const uint32_t *plane_formats;
1226 int num_plane_formats;
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001227 int ret;
1228
Chris Wilsond1686ae2012-04-10 11:41:49 +01001229 if (INTEL_INFO(dev)->gen < 5)
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001230 return -ENODEV;
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001231
Daniel Vetterb14c5672013-09-19 12:18:32 +02001232 intel_plane = kzalloc(sizeof(*intel_plane), GFP_KERNEL);
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001233 if (!intel_plane)
1234 return -ENOMEM;
1235
Chris Wilsond1686ae2012-04-10 11:41:49 +01001236 switch (INTEL_INFO(dev)->gen) {
1237 case 5:
1238 case 6:
Damien Lespiau2d354c32012-10-22 18:19:27 +01001239 intel_plane->can_scale = true;
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001240 intel_plane->max_downscale = 16;
Chris Wilsond1686ae2012-04-10 11:41:49 +01001241 intel_plane->update_plane = ilk_update_plane;
1242 intel_plane->disable_plane = ilk_disable_plane;
1243 intel_plane->update_colorkey = ilk_update_colorkey;
1244 intel_plane->get_colorkey = ilk_get_colorkey;
1245
1246 if (IS_GEN6(dev)) {
1247 plane_formats = snb_plane_formats;
1248 num_plane_formats = ARRAY_SIZE(snb_plane_formats);
1249 } else {
1250 plane_formats = ilk_plane_formats;
1251 num_plane_formats = ARRAY_SIZE(ilk_plane_formats);
1252 }
1253 break;
1254
1255 case 7:
Ben Widawsky4e0bbc32013-11-02 21:07:07 -07001256 case 8:
Damien Lespiaud49f7092013-04-25 15:15:00 +01001257 if (IS_IVYBRIDGE(dev)) {
Damien Lespiau2d354c32012-10-22 18:19:27 +01001258 intel_plane->can_scale = true;
Damien Lespiaud49f7092013-04-25 15:15:00 +01001259 intel_plane->max_downscale = 2;
1260 } else {
1261 intel_plane->can_scale = false;
1262 intel_plane->max_downscale = 1;
1263 }
Chris Wilsond1686ae2012-04-10 11:41:49 +01001264
Jesse Barnes7f1f3852013-04-02 11:22:20 -07001265 if (IS_VALLEYVIEW(dev)) {
Jesse Barnes7f1f3852013-04-02 11:22:20 -07001266 intel_plane->update_plane = vlv_update_plane;
1267 intel_plane->disable_plane = vlv_disable_plane;
1268 intel_plane->update_colorkey = vlv_update_colorkey;
1269 intel_plane->get_colorkey = vlv_get_colorkey;
1270
1271 plane_formats = vlv_plane_formats;
1272 num_plane_formats = ARRAY_SIZE(vlv_plane_formats);
1273 } else {
Jesse Barnes7f1f3852013-04-02 11:22:20 -07001274 intel_plane->update_plane = ivb_update_plane;
1275 intel_plane->disable_plane = ivb_disable_plane;
1276 intel_plane->update_colorkey = ivb_update_colorkey;
1277 intel_plane->get_colorkey = ivb_get_colorkey;
1278
1279 plane_formats = snb_plane_formats;
1280 num_plane_formats = ARRAY_SIZE(snb_plane_formats);
1281 }
Chris Wilsond1686ae2012-04-10 11:41:49 +01001282 break;
1283
1284 default:
Jesper Juhla8b0bba2012-06-27 00:55:37 +02001285 kfree(intel_plane);
Chris Wilsond1686ae2012-04-10 11:41:49 +01001286 return -ENODEV;
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001287 }
1288
1289 intel_plane->pipe = pipe;
Jesse Barnes7f1f3852013-04-02 11:22:20 -07001290 intel_plane->plane = plane;
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001291 possible_crtcs = (1 << pipe);
1292 ret = drm_plane_init(dev, &intel_plane->base, possible_crtcs,
Chris Wilsond1686ae2012-04-10 11:41:49 +01001293 &intel_plane_funcs,
1294 plane_formats, num_plane_formats,
1295 false);
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001296 if (ret)
1297 kfree(intel_plane);
1298
1299 return ret;
1300}