2 * Copyright © 2011 Intel Corporation
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:
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
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
24 * Jesse Barnes <jbarnes@virtuousgeek.org>
26 * New plane/sprite handling.
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
33 #include <drm/drm_crtc.h>
34 #include <drm/drm_fourcc.h>
35 #include <drm/drm_rect.h>
36 #include "intel_drv.h"
37 #include <drm/i915_drm.h>
41 format_is_yuv(uint32_t format)
54 static int usecs_to_scanlines(const struct drm_display_mode *mode, int usecs)
57 if (!mode->crtc_htotal)
60 return DIV_ROUND_UP(usecs * mode->crtc_clock, 1000 * mode->crtc_htotal);
64 * intel_pipe_update_start() - start update of a set of display registers
65 * @crtc: the crtc of which the registers are going to be updated
66 * @start_vbl_count: vblank counter return pointer used for error checking
68 * Mark the start of an update to pipe registers that should be updated
69 * atomically regarding vblank. If the next vblank will happens within
70 * the next 100 us, this function waits until the vblank passes.
72 * After a successful call to this function, interrupts will be disabled
73 * until a subsequent call to intel_pipe_update_end(). That is done to
74 * avoid random delays. The value written to @start_vbl_count should be
75 * supplied to intel_pipe_update_end() for error checking.
77 * Return: true if the call was successful
79 bool intel_pipe_update_start(struct intel_crtc *crtc, uint32_t *start_vbl_count)
81 struct drm_device *dev = crtc->base.dev;
82 const struct drm_display_mode *mode = &crtc->config.adjusted_mode;
83 enum pipe pipe = crtc->pipe;
84 long timeout = msecs_to_jiffies_timeout(1);
85 int scanline, min, max, vblank_start;
86 wait_queue_head_t *wq = drm_crtc_vblank_waitqueue(&crtc->base);
89 vblank_start = mode->crtc_vblank_start;
90 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
91 vblank_start = DIV_ROUND_UP(vblank_start, 2);
93 /* FIXME needs to be calibrated sensibly */
94 min = vblank_start - usecs_to_scanlines(mode, 100);
95 max = vblank_start - 1;
97 if (min <= 0 || max <= 0)
100 if (WARN_ON(drm_vblank_get(dev, pipe)))
105 trace_i915_pipe_update_start(crtc, min, max);
109 * prepare_to_wait() has a memory barrier, which guarantees
110 * other CPUs can see the task state update by the time we
113 prepare_to_wait(wq, &wait, TASK_UNINTERRUPTIBLE);
115 scanline = intel_get_crtc_scanline(crtc);
116 if (scanline < min || scanline > max)
120 DRM_ERROR("Potential atomic update failure on pipe %c\n",
121 pipe_name(crtc->pipe));
127 timeout = schedule_timeout(timeout);
132 finish_wait(wq, &wait);
134 drm_vblank_put(dev, pipe);
136 *start_vbl_count = dev->driver->get_vblank_counter(dev, pipe);
138 trace_i915_pipe_update_vblank_evaded(crtc, min, max, *start_vbl_count);
144 * intel_pipe_update_end() - end update of a set of display registers
145 * @crtc: the crtc of which the registers were updated
146 * @start_vbl_count: start vblank counter (used for error checking)
148 * Mark the end of an update started with intel_pipe_update_start(). This
149 * re-enables interrupts and verifies the update was actually completed
150 * before a vblank using the value of @start_vbl_count.
152 void intel_pipe_update_end(struct intel_crtc *crtc, u32 start_vbl_count)
154 struct drm_device *dev = crtc->base.dev;
155 enum pipe pipe = crtc->pipe;
156 u32 end_vbl_count = dev->driver->get_vblank_counter(dev, pipe);
158 trace_i915_pipe_update_end(crtc, end_vbl_count);
162 if (start_vbl_count != end_vbl_count)
163 DRM_ERROR("Atomic update failure on pipe %c (start=%u end=%u)\n",
164 pipe_name(pipe), start_vbl_count, end_vbl_count);
167 static void intel_update_primary_plane(struct intel_crtc *crtc)
169 struct drm_i915_private *dev_priv = crtc->base.dev->dev_private;
170 int reg = DSPCNTR(crtc->plane);
172 if (crtc->primary_enabled)
173 I915_WRITE(reg, I915_READ(reg) | DISPLAY_PLANE_ENABLE);
175 I915_WRITE(reg, I915_READ(reg) & ~DISPLAY_PLANE_ENABLE);
179 skl_update_plane(struct drm_plane *drm_plane, struct drm_crtc *crtc,
180 struct drm_framebuffer *fb,
181 struct drm_i915_gem_object *obj, int crtc_x, int crtc_y,
182 unsigned int crtc_w, unsigned int crtc_h,
183 uint32_t x, uint32_t y,
184 uint32_t src_w, uint32_t src_h)
186 struct drm_device *dev = drm_plane->dev;
187 struct drm_i915_private *dev_priv = dev->dev_private;
188 struct intel_plane *intel_plane = to_intel_plane(drm_plane);
189 const int pipe = intel_plane->pipe;
190 const int plane = intel_plane->plane + 1;
191 u32 plane_ctl, stride;
192 int pixel_size = drm_format_plane_cpp(fb->pixel_format, 0);
194 plane_ctl = I915_READ(PLANE_CTL(pipe, plane));
196 /* Mask out pixel format bits in case we change it */
197 plane_ctl &= ~PLANE_CTL_FORMAT_MASK;
198 plane_ctl &= ~PLANE_CTL_ORDER_RGBX;
199 plane_ctl &= ~PLANE_CTL_YUV422_ORDER_MASK;
200 plane_ctl &= ~PLANE_CTL_TILED_MASK;
201 plane_ctl &= ~PLANE_CTL_ALPHA_MASK;
202 plane_ctl &= ~PLANE_CTL_ROTATE_MASK;
204 /* Trickle feed has to be enabled */
205 plane_ctl &= ~PLANE_CTL_TRICKLE_FEED_DISABLE;
207 switch (fb->pixel_format) {
208 case DRM_FORMAT_RGB565:
209 plane_ctl |= PLANE_CTL_FORMAT_RGB_565;
211 case DRM_FORMAT_XBGR8888:
212 plane_ctl |= PLANE_CTL_FORMAT_XRGB_8888 | PLANE_CTL_ORDER_RGBX;
214 case DRM_FORMAT_XRGB8888:
215 plane_ctl |= PLANE_CTL_FORMAT_XRGB_8888;
218 * XXX: For ARBG/ABGR formats we default to expecting scanout buffers
219 * to be already pre-multiplied. We need to add a knob (or a different
220 * DRM_FORMAT) for user-space to configure that.
222 case DRM_FORMAT_ABGR8888:
223 plane_ctl |= PLANE_CTL_FORMAT_XRGB_8888 |
224 PLANE_CTL_ORDER_RGBX |
225 PLANE_CTL_ALPHA_SW_PREMULTIPLY;
227 case DRM_FORMAT_ARGB8888:
228 plane_ctl |= PLANE_CTL_FORMAT_XRGB_8888 |
229 PLANE_CTL_ALPHA_SW_PREMULTIPLY;
231 case DRM_FORMAT_YUYV:
232 plane_ctl |= PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YUYV;
234 case DRM_FORMAT_YVYU:
235 plane_ctl |= PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YVYU;
237 case DRM_FORMAT_UYVY:
238 plane_ctl |= PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_UYVY;
240 case DRM_FORMAT_VYUY:
241 plane_ctl |= PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_VYUY;
247 switch (obj->tiling_mode) {
248 case I915_TILING_NONE:
249 stride = fb->pitches[0] >> 6;
252 plane_ctl |= PLANE_CTL_TILED_X;
253 stride = fb->pitches[0] >> 9;
258 if (intel_plane->rotation == BIT(DRM_ROTATE_180))
259 plane_ctl |= PLANE_CTL_ROTATE_180;
261 plane_ctl |= PLANE_CTL_ENABLE;
262 plane_ctl |= PLANE_CTL_PIPE_CSC_ENABLE;
264 intel_update_sprite_watermarks(drm_plane, crtc, src_w, src_h,
266 src_w != crtc_w || src_h != crtc_h);
268 /* Sizes are 0 based */
274 I915_WRITE(PLANE_OFFSET(pipe, plane), (y << 16) | x);
275 I915_WRITE(PLANE_STRIDE(pipe, plane), stride);
276 I915_WRITE(PLANE_POS(pipe, plane), (crtc_y << 16) | crtc_x);
277 I915_WRITE(PLANE_SIZE(pipe, plane), (crtc_h << 16) | crtc_w);
278 I915_WRITE(PLANE_CTL(pipe, plane), plane_ctl);
279 I915_WRITE(PLANE_SURF(pipe, plane), i915_gem_obj_ggtt_offset(obj));
280 POSTING_READ(PLANE_SURF(pipe, plane));
284 skl_disable_plane(struct drm_plane *drm_plane, struct drm_crtc *crtc)
286 struct drm_device *dev = drm_plane->dev;
287 struct drm_i915_private *dev_priv = dev->dev_private;
288 struct intel_plane *intel_plane = to_intel_plane(drm_plane);
289 const int pipe = intel_plane->pipe;
290 const int plane = intel_plane->plane + 1;
292 I915_WRITE(PLANE_CTL(pipe, plane),
293 I915_READ(PLANE_CTL(pipe, plane)) & ~PLANE_CTL_ENABLE);
295 /* Activate double buffered register update */
296 I915_WRITE(PLANE_CTL(pipe, plane), 0);
297 POSTING_READ(PLANE_CTL(pipe, plane));
299 intel_update_sprite_watermarks(drm_plane, crtc, 0, 0, 0, false, false);
303 skl_update_colorkey(struct drm_plane *drm_plane,
304 struct drm_intel_sprite_colorkey *key)
306 struct drm_device *dev = drm_plane->dev;
307 struct drm_i915_private *dev_priv = dev->dev_private;
308 struct intel_plane *intel_plane = to_intel_plane(drm_plane);
309 const int pipe = intel_plane->pipe;
310 const int plane = intel_plane->plane;
313 I915_WRITE(PLANE_KEYVAL(pipe, plane), key->min_value);
314 I915_WRITE(PLANE_KEYMAX(pipe, plane), key->max_value);
315 I915_WRITE(PLANE_KEYMSK(pipe, plane), key->channel_mask);
317 plane_ctl = I915_READ(PLANE_CTL(pipe, plane));
318 plane_ctl &= ~PLANE_CTL_KEY_ENABLE_MASK;
319 if (key->flags & I915_SET_COLORKEY_DESTINATION)
320 plane_ctl |= PLANE_CTL_KEY_ENABLE_DESTINATION;
321 else if (key->flags & I915_SET_COLORKEY_SOURCE)
322 plane_ctl |= PLANE_CTL_KEY_ENABLE_SOURCE;
323 I915_WRITE(PLANE_CTL(pipe, plane), plane_ctl);
325 POSTING_READ(PLANE_CTL(pipe, plane));
331 skl_get_colorkey(struct drm_plane *drm_plane,
332 struct drm_intel_sprite_colorkey *key)
334 struct drm_device *dev = drm_plane->dev;
335 struct drm_i915_private *dev_priv = dev->dev_private;
336 struct intel_plane *intel_plane = to_intel_plane(drm_plane);
337 const int pipe = intel_plane->pipe;
338 const int plane = intel_plane->plane;
341 key->min_value = I915_READ(PLANE_KEYVAL(pipe, plane));
342 key->max_value = I915_READ(PLANE_KEYMAX(pipe, plane));
343 key->channel_mask = I915_READ(PLANE_KEYMSK(pipe, plane));
345 plane_ctl = I915_READ(PLANE_CTL(pipe, plane));
347 switch (plane_ctl & PLANE_CTL_KEY_ENABLE_MASK) {
348 case PLANE_CTL_KEY_ENABLE_DESTINATION:
349 key->flags = I915_SET_COLORKEY_DESTINATION;
351 case PLANE_CTL_KEY_ENABLE_SOURCE:
352 key->flags = I915_SET_COLORKEY_SOURCE;
355 key->flags = I915_SET_COLORKEY_NONE;
360 chv_update_csc(struct intel_plane *intel_plane, uint32_t format)
362 struct drm_i915_private *dev_priv = intel_plane->base.dev->dev_private;
363 int plane = intel_plane->plane;
365 /* Seems RGB data bypasses the CSC always */
366 if (!format_is_yuv(format))
370 * BT.601 limited range YCbCr -> full range RGB
372 * |r| | 6537 4769 0| |cr |
373 * |g| = |-3330 4769 -1605| x |y-64|
374 * |b| | 0 4769 8263| |cb |
376 * Cb and Cr apparently come in as signed already, so no
377 * need for any offset. For Y we need to remove the offset.
379 I915_WRITE(SPCSCYGOFF(plane), SPCSC_OOFF(0) | SPCSC_IOFF(-64));
380 I915_WRITE(SPCSCCBOFF(plane), SPCSC_OOFF(0) | SPCSC_IOFF(0));
381 I915_WRITE(SPCSCCROFF(plane), SPCSC_OOFF(0) | SPCSC_IOFF(0));
383 I915_WRITE(SPCSCC01(plane), SPCSC_C1(4769) | SPCSC_C0(6537));
384 I915_WRITE(SPCSCC23(plane), SPCSC_C1(-3330) | SPCSC_C0(0));
385 I915_WRITE(SPCSCC45(plane), SPCSC_C1(-1605) | SPCSC_C0(4769));
386 I915_WRITE(SPCSCC67(plane), SPCSC_C1(4769) | SPCSC_C0(0));
387 I915_WRITE(SPCSCC8(plane), SPCSC_C0(8263));
389 I915_WRITE(SPCSCYGICLAMP(plane), SPCSC_IMAX(940) | SPCSC_IMIN(64));
390 I915_WRITE(SPCSCCBICLAMP(plane), SPCSC_IMAX(448) | SPCSC_IMIN(-448));
391 I915_WRITE(SPCSCCRICLAMP(plane), SPCSC_IMAX(448) | SPCSC_IMIN(-448));
393 I915_WRITE(SPCSCYGOCLAMP(plane), SPCSC_OMAX(1023) | SPCSC_OMIN(0));
394 I915_WRITE(SPCSCCBOCLAMP(plane), SPCSC_OMAX(1023) | SPCSC_OMIN(0));
395 I915_WRITE(SPCSCCROCLAMP(plane), SPCSC_OMAX(1023) | SPCSC_OMIN(0));
399 vlv_update_plane(struct drm_plane *dplane, struct drm_crtc *crtc,
400 struct drm_framebuffer *fb,
401 struct drm_i915_gem_object *obj, int crtc_x, int crtc_y,
402 unsigned int crtc_w, unsigned int crtc_h,
403 uint32_t x, uint32_t y,
404 uint32_t src_w, uint32_t src_h)
406 struct drm_device *dev = dplane->dev;
407 struct drm_i915_private *dev_priv = dev->dev_private;
408 struct intel_plane *intel_plane = to_intel_plane(dplane);
409 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
410 int pipe = intel_plane->pipe;
411 int plane = intel_plane->plane;
413 unsigned long sprsurf_offset, linear_offset;
414 int pixel_size = drm_format_plane_cpp(fb->pixel_format, 0);
418 sprctl = I915_READ(SPCNTR(pipe, plane));
420 /* Mask out pixel format bits in case we change it */
421 sprctl &= ~SP_PIXFORMAT_MASK;
422 sprctl &= ~SP_YUV_BYTE_ORDER_MASK;
424 sprctl &= ~SP_ROTATE_180;
426 switch (fb->pixel_format) {
427 case DRM_FORMAT_YUYV:
428 sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_YUYV;
430 case DRM_FORMAT_YVYU:
431 sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_YVYU;
433 case DRM_FORMAT_UYVY:
434 sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_UYVY;
436 case DRM_FORMAT_VYUY:
437 sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_VYUY;
439 case DRM_FORMAT_RGB565:
440 sprctl |= SP_FORMAT_BGR565;
442 case DRM_FORMAT_XRGB8888:
443 sprctl |= SP_FORMAT_BGRX8888;
445 case DRM_FORMAT_ARGB8888:
446 sprctl |= SP_FORMAT_BGRA8888;
448 case DRM_FORMAT_XBGR2101010:
449 sprctl |= SP_FORMAT_RGBX1010102;
451 case DRM_FORMAT_ABGR2101010:
452 sprctl |= SP_FORMAT_RGBA1010102;
454 case DRM_FORMAT_XBGR8888:
455 sprctl |= SP_FORMAT_RGBX8888;
457 case DRM_FORMAT_ABGR8888:
458 sprctl |= SP_FORMAT_RGBA8888;
462 * If we get here one of the upper layers failed to filter
463 * out the unsupported plane formats
470 * Enable gamma to match primary/cursor plane behaviour.
471 * FIXME should be user controllable via propertiesa.
473 sprctl |= SP_GAMMA_ENABLE;
475 if (obj->tiling_mode != I915_TILING_NONE)
480 intel_update_sprite_watermarks(dplane, crtc, src_w, src_h,
482 src_w != crtc_w || src_h != crtc_h);
484 /* Sizes are 0 based */
490 linear_offset = y * fb->pitches[0] + x * pixel_size;
491 sprsurf_offset = intel_gen4_compute_page_offset(&x, &y,
495 linear_offset -= sprsurf_offset;
497 if (intel_plane->rotation == BIT(DRM_ROTATE_180)) {
498 sprctl |= SP_ROTATE_180;
502 linear_offset += src_h * fb->pitches[0] + src_w * pixel_size;
505 atomic_update = intel_pipe_update_start(intel_crtc, &start_vbl_count);
507 intel_update_primary_plane(intel_crtc);
509 if (IS_CHERRYVIEW(dev) && pipe == PIPE_B)
510 chv_update_csc(intel_plane, fb->pixel_format);
512 I915_WRITE(SPSTRIDE(pipe, plane), fb->pitches[0]);
513 I915_WRITE(SPPOS(pipe, plane), (crtc_y << 16) | crtc_x);
515 if (obj->tiling_mode != I915_TILING_NONE)
516 I915_WRITE(SPTILEOFF(pipe, plane), (y << 16) | x);
518 I915_WRITE(SPLINOFF(pipe, plane), linear_offset);
520 I915_WRITE(SPCONSTALPHA(pipe, plane), 0);
522 I915_WRITE(SPSIZE(pipe, plane), (crtc_h << 16) | crtc_w);
523 I915_WRITE(SPCNTR(pipe, plane), sprctl);
524 I915_WRITE(SPSURF(pipe, plane), i915_gem_obj_ggtt_offset(obj) +
527 intel_flush_primary_plane(dev_priv, intel_crtc->plane);
530 intel_pipe_update_end(intel_crtc, start_vbl_count);
534 vlv_disable_plane(struct drm_plane *dplane, struct drm_crtc *crtc)
536 struct drm_device *dev = dplane->dev;
537 struct drm_i915_private *dev_priv = dev->dev_private;
538 struct intel_plane *intel_plane = to_intel_plane(dplane);
539 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
540 int pipe = intel_plane->pipe;
541 int plane = intel_plane->plane;
545 atomic_update = intel_pipe_update_start(intel_crtc, &start_vbl_count);
547 intel_update_primary_plane(intel_crtc);
549 I915_WRITE(SPCNTR(pipe, plane), I915_READ(SPCNTR(pipe, plane)) &
551 /* Activate double buffered register update */
552 I915_WRITE(SPSURF(pipe, plane), 0);
554 intel_flush_primary_plane(dev_priv, intel_crtc->plane);
557 intel_pipe_update_end(intel_crtc, start_vbl_count);
559 intel_update_sprite_watermarks(dplane, crtc, 0, 0, 0, false, false);
563 vlv_update_colorkey(struct drm_plane *dplane,
564 struct drm_intel_sprite_colorkey *key)
566 struct drm_device *dev = dplane->dev;
567 struct drm_i915_private *dev_priv = dev->dev_private;
568 struct intel_plane *intel_plane = to_intel_plane(dplane);
569 int pipe = intel_plane->pipe;
570 int plane = intel_plane->plane;
573 if (key->flags & I915_SET_COLORKEY_DESTINATION)
576 I915_WRITE(SPKEYMINVAL(pipe, plane), key->min_value);
577 I915_WRITE(SPKEYMAXVAL(pipe, plane), key->max_value);
578 I915_WRITE(SPKEYMSK(pipe, plane), key->channel_mask);
580 sprctl = I915_READ(SPCNTR(pipe, plane));
581 sprctl &= ~SP_SOURCE_KEY;
582 if (key->flags & I915_SET_COLORKEY_SOURCE)
583 sprctl |= SP_SOURCE_KEY;
584 I915_WRITE(SPCNTR(pipe, plane), sprctl);
586 POSTING_READ(SPKEYMSK(pipe, plane));
592 vlv_get_colorkey(struct drm_plane *dplane,
593 struct drm_intel_sprite_colorkey *key)
595 struct drm_device *dev = dplane->dev;
596 struct drm_i915_private *dev_priv = dev->dev_private;
597 struct intel_plane *intel_plane = to_intel_plane(dplane);
598 int pipe = intel_plane->pipe;
599 int plane = intel_plane->plane;
602 key->min_value = I915_READ(SPKEYMINVAL(pipe, plane));
603 key->max_value = I915_READ(SPKEYMAXVAL(pipe, plane));
604 key->channel_mask = I915_READ(SPKEYMSK(pipe, plane));
606 sprctl = I915_READ(SPCNTR(pipe, plane));
607 if (sprctl & SP_SOURCE_KEY)
608 key->flags = I915_SET_COLORKEY_SOURCE;
610 key->flags = I915_SET_COLORKEY_NONE;
614 ivb_update_plane(struct drm_plane *plane, struct drm_crtc *crtc,
615 struct drm_framebuffer *fb,
616 struct drm_i915_gem_object *obj, int crtc_x, int crtc_y,
617 unsigned int crtc_w, unsigned int crtc_h,
618 uint32_t x, uint32_t y,
619 uint32_t src_w, uint32_t src_h)
621 struct drm_device *dev = plane->dev;
622 struct drm_i915_private *dev_priv = dev->dev_private;
623 struct intel_plane *intel_plane = to_intel_plane(plane);
624 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
625 int pipe = intel_plane->pipe;
626 u32 sprctl, sprscale = 0;
627 unsigned long sprsurf_offset, linear_offset;
628 int pixel_size = drm_format_plane_cpp(fb->pixel_format, 0);
632 sprctl = I915_READ(SPRCTL(pipe));
634 /* Mask out pixel format bits in case we change it */
635 sprctl &= ~SPRITE_PIXFORMAT_MASK;
636 sprctl &= ~SPRITE_RGB_ORDER_RGBX;
637 sprctl &= ~SPRITE_YUV_BYTE_ORDER_MASK;
638 sprctl &= ~SPRITE_TILED;
639 sprctl &= ~SPRITE_ROTATE_180;
641 switch (fb->pixel_format) {
642 case DRM_FORMAT_XBGR8888:
643 sprctl |= SPRITE_FORMAT_RGBX888 | SPRITE_RGB_ORDER_RGBX;
645 case DRM_FORMAT_XRGB8888:
646 sprctl |= SPRITE_FORMAT_RGBX888;
648 case DRM_FORMAT_YUYV:
649 sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_YUYV;
651 case DRM_FORMAT_YVYU:
652 sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_YVYU;
654 case DRM_FORMAT_UYVY:
655 sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_UYVY;
657 case DRM_FORMAT_VYUY:
658 sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_VYUY;
665 * Enable gamma to match primary/cursor plane behaviour.
666 * FIXME should be user controllable via propertiesa.
668 sprctl |= SPRITE_GAMMA_ENABLE;
670 if (obj->tiling_mode != I915_TILING_NONE)
671 sprctl |= SPRITE_TILED;
673 if (IS_HASWELL(dev) || IS_BROADWELL(dev))
674 sprctl &= ~SPRITE_TRICKLE_FEED_DISABLE;
676 sprctl |= SPRITE_TRICKLE_FEED_DISABLE;
678 sprctl |= SPRITE_ENABLE;
680 if (IS_HASWELL(dev) || IS_BROADWELL(dev))
681 sprctl |= SPRITE_PIPE_CSC_ENABLE;
683 intel_update_sprite_watermarks(plane, crtc, src_w, src_h, pixel_size,
685 src_w != crtc_w || src_h != crtc_h);
687 /* Sizes are 0 based */
693 if (crtc_w != src_w || crtc_h != src_h)
694 sprscale = SPRITE_SCALE_ENABLE | (src_w << 16) | src_h;
696 linear_offset = y * fb->pitches[0] + x * pixel_size;
698 intel_gen4_compute_page_offset(&x, &y, obj->tiling_mode,
699 pixel_size, fb->pitches[0]);
700 linear_offset -= sprsurf_offset;
702 if (intel_plane->rotation == BIT(DRM_ROTATE_180)) {
703 sprctl |= SPRITE_ROTATE_180;
705 /* HSW and BDW does this automagically in hardware */
706 if (!IS_HASWELL(dev) && !IS_BROADWELL(dev)) {
709 linear_offset += src_h * fb->pitches[0] +
714 atomic_update = intel_pipe_update_start(intel_crtc, &start_vbl_count);
716 intel_update_primary_plane(intel_crtc);
718 I915_WRITE(SPRSTRIDE(pipe), fb->pitches[0]);
719 I915_WRITE(SPRPOS(pipe), (crtc_y << 16) | crtc_x);
721 /* HSW consolidates SPRTILEOFF and SPRLINOFF into a single SPROFFSET
723 if (IS_HASWELL(dev) || IS_BROADWELL(dev))
724 I915_WRITE(SPROFFSET(pipe), (y << 16) | x);
725 else if (obj->tiling_mode != I915_TILING_NONE)
726 I915_WRITE(SPRTILEOFF(pipe), (y << 16) | x);
728 I915_WRITE(SPRLINOFF(pipe), linear_offset);
730 I915_WRITE(SPRSIZE(pipe), (crtc_h << 16) | crtc_w);
731 if (intel_plane->can_scale)
732 I915_WRITE(SPRSCALE(pipe), sprscale);
733 I915_WRITE(SPRCTL(pipe), sprctl);
734 I915_WRITE(SPRSURF(pipe),
735 i915_gem_obj_ggtt_offset(obj) + sprsurf_offset);
737 intel_flush_primary_plane(dev_priv, intel_crtc->plane);
740 intel_pipe_update_end(intel_crtc, start_vbl_count);
744 ivb_disable_plane(struct drm_plane *plane, struct drm_crtc *crtc)
746 struct drm_device *dev = plane->dev;
747 struct drm_i915_private *dev_priv = dev->dev_private;
748 struct intel_plane *intel_plane = to_intel_plane(plane);
749 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
750 int pipe = intel_plane->pipe;
754 atomic_update = intel_pipe_update_start(intel_crtc, &start_vbl_count);
756 intel_update_primary_plane(intel_crtc);
758 I915_WRITE(SPRCTL(pipe), I915_READ(SPRCTL(pipe)) & ~SPRITE_ENABLE);
759 /* Can't leave the scaler enabled... */
760 if (intel_plane->can_scale)
761 I915_WRITE(SPRSCALE(pipe), 0);
762 /* Activate double buffered register update */
763 I915_WRITE(SPRSURF(pipe), 0);
765 intel_flush_primary_plane(dev_priv, intel_crtc->plane);
768 intel_pipe_update_end(intel_crtc, start_vbl_count);
771 * Avoid underruns when disabling the sprite.
772 * FIXME remove once watermark updates are done properly.
774 intel_wait_for_vblank(dev, pipe);
776 intel_update_sprite_watermarks(plane, crtc, 0, 0, 0, false, false);
780 ivb_update_colorkey(struct drm_plane *plane,
781 struct drm_intel_sprite_colorkey *key)
783 struct drm_device *dev = plane->dev;
784 struct drm_i915_private *dev_priv = dev->dev_private;
785 struct intel_plane *intel_plane;
789 intel_plane = to_intel_plane(plane);
791 I915_WRITE(SPRKEYVAL(intel_plane->pipe), key->min_value);
792 I915_WRITE(SPRKEYMAX(intel_plane->pipe), key->max_value);
793 I915_WRITE(SPRKEYMSK(intel_plane->pipe), key->channel_mask);
795 sprctl = I915_READ(SPRCTL(intel_plane->pipe));
796 sprctl &= ~(SPRITE_SOURCE_KEY | SPRITE_DEST_KEY);
797 if (key->flags & I915_SET_COLORKEY_DESTINATION)
798 sprctl |= SPRITE_DEST_KEY;
799 else if (key->flags & I915_SET_COLORKEY_SOURCE)
800 sprctl |= SPRITE_SOURCE_KEY;
801 I915_WRITE(SPRCTL(intel_plane->pipe), sprctl);
803 POSTING_READ(SPRKEYMSK(intel_plane->pipe));
809 ivb_get_colorkey(struct drm_plane *plane, struct drm_intel_sprite_colorkey *key)
811 struct drm_device *dev = plane->dev;
812 struct drm_i915_private *dev_priv = dev->dev_private;
813 struct intel_plane *intel_plane;
816 intel_plane = to_intel_plane(plane);
818 key->min_value = I915_READ(SPRKEYVAL(intel_plane->pipe));
819 key->max_value = I915_READ(SPRKEYMAX(intel_plane->pipe));
820 key->channel_mask = I915_READ(SPRKEYMSK(intel_plane->pipe));
823 sprctl = I915_READ(SPRCTL(intel_plane->pipe));
825 if (sprctl & SPRITE_DEST_KEY)
826 key->flags = I915_SET_COLORKEY_DESTINATION;
827 else if (sprctl & SPRITE_SOURCE_KEY)
828 key->flags = I915_SET_COLORKEY_SOURCE;
830 key->flags = I915_SET_COLORKEY_NONE;
834 ilk_update_plane(struct drm_plane *plane, struct drm_crtc *crtc,
835 struct drm_framebuffer *fb,
836 struct drm_i915_gem_object *obj, int crtc_x, int crtc_y,
837 unsigned int crtc_w, unsigned int crtc_h,
838 uint32_t x, uint32_t y,
839 uint32_t src_w, uint32_t src_h)
841 struct drm_device *dev = plane->dev;
842 struct drm_i915_private *dev_priv = dev->dev_private;
843 struct intel_plane *intel_plane = to_intel_plane(plane);
844 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
845 int pipe = intel_plane->pipe;
846 unsigned long dvssurf_offset, linear_offset;
847 u32 dvscntr, dvsscale;
848 int pixel_size = drm_format_plane_cpp(fb->pixel_format, 0);
852 dvscntr = I915_READ(DVSCNTR(pipe));
854 /* Mask out pixel format bits in case we change it */
855 dvscntr &= ~DVS_PIXFORMAT_MASK;
856 dvscntr &= ~DVS_RGB_ORDER_XBGR;
857 dvscntr &= ~DVS_YUV_BYTE_ORDER_MASK;
858 dvscntr &= ~DVS_TILED;
859 dvscntr &= ~DVS_ROTATE_180;
861 switch (fb->pixel_format) {
862 case DRM_FORMAT_XBGR8888:
863 dvscntr |= DVS_FORMAT_RGBX888 | DVS_RGB_ORDER_XBGR;
865 case DRM_FORMAT_XRGB8888:
866 dvscntr |= DVS_FORMAT_RGBX888;
868 case DRM_FORMAT_YUYV:
869 dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_YUYV;
871 case DRM_FORMAT_YVYU:
872 dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_YVYU;
874 case DRM_FORMAT_UYVY:
875 dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_UYVY;
877 case DRM_FORMAT_VYUY:
878 dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_VYUY;
885 * Enable gamma to match primary/cursor plane behaviour.
886 * FIXME should be user controllable via propertiesa.
888 dvscntr |= DVS_GAMMA_ENABLE;
890 if (obj->tiling_mode != I915_TILING_NONE)
891 dvscntr |= DVS_TILED;
894 dvscntr |= DVS_TRICKLE_FEED_DISABLE; /* must disable */
895 dvscntr |= DVS_ENABLE;
897 intel_update_sprite_watermarks(plane, crtc, src_w, src_h,
899 src_w != crtc_w || src_h != crtc_h);
901 /* Sizes are 0 based */
908 if (crtc_w != src_w || crtc_h != src_h)
909 dvsscale = DVS_SCALE_ENABLE | (src_w << 16) | src_h;
911 linear_offset = y * fb->pitches[0] + x * pixel_size;
913 intel_gen4_compute_page_offset(&x, &y, obj->tiling_mode,
914 pixel_size, fb->pitches[0]);
915 linear_offset -= dvssurf_offset;
917 if (intel_plane->rotation == BIT(DRM_ROTATE_180)) {
918 dvscntr |= DVS_ROTATE_180;
922 linear_offset += src_h * fb->pitches[0] + src_w * pixel_size;
925 atomic_update = intel_pipe_update_start(intel_crtc, &start_vbl_count);
927 intel_update_primary_plane(intel_crtc);
929 I915_WRITE(DVSSTRIDE(pipe), fb->pitches[0]);
930 I915_WRITE(DVSPOS(pipe), (crtc_y << 16) | crtc_x);
932 if (obj->tiling_mode != I915_TILING_NONE)
933 I915_WRITE(DVSTILEOFF(pipe), (y << 16) | x);
935 I915_WRITE(DVSLINOFF(pipe), linear_offset);
937 I915_WRITE(DVSSIZE(pipe), (crtc_h << 16) | crtc_w);
938 I915_WRITE(DVSSCALE(pipe), dvsscale);
939 I915_WRITE(DVSCNTR(pipe), dvscntr);
940 I915_WRITE(DVSSURF(pipe),
941 i915_gem_obj_ggtt_offset(obj) + dvssurf_offset);
943 intel_flush_primary_plane(dev_priv, intel_crtc->plane);
946 intel_pipe_update_end(intel_crtc, start_vbl_count);
950 ilk_disable_plane(struct drm_plane *plane, struct drm_crtc *crtc)
952 struct drm_device *dev = plane->dev;
953 struct drm_i915_private *dev_priv = dev->dev_private;
954 struct intel_plane *intel_plane = to_intel_plane(plane);
955 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
956 int pipe = intel_plane->pipe;
960 atomic_update = intel_pipe_update_start(intel_crtc, &start_vbl_count);
962 intel_update_primary_plane(intel_crtc);
964 I915_WRITE(DVSCNTR(pipe), I915_READ(DVSCNTR(pipe)) & ~DVS_ENABLE);
965 /* Disable the scaler */
966 I915_WRITE(DVSSCALE(pipe), 0);
967 /* Flush double buffered register updates */
968 I915_WRITE(DVSSURF(pipe), 0);
970 intel_flush_primary_plane(dev_priv, intel_crtc->plane);
973 intel_pipe_update_end(intel_crtc, start_vbl_count);
976 * Avoid underruns when disabling the sprite.
977 * FIXME remove once watermark updates are done properly.
979 intel_wait_for_vblank(dev, pipe);
981 intel_update_sprite_watermarks(plane, crtc, 0, 0, 0, false, false);
985 intel_post_enable_primary(struct drm_crtc *crtc)
987 struct drm_device *dev = crtc->dev;
988 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
991 * BDW signals flip done immediately if the plane
992 * is disabled, even if the plane enable is already
993 * armed to occur at the next vblank :(
995 if (IS_BROADWELL(dev))
996 intel_wait_for_vblank(dev, intel_crtc->pipe);
999 * FIXME IPS should be fine as long as one plane is
1000 * enabled, but in practice it seems to have problems
1001 * when going from primary only to sprite only and vice
1004 hsw_enable_ips(intel_crtc);
1006 mutex_lock(&dev->struct_mutex);
1007 intel_update_fbc(dev);
1008 mutex_unlock(&dev->struct_mutex);
1012 intel_pre_disable_primary(struct drm_crtc *crtc)
1014 struct drm_device *dev = crtc->dev;
1015 struct drm_i915_private *dev_priv = dev->dev_private;
1016 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
1018 mutex_lock(&dev->struct_mutex);
1019 if (dev_priv->fbc.plane == intel_crtc->plane)
1020 intel_disable_fbc(dev);
1021 mutex_unlock(&dev->struct_mutex);
1024 * FIXME IPS should be fine as long as one plane is
1025 * enabled, but in practice it seems to have problems
1026 * when going from primary only to sprite only and vice
1029 hsw_disable_ips(intel_crtc);
1033 ilk_update_colorkey(struct drm_plane *plane,
1034 struct drm_intel_sprite_colorkey *key)
1036 struct drm_device *dev = plane->dev;
1037 struct drm_i915_private *dev_priv = dev->dev_private;
1038 struct intel_plane *intel_plane;
1042 intel_plane = to_intel_plane(plane);
1044 I915_WRITE(DVSKEYVAL(intel_plane->pipe), key->min_value);
1045 I915_WRITE(DVSKEYMAX(intel_plane->pipe), key->max_value);
1046 I915_WRITE(DVSKEYMSK(intel_plane->pipe), key->channel_mask);
1048 dvscntr = I915_READ(DVSCNTR(intel_plane->pipe));
1049 dvscntr &= ~(DVS_SOURCE_KEY | DVS_DEST_KEY);
1050 if (key->flags & I915_SET_COLORKEY_DESTINATION)
1051 dvscntr |= DVS_DEST_KEY;
1052 else if (key->flags & I915_SET_COLORKEY_SOURCE)
1053 dvscntr |= DVS_SOURCE_KEY;
1054 I915_WRITE(DVSCNTR(intel_plane->pipe), dvscntr);
1056 POSTING_READ(DVSKEYMSK(intel_plane->pipe));
1062 ilk_get_colorkey(struct drm_plane *plane, struct drm_intel_sprite_colorkey *key)
1064 struct drm_device *dev = plane->dev;
1065 struct drm_i915_private *dev_priv = dev->dev_private;
1066 struct intel_plane *intel_plane;
1069 intel_plane = to_intel_plane(plane);
1071 key->min_value = I915_READ(DVSKEYVAL(intel_plane->pipe));
1072 key->max_value = I915_READ(DVSKEYMAX(intel_plane->pipe));
1073 key->channel_mask = I915_READ(DVSKEYMSK(intel_plane->pipe));
1076 dvscntr = I915_READ(DVSCNTR(intel_plane->pipe));
1078 if (dvscntr & DVS_DEST_KEY)
1079 key->flags = I915_SET_COLORKEY_DESTINATION;
1080 else if (dvscntr & DVS_SOURCE_KEY)
1081 key->flags = I915_SET_COLORKEY_SOURCE;
1083 key->flags = I915_SET_COLORKEY_NONE;
1086 static bool colorkey_enabled(struct intel_plane *intel_plane)
1088 struct drm_intel_sprite_colorkey key;
1090 intel_plane->get_colorkey(&intel_plane->base, &key);
1092 return key.flags != I915_SET_COLORKEY_NONE;
1096 intel_check_sprite_plane(struct drm_plane *plane,
1097 struct intel_plane_state *state)
1099 struct intel_crtc *intel_crtc = to_intel_crtc(state->base.crtc);
1100 struct intel_plane *intel_plane = to_intel_plane(plane);
1101 struct drm_framebuffer *fb = state->base.fb;
1102 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
1104 unsigned int crtc_w, crtc_h;
1105 uint32_t src_x, src_y, src_w, src_h;
1106 struct drm_rect *src = &state->src;
1107 struct drm_rect *dst = &state->dst;
1108 struct drm_rect *orig_src = &state->orig_src;
1109 const struct drm_rect *clip = &state->clip;
1111 int max_scale, min_scale;
1112 int pixel_size = drm_format_plane_cpp(fb->pixel_format, 0);
1114 /* Don't modify another pipe's plane */
1115 if (intel_plane->pipe != intel_crtc->pipe) {
1116 DRM_DEBUG_KMS("Wrong plane <-> crtc mapping\n");
1120 /* FIXME check all gen limits */
1121 if (fb->width < 3 || fb->height < 3 || fb->pitches[0] > 16384) {
1122 DRM_DEBUG_KMS("Unsuitable framebuffer for plane\n");
1126 /* Sprite planes can be linear or x-tiled surfaces */
1127 switch (obj->tiling_mode) {
1128 case I915_TILING_NONE:
1132 DRM_DEBUG_KMS("Unsupported tiling mode\n");
1137 * FIXME the following code does a bunch of fuzzy adjustments to the
1138 * coordinates and sizes. We probably need some way to decide whether
1139 * more strict checking should be done instead.
1141 max_scale = intel_plane->max_downscale << 16;
1142 min_scale = intel_plane->can_scale ? 1 : (1 << 16);
1144 drm_rect_rotate(src, fb->width << 16, fb->height << 16,
1145 intel_plane->rotation);
1147 hscale = drm_rect_calc_hscale_relaxed(src, dst, min_scale, max_scale);
1150 vscale = drm_rect_calc_vscale_relaxed(src, dst, min_scale, max_scale);
1153 state->visible = drm_rect_clip_scaled(src, dst, clip, hscale, vscale);
1157 crtc_w = drm_rect_width(dst);
1158 crtc_h = drm_rect_height(dst);
1160 if (state->visible) {
1161 /* check again in case clipping clamped the results */
1162 hscale = drm_rect_calc_hscale(src, dst, min_scale, max_scale);
1164 DRM_DEBUG_KMS("Horizontal scaling factor out of limits\n");
1165 drm_rect_debug_print(src, true);
1166 drm_rect_debug_print(dst, false);
1171 vscale = drm_rect_calc_vscale(src, dst, min_scale, max_scale);
1173 DRM_DEBUG_KMS("Vertical scaling factor out of limits\n");
1174 drm_rect_debug_print(src, true);
1175 drm_rect_debug_print(dst, false);
1180 /* Make the source viewport size an exact multiple of the scaling factors. */
1181 drm_rect_adjust_size(src,
1182 drm_rect_width(dst) * hscale - drm_rect_width(src),
1183 drm_rect_height(dst) * vscale - drm_rect_height(src));
1185 drm_rect_rotate_inv(src, fb->width << 16, fb->height << 16,
1186 intel_plane->rotation);
1188 /* sanity check to make sure the src viewport wasn't enlarged */
1189 WARN_ON(src->x1 < (int) orig_src->x1 ||
1190 src->y1 < (int) orig_src->y1 ||
1191 src->x2 > (int) orig_src->x2 ||
1192 src->y2 > (int) orig_src->y2);
1195 * Hardware doesn't handle subpixel coordinates.
1196 * Adjust to (macro)pixel boundary, but be careful not to
1197 * increase the source viewport size, because that could
1198 * push the downscaling factor out of bounds.
1200 src_x = src->x1 >> 16;
1201 src_w = drm_rect_width(src) >> 16;
1202 src_y = src->y1 >> 16;
1203 src_h = drm_rect_height(src) >> 16;
1205 if (format_is_yuv(fb->pixel_format)) {
1210 * Must keep src and dst the
1211 * same if we can't scale.
1213 if (!intel_plane->can_scale)
1217 state->visible = false;
1221 /* Check size restrictions when scaling */
1222 if (state->visible && (src_w != crtc_w || src_h != crtc_h)) {
1223 unsigned int width_bytes;
1225 WARN_ON(!intel_plane->can_scale);
1227 /* FIXME interlacing min height is 6 */
1229 if (crtc_w < 3 || crtc_h < 3)
1230 state->visible = false;
1232 if (src_w < 3 || src_h < 3)
1233 state->visible = false;
1235 width_bytes = ((src_x * pixel_size) & 63) +
1238 if (src_w > 2048 || src_h > 2048 ||
1239 width_bytes > 4096 || fb->pitches[0] > 4096) {
1240 DRM_DEBUG_KMS("Source dimensions exceed hardware limits\n");
1245 if (state->visible) {
1247 src->x2 = src_x + src_w;
1249 src->y2 = src_y + src_h;
1253 dst->x2 = crtc_x + crtc_w;
1255 dst->y2 = crtc_y + crtc_h;
1261 intel_commit_sprite_plane(struct drm_plane *plane,
1262 struct intel_plane_state *state)
1264 struct drm_device *dev = plane->dev;
1265 struct drm_crtc *crtc = state->base.crtc;
1266 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
1267 struct intel_plane *intel_plane = to_intel_plane(plane);
1268 enum pipe pipe = intel_crtc->pipe;
1269 struct drm_framebuffer *fb = state->base.fb;
1270 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
1271 struct drm_i915_gem_object *old_obj = intel_plane->obj;
1273 unsigned int crtc_w, crtc_h;
1274 uint32_t src_x, src_y, src_w, src_h;
1275 struct drm_rect *dst = &state->dst;
1276 const struct drm_rect *clip = &state->clip;
1277 bool primary_enabled;
1280 * If the sprite is completely covering the primary plane,
1281 * we can disable the primary and save power.
1283 primary_enabled = !drm_rect_equals(dst, clip) || colorkey_enabled(intel_plane);
1284 WARN_ON(!primary_enabled && !state->visible && intel_crtc->active);
1286 intel_plane->crtc_x = state->orig_dst.x1;
1287 intel_plane->crtc_y = state->orig_dst.y1;
1288 intel_plane->crtc_w = drm_rect_width(&state->orig_dst);
1289 intel_plane->crtc_h = drm_rect_height(&state->orig_dst);
1290 intel_plane->src_x = state->orig_src.x1;
1291 intel_plane->src_y = state->orig_src.y1;
1292 intel_plane->src_w = drm_rect_width(&state->orig_src);
1293 intel_plane->src_h = drm_rect_height(&state->orig_src);
1294 intel_plane->obj = obj;
1296 if (intel_crtc->active) {
1297 bool primary_was_enabled = intel_crtc->primary_enabled;
1299 intel_crtc->primary_enabled = primary_enabled;
1301 if (primary_was_enabled != primary_enabled)
1302 intel_crtc_wait_for_pending_flips(crtc);
1304 if (primary_was_enabled && !primary_enabled)
1305 intel_pre_disable_primary(crtc);
1307 if (state->visible) {
1308 crtc_x = state->dst.x1;
1309 crtc_y = state->dst.y1;
1310 crtc_w = drm_rect_width(&state->dst);
1311 crtc_h = drm_rect_height(&state->dst);
1312 src_x = state->src.x1;
1313 src_y = state->src.y1;
1314 src_w = drm_rect_width(&state->src);
1315 src_h = drm_rect_height(&state->src);
1316 intel_plane->update_plane(plane, crtc, fb, obj,
1317 crtc_x, crtc_y, crtc_w, crtc_h,
1318 src_x, src_y, src_w, src_h);
1320 intel_plane->disable_plane(plane, crtc);
1324 intel_frontbuffer_flip(dev, INTEL_FRONTBUFFER_SPRITE(pipe));
1326 if (!primary_was_enabled && primary_enabled)
1327 intel_post_enable_primary(crtc);
1330 /* Unpin old obj after new one is active to avoid ugliness */
1331 if (old_obj && old_obj != obj) {
1334 * It's fairly common to simply update the position of
1335 * an existing object. In that case, we don't need to
1336 * wait for vblank to avoid ugliness, we only need to
1337 * do the pin & ref bookkeeping.
1339 if (intel_crtc->active)
1340 intel_wait_for_vblank(dev, intel_crtc->pipe);
1342 mutex_lock(&dev->struct_mutex);
1343 intel_unpin_fb_obj(old_obj);
1344 mutex_unlock(&dev->struct_mutex);
1349 intel_update_plane(struct drm_plane *plane, struct drm_crtc *crtc,
1350 struct drm_framebuffer *fb, int crtc_x, int crtc_y,
1351 unsigned int crtc_w, unsigned int crtc_h,
1352 uint32_t src_x, uint32_t src_y,
1353 uint32_t src_w, uint32_t src_h)
1355 struct drm_framebuffer *old_fb = plane->fb;
1356 struct intel_plane_state state;
1357 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
1360 state.base.crtc = crtc;
1363 /* sample coordinates in 16.16 fixed point */
1364 state.src.x1 = src_x;
1365 state.src.x2 = src_x + src_w;
1366 state.src.y1 = src_y;
1367 state.src.y2 = src_y + src_h;
1369 /* integer pixels */
1370 state.dst.x1 = crtc_x;
1371 state.dst.x2 = crtc_x + crtc_w;
1372 state.dst.y1 = crtc_y;
1373 state.dst.y2 = crtc_y + crtc_h;
1377 state.clip.x2 = intel_crtc->active ? intel_crtc->config.pipe_src_w : 0;
1378 state.clip.y2 = intel_crtc->active ? intel_crtc->config.pipe_src_h : 0;
1379 state.orig_src = state.src;
1380 state.orig_dst = state.dst;
1382 ret = intel_check_sprite_plane(plane, &state);
1386 if (fb != old_fb && fb) {
1387 ret = intel_prepare_plane_fb(plane, fb);
1392 intel_commit_sprite_plane(plane, &state);
1397 intel_disable_plane(struct drm_plane *plane)
1399 struct drm_device *dev = plane->dev;
1400 struct intel_plane *intel_plane = to_intel_plane(plane);
1401 struct intel_crtc *intel_crtc;
1407 if (WARN_ON(!plane->crtc))
1410 intel_crtc = to_intel_crtc(plane->crtc);
1411 pipe = intel_crtc->pipe;
1413 if (intel_crtc->active) {
1414 bool primary_was_enabled = intel_crtc->primary_enabled;
1416 intel_crtc->primary_enabled = true;
1418 intel_plane->disable_plane(plane, plane->crtc);
1420 if (!primary_was_enabled && intel_crtc->primary_enabled)
1421 intel_post_enable_primary(plane->crtc);
1424 if (intel_plane->obj) {
1425 if (intel_crtc->active)
1426 intel_wait_for_vblank(dev, intel_plane->pipe);
1428 mutex_lock(&dev->struct_mutex);
1429 intel_unpin_fb_obj(intel_plane->obj);
1430 i915_gem_track_fb(intel_plane->obj, NULL,
1431 INTEL_FRONTBUFFER_SPRITE(pipe));
1432 mutex_unlock(&dev->struct_mutex);
1434 intel_plane->obj = NULL;
1440 static void intel_destroy_plane(struct drm_plane *plane)
1442 struct intel_plane *intel_plane = to_intel_plane(plane);
1443 intel_disable_plane(plane);
1444 drm_plane_cleanup(plane);
1448 int intel_sprite_set_colorkey(struct drm_device *dev, void *data,
1449 struct drm_file *file_priv)
1451 struct drm_intel_sprite_colorkey *set = data;
1452 struct drm_plane *plane;
1453 struct intel_plane *intel_plane;
1456 if (!drm_core_check_feature(dev, DRIVER_MODESET))
1459 /* Make sure we don't try to enable both src & dest simultaneously */
1460 if ((set->flags & (I915_SET_COLORKEY_DESTINATION | I915_SET_COLORKEY_SOURCE)) == (I915_SET_COLORKEY_DESTINATION | I915_SET_COLORKEY_SOURCE))
1463 drm_modeset_lock_all(dev);
1465 plane = drm_plane_find(dev, set->plane_id);
1471 intel_plane = to_intel_plane(plane);
1472 ret = intel_plane->update_colorkey(plane, set);
1475 drm_modeset_unlock_all(dev);
1479 int intel_sprite_get_colorkey(struct drm_device *dev, void *data,
1480 struct drm_file *file_priv)
1482 struct drm_intel_sprite_colorkey *get = data;
1483 struct drm_plane *plane;
1484 struct intel_plane *intel_plane;
1487 if (!drm_core_check_feature(dev, DRIVER_MODESET))
1490 drm_modeset_lock_all(dev);
1492 plane = drm_plane_find(dev, get->plane_id);
1498 intel_plane = to_intel_plane(plane);
1499 intel_plane->get_colorkey(plane, get);
1502 drm_modeset_unlock_all(dev);
1506 int intel_plane_set_property(struct drm_plane *plane,
1507 struct drm_property *prop,
1510 struct drm_device *dev = plane->dev;
1511 struct intel_plane *intel_plane = to_intel_plane(plane);
1515 if (prop == dev->mode_config.rotation_property) {
1516 /* exactly one rotation angle please */
1517 if (hweight32(val & 0xf) != 1)
1520 if (intel_plane->rotation == val)
1523 old_val = intel_plane->rotation;
1524 intel_plane->rotation = val;
1525 ret = intel_plane_restore(plane);
1527 intel_plane->rotation = old_val;
1533 int intel_plane_restore(struct drm_plane *plane)
1535 struct intel_plane *intel_plane = to_intel_plane(plane);
1537 if (!plane->crtc || !plane->fb)
1540 return plane->funcs->update_plane(plane, plane->crtc, plane->fb,
1541 intel_plane->crtc_x, intel_plane->crtc_y,
1542 intel_plane->crtc_w, intel_plane->crtc_h,
1543 intel_plane->src_x, intel_plane->src_y,
1544 intel_plane->src_w, intel_plane->src_h);
1547 void intel_plane_disable(struct drm_plane *plane)
1549 if (!plane->crtc || !plane->fb)
1552 intel_disable_plane(plane);
1555 static const struct drm_plane_funcs intel_plane_funcs = {
1556 .update_plane = intel_update_plane,
1557 .disable_plane = intel_disable_plane,
1558 .destroy = intel_destroy_plane,
1559 .set_property = intel_plane_set_property,
1562 static uint32_t ilk_plane_formats[] = {
1563 DRM_FORMAT_XRGB8888,
1570 static uint32_t snb_plane_formats[] = {
1571 DRM_FORMAT_XBGR8888,
1572 DRM_FORMAT_XRGB8888,
1579 static uint32_t vlv_plane_formats[] = {
1581 DRM_FORMAT_ABGR8888,
1582 DRM_FORMAT_ARGB8888,
1583 DRM_FORMAT_XBGR8888,
1584 DRM_FORMAT_XRGB8888,
1585 DRM_FORMAT_XBGR2101010,
1586 DRM_FORMAT_ABGR2101010,
1593 static uint32_t skl_plane_formats[] = {
1595 DRM_FORMAT_ABGR8888,
1596 DRM_FORMAT_ARGB8888,
1597 DRM_FORMAT_XBGR8888,
1598 DRM_FORMAT_XRGB8888,
1606 intel_plane_init(struct drm_device *dev, enum pipe pipe, int plane)
1608 struct intel_plane *intel_plane;
1609 unsigned long possible_crtcs;
1610 const uint32_t *plane_formats;
1611 int num_plane_formats;
1614 if (INTEL_INFO(dev)->gen < 5)
1617 intel_plane = kzalloc(sizeof(*intel_plane), GFP_KERNEL);
1621 switch (INTEL_INFO(dev)->gen) {
1624 intel_plane->can_scale = true;
1625 intel_plane->max_downscale = 16;
1626 intel_plane->update_plane = ilk_update_plane;
1627 intel_plane->disable_plane = ilk_disable_plane;
1628 intel_plane->update_colorkey = ilk_update_colorkey;
1629 intel_plane->get_colorkey = ilk_get_colorkey;
1632 plane_formats = snb_plane_formats;
1633 num_plane_formats = ARRAY_SIZE(snb_plane_formats);
1635 plane_formats = ilk_plane_formats;
1636 num_plane_formats = ARRAY_SIZE(ilk_plane_formats);
1642 if (IS_IVYBRIDGE(dev)) {
1643 intel_plane->can_scale = true;
1644 intel_plane->max_downscale = 2;
1646 intel_plane->can_scale = false;
1647 intel_plane->max_downscale = 1;
1650 if (IS_VALLEYVIEW(dev)) {
1651 intel_plane->update_plane = vlv_update_plane;
1652 intel_plane->disable_plane = vlv_disable_plane;
1653 intel_plane->update_colorkey = vlv_update_colorkey;
1654 intel_plane->get_colorkey = vlv_get_colorkey;
1656 plane_formats = vlv_plane_formats;
1657 num_plane_formats = ARRAY_SIZE(vlv_plane_formats);
1659 intel_plane->update_plane = ivb_update_plane;
1660 intel_plane->disable_plane = ivb_disable_plane;
1661 intel_plane->update_colorkey = ivb_update_colorkey;
1662 intel_plane->get_colorkey = ivb_get_colorkey;
1664 plane_formats = snb_plane_formats;
1665 num_plane_formats = ARRAY_SIZE(snb_plane_formats);
1670 * FIXME: Skylake planes can be scaled (with some restrictions),
1671 * but this is for another time.
1673 intel_plane->can_scale = false;
1674 intel_plane->max_downscale = 1;
1675 intel_plane->update_plane = skl_update_plane;
1676 intel_plane->disable_plane = skl_disable_plane;
1677 intel_plane->update_colorkey = skl_update_colorkey;
1678 intel_plane->get_colorkey = skl_get_colorkey;
1680 plane_formats = skl_plane_formats;
1681 num_plane_formats = ARRAY_SIZE(skl_plane_formats);
1688 intel_plane->pipe = pipe;
1689 intel_plane->plane = plane;
1690 intel_plane->rotation = BIT(DRM_ROTATE_0);
1691 possible_crtcs = (1 << pipe);
1692 ret = drm_universal_plane_init(dev, &intel_plane->base, possible_crtcs,
1694 plane_formats, num_plane_formats,
1695 DRM_PLANE_TYPE_OVERLAY);
1701 if (!dev->mode_config.rotation_property)
1702 dev->mode_config.rotation_property =
1703 drm_mode_create_rotation_property(dev,
1705 BIT(DRM_ROTATE_180));
1707 if (dev->mode_config.rotation_property)
1708 drm_object_attach_property(&intel_plane->base.base,
1709 dev->mode_config.rotation_property,
1710 intel_plane->rotation);