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
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_atomic_helper.h>
34 #include <drm/drm_crtc.h>
35 #include <drm/drm_fourcc.h>
36 #include <drm/drm_rect.h>
37 #include <drm/drm_atomic.h>
38 #include <drm/drm_plane_helper.h>
39 #include "intel_drv.h"
40 #include "intel_frontbuffer.h"
41 #include <drm/i915_drm.h>
44 int intel_usecs_to_scanlines(const struct drm_display_mode *adjusted_mode,
48 if (!adjusted_mode->crtc_htotal)
51 return DIV_ROUND_UP(usecs * adjusted_mode->crtc_clock,
52 1000 * adjusted_mode->crtc_htotal);
55 /* FIXME: We should instead only take spinlocks once for the entire update
56 * instead of once per mmio. */
57 #if IS_ENABLED(CONFIG_PROVE_LOCKING)
58 #define VBLANK_EVASION_TIME_US 250
60 #define VBLANK_EVASION_TIME_US 100
64 * intel_pipe_update_start() - start update of a set of display registers
65 * @new_crtc_state: the new crtc state
67 * Mark the start of an update to pipe registers that should be updated
68 * atomically regarding vblank. If the next vblank will happens within
69 * the next 100 us, this function waits until the vblank passes.
71 * After a successful call to this function, interrupts will be disabled
72 * until a subsequent call to intel_pipe_update_end(). That is done to
73 * avoid random delays.
75 void intel_pipe_update_start(const struct intel_crtc_state *new_crtc_state)
77 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc);
78 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
79 const struct drm_display_mode *adjusted_mode = &new_crtc_state->base.adjusted_mode;
80 long timeout = msecs_to_jiffies_timeout(1);
81 int scanline, min, max, vblank_start;
82 wait_queue_head_t *wq = drm_crtc_vblank_waitqueue(&crtc->base);
83 bool need_vlv_dsi_wa = (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
84 intel_crtc_has_type(new_crtc_state, INTEL_OUTPUT_DSI);
88 vblank_start = adjusted_mode->crtc_vblank_start;
89 if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE)
90 vblank_start = DIV_ROUND_UP(vblank_start, 2);
92 /* FIXME needs to be calibrated sensibly */
93 min = vblank_start - intel_usecs_to_scanlines(adjusted_mode,
94 VBLANK_EVASION_TIME_US);
95 max = vblank_start - 1;
97 if (min <= 0 || max <= 0)
100 if (WARN_ON(drm_crtc_vblank_get(&crtc->base)))
104 * Wait for psr to idle out after enabling the VBL interrupts
105 * VBL interrupts will start the PSR exit and prevent a PSR
108 if (intel_psr_wait_for_idle(new_crtc_state, &psr_status))
109 DRM_ERROR("PSR idle timed out 0x%x, atomic update may fail\n",
114 crtc->debug.min_vbl = min;
115 crtc->debug.max_vbl = max;
116 trace_i915_pipe_update_start(crtc);
120 * prepare_to_wait() has a memory barrier, which guarantees
121 * other CPUs can see the task state update by the time we
124 prepare_to_wait(wq, &wait, TASK_UNINTERRUPTIBLE);
126 scanline = intel_get_crtc_scanline(crtc);
127 if (scanline < min || scanline > max)
131 DRM_ERROR("Potential atomic update failure on pipe %c\n",
132 pipe_name(crtc->pipe));
138 timeout = schedule_timeout(timeout);
143 finish_wait(wq, &wait);
145 drm_crtc_vblank_put(&crtc->base);
148 * On VLV/CHV DSI the scanline counter would appear to
149 * increment approx. 1/3 of a scanline before start of vblank.
150 * The registers still get latched at start of vblank however.
151 * This means we must not write any registers on the first
152 * line of vblank (since not the whole line is actually in
153 * vblank). And unfortunately we can't use the interrupt to
154 * wait here since it will fire too soon. We could use the
155 * frame start interrupt instead since it will fire after the
156 * critical scanline, but that would require more changes
157 * in the interrupt code. So for now we'll just do the nasty
158 * thing and poll for the bad scanline to pass us by.
160 * FIXME figure out if BXT+ DSI suffers from this as well
162 while (need_vlv_dsi_wa && scanline == vblank_start)
163 scanline = intel_get_crtc_scanline(crtc);
165 crtc->debug.scanline_start = scanline;
166 crtc->debug.start_vbl_time = ktime_get();
167 crtc->debug.start_vbl_count = intel_crtc_get_vblank_counter(crtc);
169 trace_i915_pipe_update_vblank_evaded(crtc);
177 * intel_pipe_update_end() - end update of a set of display registers
178 * @new_crtc_state: the new crtc state
180 * Mark the end of an update started with intel_pipe_update_start(). This
181 * re-enables interrupts and verifies the update was actually completed
184 void intel_pipe_update_end(struct intel_crtc_state *new_crtc_state)
186 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc);
187 enum pipe pipe = crtc->pipe;
188 int scanline_end = intel_get_crtc_scanline(crtc);
189 u32 end_vbl_count = intel_crtc_get_vblank_counter(crtc);
190 ktime_t end_vbl_time = ktime_get();
191 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
193 trace_i915_pipe_update_end(crtc, end_vbl_count, scanline_end);
195 /* We're still in the vblank-evade critical section, this can't race.
196 * Would be slightly nice to just grab the vblank count and arm the
197 * event outside of the critical section - the spinlock might spin for a
199 if (new_crtc_state->base.event) {
200 WARN_ON(drm_crtc_vblank_get(&crtc->base) != 0);
202 spin_lock(&crtc->base.dev->event_lock);
203 drm_crtc_arm_vblank_event(&crtc->base, new_crtc_state->base.event);
204 spin_unlock(&crtc->base.dev->event_lock);
206 new_crtc_state->base.event = NULL;
211 if (intel_vgpu_active(dev_priv))
214 if (crtc->debug.start_vbl_count &&
215 crtc->debug.start_vbl_count != end_vbl_count) {
216 DRM_ERROR("Atomic update failure on pipe %c (start=%u end=%u) time %lld us, min %d, max %d, scanline start %d, end %d\n",
217 pipe_name(pipe), crtc->debug.start_vbl_count,
219 ktime_us_delta(end_vbl_time, crtc->debug.start_vbl_time),
220 crtc->debug.min_vbl, crtc->debug.max_vbl,
221 crtc->debug.scanline_start, scanline_end);
223 #ifdef CONFIG_DRM_I915_DEBUG_VBLANK_EVADE
224 else if (ktime_us_delta(end_vbl_time, crtc->debug.start_vbl_time) >
225 VBLANK_EVASION_TIME_US)
226 DRM_WARN("Atomic update on pipe (%c) took %lld us, max time under evasion is %u us\n",
228 ktime_us_delta(end_vbl_time, crtc->debug.start_vbl_time),
229 VBLANK_EVASION_TIME_US);
233 int intel_plane_check_stride(const struct intel_plane_state *plane_state)
235 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
236 const struct drm_framebuffer *fb = plane_state->base.fb;
237 unsigned int rotation = plane_state->base.rotation;
238 u32 stride, max_stride;
240 /* FIXME other color planes? */
241 stride = plane_state->color_plane[0].stride;
242 max_stride = plane->max_stride(plane, fb->format->format,
243 fb->modifier, rotation);
245 if (stride > max_stride) {
246 DRM_DEBUG_KMS("[FB:%d] stride (%d) exceeds [PLANE:%d:%s] max stride (%d)\n",
248 plane->base.base.id, plane->base.name, max_stride);
255 int intel_plane_check_src_coordinates(struct intel_plane_state *plane_state)
257 const struct drm_framebuffer *fb = plane_state->base.fb;
258 struct drm_rect *src = &plane_state->base.src;
259 u32 src_x, src_y, src_w, src_h;
262 * Hardware doesn't handle subpixel coordinates.
263 * Adjust to (macro)pixel boundary, but be careful not to
264 * increase the source viewport size, because that could
265 * push the downscaling factor out of bounds.
267 src_x = src->x1 >> 16;
268 src_w = drm_rect_width(src) >> 16;
269 src_y = src->y1 >> 16;
270 src_h = drm_rect_height(src) >> 16;
272 src->x1 = src_x << 16;
273 src->x2 = (src_x + src_w) << 16;
274 src->y1 = src_y << 16;
275 src->y2 = (src_y + src_h) << 16;
277 if (fb->format->is_yuv &&
278 fb->format->format != DRM_FORMAT_NV12 &&
279 (src_x & 1 || src_w & 1)) {
280 DRM_DEBUG_KMS("src x/w (%u, %u) must be a multiple of 2 for YUV planes\n",
289 skl_plane_max_stride(struct intel_plane *plane,
290 u32 pixel_format, u64 modifier,
291 unsigned int rotation)
293 int cpp = drm_format_plane_cpp(pixel_format, 0);
296 * "The stride in bytes must not exceed the
297 * of the size of 8K pixels and 32K bytes."
299 if (drm_rotation_90_or_270(rotation))
300 return min(8192, 32768 / cpp);
302 return min(8192 * cpp, 32768);
306 skl_program_scaler(struct intel_plane *plane,
307 const struct intel_crtc_state *crtc_state,
308 const struct intel_plane_state *plane_state)
310 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
311 enum pipe pipe = plane->pipe;
312 int scaler_id = plane_state->scaler_id;
313 const struct intel_scaler *scaler =
314 &crtc_state->scaler_state.scalers[scaler_id];
315 int crtc_x = plane_state->base.dst.x1;
316 int crtc_y = plane_state->base.dst.y1;
317 uint32_t crtc_w = drm_rect_width(&plane_state->base.dst);
318 uint32_t crtc_h = drm_rect_height(&plane_state->base.dst);
319 u16 y_hphase, uv_rgb_hphase;
320 u16 y_vphase, uv_rgb_vphase;
323 hscale = drm_rect_calc_hscale(&plane_state->base.src,
324 &plane_state->base.dst,
326 vscale = drm_rect_calc_vscale(&plane_state->base.src,
327 &plane_state->base.dst,
330 /* TODO: handle sub-pixel coordinates */
331 if (plane_state->base.fb->format->format == DRM_FORMAT_NV12) {
332 y_hphase = skl_scaler_calc_phase(1, hscale, false);
333 y_vphase = skl_scaler_calc_phase(1, vscale, false);
335 /* MPEG2 chroma siting convention */
336 uv_rgb_hphase = skl_scaler_calc_phase(2, hscale, true);
337 uv_rgb_vphase = skl_scaler_calc_phase(2, vscale, false);
343 uv_rgb_hphase = skl_scaler_calc_phase(1, hscale, false);
344 uv_rgb_vphase = skl_scaler_calc_phase(1, vscale, false);
347 I915_WRITE_FW(SKL_PS_CTRL(pipe, scaler_id),
348 PS_SCALER_EN | PS_PLANE_SEL(plane->id) | scaler->mode);
349 I915_WRITE_FW(SKL_PS_PWR_GATE(pipe, scaler_id), 0);
350 I915_WRITE_FW(SKL_PS_VPHASE(pipe, scaler_id),
351 PS_Y_PHASE(y_vphase) | PS_UV_RGB_PHASE(uv_rgb_vphase));
352 I915_WRITE_FW(SKL_PS_HPHASE(pipe, scaler_id),
353 PS_Y_PHASE(y_hphase) | PS_UV_RGB_PHASE(uv_rgb_hphase));
354 I915_WRITE_FW(SKL_PS_WIN_POS(pipe, scaler_id), (crtc_x << 16) | crtc_y);
355 I915_WRITE_FW(SKL_PS_WIN_SZ(pipe, scaler_id), (crtc_w << 16) | crtc_h);
359 skl_update_plane(struct intel_plane *plane,
360 const struct intel_crtc_state *crtc_state,
361 const struct intel_plane_state *plane_state)
363 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
364 enum plane_id plane_id = plane->id;
365 enum pipe pipe = plane->pipe;
366 u32 plane_ctl = plane_state->ctl;
367 const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
368 u32 surf_addr = plane_state->color_plane[0].offset;
369 u32 stride = skl_plane_stride(plane_state, 0);
370 u32 aux_stride = skl_plane_stride(plane_state, 1);
371 int crtc_x = plane_state->base.dst.x1;
372 int crtc_y = plane_state->base.dst.y1;
373 uint32_t x = plane_state->color_plane[0].x;
374 uint32_t y = plane_state->color_plane[0].y;
375 uint32_t src_w = drm_rect_width(&plane_state->base.src) >> 16;
376 uint32_t src_h = drm_rect_height(&plane_state->base.src) >> 16;
377 unsigned long irqflags;
379 /* Sizes are 0 based */
383 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
385 if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv))
386 I915_WRITE_FW(PLANE_COLOR_CTL(pipe, plane_id),
387 plane_state->color_ctl);
390 I915_WRITE_FW(PLANE_KEYVAL(pipe, plane_id), key->min_value);
391 I915_WRITE_FW(PLANE_KEYMAX(pipe, plane_id), key->max_value);
392 I915_WRITE_FW(PLANE_KEYMSK(pipe, plane_id), key->channel_mask);
395 I915_WRITE_FW(PLANE_OFFSET(pipe, plane_id), (y << 16) | x);
396 I915_WRITE_FW(PLANE_STRIDE(pipe, plane_id), stride);
397 I915_WRITE_FW(PLANE_SIZE(pipe, plane_id), (src_h << 16) | src_w);
398 I915_WRITE_FW(PLANE_AUX_DIST(pipe, plane_id),
399 (plane_state->color_plane[1].offset - surf_addr) | aux_stride);
400 I915_WRITE_FW(PLANE_AUX_OFFSET(pipe, plane_id),
401 (plane_state->color_plane[1].y << 16) |
402 plane_state->color_plane[1].x);
404 if (plane_state->scaler_id >= 0) {
405 skl_program_scaler(plane, crtc_state, plane_state);
407 I915_WRITE_FW(PLANE_POS(pipe, plane_id), 0);
409 I915_WRITE_FW(PLANE_POS(pipe, plane_id), (crtc_y << 16) | crtc_x);
412 I915_WRITE_FW(PLANE_CTL(pipe, plane_id), plane_ctl);
413 I915_WRITE_FW(PLANE_SURF(pipe, plane_id),
414 intel_plane_ggtt_offset(plane_state) + surf_addr);
415 POSTING_READ_FW(PLANE_SURF(pipe, plane_id));
417 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
421 skl_disable_plane(struct intel_plane *plane, struct intel_crtc *crtc)
423 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
424 enum plane_id plane_id = plane->id;
425 enum pipe pipe = plane->pipe;
426 unsigned long irqflags;
428 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
430 I915_WRITE_FW(PLANE_CTL(pipe, plane_id), 0);
432 I915_WRITE_FW(PLANE_SURF(pipe, plane_id), 0);
433 POSTING_READ_FW(PLANE_SURF(pipe, plane_id));
435 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
439 skl_plane_get_hw_state(struct intel_plane *plane,
442 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
443 enum intel_display_power_domain power_domain;
444 enum plane_id plane_id = plane->id;
447 power_domain = POWER_DOMAIN_PIPE(plane->pipe);
448 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
451 ret = I915_READ(PLANE_CTL(plane->pipe, plane_id)) & PLANE_CTL_ENABLE;
455 intel_display_power_put(dev_priv, power_domain);
461 chv_update_csc(const struct intel_plane_state *plane_state)
463 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
464 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
465 const struct drm_framebuffer *fb = plane_state->base.fb;
466 enum plane_id plane_id = plane->id;
468 * |r| | c0 c1 c2 | |cr|
469 * |g| = | c3 c4 c5 | x |y |
470 * |b| | c6 c7 c8 | |cb|
472 * Coefficients are s3.12.
474 * Cb and Cr apparently come in as signed already, and
475 * we always get full range data in on account of CLRC0/1.
477 static const s16 csc_matrix[][9] = {
478 /* BT.601 full range YCbCr -> full range RGB */
479 [DRM_COLOR_YCBCR_BT601] = {
484 /* BT.709 full range YCbCr -> full range RGB */
485 [DRM_COLOR_YCBCR_BT709] = {
491 const s16 *csc = csc_matrix[plane_state->base.color_encoding];
493 /* Seems RGB data bypasses the CSC always */
494 if (!fb->format->is_yuv)
497 I915_WRITE_FW(SPCSCYGOFF(plane_id), SPCSC_OOFF(0) | SPCSC_IOFF(0));
498 I915_WRITE_FW(SPCSCCBOFF(plane_id), SPCSC_OOFF(0) | SPCSC_IOFF(0));
499 I915_WRITE_FW(SPCSCCROFF(plane_id), SPCSC_OOFF(0) | SPCSC_IOFF(0));
501 I915_WRITE_FW(SPCSCC01(plane_id), SPCSC_C1(csc[1]) | SPCSC_C0(csc[0]));
502 I915_WRITE_FW(SPCSCC23(plane_id), SPCSC_C1(csc[3]) | SPCSC_C0(csc[2]));
503 I915_WRITE_FW(SPCSCC45(plane_id), SPCSC_C1(csc[5]) | SPCSC_C0(csc[4]));
504 I915_WRITE_FW(SPCSCC67(plane_id), SPCSC_C1(csc[7]) | SPCSC_C0(csc[6]));
505 I915_WRITE_FW(SPCSCC8(plane_id), SPCSC_C0(csc[8]));
507 I915_WRITE_FW(SPCSCYGICLAMP(plane_id), SPCSC_IMAX(1023) | SPCSC_IMIN(0));
508 I915_WRITE_FW(SPCSCCBICLAMP(plane_id), SPCSC_IMAX(512) | SPCSC_IMIN(-512));
509 I915_WRITE_FW(SPCSCCRICLAMP(plane_id), SPCSC_IMAX(512) | SPCSC_IMIN(-512));
511 I915_WRITE_FW(SPCSCYGOCLAMP(plane_id), SPCSC_OMAX(1023) | SPCSC_OMIN(0));
512 I915_WRITE_FW(SPCSCCBOCLAMP(plane_id), SPCSC_OMAX(1023) | SPCSC_OMIN(0));
513 I915_WRITE_FW(SPCSCCROCLAMP(plane_id), SPCSC_OMAX(1023) | SPCSC_OMIN(0));
520 vlv_update_clrc(const struct intel_plane_state *plane_state)
522 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
523 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
524 const struct drm_framebuffer *fb = plane_state->base.fb;
525 enum pipe pipe = plane->pipe;
526 enum plane_id plane_id = plane->id;
527 int contrast, brightness, sh_scale, sh_sin, sh_cos;
529 if (fb->format->is_yuv &&
530 plane_state->base.color_range == DRM_COLOR_YCBCR_LIMITED_RANGE) {
532 * Expand limited range to full range:
533 * Contrast is applied first and is used to expand Y range.
534 * Brightness is applied second and is used to remove the
535 * offset from Y. Saturation/hue is used to expand CbCr range.
537 contrast = DIV_ROUND_CLOSEST(255 << 6, 235 - 16);
538 brightness = -DIV_ROUND_CLOSEST(16 * 255, 235 - 16);
539 sh_scale = DIV_ROUND_CLOSEST(128 << 7, 240 - 128);
540 sh_sin = SIN_0 * sh_scale;
541 sh_cos = COS_0 * sh_scale;
543 /* Pass-through everything. */
547 sh_sin = SIN_0 * sh_scale;
548 sh_cos = COS_0 * sh_scale;
551 /* FIXME these register are single buffered :( */
552 I915_WRITE_FW(SPCLRC0(pipe, plane_id),
553 SP_CONTRAST(contrast) | SP_BRIGHTNESS(brightness));
554 I915_WRITE_FW(SPCLRC1(pipe, plane_id),
555 SP_SH_SIN(sh_sin) | SP_SH_COS(sh_cos));
558 static u32 vlv_sprite_ctl(const struct intel_crtc_state *crtc_state,
559 const struct intel_plane_state *plane_state)
561 const struct drm_framebuffer *fb = plane_state->base.fb;
562 unsigned int rotation = plane_state->base.rotation;
563 const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
566 sprctl = SP_ENABLE | SP_GAMMA_ENABLE;
568 switch (fb->format->format) {
569 case DRM_FORMAT_YUYV:
570 sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_YUYV;
572 case DRM_FORMAT_YVYU:
573 sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_YVYU;
575 case DRM_FORMAT_UYVY:
576 sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_UYVY;
578 case DRM_FORMAT_VYUY:
579 sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_VYUY;
581 case DRM_FORMAT_RGB565:
582 sprctl |= SP_FORMAT_BGR565;
584 case DRM_FORMAT_XRGB8888:
585 sprctl |= SP_FORMAT_BGRX8888;
587 case DRM_FORMAT_ARGB8888:
588 sprctl |= SP_FORMAT_BGRA8888;
590 case DRM_FORMAT_XBGR2101010:
591 sprctl |= SP_FORMAT_RGBX1010102;
593 case DRM_FORMAT_ABGR2101010:
594 sprctl |= SP_FORMAT_RGBA1010102;
596 case DRM_FORMAT_XBGR8888:
597 sprctl |= SP_FORMAT_RGBX8888;
599 case DRM_FORMAT_ABGR8888:
600 sprctl |= SP_FORMAT_RGBA8888;
603 MISSING_CASE(fb->format->format);
607 if (plane_state->base.color_encoding == DRM_COLOR_YCBCR_BT709)
608 sprctl |= SP_YUV_FORMAT_BT709;
610 if (fb->modifier == I915_FORMAT_MOD_X_TILED)
613 if (rotation & DRM_MODE_ROTATE_180)
614 sprctl |= SP_ROTATE_180;
616 if (rotation & DRM_MODE_REFLECT_X)
619 if (key->flags & I915_SET_COLORKEY_SOURCE)
620 sprctl |= SP_SOURCE_KEY;
626 vlv_update_plane(struct intel_plane *plane,
627 const struct intel_crtc_state *crtc_state,
628 const struct intel_plane_state *plane_state)
630 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
631 const struct drm_framebuffer *fb = plane_state->base.fb;
632 enum pipe pipe = plane->pipe;
633 enum plane_id plane_id = plane->id;
634 u32 sprctl = plane_state->ctl;
635 u32 sprsurf_offset = plane_state->color_plane[0].offset;
637 const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
638 int crtc_x = plane_state->base.dst.x1;
639 int crtc_y = plane_state->base.dst.y1;
640 uint32_t crtc_w = drm_rect_width(&plane_state->base.dst);
641 uint32_t crtc_h = drm_rect_height(&plane_state->base.dst);
642 uint32_t x = plane_state->color_plane[0].x;
643 uint32_t y = plane_state->color_plane[0].y;
644 unsigned long irqflags;
646 /* Sizes are 0 based */
650 linear_offset = intel_fb_xy_to_linear(x, y, plane_state, 0);
652 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
654 vlv_update_clrc(plane_state);
656 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B)
657 chv_update_csc(plane_state);
660 I915_WRITE_FW(SPKEYMINVAL(pipe, plane_id), key->min_value);
661 I915_WRITE_FW(SPKEYMAXVAL(pipe, plane_id), key->max_value);
662 I915_WRITE_FW(SPKEYMSK(pipe, plane_id), key->channel_mask);
664 I915_WRITE_FW(SPSTRIDE(pipe, plane_id),
665 plane_state->color_plane[0].stride);
666 I915_WRITE_FW(SPPOS(pipe, plane_id), (crtc_y << 16) | crtc_x);
668 if (fb->modifier == I915_FORMAT_MOD_X_TILED)
669 I915_WRITE_FW(SPTILEOFF(pipe, plane_id), (y << 16) | x);
671 I915_WRITE_FW(SPLINOFF(pipe, plane_id), linear_offset);
673 I915_WRITE_FW(SPCONSTALPHA(pipe, plane_id), 0);
675 I915_WRITE_FW(SPSIZE(pipe, plane_id), (crtc_h << 16) | crtc_w);
676 I915_WRITE_FW(SPCNTR(pipe, plane_id), sprctl);
677 I915_WRITE_FW(SPSURF(pipe, plane_id),
678 intel_plane_ggtt_offset(plane_state) + sprsurf_offset);
679 POSTING_READ_FW(SPSURF(pipe, plane_id));
681 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
685 vlv_disable_plane(struct intel_plane *plane, struct intel_crtc *crtc)
687 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
688 enum pipe pipe = plane->pipe;
689 enum plane_id plane_id = plane->id;
690 unsigned long irqflags;
692 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
694 I915_WRITE_FW(SPCNTR(pipe, plane_id), 0);
696 I915_WRITE_FW(SPSURF(pipe, plane_id), 0);
697 POSTING_READ_FW(SPSURF(pipe, plane_id));
699 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
703 vlv_plane_get_hw_state(struct intel_plane *plane,
706 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
707 enum intel_display_power_domain power_domain;
708 enum plane_id plane_id = plane->id;
711 power_domain = POWER_DOMAIN_PIPE(plane->pipe);
712 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
715 ret = I915_READ(SPCNTR(plane->pipe, plane_id)) & SP_ENABLE;
719 intel_display_power_put(dev_priv, power_domain);
724 static u32 ivb_sprite_ctl(const struct intel_crtc_state *crtc_state,
725 const struct intel_plane_state *plane_state)
727 struct drm_i915_private *dev_priv =
728 to_i915(plane_state->base.plane->dev);
729 const struct drm_framebuffer *fb = plane_state->base.fb;
730 unsigned int rotation = plane_state->base.rotation;
731 const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
734 sprctl = SPRITE_ENABLE | SPRITE_GAMMA_ENABLE;
736 if (IS_IVYBRIDGE(dev_priv))
737 sprctl |= SPRITE_TRICKLE_FEED_DISABLE;
739 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
740 sprctl |= SPRITE_PIPE_CSC_ENABLE;
742 switch (fb->format->format) {
743 case DRM_FORMAT_XBGR8888:
744 sprctl |= SPRITE_FORMAT_RGBX888 | SPRITE_RGB_ORDER_RGBX;
746 case DRM_FORMAT_XRGB8888:
747 sprctl |= SPRITE_FORMAT_RGBX888;
749 case DRM_FORMAT_YUYV:
750 sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_YUYV;
752 case DRM_FORMAT_YVYU:
753 sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_YVYU;
755 case DRM_FORMAT_UYVY:
756 sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_UYVY;
758 case DRM_FORMAT_VYUY:
759 sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_VYUY;
762 MISSING_CASE(fb->format->format);
766 if (plane_state->base.color_encoding == DRM_COLOR_YCBCR_BT709)
767 sprctl |= SPRITE_YUV_TO_RGB_CSC_FORMAT_BT709;
769 if (plane_state->base.color_range == DRM_COLOR_YCBCR_FULL_RANGE)
770 sprctl |= SPRITE_YUV_RANGE_CORRECTION_DISABLE;
772 if (fb->modifier == I915_FORMAT_MOD_X_TILED)
773 sprctl |= SPRITE_TILED;
775 if (rotation & DRM_MODE_ROTATE_180)
776 sprctl |= SPRITE_ROTATE_180;
778 if (key->flags & I915_SET_COLORKEY_DESTINATION)
779 sprctl |= SPRITE_DEST_KEY;
780 else if (key->flags & I915_SET_COLORKEY_SOURCE)
781 sprctl |= SPRITE_SOURCE_KEY;
787 ivb_update_plane(struct intel_plane *plane,
788 const struct intel_crtc_state *crtc_state,
789 const struct intel_plane_state *plane_state)
791 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
792 const struct drm_framebuffer *fb = plane_state->base.fb;
793 enum pipe pipe = plane->pipe;
794 u32 sprctl = plane_state->ctl, sprscale = 0;
795 u32 sprsurf_offset = plane_state->color_plane[0].offset;
797 const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
798 int crtc_x = plane_state->base.dst.x1;
799 int crtc_y = plane_state->base.dst.y1;
800 uint32_t crtc_w = drm_rect_width(&plane_state->base.dst);
801 uint32_t crtc_h = drm_rect_height(&plane_state->base.dst);
802 uint32_t x = plane_state->color_plane[0].x;
803 uint32_t y = plane_state->color_plane[0].y;
804 uint32_t src_w = drm_rect_width(&plane_state->base.src) >> 16;
805 uint32_t src_h = drm_rect_height(&plane_state->base.src) >> 16;
806 unsigned long irqflags;
808 /* Sizes are 0 based */
814 if (crtc_w != src_w || crtc_h != src_h)
815 sprscale = SPRITE_SCALE_ENABLE | (src_w << 16) | src_h;
817 linear_offset = intel_fb_xy_to_linear(x, y, plane_state, 0);
819 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
822 I915_WRITE_FW(SPRKEYVAL(pipe), key->min_value);
823 I915_WRITE_FW(SPRKEYMAX(pipe), key->max_value);
824 I915_WRITE_FW(SPRKEYMSK(pipe), key->channel_mask);
827 I915_WRITE_FW(SPRSTRIDE(pipe), plane_state->color_plane[0].stride);
828 I915_WRITE_FW(SPRPOS(pipe), (crtc_y << 16) | crtc_x);
830 /* HSW consolidates SPRTILEOFF and SPRLINOFF into a single SPROFFSET
832 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
833 I915_WRITE_FW(SPROFFSET(pipe), (y << 16) | x);
834 else if (fb->modifier == I915_FORMAT_MOD_X_TILED)
835 I915_WRITE_FW(SPRTILEOFF(pipe), (y << 16) | x);
837 I915_WRITE_FW(SPRLINOFF(pipe), linear_offset);
839 I915_WRITE_FW(SPRSIZE(pipe), (crtc_h << 16) | crtc_w);
840 if (IS_IVYBRIDGE(dev_priv))
841 I915_WRITE_FW(SPRSCALE(pipe), sprscale);
842 I915_WRITE_FW(SPRCTL(pipe), sprctl);
843 I915_WRITE_FW(SPRSURF(pipe),
844 intel_plane_ggtt_offset(plane_state) + sprsurf_offset);
845 POSTING_READ_FW(SPRSURF(pipe));
847 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
851 ivb_disable_plane(struct intel_plane *plane, struct intel_crtc *crtc)
853 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
854 enum pipe pipe = plane->pipe;
855 unsigned long irqflags;
857 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
859 I915_WRITE_FW(SPRCTL(pipe), 0);
860 /* Can't leave the scaler enabled... */
861 if (IS_IVYBRIDGE(dev_priv))
862 I915_WRITE_FW(SPRSCALE(pipe), 0);
864 I915_WRITE_FW(SPRSURF(pipe), 0);
865 POSTING_READ_FW(SPRSURF(pipe));
867 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
871 ivb_plane_get_hw_state(struct intel_plane *plane,
874 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
875 enum intel_display_power_domain power_domain;
878 power_domain = POWER_DOMAIN_PIPE(plane->pipe);
879 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
882 ret = I915_READ(SPRCTL(plane->pipe)) & SPRITE_ENABLE;
886 intel_display_power_put(dev_priv, power_domain);
892 g4x_sprite_max_stride(struct intel_plane *plane,
893 u32 pixel_format, u64 modifier,
894 unsigned int rotation)
899 static u32 g4x_sprite_ctl(const struct intel_crtc_state *crtc_state,
900 const struct intel_plane_state *plane_state)
902 struct drm_i915_private *dev_priv =
903 to_i915(plane_state->base.plane->dev);
904 const struct drm_framebuffer *fb = plane_state->base.fb;
905 unsigned int rotation = plane_state->base.rotation;
906 const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
909 dvscntr = DVS_ENABLE | DVS_GAMMA_ENABLE;
911 if (IS_GEN6(dev_priv))
912 dvscntr |= DVS_TRICKLE_FEED_DISABLE;
914 switch (fb->format->format) {
915 case DRM_FORMAT_XBGR8888:
916 dvscntr |= DVS_FORMAT_RGBX888 | DVS_RGB_ORDER_XBGR;
918 case DRM_FORMAT_XRGB8888:
919 dvscntr |= DVS_FORMAT_RGBX888;
921 case DRM_FORMAT_YUYV:
922 dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_YUYV;
924 case DRM_FORMAT_YVYU:
925 dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_YVYU;
927 case DRM_FORMAT_UYVY:
928 dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_UYVY;
930 case DRM_FORMAT_VYUY:
931 dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_VYUY;
934 MISSING_CASE(fb->format->format);
938 if (plane_state->base.color_encoding == DRM_COLOR_YCBCR_BT709)
939 dvscntr |= DVS_YUV_FORMAT_BT709;
941 if (plane_state->base.color_range == DRM_COLOR_YCBCR_FULL_RANGE)
942 dvscntr |= DVS_YUV_RANGE_CORRECTION_DISABLE;
944 if (fb->modifier == I915_FORMAT_MOD_X_TILED)
945 dvscntr |= DVS_TILED;
947 if (rotation & DRM_MODE_ROTATE_180)
948 dvscntr |= DVS_ROTATE_180;
950 if (key->flags & I915_SET_COLORKEY_DESTINATION)
951 dvscntr |= DVS_DEST_KEY;
952 else if (key->flags & I915_SET_COLORKEY_SOURCE)
953 dvscntr |= DVS_SOURCE_KEY;
959 g4x_update_plane(struct intel_plane *plane,
960 const struct intel_crtc_state *crtc_state,
961 const struct intel_plane_state *plane_state)
963 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
964 const struct drm_framebuffer *fb = plane_state->base.fb;
965 enum pipe pipe = plane->pipe;
966 u32 dvscntr = plane_state->ctl, dvsscale = 0;
967 u32 dvssurf_offset = plane_state->color_plane[0].offset;
969 const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
970 int crtc_x = plane_state->base.dst.x1;
971 int crtc_y = plane_state->base.dst.y1;
972 uint32_t crtc_w = drm_rect_width(&plane_state->base.dst);
973 uint32_t crtc_h = drm_rect_height(&plane_state->base.dst);
974 uint32_t x = plane_state->color_plane[0].x;
975 uint32_t y = plane_state->color_plane[0].y;
976 uint32_t src_w = drm_rect_width(&plane_state->base.src) >> 16;
977 uint32_t src_h = drm_rect_height(&plane_state->base.src) >> 16;
978 unsigned long irqflags;
980 /* Sizes are 0 based */
986 if (crtc_w != src_w || crtc_h != src_h)
987 dvsscale = DVS_SCALE_ENABLE | (src_w << 16) | src_h;
989 linear_offset = intel_fb_xy_to_linear(x, y, plane_state, 0);
991 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
994 I915_WRITE_FW(DVSKEYVAL(pipe), key->min_value);
995 I915_WRITE_FW(DVSKEYMAX(pipe), key->max_value);
996 I915_WRITE_FW(DVSKEYMSK(pipe), key->channel_mask);
999 I915_WRITE_FW(DVSSTRIDE(pipe), plane_state->color_plane[0].stride);
1000 I915_WRITE_FW(DVSPOS(pipe), (crtc_y << 16) | crtc_x);
1002 if (fb->modifier == I915_FORMAT_MOD_X_TILED)
1003 I915_WRITE_FW(DVSTILEOFF(pipe), (y << 16) | x);
1005 I915_WRITE_FW(DVSLINOFF(pipe), linear_offset);
1007 I915_WRITE_FW(DVSSIZE(pipe), (crtc_h << 16) | crtc_w);
1008 I915_WRITE_FW(DVSSCALE(pipe), dvsscale);
1009 I915_WRITE_FW(DVSCNTR(pipe), dvscntr);
1010 I915_WRITE_FW(DVSSURF(pipe),
1011 intel_plane_ggtt_offset(plane_state) + dvssurf_offset);
1012 POSTING_READ_FW(DVSSURF(pipe));
1014 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
1018 g4x_disable_plane(struct intel_plane *plane, struct intel_crtc *crtc)
1020 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
1021 enum pipe pipe = plane->pipe;
1022 unsigned long irqflags;
1024 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
1026 I915_WRITE_FW(DVSCNTR(pipe), 0);
1027 /* Disable the scaler */
1028 I915_WRITE_FW(DVSSCALE(pipe), 0);
1030 I915_WRITE_FW(DVSSURF(pipe), 0);
1031 POSTING_READ_FW(DVSSURF(pipe));
1033 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
1037 g4x_plane_get_hw_state(struct intel_plane *plane,
1040 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
1041 enum intel_display_power_domain power_domain;
1044 power_domain = POWER_DOMAIN_PIPE(plane->pipe);
1045 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
1048 ret = I915_READ(DVSCNTR(plane->pipe)) & DVS_ENABLE;
1050 *pipe = plane->pipe;
1052 intel_display_power_put(dev_priv, power_domain);
1058 g4x_sprite_check_scaling(struct intel_crtc_state *crtc_state,
1059 struct intel_plane_state *plane_state)
1061 const struct drm_framebuffer *fb = plane_state->base.fb;
1062 const struct drm_rect *src = &plane_state->base.src;
1063 const struct drm_rect *dst = &plane_state->base.dst;
1064 int src_x, src_y, src_w, src_h, crtc_w, crtc_h;
1065 const struct drm_display_mode *adjusted_mode =
1066 &crtc_state->base.adjusted_mode;
1067 unsigned int cpp = fb->format->cpp[0];
1068 unsigned int width_bytes;
1069 int min_width, min_height;
1071 crtc_w = drm_rect_width(dst);
1072 crtc_h = drm_rect_height(dst);
1074 src_x = src->x1 >> 16;
1075 src_y = src->y1 >> 16;
1076 src_w = drm_rect_width(src) >> 16;
1077 src_h = drm_rect_height(src) >> 16;
1079 if (src_w == crtc_w && src_h == crtc_h)
1084 if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
1086 DRM_DEBUG_KMS("Source height must be even with interlaced modes\n");
1094 width_bytes = ((src_x * cpp) & 63) + src_w * cpp;
1096 if (src_w < min_width || src_h < min_height ||
1097 src_w > 2048 || src_h > 2048) {
1098 DRM_DEBUG_KMS("Source dimensions (%dx%d) exceed hardware limits (%dx%d - %dx%d)\n",
1099 src_w, src_h, min_width, min_height, 2048, 2048);
1103 if (width_bytes > 4096) {
1104 DRM_DEBUG_KMS("Fetch width (%d) exceeds hardware max with scaling (%u)\n",
1109 if (width_bytes > 4096 || fb->pitches[0] > 4096) {
1110 DRM_DEBUG_KMS("Stride (%u) exceeds hardware max with scaling (%u)\n",
1111 fb->pitches[0], 4096);
1119 g4x_sprite_check(struct intel_crtc_state *crtc_state,
1120 struct intel_plane_state *plane_state)
1122 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
1123 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
1124 int max_scale, min_scale;
1127 if (INTEL_GEN(dev_priv) < 7) {
1129 max_scale = 16 << 16;
1130 } else if (IS_IVYBRIDGE(dev_priv)) {
1132 max_scale = 2 << 16;
1134 min_scale = DRM_PLANE_HELPER_NO_SCALING;
1135 max_scale = DRM_PLANE_HELPER_NO_SCALING;
1138 ret = drm_atomic_helper_check_plane_state(&plane_state->base,
1140 min_scale, max_scale,
1145 if (!plane_state->base.visible)
1148 ret = intel_plane_check_src_coordinates(plane_state);
1152 ret = g4x_sprite_check_scaling(crtc_state, plane_state);
1156 ret = i9xx_check_plane_surface(plane_state);
1160 if (INTEL_GEN(dev_priv) >= 7)
1161 plane_state->ctl = ivb_sprite_ctl(crtc_state, plane_state);
1163 plane_state->ctl = g4x_sprite_ctl(crtc_state, plane_state);
1168 int chv_plane_check_rotation(const struct intel_plane_state *plane_state)
1170 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
1171 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
1172 unsigned int rotation = plane_state->base.rotation;
1174 /* CHV ignores the mirror bit when the rotate bit is set :( */
1175 if (IS_CHERRYVIEW(dev_priv) &&
1176 rotation & DRM_MODE_ROTATE_180 &&
1177 rotation & DRM_MODE_REFLECT_X) {
1178 DRM_DEBUG_KMS("Cannot rotate and reflect at the same time\n");
1186 vlv_sprite_check(struct intel_crtc_state *crtc_state,
1187 struct intel_plane_state *plane_state)
1191 ret = chv_plane_check_rotation(plane_state);
1195 ret = drm_atomic_helper_check_plane_state(&plane_state->base,
1197 DRM_PLANE_HELPER_NO_SCALING,
1198 DRM_PLANE_HELPER_NO_SCALING,
1203 if (!plane_state->base.visible)
1206 ret = intel_plane_check_src_coordinates(plane_state);
1210 ret = i9xx_check_plane_surface(plane_state);
1214 plane_state->ctl = vlv_sprite_ctl(crtc_state, plane_state);
1219 static int skl_plane_check_fb(const struct intel_crtc_state *crtc_state,
1220 const struct intel_plane_state *plane_state)
1222 const struct drm_framebuffer *fb = plane_state->base.fb;
1223 unsigned int rotation = plane_state->base.rotation;
1224 struct drm_format_name_buf format_name;
1229 if (rotation & ~(DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180) &&
1230 is_ccs_modifier(fb->modifier)) {
1231 DRM_DEBUG_KMS("RC support only with 0/180 degree rotation (%x)\n",
1236 if (rotation & DRM_MODE_REFLECT_X &&
1237 fb->modifier == DRM_FORMAT_MOD_LINEAR) {
1238 DRM_DEBUG_KMS("horizontal flip is not supported with linear surface formats\n");
1242 if (drm_rotation_90_or_270(rotation)) {
1243 if (fb->modifier != I915_FORMAT_MOD_Y_TILED &&
1244 fb->modifier != I915_FORMAT_MOD_Yf_TILED) {
1245 DRM_DEBUG_KMS("Y/Yf tiling required for 90/270!\n");
1250 * 90/270 is not allowed with RGB64 16:16:16:16,
1251 * RGB 16-bit 5:6:5, and Indexed 8-bit.
1252 * TBD: Add RGB64 case once its added in supported format list.
1254 switch (fb->format->format) {
1256 case DRM_FORMAT_RGB565:
1257 DRM_DEBUG_KMS("Unsupported pixel format %s for 90/270!\n",
1258 drm_get_format_name(fb->format->format,
1266 /* Y-tiling is not supported in IF-ID Interlace mode */
1267 if (crtc_state->base.enable &&
1268 crtc_state->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE &&
1269 (fb->modifier == I915_FORMAT_MOD_Y_TILED ||
1270 fb->modifier == I915_FORMAT_MOD_Yf_TILED ||
1271 fb->modifier == I915_FORMAT_MOD_Y_TILED_CCS ||
1272 fb->modifier == I915_FORMAT_MOD_Yf_TILED_CCS)) {
1273 DRM_DEBUG_KMS("Y/Yf tiling not supported in IF-ID mode\n");
1280 static int skl_plane_check_dst_coordinates(const struct intel_crtc_state *crtc_state,
1281 const struct intel_plane_state *plane_state)
1283 struct drm_i915_private *dev_priv =
1284 to_i915(plane_state->base.plane->dev);
1285 int crtc_x = plane_state->base.dst.x1;
1286 int crtc_w = drm_rect_width(&plane_state->base.dst);
1287 int pipe_src_w = crtc_state->pipe_src_w;
1290 * Display WA #1175: cnl,glk
1291 * Planes other than the cursor may cause FIFO underflow and display
1292 * corruption if starting less than 4 pixels from the right edge of
1294 * Besides the above WA fix the similar problem, where planes other
1295 * than the cursor ending less than 4 pixels from the left edge of the
1296 * screen may cause FIFO underflow and display corruption.
1298 if ((IS_GEMINILAKE(dev_priv) || IS_CANNONLAKE(dev_priv)) &&
1299 (crtc_x + crtc_w < 4 || crtc_x > pipe_src_w - 4)) {
1300 DRM_DEBUG_KMS("requested plane X %s position %d invalid (valid range %d-%d)\n",
1301 crtc_x + crtc_w < 4 ? "end" : "start",
1302 crtc_x + crtc_w < 4 ? crtc_x + crtc_w : crtc_x,
1310 int skl_plane_check(struct intel_crtc_state *crtc_state,
1311 struct intel_plane_state *plane_state)
1313 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
1314 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
1315 int max_scale, min_scale;
1318 ret = skl_plane_check_fb(crtc_state, plane_state);
1322 /* use scaler when colorkey is not required */
1323 if (!plane_state->ckey.flags) {
1324 const struct drm_framebuffer *fb = plane_state->base.fb;
1327 max_scale = skl_max_scale(crtc_state,
1328 fb ? fb->format->format : 0);
1330 min_scale = DRM_PLANE_HELPER_NO_SCALING;
1331 max_scale = DRM_PLANE_HELPER_NO_SCALING;
1334 ret = drm_atomic_helper_check_plane_state(&plane_state->base,
1336 min_scale, max_scale,
1341 if (!plane_state->base.visible)
1344 ret = skl_plane_check_dst_coordinates(crtc_state, plane_state);
1348 ret = intel_plane_check_src_coordinates(plane_state);
1352 ret = skl_check_plane_surface(plane_state);
1356 plane_state->ctl = skl_plane_ctl(crtc_state, plane_state);
1358 if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv))
1359 plane_state->color_ctl = glk_plane_color_ctl(crtc_state,
1365 static bool has_dst_key_in_primary_plane(struct drm_i915_private *dev_priv)
1367 return INTEL_GEN(dev_priv) >= 9;
1370 static void intel_plane_set_ckey(struct intel_plane_state *plane_state,
1371 const struct drm_intel_sprite_colorkey *set)
1373 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
1374 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
1375 struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
1380 * We want src key enabled on the
1381 * sprite and not on the primary.
1383 if (plane->id == PLANE_PRIMARY &&
1384 set->flags & I915_SET_COLORKEY_SOURCE)
1388 * On SKL+ we want dst key enabled on
1389 * the primary and not on the sprite.
1391 if (INTEL_GEN(dev_priv) >= 9 && plane->id != PLANE_PRIMARY &&
1392 set->flags & I915_SET_COLORKEY_DESTINATION)
1396 int intel_sprite_set_colorkey_ioctl(struct drm_device *dev, void *data,
1397 struct drm_file *file_priv)
1399 struct drm_i915_private *dev_priv = to_i915(dev);
1400 struct drm_intel_sprite_colorkey *set = data;
1401 struct drm_plane *plane;
1402 struct drm_plane_state *plane_state;
1403 struct drm_atomic_state *state;
1404 struct drm_modeset_acquire_ctx ctx;
1407 /* ignore the pointless "none" flag */
1408 set->flags &= ~I915_SET_COLORKEY_NONE;
1410 if (set->flags & ~(I915_SET_COLORKEY_DESTINATION | I915_SET_COLORKEY_SOURCE))
1413 /* Make sure we don't try to enable both src & dest simultaneously */
1414 if ((set->flags & (I915_SET_COLORKEY_DESTINATION | I915_SET_COLORKEY_SOURCE)) == (I915_SET_COLORKEY_DESTINATION | I915_SET_COLORKEY_SOURCE))
1417 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
1418 set->flags & I915_SET_COLORKEY_DESTINATION)
1421 plane = drm_plane_find(dev, file_priv, set->plane_id);
1422 if (!plane || plane->type != DRM_PLANE_TYPE_OVERLAY)
1426 * SKL+ only plane 2 can do destination keying against plane 1.
1427 * Also multiple planes can't do destination keying on the same
1428 * pipe simultaneously.
1430 if (INTEL_GEN(dev_priv) >= 9 &&
1431 to_intel_plane(plane)->id >= PLANE_SPRITE1 &&
1432 set->flags & I915_SET_COLORKEY_DESTINATION)
1435 drm_modeset_acquire_init(&ctx, 0);
1437 state = drm_atomic_state_alloc(plane->dev);
1442 state->acquire_ctx = &ctx;
1445 plane_state = drm_atomic_get_plane_state(state, plane);
1446 ret = PTR_ERR_OR_ZERO(plane_state);
1448 intel_plane_set_ckey(to_intel_plane_state(plane_state), set);
1451 * On some platforms we have to configure
1452 * the dst colorkey on the primary plane.
1454 if (!ret && has_dst_key_in_primary_plane(dev_priv)) {
1455 struct intel_crtc *crtc =
1456 intel_get_crtc_for_pipe(dev_priv,
1457 to_intel_plane(plane)->pipe);
1459 plane_state = drm_atomic_get_plane_state(state,
1460 crtc->base.primary);
1461 ret = PTR_ERR_OR_ZERO(plane_state);
1463 intel_plane_set_ckey(to_intel_plane_state(plane_state), set);
1467 ret = drm_atomic_commit(state);
1469 if (ret != -EDEADLK)
1472 drm_atomic_state_clear(state);
1473 drm_modeset_backoff(&ctx);
1476 drm_atomic_state_put(state);
1478 drm_modeset_drop_locks(&ctx);
1479 drm_modeset_acquire_fini(&ctx);
1483 static const uint32_t g4x_plane_formats[] = {
1484 DRM_FORMAT_XRGB8888,
1491 static const uint64_t i9xx_plane_format_modifiers[] = {
1492 I915_FORMAT_MOD_X_TILED,
1493 DRM_FORMAT_MOD_LINEAR,
1494 DRM_FORMAT_MOD_INVALID
1497 static const uint32_t snb_plane_formats[] = {
1498 DRM_FORMAT_XBGR8888,
1499 DRM_FORMAT_XRGB8888,
1506 static const uint32_t vlv_plane_formats[] = {
1508 DRM_FORMAT_ABGR8888,
1509 DRM_FORMAT_ARGB8888,
1510 DRM_FORMAT_XBGR8888,
1511 DRM_FORMAT_XRGB8888,
1512 DRM_FORMAT_XBGR2101010,
1513 DRM_FORMAT_ABGR2101010,
1520 static uint32_t skl_plane_formats[] = {
1522 DRM_FORMAT_ABGR8888,
1523 DRM_FORMAT_ARGB8888,
1524 DRM_FORMAT_XBGR8888,
1525 DRM_FORMAT_XRGB8888,
1532 static uint32_t skl_planar_formats[] = {
1534 DRM_FORMAT_ABGR8888,
1535 DRM_FORMAT_ARGB8888,
1536 DRM_FORMAT_XBGR8888,
1537 DRM_FORMAT_XRGB8888,
1545 static const uint64_t skl_plane_format_modifiers_noccs[] = {
1546 I915_FORMAT_MOD_Yf_TILED,
1547 I915_FORMAT_MOD_Y_TILED,
1548 I915_FORMAT_MOD_X_TILED,
1549 DRM_FORMAT_MOD_LINEAR,
1550 DRM_FORMAT_MOD_INVALID
1553 static const uint64_t skl_plane_format_modifiers_ccs[] = {
1554 I915_FORMAT_MOD_Yf_TILED_CCS,
1555 I915_FORMAT_MOD_Y_TILED_CCS,
1556 I915_FORMAT_MOD_Yf_TILED,
1557 I915_FORMAT_MOD_Y_TILED,
1558 I915_FORMAT_MOD_X_TILED,
1559 DRM_FORMAT_MOD_LINEAR,
1560 DRM_FORMAT_MOD_INVALID
1563 static bool g4x_sprite_format_mod_supported(struct drm_plane *_plane,
1564 u32 format, u64 modifier)
1567 case DRM_FORMAT_MOD_LINEAR:
1568 case I915_FORMAT_MOD_X_TILED:
1575 case DRM_FORMAT_XRGB8888:
1576 case DRM_FORMAT_YUYV:
1577 case DRM_FORMAT_YVYU:
1578 case DRM_FORMAT_UYVY:
1579 case DRM_FORMAT_VYUY:
1580 if (modifier == DRM_FORMAT_MOD_LINEAR ||
1581 modifier == I915_FORMAT_MOD_X_TILED)
1589 static bool snb_sprite_format_mod_supported(struct drm_plane *_plane,
1590 u32 format, u64 modifier)
1593 case DRM_FORMAT_MOD_LINEAR:
1594 case I915_FORMAT_MOD_X_TILED:
1601 case DRM_FORMAT_XRGB8888:
1602 case DRM_FORMAT_XBGR8888:
1603 case DRM_FORMAT_YUYV:
1604 case DRM_FORMAT_YVYU:
1605 case DRM_FORMAT_UYVY:
1606 case DRM_FORMAT_VYUY:
1607 if (modifier == DRM_FORMAT_MOD_LINEAR ||
1608 modifier == I915_FORMAT_MOD_X_TILED)
1616 static bool vlv_sprite_format_mod_supported(struct drm_plane *_plane,
1617 u32 format, u64 modifier)
1620 case DRM_FORMAT_MOD_LINEAR:
1621 case I915_FORMAT_MOD_X_TILED:
1628 case DRM_FORMAT_RGB565:
1629 case DRM_FORMAT_ABGR8888:
1630 case DRM_FORMAT_ARGB8888:
1631 case DRM_FORMAT_XBGR8888:
1632 case DRM_FORMAT_XRGB8888:
1633 case DRM_FORMAT_XBGR2101010:
1634 case DRM_FORMAT_ABGR2101010:
1635 case DRM_FORMAT_YUYV:
1636 case DRM_FORMAT_YVYU:
1637 case DRM_FORMAT_UYVY:
1638 case DRM_FORMAT_VYUY:
1639 if (modifier == DRM_FORMAT_MOD_LINEAR ||
1640 modifier == I915_FORMAT_MOD_X_TILED)
1648 static bool skl_plane_format_mod_supported(struct drm_plane *_plane,
1649 u32 format, u64 modifier)
1651 struct intel_plane *plane = to_intel_plane(_plane);
1654 case DRM_FORMAT_MOD_LINEAR:
1655 case I915_FORMAT_MOD_X_TILED:
1656 case I915_FORMAT_MOD_Y_TILED:
1657 case I915_FORMAT_MOD_Yf_TILED:
1659 case I915_FORMAT_MOD_Y_TILED_CCS:
1660 case I915_FORMAT_MOD_Yf_TILED_CCS:
1661 if (!plane->has_ccs)
1669 case DRM_FORMAT_XRGB8888:
1670 case DRM_FORMAT_XBGR8888:
1671 case DRM_FORMAT_ARGB8888:
1672 case DRM_FORMAT_ABGR8888:
1673 if (is_ccs_modifier(modifier))
1676 case DRM_FORMAT_RGB565:
1677 case DRM_FORMAT_XRGB2101010:
1678 case DRM_FORMAT_XBGR2101010:
1679 case DRM_FORMAT_YUYV:
1680 case DRM_FORMAT_YVYU:
1681 case DRM_FORMAT_UYVY:
1682 case DRM_FORMAT_VYUY:
1683 case DRM_FORMAT_NV12:
1684 if (modifier == I915_FORMAT_MOD_Yf_TILED)
1688 if (modifier == DRM_FORMAT_MOD_LINEAR ||
1689 modifier == I915_FORMAT_MOD_X_TILED ||
1690 modifier == I915_FORMAT_MOD_Y_TILED)
1698 static const struct drm_plane_funcs g4x_sprite_funcs = {
1699 .update_plane = drm_atomic_helper_update_plane,
1700 .disable_plane = drm_atomic_helper_disable_plane,
1701 .destroy = intel_plane_destroy,
1702 .atomic_get_property = intel_plane_atomic_get_property,
1703 .atomic_set_property = intel_plane_atomic_set_property,
1704 .atomic_duplicate_state = intel_plane_duplicate_state,
1705 .atomic_destroy_state = intel_plane_destroy_state,
1706 .format_mod_supported = g4x_sprite_format_mod_supported,
1709 static const struct drm_plane_funcs snb_sprite_funcs = {
1710 .update_plane = drm_atomic_helper_update_plane,
1711 .disable_plane = drm_atomic_helper_disable_plane,
1712 .destroy = intel_plane_destroy,
1713 .atomic_get_property = intel_plane_atomic_get_property,
1714 .atomic_set_property = intel_plane_atomic_set_property,
1715 .atomic_duplicate_state = intel_plane_duplicate_state,
1716 .atomic_destroy_state = intel_plane_destroy_state,
1717 .format_mod_supported = snb_sprite_format_mod_supported,
1720 static const struct drm_plane_funcs vlv_sprite_funcs = {
1721 .update_plane = drm_atomic_helper_update_plane,
1722 .disable_plane = drm_atomic_helper_disable_plane,
1723 .destroy = intel_plane_destroy,
1724 .atomic_get_property = intel_plane_atomic_get_property,
1725 .atomic_set_property = intel_plane_atomic_set_property,
1726 .atomic_duplicate_state = intel_plane_duplicate_state,
1727 .atomic_destroy_state = intel_plane_destroy_state,
1728 .format_mod_supported = vlv_sprite_format_mod_supported,
1731 static const struct drm_plane_funcs skl_plane_funcs = {
1732 .update_plane = drm_atomic_helper_update_plane,
1733 .disable_plane = drm_atomic_helper_disable_plane,
1734 .destroy = intel_plane_destroy,
1735 .atomic_get_property = intel_plane_atomic_get_property,
1736 .atomic_set_property = intel_plane_atomic_set_property,
1737 .atomic_duplicate_state = intel_plane_duplicate_state,
1738 .atomic_destroy_state = intel_plane_destroy_state,
1739 .format_mod_supported = skl_plane_format_mod_supported,
1742 bool skl_plane_has_ccs(struct drm_i915_private *dev_priv,
1743 enum pipe pipe, enum plane_id plane_id)
1745 if (plane_id == PLANE_CURSOR)
1748 if (INTEL_GEN(dev_priv) >= 10)
1751 if (IS_GEMINILAKE(dev_priv))
1752 return pipe != PIPE_C;
1754 return pipe != PIPE_C &&
1755 (plane_id == PLANE_PRIMARY ||
1756 plane_id == PLANE_SPRITE0);
1759 struct intel_plane *
1760 intel_sprite_plane_create(struct drm_i915_private *dev_priv,
1761 enum pipe pipe, int plane)
1763 struct intel_plane *intel_plane = NULL;
1764 struct intel_plane_state *state = NULL;
1765 const struct drm_plane_funcs *plane_funcs;
1766 unsigned long possible_crtcs;
1767 const uint32_t *plane_formats;
1768 const uint64_t *modifiers;
1769 unsigned int supported_rotations;
1770 int num_plane_formats;
1773 intel_plane = kzalloc(sizeof(*intel_plane), GFP_KERNEL);
1779 state = intel_create_plane_state(&intel_plane->base);
1784 intel_plane->base.state = &state->base;
1786 if (INTEL_GEN(dev_priv) >= 9) {
1787 state->scaler_id = -1;
1789 intel_plane->has_ccs = skl_plane_has_ccs(dev_priv, pipe,
1790 PLANE_SPRITE0 + plane);
1792 intel_plane->max_stride = skl_plane_max_stride;
1793 intel_plane->update_plane = skl_update_plane;
1794 intel_plane->disable_plane = skl_disable_plane;
1795 intel_plane->get_hw_state = skl_plane_get_hw_state;
1796 intel_plane->check_plane = skl_plane_check;
1798 if (skl_plane_has_planar(dev_priv, pipe,
1799 PLANE_SPRITE0 + plane)) {
1800 plane_formats = skl_planar_formats;
1801 num_plane_formats = ARRAY_SIZE(skl_planar_formats);
1803 plane_formats = skl_plane_formats;
1804 num_plane_formats = ARRAY_SIZE(skl_plane_formats);
1807 if (intel_plane->has_ccs)
1808 modifiers = skl_plane_format_modifiers_ccs;
1810 modifiers = skl_plane_format_modifiers_noccs;
1812 plane_funcs = &skl_plane_funcs;
1813 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
1814 intel_plane->max_stride = i9xx_plane_max_stride;
1815 intel_plane->update_plane = vlv_update_plane;
1816 intel_plane->disable_plane = vlv_disable_plane;
1817 intel_plane->get_hw_state = vlv_plane_get_hw_state;
1818 intel_plane->check_plane = vlv_sprite_check;
1820 plane_formats = vlv_plane_formats;
1821 num_plane_formats = ARRAY_SIZE(vlv_plane_formats);
1822 modifiers = i9xx_plane_format_modifiers;
1824 plane_funcs = &vlv_sprite_funcs;
1825 } else if (INTEL_GEN(dev_priv) >= 7) {
1826 intel_plane->max_stride = g4x_sprite_max_stride;
1827 intel_plane->update_plane = ivb_update_plane;
1828 intel_plane->disable_plane = ivb_disable_plane;
1829 intel_plane->get_hw_state = ivb_plane_get_hw_state;
1830 intel_plane->check_plane = g4x_sprite_check;
1832 plane_formats = snb_plane_formats;
1833 num_plane_formats = ARRAY_SIZE(snb_plane_formats);
1834 modifiers = i9xx_plane_format_modifiers;
1836 plane_funcs = &snb_sprite_funcs;
1838 intel_plane->max_stride = g4x_sprite_max_stride;
1839 intel_plane->update_plane = g4x_update_plane;
1840 intel_plane->disable_plane = g4x_disable_plane;
1841 intel_plane->get_hw_state = g4x_plane_get_hw_state;
1842 intel_plane->check_plane = g4x_sprite_check;
1844 modifiers = i9xx_plane_format_modifiers;
1845 if (IS_GEN6(dev_priv)) {
1846 plane_formats = snb_plane_formats;
1847 num_plane_formats = ARRAY_SIZE(snb_plane_formats);
1849 plane_funcs = &snb_sprite_funcs;
1851 plane_formats = g4x_plane_formats;
1852 num_plane_formats = ARRAY_SIZE(g4x_plane_formats);
1854 plane_funcs = &g4x_sprite_funcs;
1858 if (INTEL_GEN(dev_priv) >= 9) {
1859 supported_rotations =
1860 DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_90 |
1861 DRM_MODE_ROTATE_180 | DRM_MODE_ROTATE_270;
1862 } else if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B) {
1863 supported_rotations =
1864 DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180 |
1867 supported_rotations =
1868 DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180;
1871 intel_plane->pipe = pipe;
1872 intel_plane->i9xx_plane = plane;
1873 intel_plane->id = PLANE_SPRITE0 + plane;
1874 intel_plane->frontbuffer_bit = INTEL_FRONTBUFFER(pipe, intel_plane->id);
1876 possible_crtcs = (1 << pipe);
1878 if (INTEL_GEN(dev_priv) >= 9)
1879 ret = drm_universal_plane_init(&dev_priv->drm, &intel_plane->base,
1880 possible_crtcs, plane_funcs,
1881 plane_formats, num_plane_formats,
1883 DRM_PLANE_TYPE_OVERLAY,
1884 "plane %d%c", plane + 2, pipe_name(pipe));
1886 ret = drm_universal_plane_init(&dev_priv->drm, &intel_plane->base,
1887 possible_crtcs, plane_funcs,
1888 plane_formats, num_plane_formats,
1890 DRM_PLANE_TYPE_OVERLAY,
1891 "sprite %c", sprite_name(pipe, plane));
1895 drm_plane_create_rotation_property(&intel_plane->base,
1897 supported_rotations);
1899 drm_plane_create_color_properties(&intel_plane->base,
1900 BIT(DRM_COLOR_YCBCR_BT601) |
1901 BIT(DRM_COLOR_YCBCR_BT709),
1902 BIT(DRM_COLOR_YCBCR_LIMITED_RANGE) |
1903 BIT(DRM_COLOR_YCBCR_FULL_RANGE),
1904 DRM_COLOR_YCBCR_BT709,
1905 DRM_COLOR_YCBCR_LIMITED_RANGE);
1907 drm_plane_helper_add(&intel_plane->base, &intel_plane_helper_funcs);
1915 return ERR_PTR(ret);