blob: 4912161c95b3183165e5227fd3e2a5b0efb9e95a [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
Damien Lespiaudc2a41b2013-12-04 00:49:41 +0000142skl_update_plane(struct drm_plane *drm_plane, struct drm_crtc *crtc,
143 struct drm_framebuffer *fb,
144 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 = drm_plane->dev;
150 struct drm_i915_private *dev_priv = dev->dev_private;
151 struct intel_plane *intel_plane = to_intel_plane(drm_plane);
152 const int pipe = intel_plane->pipe;
153 const int plane = intel_plane->plane + 1;
154 u32 plane_ctl, stride;
155 int pixel_size = drm_format_plane_cpp(fb->pixel_format, 0);
156
157 plane_ctl = I915_READ(PLANE_CTL(pipe, plane));
158
159 /* Mask out pixel format bits in case we change it */
160 plane_ctl &= ~PLANE_CTL_FORMAT_MASK;
161 plane_ctl &= ~PLANE_CTL_ORDER_RGBX;
162 plane_ctl &= ~PLANE_CTL_YUV422_ORDER_MASK;
163 plane_ctl &= ~PLANE_CTL_TILED_MASK;
164 plane_ctl &= ~PLANE_CTL_ALPHA_MASK;
Sonika Jindal1447dde2014-10-04 10:53:31 +0100165 plane_ctl &= ~PLANE_CTL_ROTATE_MASK;
Damien Lespiaudc2a41b2013-12-04 00:49:41 +0000166
167 /* Trickle feed has to be enabled */
168 plane_ctl &= ~PLANE_CTL_TRICKLE_FEED_DISABLE;
169
170 switch (fb->pixel_format) {
171 case DRM_FORMAT_RGB565:
172 plane_ctl |= PLANE_CTL_FORMAT_RGB_565;
173 break;
174 case DRM_FORMAT_XBGR8888:
175 plane_ctl |= PLANE_CTL_FORMAT_XRGB_8888 | PLANE_CTL_ORDER_RGBX;
176 break;
177 case DRM_FORMAT_XRGB8888:
178 plane_ctl |= PLANE_CTL_FORMAT_XRGB_8888;
179 break;
180 /*
181 * XXX: For ARBG/ABGR formats we default to expecting scanout buffers
182 * to be already pre-multiplied. We need to add a knob (or a different
183 * DRM_FORMAT) for user-space to configure that.
184 */
185 case DRM_FORMAT_ABGR8888:
186 plane_ctl |= PLANE_CTL_FORMAT_XRGB_8888 |
187 PLANE_CTL_ORDER_RGBX |
188 PLANE_CTL_ALPHA_SW_PREMULTIPLY;
189 break;
190 case DRM_FORMAT_ARGB8888:
191 plane_ctl |= PLANE_CTL_FORMAT_XRGB_8888 |
192 PLANE_CTL_ALPHA_SW_PREMULTIPLY;
193 break;
194 case DRM_FORMAT_YUYV:
195 plane_ctl |= PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YUYV;
196 break;
197 case DRM_FORMAT_YVYU:
198 plane_ctl |= PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YVYU;
199 break;
200 case DRM_FORMAT_UYVY:
201 plane_ctl |= PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_UYVY;
202 break;
203 case DRM_FORMAT_VYUY:
204 plane_ctl |= PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_VYUY;
205 break;
206 default:
207 BUG();
208 }
209
210 switch (obj->tiling_mode) {
211 case I915_TILING_NONE:
212 stride = fb->pitches[0] >> 6;
213 break;
214 case I915_TILING_X:
215 plane_ctl |= PLANE_CTL_TILED_X;
216 stride = fb->pitches[0] >> 9;
217 break;
218 default:
219 BUG();
220 }
Sonika Jindal1447dde2014-10-04 10:53:31 +0100221 if (intel_plane->rotation == BIT(DRM_ROTATE_180))
222 plane_ctl |= PLANE_CTL_ROTATE_180;
Damien Lespiaudc2a41b2013-12-04 00:49:41 +0000223
224 plane_ctl |= PLANE_CTL_ENABLE;
225 plane_ctl |= PLANE_CTL_PIPE_CSC_ENABLE;
226
227 intel_update_sprite_watermarks(drm_plane, crtc, src_w, src_h,
228 pixel_size, true,
229 src_w != crtc_w || src_h != crtc_h);
230
231 /* Sizes are 0 based */
232 src_w--;
233 src_h--;
234 crtc_w--;
235 crtc_h--;
236
237 I915_WRITE(PLANE_OFFSET(pipe, plane), (y << 16) | x);
238 I915_WRITE(PLANE_STRIDE(pipe, plane), stride);
239 I915_WRITE(PLANE_POS(pipe, plane), (crtc_y << 16) | crtc_x);
240 I915_WRITE(PLANE_SIZE(pipe, plane), (crtc_h << 16) | crtc_w);
241 I915_WRITE(PLANE_CTL(pipe, plane), plane_ctl);
242 I915_WRITE(PLANE_SURF(pipe, plane), i915_gem_obj_ggtt_offset(obj));
243 POSTING_READ(PLANE_SURF(pipe, plane));
244}
245
246static void
247skl_disable_plane(struct drm_plane *drm_plane, struct drm_crtc *crtc)
248{
249 struct drm_device *dev = drm_plane->dev;
250 struct drm_i915_private *dev_priv = dev->dev_private;
251 struct intel_plane *intel_plane = to_intel_plane(drm_plane);
252 const int pipe = intel_plane->pipe;
253 const int plane = intel_plane->plane + 1;
254
255 I915_WRITE(PLANE_CTL(pipe, plane),
256 I915_READ(PLANE_CTL(pipe, plane)) & ~PLANE_CTL_ENABLE);
257
258 /* Activate double buffered register update */
259 I915_WRITE(PLANE_CTL(pipe, plane), 0);
260 POSTING_READ(PLANE_CTL(pipe, plane));
261
262 intel_update_sprite_watermarks(drm_plane, crtc, 0, 0, 0, false, false);
263}
264
265static int
266skl_update_colorkey(struct drm_plane *drm_plane,
267 struct drm_intel_sprite_colorkey *key)
268{
269 struct drm_device *dev = drm_plane->dev;
270 struct drm_i915_private *dev_priv = dev->dev_private;
271 struct intel_plane *intel_plane = to_intel_plane(drm_plane);
272 const int pipe = intel_plane->pipe;
273 const int plane = intel_plane->plane;
274 u32 plane_ctl;
275
276 I915_WRITE(PLANE_KEYVAL(pipe, plane), key->min_value);
277 I915_WRITE(PLANE_KEYMAX(pipe, plane), key->max_value);
278 I915_WRITE(PLANE_KEYMSK(pipe, plane), key->channel_mask);
279
280 plane_ctl = I915_READ(PLANE_CTL(pipe, plane));
281 plane_ctl &= ~PLANE_CTL_KEY_ENABLE_MASK;
282 if (key->flags & I915_SET_COLORKEY_DESTINATION)
283 plane_ctl |= PLANE_CTL_KEY_ENABLE_DESTINATION;
284 else if (key->flags & I915_SET_COLORKEY_SOURCE)
285 plane_ctl |= PLANE_CTL_KEY_ENABLE_SOURCE;
286 I915_WRITE(PLANE_CTL(pipe, plane), plane_ctl);
287
288 POSTING_READ(PLANE_CTL(pipe, plane));
289
290 return 0;
291}
292
293static void
294skl_get_colorkey(struct drm_plane *drm_plane,
295 struct drm_intel_sprite_colorkey *key)
296{
297 struct drm_device *dev = drm_plane->dev;
298 struct drm_i915_private *dev_priv = dev->dev_private;
299 struct intel_plane *intel_plane = to_intel_plane(drm_plane);
300 const int pipe = intel_plane->pipe;
301 const int plane = intel_plane->plane;
302 u32 plane_ctl;
303
304 key->min_value = I915_READ(PLANE_KEYVAL(pipe, plane));
305 key->max_value = I915_READ(PLANE_KEYMAX(pipe, plane));
306 key->channel_mask = I915_READ(PLANE_KEYMSK(pipe, plane));
307
308 plane_ctl = I915_READ(PLANE_CTL(pipe, plane));
309
310 switch (plane_ctl & PLANE_CTL_KEY_ENABLE_MASK) {
311 case PLANE_CTL_KEY_ENABLE_DESTINATION:
312 key->flags = I915_SET_COLORKEY_DESTINATION;
313 break;
314 case PLANE_CTL_KEY_ENABLE_SOURCE:
315 key->flags = I915_SET_COLORKEY_SOURCE;
316 break;
317 default:
318 key->flags = I915_SET_COLORKEY_NONE;
319 }
320}
321
322static void
Ville Syrjäläb39d53f2013-08-06 22:24:09 +0300323vlv_update_plane(struct drm_plane *dplane, struct drm_crtc *crtc,
324 struct drm_framebuffer *fb,
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700325 struct drm_i915_gem_object *obj, int crtc_x, int crtc_y,
326 unsigned int crtc_w, unsigned int crtc_h,
327 uint32_t x, uint32_t y,
328 uint32_t src_w, uint32_t src_h)
329{
330 struct drm_device *dev = dplane->dev;
331 struct drm_i915_private *dev_priv = dev->dev_private;
332 struct intel_plane *intel_plane = to_intel_plane(dplane);
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300333 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700334 int pipe = intel_plane->pipe;
335 int plane = intel_plane->plane;
336 u32 sprctl;
337 unsigned long sprsurf_offset, linear_offset;
338 int pixel_size = drm_format_plane_cpp(fb->pixel_format, 0);
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300339 u32 start_vbl_count;
340 bool atomic_update;
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700341
342 sprctl = I915_READ(SPCNTR(pipe, plane));
343
344 /* Mask out pixel format bits in case we change it */
345 sprctl &= ~SP_PIXFORMAT_MASK;
346 sprctl &= ~SP_YUV_BYTE_ORDER_MASK;
347 sprctl &= ~SP_TILED;
Ville Syrjälä76eebda2014-08-05 11:26:52 +0530348 sprctl &= ~SP_ROTATE_180;
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700349
350 switch (fb->pixel_format) {
351 case DRM_FORMAT_YUYV:
352 sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_YUYV;
353 break;
354 case DRM_FORMAT_YVYU:
355 sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_YVYU;
356 break;
357 case DRM_FORMAT_UYVY:
358 sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_UYVY;
359 break;
360 case DRM_FORMAT_VYUY:
361 sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_VYUY;
362 break;
363 case DRM_FORMAT_RGB565:
364 sprctl |= SP_FORMAT_BGR565;
365 break;
366 case DRM_FORMAT_XRGB8888:
367 sprctl |= SP_FORMAT_BGRX8888;
368 break;
369 case DRM_FORMAT_ARGB8888:
370 sprctl |= SP_FORMAT_BGRA8888;
371 break;
372 case DRM_FORMAT_XBGR2101010:
373 sprctl |= SP_FORMAT_RGBX1010102;
374 break;
375 case DRM_FORMAT_ABGR2101010:
376 sprctl |= SP_FORMAT_RGBA1010102;
377 break;
378 case DRM_FORMAT_XBGR8888:
379 sprctl |= SP_FORMAT_RGBX8888;
380 break;
381 case DRM_FORMAT_ABGR8888:
382 sprctl |= SP_FORMAT_RGBA8888;
383 break;
384 default:
385 /*
386 * If we get here one of the upper layers failed to filter
387 * out the unsupported plane formats
388 */
389 BUG();
390 break;
391 }
392
Ville Syrjälä4ea67bc2013-11-18 18:32:38 -0800393 /*
394 * Enable gamma to match primary/cursor plane behaviour.
395 * FIXME should be user controllable via propertiesa.
396 */
397 sprctl |= SP_GAMMA_ENABLE;
398
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700399 if (obj->tiling_mode != I915_TILING_NONE)
400 sprctl |= SP_TILED;
401
402 sprctl |= SP_ENABLE;
403
Damien Lespiaued57cb82014-07-15 09:21:24 +0200404 intel_update_sprite_watermarks(dplane, crtc, src_w, src_h,
405 pixel_size, true,
Ville Syrjälä67ca28f2013-07-05 11:57:14 +0300406 src_w != crtc_w || src_h != crtc_h);
407
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700408 /* Sizes are 0 based */
409 src_w--;
410 src_h--;
411 crtc_w--;
412 crtc_h--;
413
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700414 linear_offset = y * fb->pitches[0] + x * pixel_size;
415 sprsurf_offset = intel_gen4_compute_page_offset(&x, &y,
416 obj->tiling_mode,
417 pixel_size,
418 fb->pitches[0]);
419 linear_offset -= sprsurf_offset;
420
Ville Syrjälä76eebda2014-08-05 11:26:52 +0530421 if (intel_plane->rotation == BIT(DRM_ROTATE_180)) {
422 sprctl |= SP_ROTATE_180;
423
424 x += src_w;
425 y += src_h;
426 linear_offset += src_h * fb->pitches[0] + src_w * pixel_size;
427 }
428
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300429 atomic_update = intel_pipe_update_start(intel_crtc, &start_vbl_count);
430
Ville Syrjälä5b633d62014-04-29 13:35:47 +0300431 intel_update_primary_plane(intel_crtc);
432
Ville Syrjäläca6ad022014-01-17 20:09:03 +0200433 I915_WRITE(SPSTRIDE(pipe, plane), fb->pitches[0]);
434 I915_WRITE(SPPOS(pipe, plane), (crtc_y << 16) | crtc_x);
435
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700436 if (obj->tiling_mode != I915_TILING_NONE)
437 I915_WRITE(SPTILEOFF(pipe, plane), (y << 16) | x);
438 else
439 I915_WRITE(SPLINOFF(pipe, plane), linear_offset);
440
Ville Syrjäläc14b0482014-10-16 20:52:34 +0300441 I915_WRITE(SPCONSTALPHA(pipe, plane), 0);
442
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700443 I915_WRITE(SPSIZE(pipe, plane), (crtc_h << 16) | crtc_w);
444 I915_WRITE(SPCNTR(pipe, plane), sprctl);
Daniel Vetter85ba7b72014-01-24 10:31:44 +0100445 I915_WRITE(SPSURF(pipe, plane), i915_gem_obj_ggtt_offset(obj) +
446 sprsurf_offset);
Ville Syrjälä5b633d62014-04-29 13:35:47 +0300447
448 intel_flush_primary_plane(dev_priv, intel_crtc->plane);
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300449
450 if (atomic_update)
451 intel_pipe_update_end(intel_crtc, start_vbl_count);
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700452}
453
454static void
Ville Syrjäläb39d53f2013-08-06 22:24:09 +0300455vlv_disable_plane(struct drm_plane *dplane, struct drm_crtc *crtc)
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700456{
457 struct drm_device *dev = dplane->dev;
458 struct drm_i915_private *dev_priv = dev->dev_private;
459 struct intel_plane *intel_plane = to_intel_plane(dplane);
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300460 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700461 int pipe = intel_plane->pipe;
462 int plane = intel_plane->plane;
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300463 u32 start_vbl_count;
464 bool atomic_update;
465
466 atomic_update = intel_pipe_update_start(intel_crtc, &start_vbl_count);
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700467
Ville Syrjälä5b633d62014-04-29 13:35:47 +0300468 intel_update_primary_plane(intel_crtc);
469
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700470 I915_WRITE(SPCNTR(pipe, plane), I915_READ(SPCNTR(pipe, plane)) &
471 ~SP_ENABLE);
472 /* Activate double buffered register update */
Daniel Vetter85ba7b72014-01-24 10:31:44 +0100473 I915_WRITE(SPSURF(pipe, plane), 0);
Ville Syrjälä5b633d62014-04-29 13:35:47 +0300474
475 intel_flush_primary_plane(dev_priv, intel_crtc->plane);
Ville Syrjäläa95fd8c2013-08-06 22:24:12 +0300476
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300477 if (atomic_update)
478 intel_pipe_update_end(intel_crtc, start_vbl_count);
479
Damien Lespiaued57cb82014-07-15 09:21:24 +0200480 intel_update_sprite_watermarks(dplane, crtc, 0, 0, 0, false, false);
Jesse Barnes7f1f3852013-04-02 11:22:20 -0700481}
482
483static int
484vlv_update_colorkey(struct drm_plane *dplane,
485 struct drm_intel_sprite_colorkey *key)
486{
487 struct drm_device *dev = dplane->dev;
488 struct drm_i915_private *dev_priv = dev->dev_private;
489 struct intel_plane *intel_plane = to_intel_plane(dplane);
490 int pipe = intel_plane->pipe;
491 int plane = intel_plane->plane;
492 u32 sprctl;
493
494 if (key->flags & I915_SET_COLORKEY_DESTINATION)
495 return -EINVAL;
496
497 I915_WRITE(SPKEYMINVAL(pipe, plane), key->min_value);
498 I915_WRITE(SPKEYMAXVAL(pipe, plane), key->max_value);
499 I915_WRITE(SPKEYMSK(pipe, plane), key->channel_mask);
500
501 sprctl = I915_READ(SPCNTR(pipe, plane));
502 sprctl &= ~SP_SOURCE_KEY;
503 if (key->flags & I915_SET_COLORKEY_SOURCE)
504 sprctl |= SP_SOURCE_KEY;
505 I915_WRITE(SPCNTR(pipe, plane), sprctl);
506
507 POSTING_READ(SPKEYMSK(pipe, plane));
508
509 return 0;
510}
511
512static void
513vlv_get_colorkey(struct drm_plane *dplane,
514 struct drm_intel_sprite_colorkey *key)
515{
516 struct drm_device *dev = dplane->dev;
517 struct drm_i915_private *dev_priv = dev->dev_private;
518 struct intel_plane *intel_plane = to_intel_plane(dplane);
519 int pipe = intel_plane->pipe;
520 int plane = intel_plane->plane;
521 u32 sprctl;
522
523 key->min_value = I915_READ(SPKEYMINVAL(pipe, plane));
524 key->max_value = I915_READ(SPKEYMAXVAL(pipe, plane));
525 key->channel_mask = I915_READ(SPKEYMSK(pipe, plane));
526
527 sprctl = I915_READ(SPCNTR(pipe, plane));
528 if (sprctl & SP_SOURCE_KEY)
529 key->flags = I915_SET_COLORKEY_SOURCE;
530 else
531 key->flags = I915_SET_COLORKEY_NONE;
532}
533
534static void
Ville Syrjäläb39d53f2013-08-06 22:24:09 +0300535ivb_update_plane(struct drm_plane *plane, struct drm_crtc *crtc,
536 struct drm_framebuffer *fb,
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800537 struct drm_i915_gem_object *obj, int crtc_x, int crtc_y,
538 unsigned int crtc_w, unsigned int crtc_h,
539 uint32_t x, uint32_t y,
540 uint32_t src_w, uint32_t src_h)
541{
542 struct drm_device *dev = plane->dev;
543 struct drm_i915_private *dev_priv = dev->dev_private;
544 struct intel_plane *intel_plane = to_intel_plane(plane);
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300545 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800546 int pipe = intel_plane->pipe;
547 u32 sprctl, sprscale = 0;
Damien Lespiau5a35e992012-10-26 18:20:12 +0100548 unsigned long sprsurf_offset, linear_offset;
Ville Syrjälä2bd3c3c2012-10-31 17:50:20 +0200549 int pixel_size = drm_format_plane_cpp(fb->pixel_format, 0);
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300550 u32 start_vbl_count;
551 bool atomic_update;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800552
553 sprctl = I915_READ(SPRCTL(pipe));
554
555 /* Mask out pixel format bits in case we change it */
556 sprctl &= ~SPRITE_PIXFORMAT_MASK;
557 sprctl &= ~SPRITE_RGB_ORDER_RGBX;
558 sprctl &= ~SPRITE_YUV_BYTE_ORDER_MASK;
Jesse Barnese86fe0d2012-06-26 13:10:11 -0700559 sprctl &= ~SPRITE_TILED;
Ville Syrjälä76eebda2014-08-05 11:26:52 +0530560 sprctl &= ~SPRITE_ROTATE_180;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800561
562 switch (fb->pixel_format) {
563 case DRM_FORMAT_XBGR8888:
Vijay Purushothaman5ee36912012-08-23 12:08:57 +0530564 sprctl |= SPRITE_FORMAT_RGBX888 | SPRITE_RGB_ORDER_RGBX;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800565 break;
566 case DRM_FORMAT_XRGB8888:
Vijay Purushothaman5ee36912012-08-23 12:08:57 +0530567 sprctl |= SPRITE_FORMAT_RGBX888;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800568 break;
569 case DRM_FORMAT_YUYV:
570 sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_YUYV;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800571 break;
572 case DRM_FORMAT_YVYU:
573 sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_YVYU;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800574 break;
575 case DRM_FORMAT_UYVY:
576 sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_UYVY;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800577 break;
578 case DRM_FORMAT_VYUY:
579 sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_VYUY;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800580 break;
581 default:
Ville Syrjälä28d491d2012-10-31 17:50:21 +0200582 BUG();
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800583 }
584
Ville Syrjälä4ea67bc2013-11-18 18:32:38 -0800585 /*
586 * Enable gamma to match primary/cursor plane behaviour.
587 * FIXME should be user controllable via propertiesa.
588 */
589 sprctl |= SPRITE_GAMMA_ENABLE;
590
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800591 if (obj->tiling_mode != I915_TILING_NONE)
592 sprctl |= SPRITE_TILED;
593
Ville Syrjäläb42c6002013-11-03 13:47:27 +0200594 if (IS_HASWELL(dev) || IS_BROADWELL(dev))
Paulo Zanoni1f5d76d2013-08-23 19:51:28 -0300595 sprctl &= ~SPRITE_TRICKLE_FEED_DISABLE;
596 else
597 sprctl |= SPRITE_TRICKLE_FEED_DISABLE;
598
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800599 sprctl |= SPRITE_ENABLE;
600
Ville Syrjälä6bbfa1c2013-11-02 21:07:39 -0700601 if (IS_HASWELL(dev) || IS_BROADWELL(dev))
Ville Syrjälä86d3efc2013-01-18 19:11:38 +0200602 sprctl |= SPRITE_PIPE_CSC_ENABLE;
603
Damien Lespiaued57cb82014-07-15 09:21:24 +0200604 intel_update_sprite_watermarks(plane, crtc, src_w, src_h, pixel_size,
605 true,
Ville Syrjälä67ca28f2013-07-05 11:57:14 +0300606 src_w != crtc_w || src_h != crtc_h);
607
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800608 /* Sizes are 0 based */
609 src_w--;
610 src_h--;
611 crtc_w--;
612 crtc_h--;
613
Ville Syrjälä8553c182013-12-05 15:51:39 +0200614 if (crtc_w != src_w || crtc_h != src_h)
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800615 sprscale = SPRITE_SCALE_ENABLE | (src_w << 16) | src_h;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800616
Chris Wilsonca320ac2012-12-19 12:14:22 +0000617 linear_offset = y * fb->pitches[0] + x * pixel_size;
Damien Lespiau5a35e992012-10-26 18:20:12 +0100618 sprsurf_offset =
Chris Wilsonbc752862013-02-21 20:04:31 +0000619 intel_gen4_compute_page_offset(&x, &y, obj->tiling_mode,
620 pixel_size, fb->pitches[0]);
Damien Lespiau5a35e992012-10-26 18:20:12 +0100621 linear_offset -= sprsurf_offset;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800622
Ville Syrjälä76eebda2014-08-05 11:26:52 +0530623 if (intel_plane->rotation == BIT(DRM_ROTATE_180)) {
624 sprctl |= SPRITE_ROTATE_180;
625
626 /* HSW and BDW does this automagically in hardware */
627 if (!IS_HASWELL(dev) && !IS_BROADWELL(dev)) {
628 x += src_w;
629 y += src_h;
630 linear_offset += src_h * fb->pitches[0] +
631 src_w * pixel_size;
632 }
633 }
634
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300635 atomic_update = intel_pipe_update_start(intel_crtc, &start_vbl_count);
636
Ville Syrjälä5b633d62014-04-29 13:35:47 +0300637 intel_update_primary_plane(intel_crtc);
638
Ville Syrjäläca6ad022014-01-17 20:09:03 +0200639 I915_WRITE(SPRSTRIDE(pipe), fb->pitches[0]);
640 I915_WRITE(SPRPOS(pipe), (crtc_y << 16) | crtc_x);
641
Damien Lespiau5a35e992012-10-26 18:20:12 +0100642 /* HSW consolidates SPRTILEOFF and SPRLINOFF into a single SPROFFSET
643 * register */
Paulo Zanonib3dc6852013-11-02 21:07:33 -0700644 if (IS_HASWELL(dev) || IS_BROADWELL(dev))
Damien Lespiau5a35e992012-10-26 18:20:12 +0100645 I915_WRITE(SPROFFSET(pipe), (y << 16) | x);
646 else if (obj->tiling_mode != I915_TILING_NONE)
647 I915_WRITE(SPRTILEOFF(pipe), (y << 16) | x);
648 else
649 I915_WRITE(SPRLINOFF(pipe), linear_offset);
Damien Lespiauc54173a2012-10-26 18:20:11 +0100650
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800651 I915_WRITE(SPRSIZE(pipe), (crtc_h << 16) | crtc_w);
Damien Lespiau2d354c32012-10-22 18:19:27 +0100652 if (intel_plane->can_scale)
653 I915_WRITE(SPRSCALE(pipe), sprscale);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800654 I915_WRITE(SPRCTL(pipe), sprctl);
Daniel Vetter85ba7b72014-01-24 10:31:44 +0100655 I915_WRITE(SPRSURF(pipe),
656 i915_gem_obj_ggtt_offset(obj) + sprsurf_offset);
Ville Syrjälä5b633d62014-04-29 13:35:47 +0300657
658 intel_flush_primary_plane(dev_priv, intel_crtc->plane);
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300659
660 if (atomic_update)
661 intel_pipe_update_end(intel_crtc, start_vbl_count);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800662}
663
664static void
Ville Syrjäläb39d53f2013-08-06 22:24:09 +0300665ivb_disable_plane(struct drm_plane *plane, struct drm_crtc *crtc)
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800666{
667 struct drm_device *dev = plane->dev;
668 struct drm_i915_private *dev_priv = dev->dev_private;
669 struct intel_plane *intel_plane = to_intel_plane(plane);
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300670 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800671 int pipe = intel_plane->pipe;
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300672 u32 start_vbl_count;
673 bool atomic_update;
674
675 atomic_update = intel_pipe_update_start(intel_crtc, &start_vbl_count);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800676
Ville Syrjälä5b633d62014-04-29 13:35:47 +0300677 intel_update_primary_plane(intel_crtc);
678
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800679 I915_WRITE(SPRCTL(pipe), I915_READ(SPRCTL(pipe)) & ~SPRITE_ENABLE);
680 /* Can't leave the scaler enabled... */
Damien Lespiau2d354c32012-10-22 18:19:27 +0100681 if (intel_plane->can_scale)
682 I915_WRITE(SPRSCALE(pipe), 0);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800683 /* Activate double buffered register update */
Daniel Vetter85ba7b72014-01-24 10:31:44 +0100684 I915_WRITE(SPRSURF(pipe), 0);
Ville Syrjälä5b633d62014-04-29 13:35:47 +0300685
686 intel_flush_primary_plane(dev_priv, intel_crtc->plane);
Chris Wilson828ed3e2012-04-18 17:12:26 +0100687
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300688 if (atomic_update)
689 intel_pipe_update_end(intel_crtc, start_vbl_count);
690
Ville Syrjälä1bd09ec2013-12-05 15:51:41 +0200691 /*
692 * Avoid underruns when disabling the sprite.
693 * FIXME remove once watermark updates are done properly.
694 */
695 intel_wait_for_vblank(dev, pipe);
696
Damien Lespiaued57cb82014-07-15 09:21:24 +0200697 intel_update_sprite_watermarks(plane, crtc, 0, 0, 0, false, false);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800698}
699
Jesse Barnes8ea30862012-01-03 08:05:39 -0800700static int
701ivb_update_colorkey(struct drm_plane *plane,
702 struct drm_intel_sprite_colorkey *key)
703{
704 struct drm_device *dev = plane->dev;
705 struct drm_i915_private *dev_priv = dev->dev_private;
706 struct intel_plane *intel_plane;
707 u32 sprctl;
708 int ret = 0;
709
710 intel_plane = to_intel_plane(plane);
711
712 I915_WRITE(SPRKEYVAL(intel_plane->pipe), key->min_value);
713 I915_WRITE(SPRKEYMAX(intel_plane->pipe), key->max_value);
714 I915_WRITE(SPRKEYMSK(intel_plane->pipe), key->channel_mask);
715
716 sprctl = I915_READ(SPRCTL(intel_plane->pipe));
717 sprctl &= ~(SPRITE_SOURCE_KEY | SPRITE_DEST_KEY);
718 if (key->flags & I915_SET_COLORKEY_DESTINATION)
719 sprctl |= SPRITE_DEST_KEY;
720 else if (key->flags & I915_SET_COLORKEY_SOURCE)
721 sprctl |= SPRITE_SOURCE_KEY;
722 I915_WRITE(SPRCTL(intel_plane->pipe), sprctl);
723
724 POSTING_READ(SPRKEYMSK(intel_plane->pipe));
725
726 return ret;
727}
728
729static void
730ivb_get_colorkey(struct drm_plane *plane, struct drm_intel_sprite_colorkey *key)
731{
732 struct drm_device *dev = plane->dev;
733 struct drm_i915_private *dev_priv = dev->dev_private;
734 struct intel_plane *intel_plane;
735 u32 sprctl;
736
737 intel_plane = to_intel_plane(plane);
738
739 key->min_value = I915_READ(SPRKEYVAL(intel_plane->pipe));
740 key->max_value = I915_READ(SPRKEYMAX(intel_plane->pipe));
741 key->channel_mask = I915_READ(SPRKEYMSK(intel_plane->pipe));
742 key->flags = 0;
743
744 sprctl = I915_READ(SPRCTL(intel_plane->pipe));
745
746 if (sprctl & SPRITE_DEST_KEY)
747 key->flags = I915_SET_COLORKEY_DESTINATION;
748 else if (sprctl & SPRITE_SOURCE_KEY)
749 key->flags = I915_SET_COLORKEY_SOURCE;
750 else
751 key->flags = I915_SET_COLORKEY_NONE;
752}
753
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800754static void
Ville Syrjäläb39d53f2013-08-06 22:24:09 +0300755ilk_update_plane(struct drm_plane *plane, struct drm_crtc *crtc,
756 struct drm_framebuffer *fb,
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800757 struct drm_i915_gem_object *obj, int crtc_x, int crtc_y,
758 unsigned int crtc_w, unsigned int crtc_h,
759 uint32_t x, uint32_t y,
760 uint32_t src_w, uint32_t src_h)
761{
762 struct drm_device *dev = plane->dev;
763 struct drm_i915_private *dev_priv = dev->dev_private;
764 struct intel_plane *intel_plane = to_intel_plane(plane);
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300765 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Ville Syrjälä2bd3c3c2012-10-31 17:50:20 +0200766 int pipe = intel_plane->pipe;
Damien Lespiau5a35e992012-10-26 18:20:12 +0100767 unsigned long dvssurf_offset, linear_offset;
Chris Wilson8aaa81a2012-04-14 22:14:26 +0100768 u32 dvscntr, dvsscale;
Ville Syrjälä2bd3c3c2012-10-31 17:50:20 +0200769 int pixel_size = drm_format_plane_cpp(fb->pixel_format, 0);
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300770 u32 start_vbl_count;
771 bool atomic_update;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800772
773 dvscntr = I915_READ(DVSCNTR(pipe));
774
775 /* Mask out pixel format bits in case we change it */
776 dvscntr &= ~DVS_PIXFORMAT_MASK;
Jesse Barnesab2f9df2012-02-27 12:40:10 -0800777 dvscntr &= ~DVS_RGB_ORDER_XBGR;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800778 dvscntr &= ~DVS_YUV_BYTE_ORDER_MASK;
Ander Conselvan de Oliveira79626522012-07-13 15:50:33 +0300779 dvscntr &= ~DVS_TILED;
Ville Syrjälä76eebda2014-08-05 11:26:52 +0530780 dvscntr &= ~DVS_ROTATE_180;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800781
782 switch (fb->pixel_format) {
783 case DRM_FORMAT_XBGR8888:
Jesse Barnesab2f9df2012-02-27 12:40:10 -0800784 dvscntr |= DVS_FORMAT_RGBX888 | DVS_RGB_ORDER_XBGR;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800785 break;
786 case DRM_FORMAT_XRGB8888:
Jesse Barnesab2f9df2012-02-27 12:40:10 -0800787 dvscntr |= DVS_FORMAT_RGBX888;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800788 break;
789 case DRM_FORMAT_YUYV:
790 dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_YUYV;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800791 break;
792 case DRM_FORMAT_YVYU:
793 dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_YVYU;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800794 break;
795 case DRM_FORMAT_UYVY:
796 dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_UYVY;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800797 break;
798 case DRM_FORMAT_VYUY:
799 dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_VYUY;
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800800 break;
801 default:
Ville Syrjälä28d491d2012-10-31 17:50:21 +0200802 BUG();
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800803 }
804
Ville Syrjälä4ea67bc2013-11-18 18:32:38 -0800805 /*
806 * Enable gamma to match primary/cursor plane behaviour.
807 * FIXME should be user controllable via propertiesa.
808 */
809 dvscntr |= DVS_GAMMA_ENABLE;
810
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800811 if (obj->tiling_mode != I915_TILING_NONE)
812 dvscntr |= DVS_TILED;
813
Chris Wilsond1686ae2012-04-10 11:41:49 +0100814 if (IS_GEN6(dev))
815 dvscntr |= DVS_TRICKLE_FEED_DISABLE; /* must disable */
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800816 dvscntr |= DVS_ENABLE;
817
Damien Lespiaued57cb82014-07-15 09:21:24 +0200818 intel_update_sprite_watermarks(plane, crtc, src_w, src_h,
819 pixel_size, true,
Ville Syrjälä67ca28f2013-07-05 11:57:14 +0300820 src_w != crtc_w || src_h != crtc_h);
821
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800822 /* Sizes are 0 based */
823 src_w--;
824 src_h--;
825 crtc_w--;
826 crtc_h--;
827
Chris Wilson8aaa81a2012-04-14 22:14:26 +0100828 dvsscale = 0;
Ville Syrjälä8368f012013-12-05 15:51:31 +0200829 if (crtc_w != src_w || crtc_h != src_h)
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800830 dvsscale = DVS_SCALE_ENABLE | (src_w << 16) | src_h;
831
Chris Wilsonca320ac2012-12-19 12:14:22 +0000832 linear_offset = y * fb->pitches[0] + x * pixel_size;
Damien Lespiau5a35e992012-10-26 18:20:12 +0100833 dvssurf_offset =
Chris Wilsonbc752862013-02-21 20:04:31 +0000834 intel_gen4_compute_page_offset(&x, &y, obj->tiling_mode,
835 pixel_size, fb->pitches[0]);
Damien Lespiau5a35e992012-10-26 18:20:12 +0100836 linear_offset -= dvssurf_offset;
837
Ville Syrjälä76eebda2014-08-05 11:26:52 +0530838 if (intel_plane->rotation == BIT(DRM_ROTATE_180)) {
839 dvscntr |= DVS_ROTATE_180;
840
841 x += src_w;
842 y += src_h;
843 linear_offset += src_h * fb->pitches[0] + src_w * pixel_size;
844 }
845
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300846 atomic_update = intel_pipe_update_start(intel_crtc, &start_vbl_count);
847
Ville Syrjälä5b633d62014-04-29 13:35:47 +0300848 intel_update_primary_plane(intel_crtc);
849
Ville Syrjäläca6ad022014-01-17 20:09:03 +0200850 I915_WRITE(DVSSTRIDE(pipe), fb->pitches[0]);
851 I915_WRITE(DVSPOS(pipe), (crtc_y << 16) | crtc_x);
852
Damien Lespiau5a35e992012-10-26 18:20:12 +0100853 if (obj->tiling_mode != I915_TILING_NONE)
854 I915_WRITE(DVSTILEOFF(pipe), (y << 16) | x);
855 else
856 I915_WRITE(DVSLINOFF(pipe), linear_offset);
857
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800858 I915_WRITE(DVSSIZE(pipe), (crtc_h << 16) | crtc_w);
859 I915_WRITE(DVSSCALE(pipe), dvsscale);
860 I915_WRITE(DVSCNTR(pipe), dvscntr);
Daniel Vetter85ba7b72014-01-24 10:31:44 +0100861 I915_WRITE(DVSSURF(pipe),
862 i915_gem_obj_ggtt_offset(obj) + dvssurf_offset);
Ville Syrjälä5b633d62014-04-29 13:35:47 +0300863
864 intel_flush_primary_plane(dev_priv, intel_crtc->plane);
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300865
866 if (atomic_update)
867 intel_pipe_update_end(intel_crtc, start_vbl_count);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800868}
869
870static void
Ville Syrjäläb39d53f2013-08-06 22:24:09 +0300871ilk_disable_plane(struct drm_plane *plane, struct drm_crtc *crtc)
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800872{
873 struct drm_device *dev = plane->dev;
874 struct drm_i915_private *dev_priv = dev->dev_private;
875 struct intel_plane *intel_plane = to_intel_plane(plane);
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300876 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800877 int pipe = intel_plane->pipe;
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300878 u32 start_vbl_count;
879 bool atomic_update;
880
881 atomic_update = intel_pipe_update_start(intel_crtc, &start_vbl_count);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800882
Ville Syrjälä5b633d62014-04-29 13:35:47 +0300883 intel_update_primary_plane(intel_crtc);
884
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800885 I915_WRITE(DVSCNTR(pipe), I915_READ(DVSCNTR(pipe)) & ~DVS_ENABLE);
886 /* Disable the scaler */
887 I915_WRITE(DVSSCALE(pipe), 0);
888 /* Flush double buffered register updates */
Daniel Vetter85ba7b72014-01-24 10:31:44 +0100889 I915_WRITE(DVSSURF(pipe), 0);
Ville Syrjälä5b633d62014-04-29 13:35:47 +0300890
891 intel_flush_primary_plane(dev_priv, intel_crtc->plane);
Ville Syrjäläa95fd8c2013-08-06 22:24:12 +0300892
Ville Syrjälä8d7849d2014-04-29 13:35:46 +0300893 if (atomic_update)
894 intel_pipe_update_end(intel_crtc, start_vbl_count);
895
Ville Syrjälä1bd09ec2013-12-05 15:51:41 +0200896 /*
897 * Avoid underruns when disabling the sprite.
898 * FIXME remove once watermark updates are done properly.
899 */
900 intel_wait_for_vblank(dev, pipe);
901
Damien Lespiaued57cb82014-07-15 09:21:24 +0200902 intel_update_sprite_watermarks(plane, crtc, 0, 0, 0, false, false);
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800903}
904
Jesse Barnes175bd422011-12-13 13:19:39 -0800905static void
Ville Syrjälä5b633d62014-04-29 13:35:47 +0300906intel_post_enable_primary(struct drm_crtc *crtc)
Jesse Barnes175bd422011-12-13 13:19:39 -0800907{
908 struct drm_device *dev = crtc->dev;
Jesse Barnes175bd422011-12-13 13:19:39 -0800909 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Ville Syrjäläabae50e2013-10-01 18:02:16 +0300910
Ville Syrjälä20bc86732013-10-01 18:02:17 +0300911 /*
Ville Syrjälä33c3b0d2014-06-24 13:59:28 +0300912 * BDW signals flip done immediately if the plane
913 * is disabled, even if the plane enable is already
914 * armed to occur at the next vblank :(
915 */
916 if (IS_BROADWELL(dev))
917 intel_wait_for_vblank(dev, intel_crtc->pipe);
918
919 /*
Ville Syrjälä20bc86732013-10-01 18:02:17 +0300920 * FIXME IPS should be fine as long as one plane is
921 * enabled, but in practice it seems to have problems
922 * when going from primary only to sprite only and vice
923 * versa.
924 */
Ville Syrjäläcea165c2014-04-15 21:41:35 +0300925 hsw_enable_ips(intel_crtc);
Ville Syrjälä20bc86732013-10-01 18:02:17 +0300926
Ville Syrjälä82284b62013-10-01 18:02:12 +0300927 mutex_lock(&dev->struct_mutex);
Chris Wilson93314b52012-06-13 17:36:55 +0100928 intel_update_fbc(dev);
Ville Syrjälä82284b62013-10-01 18:02:12 +0300929 mutex_unlock(&dev->struct_mutex);
Jesse Barnes175bd422011-12-13 13:19:39 -0800930}
931
932static void
Ville Syrjälä5b633d62014-04-29 13:35:47 +0300933intel_pre_disable_primary(struct drm_crtc *crtc)
Jesse Barnes175bd422011-12-13 13:19:39 -0800934{
935 struct drm_device *dev = crtc->dev;
936 struct drm_i915_private *dev_priv = dev->dev_private;
937 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Ville Syrjälä82284b62013-10-01 18:02:12 +0300938
939 mutex_lock(&dev->struct_mutex);
Ville Syrjäläabae50e2013-10-01 18:02:16 +0300940 if (dev_priv->fbc.plane == intel_crtc->plane)
941 intel_disable_fbc(dev);
Ville Syrjälä82284b62013-10-01 18:02:12 +0300942 mutex_unlock(&dev->struct_mutex);
Ville Syrjäläabae50e2013-10-01 18:02:16 +0300943
Ville Syrjälä20bc86732013-10-01 18:02:17 +0300944 /*
945 * FIXME IPS should be fine as long as one plane is
946 * enabled, but in practice it seems to have problems
947 * when going from primary only to sprite only and vice
948 * versa.
949 */
950 hsw_disable_ips(intel_crtc);
Jesse Barnes175bd422011-12-13 13:19:39 -0800951}
952
Jesse Barnesb840d907f2011-12-13 13:19:38 -0800953static int
Chris Wilsond1686ae2012-04-10 11:41:49 +0100954ilk_update_colorkey(struct drm_plane *plane,
Jesse Barnes8ea30862012-01-03 08:05:39 -0800955 struct drm_intel_sprite_colorkey *key)
956{
957 struct drm_device *dev = plane->dev;
958 struct drm_i915_private *dev_priv = dev->dev_private;
959 struct intel_plane *intel_plane;
960 u32 dvscntr;
961 int ret = 0;
962
963 intel_plane = to_intel_plane(plane);
964
965 I915_WRITE(DVSKEYVAL(intel_plane->pipe), key->min_value);
966 I915_WRITE(DVSKEYMAX(intel_plane->pipe), key->max_value);
967 I915_WRITE(DVSKEYMSK(intel_plane->pipe), key->channel_mask);
968
969 dvscntr = I915_READ(DVSCNTR(intel_plane->pipe));
970 dvscntr &= ~(DVS_SOURCE_KEY | DVS_DEST_KEY);
971 if (key->flags & I915_SET_COLORKEY_DESTINATION)
972 dvscntr |= DVS_DEST_KEY;
973 else if (key->flags & I915_SET_COLORKEY_SOURCE)
974 dvscntr |= DVS_SOURCE_KEY;
975 I915_WRITE(DVSCNTR(intel_plane->pipe), dvscntr);
976
977 POSTING_READ(DVSKEYMSK(intel_plane->pipe));
978
979 return ret;
980}
981
982static void
Chris Wilsond1686ae2012-04-10 11:41:49 +0100983ilk_get_colorkey(struct drm_plane *plane, struct drm_intel_sprite_colorkey *key)
Jesse Barnes8ea30862012-01-03 08:05:39 -0800984{
985 struct drm_device *dev = plane->dev;
986 struct drm_i915_private *dev_priv = dev->dev_private;
987 struct intel_plane *intel_plane;
988 u32 dvscntr;
989
990 intel_plane = to_intel_plane(plane);
991
992 key->min_value = I915_READ(DVSKEYVAL(intel_plane->pipe));
993 key->max_value = I915_READ(DVSKEYMAX(intel_plane->pipe));
994 key->channel_mask = I915_READ(DVSKEYMSK(intel_plane->pipe));
995 key->flags = 0;
996
997 dvscntr = I915_READ(DVSCNTR(intel_plane->pipe));
998
999 if (dvscntr & DVS_DEST_KEY)
1000 key->flags = I915_SET_COLORKEY_DESTINATION;
1001 else if (dvscntr & DVS_SOURCE_KEY)
1002 key->flags = I915_SET_COLORKEY_SOURCE;
1003 else
1004 key->flags = I915_SET_COLORKEY_NONE;
1005}
1006
Ville Syrjälä17316932013-04-24 18:52:38 +03001007static bool
1008format_is_yuv(uint32_t format)
1009{
1010 switch (format) {
1011 case DRM_FORMAT_YUYV:
1012 case DRM_FORMAT_UYVY:
1013 case DRM_FORMAT_VYUY:
1014 case DRM_FORMAT_YVYU:
1015 return true;
1016 default:
1017 return false;
1018 }
1019}
1020
Ville Syrjäläefb31d12013-12-05 15:51:40 +02001021static bool colorkey_enabled(struct intel_plane *intel_plane)
1022{
1023 struct drm_intel_sprite_colorkey key;
1024
1025 intel_plane->get_colorkey(&intel_plane->base, &key);
1026
1027 return key.flags != I915_SET_COLORKEY_NONE;
1028}
1029
Jesse Barnes8ea30862012-01-03 08:05:39 -08001030static int
Gustavo Padovan96d61a72014-09-05 17:04:47 -03001031intel_check_sprite_plane(struct drm_plane *plane,
1032 struct intel_plane_state *state)
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001033{
Gustavo Padovan96d61a72014-09-05 17:04:47 -03001034 struct intel_crtc *intel_crtc = to_intel_crtc(state->crtc);
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001035 struct intel_plane *intel_plane = to_intel_plane(plane);
Gustavo Padovan96d61a72014-09-05 17:04:47 -03001036 struct drm_framebuffer *fb = state->fb;
Gustavo Padovan77cde952014-10-24 14:51:33 +01001037 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
Gustavo Padovan96d61a72014-09-05 17:04:47 -03001038 int crtc_x, crtc_y;
1039 unsigned int crtc_w, crtc_h;
1040 uint32_t src_x, src_y, src_w, src_h;
1041 struct drm_rect *src = &state->src;
1042 struct drm_rect *dst = &state->dst;
1043 struct drm_rect *orig_src = &state->orig_src;
1044 const struct drm_rect *clip = &state->clip;
Ville Syrjälä17316932013-04-24 18:52:38 +03001045 int hscale, vscale;
1046 int max_scale, min_scale;
1047 int pixel_size = drm_format_plane_cpp(fb->pixel_format, 0);
Jesse Barnes5e1bac22013-03-26 09:25:43 -07001048
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001049 /* Don't modify another pipe's plane */
Ville Syrjälä17316932013-04-24 18:52:38 +03001050 if (intel_plane->pipe != intel_crtc->pipe) {
1051 DRM_DEBUG_KMS("Wrong plane <-> crtc mapping\n");
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001052 return -EINVAL;
Ville Syrjälä17316932013-04-24 18:52:38 +03001053 }
1054
1055 /* FIXME check all gen limits */
1056 if (fb->width < 3 || fb->height < 3 || fb->pitches[0] > 16384) {
1057 DRM_DEBUG_KMS("Unsuitable framebuffer for plane\n");
1058 return -EINVAL;
1059 }
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001060
Damien Lespiau94c64192012-10-29 15:14:51 +00001061 /* Sprite planes can be linear or x-tiled surfaces */
1062 switch (obj->tiling_mode) {
1063 case I915_TILING_NONE:
1064 case I915_TILING_X:
1065 break;
1066 default:
Ville Syrjälä17316932013-04-24 18:52:38 +03001067 DRM_DEBUG_KMS("Unsupported tiling mode\n");
Damien Lespiau94c64192012-10-29 15:14:51 +00001068 return -EINVAL;
1069 }
1070
Ville Syrjälä3c3686c2013-04-24 18:52:39 +03001071 /*
1072 * FIXME the following code does a bunch of fuzzy adjustments to the
1073 * coordinates and sizes. We probably need some way to decide whether
1074 * more strict checking should be done instead.
1075 */
Ville Syrjälä17316932013-04-24 18:52:38 +03001076 max_scale = intel_plane->max_downscale << 16;
1077 min_scale = intel_plane->can_scale ? 1 : (1 << 16);
1078
Gustavo Padovan96d61a72014-09-05 17:04:47 -03001079 drm_rect_rotate(src, fb->width << 16, fb->height << 16,
Ville Syrjälä76eebda2014-08-05 11:26:52 +05301080 intel_plane->rotation);
1081
Gustavo Padovan96d61a72014-09-05 17:04:47 -03001082 hscale = drm_rect_calc_hscale_relaxed(src, dst, min_scale, max_scale);
Ville Syrjälä3c3686c2013-04-24 18:52:39 +03001083 BUG_ON(hscale < 0);
Ville Syrjälä17316932013-04-24 18:52:38 +03001084
Gustavo Padovan96d61a72014-09-05 17:04:47 -03001085 vscale = drm_rect_calc_vscale_relaxed(src, dst, min_scale, max_scale);
Ville Syrjälä3c3686c2013-04-24 18:52:39 +03001086 BUG_ON(vscale < 0);
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001087
Gustavo Padovan96d61a72014-09-05 17:04:47 -03001088 state->visible = drm_rect_clip_scaled(src, dst, clip, hscale, vscale);
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001089
Gustavo Padovan96d61a72014-09-05 17:04:47 -03001090 crtc_x = dst->x1;
1091 crtc_y = dst->y1;
1092 crtc_w = drm_rect_width(dst);
1093 crtc_h = drm_rect_height(dst);
Damien Lespiau2d354c32012-10-22 18:19:27 +01001094
Gustavo Padovan96d61a72014-09-05 17:04:47 -03001095 if (state->visible) {
Ville Syrjälä3c3686c2013-04-24 18:52:39 +03001096 /* check again in case clipping clamped the results */
Gustavo Padovan96d61a72014-09-05 17:04:47 -03001097 hscale = drm_rect_calc_hscale(src, dst, min_scale, max_scale);
Ville Syrjälä3c3686c2013-04-24 18:52:39 +03001098 if (hscale < 0) {
1099 DRM_DEBUG_KMS("Horizontal scaling factor out of limits\n");
Gustavo Padovan96d61a72014-09-05 17:04:47 -03001100 drm_rect_debug_print(src, true);
1101 drm_rect_debug_print(dst, false);
Ville Syrjälä3c3686c2013-04-24 18:52:39 +03001102
1103 return hscale;
1104 }
1105
Gustavo Padovan96d61a72014-09-05 17:04:47 -03001106 vscale = drm_rect_calc_vscale(src, dst, min_scale, max_scale);
Ville Syrjälä3c3686c2013-04-24 18:52:39 +03001107 if (vscale < 0) {
1108 DRM_DEBUG_KMS("Vertical scaling factor out of limits\n");
Gustavo Padovan96d61a72014-09-05 17:04:47 -03001109 drm_rect_debug_print(src, true);
1110 drm_rect_debug_print(dst, false);
Ville Syrjälä3c3686c2013-04-24 18:52:39 +03001111
1112 return vscale;
1113 }
1114
Ville Syrjälä17316932013-04-24 18:52:38 +03001115 /* Make the source viewport size an exact multiple of the scaling factors. */
Gustavo Padovan96d61a72014-09-05 17:04:47 -03001116 drm_rect_adjust_size(src,
1117 drm_rect_width(dst) * hscale - drm_rect_width(src),
1118 drm_rect_height(dst) * vscale - drm_rect_height(src));
Ville Syrjälä17316932013-04-24 18:52:38 +03001119
Gustavo Padovan96d61a72014-09-05 17:04:47 -03001120 drm_rect_rotate_inv(src, fb->width << 16, fb->height << 16,
Ville Syrjälä76eebda2014-08-05 11:26:52 +05301121 intel_plane->rotation);
1122
Ville Syrjälä17316932013-04-24 18:52:38 +03001123 /* sanity check to make sure the src viewport wasn't enlarged */
Gustavo Padovan96d61a72014-09-05 17:04:47 -03001124 WARN_ON(src->x1 < (int) orig_src->x1 ||
1125 src->y1 < (int) orig_src->y1 ||
1126 src->x2 > (int) orig_src->x2 ||
1127 src->y2 > (int) orig_src->y2);
Ville Syrjälä17316932013-04-24 18:52:38 +03001128
1129 /*
1130 * Hardware doesn't handle subpixel coordinates.
1131 * Adjust to (macro)pixel boundary, but be careful not to
1132 * increase the source viewport size, because that could
1133 * push the downscaling factor out of bounds.
Ville Syrjälä17316932013-04-24 18:52:38 +03001134 */
Gustavo Padovan96d61a72014-09-05 17:04:47 -03001135 src_x = src->x1 >> 16;
1136 src_w = drm_rect_width(src) >> 16;
1137 src_y = src->y1 >> 16;
1138 src_h = drm_rect_height(src) >> 16;
Ville Syrjälä17316932013-04-24 18:52:38 +03001139
1140 if (format_is_yuv(fb->pixel_format)) {
1141 src_x &= ~1;
1142 src_w &= ~1;
1143
1144 /*
1145 * Must keep src and dst the
1146 * same if we can't scale.
1147 */
1148 if (!intel_plane->can_scale)
1149 crtc_w &= ~1;
1150
1151 if (crtc_w == 0)
Gustavo Padovan96d61a72014-09-05 17:04:47 -03001152 state->visible = false;
Ville Syrjälä17316932013-04-24 18:52:38 +03001153 }
1154 }
1155
1156 /* Check size restrictions when scaling */
Gustavo Padovan96d61a72014-09-05 17:04:47 -03001157 if (state->visible && (src_w != crtc_w || src_h != crtc_h)) {
Ville Syrjälä17316932013-04-24 18:52:38 +03001158 unsigned int width_bytes;
1159
1160 WARN_ON(!intel_plane->can_scale);
1161
1162 /* FIXME interlacing min height is 6 */
1163
1164 if (crtc_w < 3 || crtc_h < 3)
Gustavo Padovan96d61a72014-09-05 17:04:47 -03001165 state->visible = false;
Ville Syrjälä17316932013-04-24 18:52:38 +03001166
1167 if (src_w < 3 || src_h < 3)
Gustavo Padovan96d61a72014-09-05 17:04:47 -03001168 state->visible = false;
Ville Syrjälä17316932013-04-24 18:52:38 +03001169
Gustavo Padovan96d61a72014-09-05 17:04:47 -03001170 width_bytes = ((src_x * pixel_size) & 63) +
1171 src_w * pixel_size;
Ville Syrjälä17316932013-04-24 18:52:38 +03001172
1173 if (src_w > 2048 || src_h > 2048 ||
1174 width_bytes > 4096 || fb->pitches[0] > 4096) {
1175 DRM_DEBUG_KMS("Source dimensions exceed hardware limits\n");
1176 return -EINVAL;
1177 }
1178 }
1179
Gustavo Padovan96d61a72014-09-05 17:04:47 -03001180 if (state->visible) {
1181 src->x1 = src_x;
1182 src->x2 = src_x + src_w;
1183 src->y1 = src_y;
1184 src->y2 = src_y + src_h;
1185 }
1186
1187 dst->x1 = crtc_x;
1188 dst->x2 = crtc_x + crtc_w;
1189 dst->y1 = crtc_y;
1190 dst->y2 = crtc_y + crtc_h;
1191
1192 return 0;
1193}
1194
1195static int
Gustavo Padovan34aa50a2014-10-24 14:51:32 +01001196intel_prepare_sprite_plane(struct drm_plane *plane,
1197 struct intel_plane_state *state)
Gustavo Padovan96d61a72014-09-05 17:04:47 -03001198{
1199 struct drm_device *dev = plane->dev;
1200 struct drm_crtc *crtc = state->crtc;
1201 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Gustavo Padovan96d61a72014-09-05 17:04:47 -03001202 enum pipe pipe = intel_crtc->pipe;
1203 struct drm_framebuffer *fb = state->fb;
Gustavo Padovan34aa50a2014-10-24 14:51:32 +01001204 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
1205 struct drm_i915_gem_object *old_obj = intel_fb_obj(plane->fb);
Gustavo Padovan96d61a72014-09-05 17:04:47 -03001206 int ret;
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001207
Gustavo Padovan25067bf2014-09-10 12:03:17 -03001208 if (old_obj != obj) {
1209 mutex_lock(&dev->struct_mutex);
Ville Syrjälä82284b62013-10-01 18:02:12 +03001210
Gustavo Padovan25067bf2014-09-10 12:03:17 -03001211 /* Note that this will apply the VT-d workaround for scanouts,
1212 * which is more restrictive than required for sprites. (The
1213 * primary plane requires 256KiB alignment with 64 PTE padding,
1214 * the sprite planes only require 128KiB alignment and 32 PTE
1215 * padding.
1216 */
1217 ret = intel_pin_and_fence_fb_obj(dev, obj, NULL);
1218 if (ret == 0)
1219 i915_gem_track_fb(old_obj, obj,
1220 INTEL_FRONTBUFFER_SPRITE(pipe));
1221 mutex_unlock(&dev->struct_mutex);
1222 if (ret)
1223 return ret;
1224 }
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001225
Gustavo Padovan34aa50a2014-10-24 14:51:32 +01001226 return 0;
1227}
1228
1229static void
1230intel_commit_sprite_plane(struct drm_plane *plane,
1231 struct intel_plane_state *state)
1232{
1233 struct drm_device *dev = plane->dev;
1234 struct drm_crtc *crtc = state->crtc;
1235 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
1236 struct intel_plane *intel_plane = to_intel_plane(plane);
1237 enum pipe pipe = intel_crtc->pipe;
1238 struct drm_framebuffer *fb = state->fb;
Gustavo Padovan77cde952014-10-24 14:51:33 +01001239 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
1240 struct drm_i915_gem_object *old_obj = intel_fb_obj(plane->fb);
Gustavo Padovan34aa50a2014-10-24 14:51:32 +01001241 int crtc_x, crtc_y;
1242 unsigned int crtc_w, crtc_h;
1243 uint32_t src_x, src_y, src_w, src_h;
1244 struct drm_rect *dst = &state->dst;
1245 const struct drm_rect *clip = &state->clip;
1246 bool primary_enabled;
1247
1248 /*
1249 * If the sprite is completely covering the primary plane,
1250 * we can disable the primary and save power.
1251 */
1252 primary_enabled = !drm_rect_equals(dst, clip) || colorkey_enabled(intel_plane);
1253 WARN_ON(!primary_enabled && !state->visible && intel_crtc->active);
1254
Gustavo Padovan96d61a72014-09-05 17:04:47 -03001255 intel_plane->crtc_x = state->orig_dst.x1;
1256 intel_plane->crtc_y = state->orig_dst.y1;
1257 intel_plane->crtc_w = drm_rect_width(&state->orig_dst);
1258 intel_plane->crtc_h = drm_rect_height(&state->orig_dst);
1259 intel_plane->src_x = state->orig_src.x1;
1260 intel_plane->src_y = state->orig_src.y1;
1261 intel_plane->src_w = drm_rect_width(&state->orig_src);
1262 intel_plane->src_h = drm_rect_height(&state->orig_src);
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001263 intel_plane->obj = obj;
1264
Ville Syrjälä03c5b252013-10-01 18:02:11 +03001265 if (intel_crtc->active) {
Ville Syrjälä5b633d62014-04-29 13:35:47 +03001266 bool primary_was_enabled = intel_crtc->primary_enabled;
1267
1268 intel_crtc->primary_enabled = primary_enabled;
1269
Ville Syrjälä46a55d32014-05-21 14:04:46 +03001270 if (primary_was_enabled != primary_enabled)
1271 intel_crtc_wait_for_pending_flips(crtc);
1272
Ville Syrjälä5b633d62014-04-29 13:35:47 +03001273 if (primary_was_enabled && !primary_enabled)
1274 intel_pre_disable_primary(crtc);
Jesse Barnes175bd422011-12-13 13:19:39 -08001275
Gustavo Padovan96d61a72014-09-05 17:04:47 -03001276 if (state->visible) {
1277 crtc_x = state->dst.x1;
Gustavo Padovane259f172014-09-11 17:42:15 -03001278 crtc_y = state->dst.y1;
Gustavo Padovan96d61a72014-09-05 17:04:47 -03001279 crtc_w = drm_rect_width(&state->dst);
1280 crtc_h = drm_rect_height(&state->dst);
1281 src_x = state->src.x1;
1282 src_y = state->src.y1;
1283 src_w = drm_rect_width(&state->src);
1284 src_h = drm_rect_height(&state->src);
Ville Syrjälä03c5b252013-10-01 18:02:11 +03001285 intel_plane->update_plane(plane, crtc, fb, obj,
1286 crtc_x, crtc_y, crtc_w, crtc_h,
1287 src_x, src_y, src_w, src_h);
Gustavo Padovan96d61a72014-09-05 17:04:47 -03001288 } else {
Ville Syrjälä03c5b252013-10-01 18:02:11 +03001289 intel_plane->disable_plane(plane, crtc);
Gustavo Padovan96d61a72014-09-05 17:04:47 -03001290 }
1291
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001292
Daniel Vetterf99d7062014-06-19 16:01:59 +02001293 intel_frontbuffer_flip(dev, INTEL_FRONTBUFFER_SPRITE(pipe));
1294
Ville Syrjälä5b633d62014-04-29 13:35:47 +03001295 if (!primary_was_enabled && primary_enabled)
1296 intel_post_enable_primary(crtc);
Ville Syrjälä03c5b252013-10-01 18:02:11 +03001297 }
Jesse Barnes175bd422011-12-13 13:19:39 -08001298
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001299 /* Unpin old obj after new one is active to avoid ugliness */
Gustavo Padovan25067bf2014-09-10 12:03:17 -03001300 if (old_obj && old_obj != obj) {
1301
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001302 /*
1303 * It's fairly common to simply update the position of
1304 * an existing object. In that case, we don't need to
1305 * wait for vblank to avoid ugliness, we only need to
1306 * do the pin & ref bookkeeping.
1307 */
Gustavo Padovan25067bf2014-09-10 12:03:17 -03001308 if (intel_crtc->active)
Ville Syrjälä2afd9ef2013-10-01 18:02:14 +03001309 intel_wait_for_vblank(dev, intel_crtc->pipe);
Ville Syrjälä82284b62013-10-01 18:02:12 +03001310
1311 mutex_lock(&dev->struct_mutex);
Chris Wilson1690e1e2011-12-14 13:57:08 +01001312 intel_unpin_fb_obj(old_obj);
Ville Syrjälä82284b62013-10-01 18:02:12 +03001313 mutex_unlock(&dev->struct_mutex);
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001314 }
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001315}
1316
1317static int
Gustavo Padovan96d61a72014-09-05 17:04:47 -03001318intel_update_plane(struct drm_plane *plane, struct drm_crtc *crtc,
1319 struct drm_framebuffer *fb, int crtc_x, int crtc_y,
1320 unsigned int crtc_w, unsigned int crtc_h,
1321 uint32_t src_x, uint32_t src_y,
1322 uint32_t src_w, uint32_t src_h)
1323{
1324 struct intel_plane_state state;
1325 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
1326 int ret;
1327
1328 state.crtc = crtc;
1329 state.fb = fb;
1330
1331 /* sample coordinates in 16.16 fixed point */
1332 state.src.x1 = src_x;
1333 state.src.x2 = src_x + src_w;
1334 state.src.y1 = src_y;
1335 state.src.y2 = src_y + src_h;
1336
1337 /* integer pixels */
1338 state.dst.x1 = crtc_x;
1339 state.dst.x2 = crtc_x + crtc_w;
1340 state.dst.y1 = crtc_y;
1341 state.dst.y2 = crtc_y + crtc_h;
1342
1343 state.clip.x1 = 0;
1344 state.clip.y1 = 0;
1345 state.clip.x2 = intel_crtc->active ? intel_crtc->config.pipe_src_w : 0;
1346 state.clip.y2 = intel_crtc->active ? intel_crtc->config.pipe_src_h : 0;
1347 state.orig_src = state.src;
1348 state.orig_dst = state.dst;
1349
1350 ret = intel_check_sprite_plane(plane, &state);
1351 if (ret)
1352 return ret;
1353
Gustavo Padovan34aa50a2014-10-24 14:51:32 +01001354 ret = intel_prepare_sprite_plane(plane, &state);
1355 if (ret)
1356 return ret;
1357
1358 intel_commit_sprite_plane(plane, &state);
1359 return 0;
Gustavo Padovan96d61a72014-09-05 17:04:47 -03001360}
1361
1362static int
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001363intel_disable_plane(struct drm_plane *plane)
1364{
1365 struct drm_device *dev = plane->dev;
1366 struct intel_plane *intel_plane = to_intel_plane(plane);
Ville Syrjälä03c5b252013-10-01 18:02:11 +03001367 struct intel_crtc *intel_crtc;
Daniel Vettera071fa02014-06-18 23:28:09 +02001368 enum pipe pipe;
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001369
Ville Syrjälä88a94a52013-08-07 13:30:23 +03001370 if (!plane->fb)
1371 return 0;
1372
1373 if (WARN_ON(!plane->crtc))
1374 return -EINVAL;
1375
Ville Syrjälä03c5b252013-10-01 18:02:11 +03001376 intel_crtc = to_intel_crtc(plane->crtc);
Daniel Vettera071fa02014-06-18 23:28:09 +02001377 pipe = intel_crtc->pipe;
Ville Syrjälä03c5b252013-10-01 18:02:11 +03001378
1379 if (intel_crtc->active) {
Ville Syrjälä5b633d62014-04-29 13:35:47 +03001380 bool primary_was_enabled = intel_crtc->primary_enabled;
1381
1382 intel_crtc->primary_enabled = true;
1383
Ville Syrjälä03c5b252013-10-01 18:02:11 +03001384 intel_plane->disable_plane(plane, plane->crtc);
Ville Syrjälä5b633d62014-04-29 13:35:47 +03001385
1386 if (!primary_was_enabled && intel_crtc->primary_enabled)
1387 intel_post_enable_primary(plane->crtc);
Ville Syrjälä03c5b252013-10-01 18:02:11 +03001388 }
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001389
Ville Syrjälä5f3fb462013-10-01 18:02:13 +03001390 if (intel_plane->obj) {
1391 if (intel_crtc->active)
1392 intel_wait_for_vblank(dev, intel_plane->pipe);
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001393
Ville Syrjälä5f3fb462013-10-01 18:02:13 +03001394 mutex_lock(&dev->struct_mutex);
1395 intel_unpin_fb_obj(intel_plane->obj);
Daniel Vettera071fa02014-06-18 23:28:09 +02001396 i915_gem_track_fb(intel_plane->obj, NULL,
1397 INTEL_FRONTBUFFER_SPRITE(pipe));
Ville Syrjälä5f3fb462013-10-01 18:02:13 +03001398 mutex_unlock(&dev->struct_mutex);
Ville Syrjäläc626d312013-03-27 17:49:13 +02001399
Ville Syrjälä5f3fb462013-10-01 18:02:13 +03001400 intel_plane->obj = NULL;
1401 }
Ville Syrjälä82284b62013-10-01 18:02:12 +03001402
Ville Syrjälä5f3fb462013-10-01 18:02:13 +03001403 return 0;
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001404}
1405
1406static void intel_destroy_plane(struct drm_plane *plane)
1407{
1408 struct intel_plane *intel_plane = to_intel_plane(plane);
1409 intel_disable_plane(plane);
1410 drm_plane_cleanup(plane);
1411 kfree(intel_plane);
1412}
1413
Jesse Barnes8ea30862012-01-03 08:05:39 -08001414int intel_sprite_set_colorkey(struct drm_device *dev, void *data,
1415 struct drm_file *file_priv)
1416{
1417 struct drm_intel_sprite_colorkey *set = data;
Jesse Barnes8ea30862012-01-03 08:05:39 -08001418 struct drm_plane *plane;
1419 struct intel_plane *intel_plane;
1420 int ret = 0;
1421
Daniel Vetter1cff8f62012-04-24 09:55:08 +02001422 if (!drm_core_check_feature(dev, DRIVER_MODESET))
1423 return -ENODEV;
Jesse Barnes8ea30862012-01-03 08:05:39 -08001424
1425 /* Make sure we don't try to enable both src & dest simultaneously */
1426 if ((set->flags & (I915_SET_COLORKEY_DESTINATION | I915_SET_COLORKEY_SOURCE)) == (I915_SET_COLORKEY_DESTINATION | I915_SET_COLORKEY_SOURCE))
1427 return -EINVAL;
1428
Daniel Vettera0e99e62012-12-02 01:05:46 +01001429 drm_modeset_lock_all(dev);
Jesse Barnes8ea30862012-01-03 08:05:39 -08001430
Rob Clark7707e652014-07-17 23:30:04 -04001431 plane = drm_plane_find(dev, set->plane_id);
1432 if (!plane) {
Ville Syrjälä3f2c2052013-10-17 13:35:03 +03001433 ret = -ENOENT;
Jesse Barnes8ea30862012-01-03 08:05:39 -08001434 goto out_unlock;
1435 }
1436
Jesse Barnes8ea30862012-01-03 08:05:39 -08001437 intel_plane = to_intel_plane(plane);
1438 ret = intel_plane->update_colorkey(plane, set);
1439
1440out_unlock:
Daniel Vettera0e99e62012-12-02 01:05:46 +01001441 drm_modeset_unlock_all(dev);
Jesse Barnes8ea30862012-01-03 08:05:39 -08001442 return ret;
1443}
1444
1445int intel_sprite_get_colorkey(struct drm_device *dev, void *data,
1446 struct drm_file *file_priv)
1447{
1448 struct drm_intel_sprite_colorkey *get = data;
Jesse Barnes8ea30862012-01-03 08:05:39 -08001449 struct drm_plane *plane;
1450 struct intel_plane *intel_plane;
1451 int ret = 0;
1452
Daniel Vetter1cff8f62012-04-24 09:55:08 +02001453 if (!drm_core_check_feature(dev, DRIVER_MODESET))
1454 return -ENODEV;
Jesse Barnes8ea30862012-01-03 08:05:39 -08001455
Daniel Vettera0e99e62012-12-02 01:05:46 +01001456 drm_modeset_lock_all(dev);
Jesse Barnes8ea30862012-01-03 08:05:39 -08001457
Rob Clark7707e652014-07-17 23:30:04 -04001458 plane = drm_plane_find(dev, get->plane_id);
1459 if (!plane) {
Ville Syrjälä3f2c2052013-10-17 13:35:03 +03001460 ret = -ENOENT;
Jesse Barnes8ea30862012-01-03 08:05:39 -08001461 goto out_unlock;
1462 }
1463
Jesse Barnes8ea30862012-01-03 08:05:39 -08001464 intel_plane = to_intel_plane(plane);
1465 intel_plane->get_colorkey(plane, get);
1466
1467out_unlock:
Daniel Vettera0e99e62012-12-02 01:05:46 +01001468 drm_modeset_unlock_all(dev);
Jesse Barnes8ea30862012-01-03 08:05:39 -08001469 return ret;
1470}
1471
Sonika Jindal48404c12014-08-22 14:06:04 +05301472int intel_plane_set_property(struct drm_plane *plane,
1473 struct drm_property *prop,
1474 uint64_t val)
Ville Syrjälä7ed6eee2014-08-05 11:26:55 +05301475{
1476 struct drm_device *dev = plane->dev;
1477 struct intel_plane *intel_plane = to_intel_plane(plane);
1478 uint64_t old_val;
1479 int ret = -ENOENT;
1480
1481 if (prop == dev->mode_config.rotation_property) {
1482 /* exactly one rotation angle please */
1483 if (hweight32(val & 0xf) != 1)
1484 return -EINVAL;
1485
Ville Syrjälä09dba002014-09-01 18:08:25 +03001486 if (intel_plane->rotation == val)
1487 return 0;
1488
Ville Syrjälä7ed6eee2014-08-05 11:26:55 +05301489 old_val = intel_plane->rotation;
1490 intel_plane->rotation = val;
1491 ret = intel_plane_restore(plane);
1492 if (ret)
1493 intel_plane->rotation = old_val;
1494 }
1495
1496 return ret;
1497}
1498
Ville Syrjäläe57465f2014-08-05 11:26:53 +05301499int intel_plane_restore(struct drm_plane *plane)
Jesse Barnes5e1bac22013-03-26 09:25:43 -07001500{
1501 struct intel_plane *intel_plane = to_intel_plane(plane);
1502
1503 if (!plane->crtc || !plane->fb)
Ville Syrjäläe57465f2014-08-05 11:26:53 +05301504 return 0;
Jesse Barnes5e1bac22013-03-26 09:25:43 -07001505
Sonika Jindal48404c12014-08-22 14:06:04 +05301506 return plane->funcs->update_plane(plane, plane->crtc, plane->fb,
Ville Syrjäläe57465f2014-08-05 11:26:53 +05301507 intel_plane->crtc_x, intel_plane->crtc_y,
1508 intel_plane->crtc_w, intel_plane->crtc_h,
1509 intel_plane->src_x, intel_plane->src_y,
1510 intel_plane->src_w, intel_plane->src_h);
Jesse Barnes5e1bac22013-03-26 09:25:43 -07001511}
1512
Ville Syrjäläbb53d4a2013-06-04 13:49:04 +03001513void intel_plane_disable(struct drm_plane *plane)
1514{
1515 if (!plane->crtc || !plane->fb)
1516 return;
1517
1518 intel_disable_plane(plane);
1519}
1520
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001521static const struct drm_plane_funcs intel_plane_funcs = {
1522 .update_plane = intel_update_plane,
1523 .disable_plane = intel_disable_plane,
1524 .destroy = intel_destroy_plane,
Ville Syrjälä7ed6eee2014-08-05 11:26:55 +05301525 .set_property = intel_plane_set_property,
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001526};
1527
Chris Wilsond1686ae2012-04-10 11:41:49 +01001528static uint32_t ilk_plane_formats[] = {
1529 DRM_FORMAT_XRGB8888,
1530 DRM_FORMAT_YUYV,
1531 DRM_FORMAT_YVYU,
1532 DRM_FORMAT_UYVY,
1533 DRM_FORMAT_VYUY,
1534};
1535
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001536static uint32_t snb_plane_formats[] = {
1537 DRM_FORMAT_XBGR8888,
1538 DRM_FORMAT_XRGB8888,
1539 DRM_FORMAT_YUYV,
1540 DRM_FORMAT_YVYU,
1541 DRM_FORMAT_UYVY,
1542 DRM_FORMAT_VYUY,
1543};
1544
Jesse Barnes7f1f3852013-04-02 11:22:20 -07001545static uint32_t vlv_plane_formats[] = {
1546 DRM_FORMAT_RGB565,
1547 DRM_FORMAT_ABGR8888,
1548 DRM_FORMAT_ARGB8888,
1549 DRM_FORMAT_XBGR8888,
1550 DRM_FORMAT_XRGB8888,
1551 DRM_FORMAT_XBGR2101010,
1552 DRM_FORMAT_ABGR2101010,
1553 DRM_FORMAT_YUYV,
1554 DRM_FORMAT_YVYU,
1555 DRM_FORMAT_UYVY,
1556 DRM_FORMAT_VYUY,
1557};
1558
Damien Lespiaudc2a41b2013-12-04 00:49:41 +00001559static uint32_t skl_plane_formats[] = {
1560 DRM_FORMAT_RGB565,
1561 DRM_FORMAT_ABGR8888,
1562 DRM_FORMAT_ARGB8888,
1563 DRM_FORMAT_XBGR8888,
1564 DRM_FORMAT_XRGB8888,
1565 DRM_FORMAT_YUYV,
1566 DRM_FORMAT_YVYU,
1567 DRM_FORMAT_UYVY,
1568 DRM_FORMAT_VYUY,
1569};
1570
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001571int
Jesse Barnes7f1f3852013-04-02 11:22:20 -07001572intel_plane_init(struct drm_device *dev, enum pipe pipe, int plane)
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001573{
1574 struct intel_plane *intel_plane;
1575 unsigned long possible_crtcs;
Chris Wilsond1686ae2012-04-10 11:41:49 +01001576 const uint32_t *plane_formats;
1577 int num_plane_formats;
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001578 int ret;
1579
Chris Wilsond1686ae2012-04-10 11:41:49 +01001580 if (INTEL_INFO(dev)->gen < 5)
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001581 return -ENODEV;
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001582
Daniel Vetterb14c5672013-09-19 12:18:32 +02001583 intel_plane = kzalloc(sizeof(*intel_plane), GFP_KERNEL);
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001584 if (!intel_plane)
1585 return -ENOMEM;
1586
Chris Wilsond1686ae2012-04-10 11:41:49 +01001587 switch (INTEL_INFO(dev)->gen) {
1588 case 5:
1589 case 6:
Damien Lespiau2d354c32012-10-22 18:19:27 +01001590 intel_plane->can_scale = true;
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001591 intel_plane->max_downscale = 16;
Chris Wilsond1686ae2012-04-10 11:41:49 +01001592 intel_plane->update_plane = ilk_update_plane;
1593 intel_plane->disable_plane = ilk_disable_plane;
1594 intel_plane->update_colorkey = ilk_update_colorkey;
1595 intel_plane->get_colorkey = ilk_get_colorkey;
1596
1597 if (IS_GEN6(dev)) {
1598 plane_formats = snb_plane_formats;
1599 num_plane_formats = ARRAY_SIZE(snb_plane_formats);
1600 } else {
1601 plane_formats = ilk_plane_formats;
1602 num_plane_formats = ARRAY_SIZE(ilk_plane_formats);
1603 }
1604 break;
1605
1606 case 7:
Ben Widawsky4e0bbc32013-11-02 21:07:07 -07001607 case 8:
Damien Lespiaud49f7092013-04-25 15:15:00 +01001608 if (IS_IVYBRIDGE(dev)) {
Damien Lespiau2d354c32012-10-22 18:19:27 +01001609 intel_plane->can_scale = true;
Damien Lespiaud49f7092013-04-25 15:15:00 +01001610 intel_plane->max_downscale = 2;
1611 } else {
1612 intel_plane->can_scale = false;
1613 intel_plane->max_downscale = 1;
1614 }
Chris Wilsond1686ae2012-04-10 11:41:49 +01001615
Jesse Barnes7f1f3852013-04-02 11:22:20 -07001616 if (IS_VALLEYVIEW(dev)) {
Jesse Barnes7f1f3852013-04-02 11:22:20 -07001617 intel_plane->update_plane = vlv_update_plane;
1618 intel_plane->disable_plane = vlv_disable_plane;
1619 intel_plane->update_colorkey = vlv_update_colorkey;
1620 intel_plane->get_colorkey = vlv_get_colorkey;
1621
1622 plane_formats = vlv_plane_formats;
1623 num_plane_formats = ARRAY_SIZE(vlv_plane_formats);
1624 } else {
Jesse Barnes7f1f3852013-04-02 11:22:20 -07001625 intel_plane->update_plane = ivb_update_plane;
1626 intel_plane->disable_plane = ivb_disable_plane;
1627 intel_plane->update_colorkey = ivb_update_colorkey;
1628 intel_plane->get_colorkey = ivb_get_colorkey;
1629
1630 plane_formats = snb_plane_formats;
1631 num_plane_formats = ARRAY_SIZE(snb_plane_formats);
1632 }
Chris Wilsond1686ae2012-04-10 11:41:49 +01001633 break;
Damien Lespiaudc2a41b2013-12-04 00:49:41 +00001634 case 9:
1635 /*
1636 * FIXME: Skylake planes can be scaled (with some restrictions),
1637 * but this is for another time.
1638 */
1639 intel_plane->can_scale = false;
1640 intel_plane->max_downscale = 1;
1641 intel_plane->update_plane = skl_update_plane;
1642 intel_plane->disable_plane = skl_disable_plane;
1643 intel_plane->update_colorkey = skl_update_colorkey;
1644 intel_plane->get_colorkey = skl_get_colorkey;
Chris Wilsond1686ae2012-04-10 11:41:49 +01001645
Damien Lespiaudc2a41b2013-12-04 00:49:41 +00001646 plane_formats = skl_plane_formats;
1647 num_plane_formats = ARRAY_SIZE(skl_plane_formats);
1648 break;
Chris Wilsond1686ae2012-04-10 11:41:49 +01001649 default:
Jesper Juhla8b0bba2012-06-27 00:55:37 +02001650 kfree(intel_plane);
Chris Wilsond1686ae2012-04-10 11:41:49 +01001651 return -ENODEV;
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001652 }
1653
1654 intel_plane->pipe = pipe;
Jesse Barnes7f1f3852013-04-02 11:22:20 -07001655 intel_plane->plane = plane;
Ville Syrjälä76eebda2014-08-05 11:26:52 +05301656 intel_plane->rotation = BIT(DRM_ROTATE_0);
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001657 possible_crtcs = (1 << pipe);
Derek Foreman8fe8a3f2014-09-03 10:38:20 -03001658 ret = drm_universal_plane_init(dev, &intel_plane->base, possible_crtcs,
1659 &intel_plane_funcs,
1660 plane_formats, num_plane_formats,
1661 DRM_PLANE_TYPE_OVERLAY);
Ville Syrjälä7ed6eee2014-08-05 11:26:55 +05301662 if (ret) {
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001663 kfree(intel_plane);
Ville Syrjälä7ed6eee2014-08-05 11:26:55 +05301664 goto out;
1665 }
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001666
Ville Syrjälä7ed6eee2014-08-05 11:26:55 +05301667 if (!dev->mode_config.rotation_property)
1668 dev->mode_config.rotation_property =
1669 drm_mode_create_rotation_property(dev,
1670 BIT(DRM_ROTATE_0) |
1671 BIT(DRM_ROTATE_180));
1672
1673 if (dev->mode_config.rotation_property)
1674 drm_object_attach_property(&intel_plane->base.base,
1675 dev->mode_config.rotation_property,
1676 intel_plane->rotation);
1677
1678 out:
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001679 return ret;
1680}