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_atomic.h>
34 #include <drm/drm_atomic_helper.h>
35 #include <drm/drm_color_mgmt.h>
36 #include <drm/drm_crtc.h>
37 #include <drm/drm_fourcc.h>
38 #include <drm/drm_plane_helper.h>
39 #include <drm/drm_rect.h>
40 #include <drm/i915_drm.h>
43 #include "i915_trace.h"
44 #include "intel_atomic_plane.h"
45 #include "intel_display_types.h"
46 #include "intel_frontbuffer.h"
48 #include "intel_psr.h"
49 #include "intel_sprite.h"
51 int intel_usecs_to_scanlines(const struct drm_display_mode *adjusted_mode,
55 if (!adjusted_mode->crtc_htotal)
58 return DIV_ROUND_UP(usecs * adjusted_mode->crtc_clock,
59 1000 * adjusted_mode->crtc_htotal);
62 /* FIXME: We should instead only take spinlocks once for the entire update
63 * instead of once per mmio. */
64 #if IS_ENABLED(CONFIG_PROVE_LOCKING)
65 #define VBLANK_EVASION_TIME_US 250
67 #define VBLANK_EVASION_TIME_US 100
71 * intel_pipe_update_start() - start update of a set of display registers
72 * @new_crtc_state: the new crtc state
74 * Mark the start of an update to pipe registers that should be updated
75 * atomically regarding vblank. If the next vblank will happens within
76 * the next 100 us, this function waits until the vblank passes.
78 * After a successful call to this function, interrupts will be disabled
79 * until a subsequent call to intel_pipe_update_end(). That is done to
80 * avoid random delays.
82 void intel_pipe_update_start(const struct intel_crtc_state *new_crtc_state)
84 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->uapi.crtc);
85 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
86 const struct drm_display_mode *adjusted_mode = &new_crtc_state->hw.adjusted_mode;
87 long timeout = msecs_to_jiffies_timeout(1);
88 int scanline, min, max, vblank_start;
89 wait_queue_head_t *wq = drm_crtc_vblank_waitqueue(&crtc->base);
90 bool need_vlv_dsi_wa = (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
91 intel_crtc_has_type(new_crtc_state, INTEL_OUTPUT_DSI);
95 vblank_start = adjusted_mode->crtc_vblank_start;
96 if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE)
97 vblank_start = DIV_ROUND_UP(vblank_start, 2);
99 /* FIXME needs to be calibrated sensibly */
100 min = vblank_start - intel_usecs_to_scanlines(adjusted_mode,
101 VBLANK_EVASION_TIME_US);
102 max = vblank_start - 1;
104 if (min <= 0 || max <= 0)
107 if (WARN_ON(drm_crtc_vblank_get(&crtc->base)))
111 * Wait for psr to idle out after enabling the VBL interrupts
112 * VBL interrupts will start the PSR exit and prevent a PSR
115 if (intel_psr_wait_for_idle(new_crtc_state, &psr_status))
116 DRM_ERROR("PSR idle timed out 0x%x, atomic update may fail\n",
121 crtc->debug.min_vbl = min;
122 crtc->debug.max_vbl = max;
123 trace_i915_pipe_update_start(crtc);
127 * prepare_to_wait() has a memory barrier, which guarantees
128 * other CPUs can see the task state update by the time we
131 prepare_to_wait(wq, &wait, TASK_UNINTERRUPTIBLE);
133 scanline = intel_get_crtc_scanline(crtc);
134 if (scanline < min || scanline > max)
138 DRM_ERROR("Potential atomic update failure on pipe %c\n",
139 pipe_name(crtc->pipe));
145 timeout = schedule_timeout(timeout);
150 finish_wait(wq, &wait);
152 drm_crtc_vblank_put(&crtc->base);
155 * On VLV/CHV DSI the scanline counter would appear to
156 * increment approx. 1/3 of a scanline before start of vblank.
157 * The registers still get latched at start of vblank however.
158 * This means we must not write any registers on the first
159 * line of vblank (since not the whole line is actually in
160 * vblank). And unfortunately we can't use the interrupt to
161 * wait here since it will fire too soon. We could use the
162 * frame start interrupt instead since it will fire after the
163 * critical scanline, but that would require more changes
164 * in the interrupt code. So for now we'll just do the nasty
165 * thing and poll for the bad scanline to pass us by.
167 * FIXME figure out if BXT+ DSI suffers from this as well
169 while (need_vlv_dsi_wa && scanline == vblank_start)
170 scanline = intel_get_crtc_scanline(crtc);
172 crtc->debug.scanline_start = scanline;
173 crtc->debug.start_vbl_time = ktime_get();
174 crtc->debug.start_vbl_count = intel_crtc_get_vblank_counter(crtc);
176 trace_i915_pipe_update_vblank_evaded(crtc);
184 * intel_pipe_update_end() - end update of a set of display registers
185 * @new_crtc_state: the new crtc state
187 * Mark the end of an update started with intel_pipe_update_start(). This
188 * re-enables interrupts and verifies the update was actually completed
191 void intel_pipe_update_end(struct intel_crtc_state *new_crtc_state)
193 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->uapi.crtc);
194 enum pipe pipe = crtc->pipe;
195 int scanline_end = intel_get_crtc_scanline(crtc);
196 u32 end_vbl_count = intel_crtc_get_vblank_counter(crtc);
197 ktime_t end_vbl_time = ktime_get();
198 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
200 trace_i915_pipe_update_end(crtc, end_vbl_count, scanline_end);
202 /* We're still in the vblank-evade critical section, this can't race.
203 * Would be slightly nice to just grab the vblank count and arm the
204 * event outside of the critical section - the spinlock might spin for a
206 if (new_crtc_state->uapi.event) {
207 WARN_ON(drm_crtc_vblank_get(&crtc->base) != 0);
209 spin_lock(&crtc->base.dev->event_lock);
210 drm_crtc_arm_vblank_event(&crtc->base,
211 new_crtc_state->uapi.event);
212 spin_unlock(&crtc->base.dev->event_lock);
214 new_crtc_state->uapi.event = NULL;
219 if (intel_vgpu_active(dev_priv))
222 if (crtc->debug.start_vbl_count &&
223 crtc->debug.start_vbl_count != end_vbl_count) {
224 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",
225 pipe_name(pipe), crtc->debug.start_vbl_count,
227 ktime_us_delta(end_vbl_time, crtc->debug.start_vbl_time),
228 crtc->debug.min_vbl, crtc->debug.max_vbl,
229 crtc->debug.scanline_start, scanline_end);
231 #ifdef CONFIG_DRM_I915_DEBUG_VBLANK_EVADE
232 else if (ktime_us_delta(end_vbl_time, crtc->debug.start_vbl_time) >
233 VBLANK_EVASION_TIME_US)
234 DRM_WARN("Atomic update on pipe (%c) took %lld us, max time under evasion is %u us\n",
236 ktime_us_delta(end_vbl_time, crtc->debug.start_vbl_time),
237 VBLANK_EVASION_TIME_US);
241 int intel_plane_check_stride(const struct intel_plane_state *plane_state)
243 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
244 const struct drm_framebuffer *fb = plane_state->hw.fb;
245 unsigned int rotation = plane_state->hw.rotation;
246 u32 stride, max_stride;
249 * We ignore stride for all invisible planes that
250 * can be remapped. Otherwise we could end up
251 * with a false positive when the remapping didn't
252 * kick in due the plane being invisible.
254 if (intel_plane_can_remap(plane_state) &&
255 !plane_state->uapi.visible)
258 /* FIXME other color planes? */
259 stride = plane_state->color_plane[0].stride;
260 max_stride = plane->max_stride(plane, fb->format->format,
261 fb->modifier, rotation);
263 if (stride > max_stride) {
264 DRM_DEBUG_KMS("[FB:%d] stride (%d) exceeds [PLANE:%d:%s] max stride (%d)\n",
266 plane->base.base.id, plane->base.name, max_stride);
273 int intel_plane_check_src_coordinates(struct intel_plane_state *plane_state)
275 const struct drm_framebuffer *fb = plane_state->hw.fb;
276 struct drm_rect *src = &plane_state->uapi.src;
277 u32 src_x, src_y, src_w, src_h, hsub, vsub;
278 bool rotated = drm_rotation_90_or_270(plane_state->hw.rotation);
281 * Hardware doesn't handle subpixel coordinates.
282 * Adjust to (macro)pixel boundary, but be careful not to
283 * increase the source viewport size, because that could
284 * push the downscaling factor out of bounds.
286 src_x = src->x1 >> 16;
287 src_w = drm_rect_width(src) >> 16;
288 src_y = src->y1 >> 16;
289 src_h = drm_rect_height(src) >> 16;
291 drm_rect_init(src, src_x << 16, src_y << 16,
292 src_w << 16, src_h << 16);
294 if (!fb->format->is_yuv)
297 /* YUV specific checks */
299 hsub = fb->format->hsub;
300 vsub = fb->format->vsub;
302 hsub = vsub = max(fb->format->hsub, fb->format->vsub);
305 if (src_x % hsub || src_w % hsub) {
306 DRM_DEBUG_KMS("src x/w (%u, %u) must be a multiple of %u for %sYUV planes\n",
307 src_x, src_w, hsub, rotated ? "rotated " : "");
311 if (src_y % vsub || src_h % vsub) {
312 DRM_DEBUG_KMS("src y/h (%u, %u) must be a multiple of %u for %sYUV planes\n",
313 src_y, src_h, vsub, rotated ? "rotated " : "");
320 bool icl_is_hdr_plane(struct drm_i915_private *dev_priv, enum plane_id plane_id)
322 return INTEL_GEN(dev_priv) >= 11 &&
323 icl_hdr_plane_mask() & BIT(plane_id);
327 skl_plane_ratio(const struct intel_crtc_state *crtc_state,
328 const struct intel_plane_state *plane_state,
329 unsigned int *num, unsigned int *den)
331 struct drm_i915_private *dev_priv = to_i915(plane_state->uapi.plane->dev);
332 const struct drm_framebuffer *fb = plane_state->hw.fb;
334 if (fb->format->cpp[0] == 8) {
335 if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv)) {
348 static int skl_plane_min_cdclk(const struct intel_crtc_state *crtc_state,
349 const struct intel_plane_state *plane_state)
351 struct drm_i915_private *dev_priv = to_i915(plane_state->uapi.plane->dev);
352 unsigned int pixel_rate = crtc_state->pixel_rate;
353 unsigned int src_w, src_h, dst_w, dst_h;
354 unsigned int num, den;
356 skl_plane_ratio(crtc_state, plane_state, &num, &den);
358 /* two pixels per clock on glk+ */
359 if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv))
362 src_w = drm_rect_width(&plane_state->uapi.src) >> 16;
363 src_h = drm_rect_height(&plane_state->uapi.src) >> 16;
364 dst_w = drm_rect_width(&plane_state->uapi.dst);
365 dst_h = drm_rect_height(&plane_state->uapi.dst);
367 /* Downscaling limits the maximum pixel rate */
368 dst_w = min(src_w, dst_w);
369 dst_h = min(src_h, dst_h);
371 return DIV64_U64_ROUND_UP(mul_u32_u32(pixel_rate * num, src_w * src_h),
372 mul_u32_u32(den, dst_w * dst_h));
376 skl_plane_max_stride(struct intel_plane *plane,
377 u32 pixel_format, u64 modifier,
378 unsigned int rotation)
380 const struct drm_format_info *info = drm_format_info(pixel_format);
381 int cpp = info->cpp[0];
384 * "The stride in bytes must not exceed the
385 * of the size of 8K pixels and 32K bytes."
387 if (drm_rotation_90_or_270(rotation))
388 return min(8192, 32768 / cpp);
390 return min(8192 * cpp, 32768);
394 skl_program_scaler(struct intel_plane *plane,
395 const struct intel_crtc_state *crtc_state,
396 const struct intel_plane_state *plane_state)
398 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
399 const struct drm_framebuffer *fb = plane_state->hw.fb;
400 enum pipe pipe = plane->pipe;
401 int scaler_id = plane_state->scaler_id;
402 const struct intel_scaler *scaler =
403 &crtc_state->scaler_state.scalers[scaler_id];
404 int crtc_x = plane_state->uapi.dst.x1;
405 int crtc_y = plane_state->uapi.dst.y1;
406 u32 crtc_w = drm_rect_width(&plane_state->uapi.dst);
407 u32 crtc_h = drm_rect_height(&plane_state->uapi.dst);
408 u16 y_hphase, uv_rgb_hphase;
409 u16 y_vphase, uv_rgb_vphase;
412 hscale = drm_rect_calc_hscale(&plane_state->uapi.src,
413 &plane_state->uapi.dst,
415 vscale = drm_rect_calc_vscale(&plane_state->uapi.src,
416 &plane_state->uapi.dst,
419 /* TODO: handle sub-pixel coordinates */
420 if (drm_format_info_is_yuv_semiplanar(fb->format) &&
421 !icl_is_hdr_plane(dev_priv, plane->id)) {
422 y_hphase = skl_scaler_calc_phase(1, hscale, false);
423 y_vphase = skl_scaler_calc_phase(1, vscale, false);
425 /* MPEG2 chroma siting convention */
426 uv_rgb_hphase = skl_scaler_calc_phase(2, hscale, true);
427 uv_rgb_vphase = skl_scaler_calc_phase(2, vscale, false);
433 uv_rgb_hphase = skl_scaler_calc_phase(1, hscale, false);
434 uv_rgb_vphase = skl_scaler_calc_phase(1, vscale, false);
437 I915_WRITE_FW(SKL_PS_CTRL(pipe, scaler_id),
438 PS_SCALER_EN | PS_PLANE_SEL(plane->id) | scaler->mode);
439 I915_WRITE_FW(SKL_PS_VPHASE(pipe, scaler_id),
440 PS_Y_PHASE(y_vphase) | PS_UV_RGB_PHASE(uv_rgb_vphase));
441 I915_WRITE_FW(SKL_PS_HPHASE(pipe, scaler_id),
442 PS_Y_PHASE(y_hphase) | PS_UV_RGB_PHASE(uv_rgb_hphase));
443 I915_WRITE_FW(SKL_PS_WIN_POS(pipe, scaler_id), (crtc_x << 16) | crtc_y);
444 I915_WRITE_FW(SKL_PS_WIN_SZ(pipe, scaler_id), (crtc_w << 16) | crtc_h);
447 /* Preoffset values for YUV to RGB Conversion */
448 #define PREOFF_YUV_TO_RGB_HI 0x1800
449 #define PREOFF_YUV_TO_RGB_ME 0x1F00
450 #define PREOFF_YUV_TO_RGB_LO 0x1800
452 #define ROFF(x) (((x) & 0xffff) << 16)
453 #define GOFF(x) (((x) & 0xffff) << 0)
454 #define BOFF(x) (((x) & 0xffff) << 16)
457 icl_program_input_csc(struct intel_plane *plane,
458 const struct intel_crtc_state *crtc_state,
459 const struct intel_plane_state *plane_state)
461 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
462 enum pipe pipe = plane->pipe;
463 enum plane_id plane_id = plane->id;
465 static const u16 input_csc_matrix[][9] = {
467 * BT.601 full range YCbCr -> full range RGB
468 * The matrix required is :
469 * [1.000, 0.000, 1.371,
470 * 1.000, -0.336, -0.698,
471 * 1.000, 1.732, 0.0000]
473 [DRM_COLOR_YCBCR_BT601] = {
475 0x8B28, 0x7800, 0x9AC0,
479 * BT.709 full range YCbCr -> full range RGB
480 * The matrix required is :
481 * [1.000, 0.000, 1.574,
482 * 1.000, -0.187, -0.468,
483 * 1.000, 1.855, 0.0000]
485 [DRM_COLOR_YCBCR_BT709] = {
487 0x9EF8, 0x7800, 0xAC00,
491 * BT.2020 full range YCbCr -> full range RGB
492 * The matrix required is :
493 * [1.000, 0.000, 1.474,
494 * 1.000, -0.1645, -0.5713,
495 * 1.000, 1.8814, 0.0000]
497 [DRM_COLOR_YCBCR_BT2020] = {
499 0x8928, 0x7800, 0xAA88,
504 /* Matrix for Limited Range to Full Range Conversion */
505 static const u16 input_csc_matrix_lr[][9] = {
507 * BT.601 Limted range YCbCr -> full range RGB
508 * The matrix required is :
509 * [1.164384, 0.000, 1.596027,
510 * 1.164384, -0.39175, -0.812813,
511 * 1.164384, 2.017232, 0.0000]
513 [DRM_COLOR_YCBCR_BT601] = {
515 0x8D00, 0x7950, 0x9C88,
519 * BT.709 Limited range YCbCr -> full range RGB
520 * The matrix required is :
521 * [1.164384, 0.000, 1.792741,
522 * 1.164384, -0.213249, -0.532909,
523 * 1.164384, 2.112402, 0.0000]
525 [DRM_COLOR_YCBCR_BT709] = {
527 0x8888, 0x7950, 0xADA8,
531 * BT.2020 Limited range YCbCr -> full range RGB
532 * The matrix required is :
533 * [1.164, 0.000, 1.678,
534 * 1.164, -0.1873, -0.6504,
535 * 1.164, 2.1417, 0.0000]
537 [DRM_COLOR_YCBCR_BT2020] = {
539 0x8A68, 0x7950, 0xAC00,
545 if (plane_state->hw.color_range == DRM_COLOR_YCBCR_FULL_RANGE)
546 csc = input_csc_matrix[plane_state->hw.color_encoding];
548 csc = input_csc_matrix_lr[plane_state->hw.color_encoding];
550 I915_WRITE_FW(PLANE_INPUT_CSC_COEFF(pipe, plane_id, 0), ROFF(csc[0]) |
552 I915_WRITE_FW(PLANE_INPUT_CSC_COEFF(pipe, plane_id, 1), BOFF(csc[2]));
553 I915_WRITE_FW(PLANE_INPUT_CSC_COEFF(pipe, plane_id, 2), ROFF(csc[3]) |
555 I915_WRITE_FW(PLANE_INPUT_CSC_COEFF(pipe, plane_id, 3), BOFF(csc[5]));
556 I915_WRITE_FW(PLANE_INPUT_CSC_COEFF(pipe, plane_id, 4), ROFF(csc[6]) |
558 I915_WRITE_FW(PLANE_INPUT_CSC_COEFF(pipe, plane_id, 5), BOFF(csc[8]));
560 I915_WRITE_FW(PLANE_INPUT_CSC_PREOFF(pipe, plane_id, 0),
561 PREOFF_YUV_TO_RGB_HI);
562 if (plane_state->hw.color_range == DRM_COLOR_YCBCR_FULL_RANGE)
563 I915_WRITE_FW(PLANE_INPUT_CSC_PREOFF(pipe, plane_id, 1), 0);
565 I915_WRITE_FW(PLANE_INPUT_CSC_PREOFF(pipe, plane_id, 1),
566 PREOFF_YUV_TO_RGB_ME);
567 I915_WRITE_FW(PLANE_INPUT_CSC_PREOFF(pipe, plane_id, 2),
568 PREOFF_YUV_TO_RGB_LO);
569 I915_WRITE_FW(PLANE_INPUT_CSC_POSTOFF(pipe, plane_id, 0), 0x0);
570 I915_WRITE_FW(PLANE_INPUT_CSC_POSTOFF(pipe, plane_id, 1), 0x0);
571 I915_WRITE_FW(PLANE_INPUT_CSC_POSTOFF(pipe, plane_id, 2), 0x0);
575 skl_program_plane(struct intel_plane *plane,
576 const struct intel_crtc_state *crtc_state,
577 const struct intel_plane_state *plane_state,
580 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
581 enum plane_id plane_id = plane->id;
582 enum pipe pipe = plane->pipe;
583 const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
584 u32 surf_addr = plane_state->color_plane[color_plane].offset;
585 u32 stride = skl_plane_stride(plane_state, color_plane);
586 u32 aux_stride = skl_plane_stride(plane_state, 1);
587 int crtc_x = plane_state->uapi.dst.x1;
588 int crtc_y = plane_state->uapi.dst.y1;
589 u32 x = plane_state->color_plane[color_plane].x;
590 u32 y = plane_state->color_plane[color_plane].y;
591 u32 src_w = drm_rect_width(&plane_state->uapi.src) >> 16;
592 u32 src_h = drm_rect_height(&plane_state->uapi.src) >> 16;
593 const struct drm_framebuffer *fb = plane_state->hw.fb;
594 u8 alpha = plane_state->hw.alpha >> 8;
595 u32 plane_color_ctl = 0;
596 unsigned long irqflags;
598 u32 plane_ctl = plane_state->ctl;
600 plane_ctl |= skl_plane_ctl_crtc(crtc_state);
602 if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv))
603 plane_color_ctl = plane_state->color_ctl |
604 glk_plane_color_ctl_crtc(crtc_state);
606 /* Sizes are 0 based */
610 keymax = (key->max_value & 0xffffff) | PLANE_KEYMAX_ALPHA(alpha);
612 keymsk = key->channel_mask & 0x7ffffff;
614 keymsk |= PLANE_KEYMSK_ALPHA_ENABLE;
616 /* The scaler will handle the output position */
617 if (plane_state->scaler_id >= 0) {
622 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
624 I915_WRITE_FW(PLANE_STRIDE(pipe, plane_id), stride);
625 I915_WRITE_FW(PLANE_POS(pipe, plane_id), (crtc_y << 16) | crtc_x);
626 I915_WRITE_FW(PLANE_SIZE(pipe, plane_id), (src_h << 16) | src_w);
627 I915_WRITE_FW(PLANE_AUX_DIST(pipe, plane_id),
628 (plane_state->color_plane[1].offset - surf_addr) | aux_stride);
630 if (icl_is_hdr_plane(dev_priv, plane_id))
631 I915_WRITE_FW(PLANE_CUS_CTL(pipe, plane_id), plane_state->cus_ctl);
633 if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv))
634 I915_WRITE_FW(PLANE_COLOR_CTL(pipe, plane_id), plane_color_ctl);
636 if (fb->format->is_yuv && icl_is_hdr_plane(dev_priv, plane_id))
637 icl_program_input_csc(plane, crtc_state, plane_state);
639 skl_write_plane_wm(plane, crtc_state);
641 I915_WRITE_FW(PLANE_KEYVAL(pipe, plane_id), key->min_value);
642 I915_WRITE_FW(PLANE_KEYMSK(pipe, plane_id), keymsk);
643 I915_WRITE_FW(PLANE_KEYMAX(pipe, plane_id), keymax);
645 I915_WRITE_FW(PLANE_OFFSET(pipe, plane_id), (y << 16) | x);
647 if (INTEL_GEN(dev_priv) < 11)
648 I915_WRITE_FW(PLANE_AUX_OFFSET(pipe, plane_id),
649 (plane_state->color_plane[1].y << 16) |
650 plane_state->color_plane[1].x);
653 * The control register self-arms if the plane was previously
654 * disabled. Try to make the plane enable atomic by writing
655 * the control register just before the surface register.
657 I915_WRITE_FW(PLANE_CTL(pipe, plane_id), plane_ctl);
658 I915_WRITE_FW(PLANE_SURF(pipe, plane_id),
659 intel_plane_ggtt_offset(plane_state) + surf_addr);
661 if (plane_state->scaler_id >= 0)
662 skl_program_scaler(plane, crtc_state, plane_state);
664 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
668 skl_update_plane(struct intel_plane *plane,
669 const struct intel_crtc_state *crtc_state,
670 const struct intel_plane_state *plane_state)
674 if (plane_state->planar_linked_plane && !plane_state->planar_slave)
675 /* Program the UV plane on planar master */
678 skl_program_plane(plane, crtc_state, plane_state, color_plane);
681 skl_disable_plane(struct intel_plane *plane,
682 const struct intel_crtc_state *crtc_state)
684 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
685 enum plane_id plane_id = plane->id;
686 enum pipe pipe = plane->pipe;
687 unsigned long irqflags;
689 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
691 if (icl_is_hdr_plane(dev_priv, plane_id))
692 I915_WRITE_FW(PLANE_CUS_CTL(pipe, plane_id), 0);
694 skl_write_plane_wm(plane, crtc_state);
696 I915_WRITE_FW(PLANE_CTL(pipe, plane_id), 0);
697 I915_WRITE_FW(PLANE_SURF(pipe, plane_id), 0);
699 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
703 skl_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;
709 intel_wakeref_t wakeref;
712 power_domain = POWER_DOMAIN_PIPE(plane->pipe);
713 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
717 ret = I915_READ(PLANE_CTL(plane->pipe, plane_id)) & PLANE_CTL_ENABLE;
721 intel_display_power_put(dev_priv, power_domain, wakeref);
726 static void i9xx_plane_linear_gamma(u16 gamma[8])
728 /* The points are not evenly spaced. */
729 static const u8 in[8] = { 0, 1, 2, 4, 8, 16, 24, 32 };
732 for (i = 0; i < 8; i++)
733 gamma[i] = (in[i] << 8) / 32;
737 chv_update_csc(const struct intel_plane_state *plane_state)
739 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
740 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
741 const struct drm_framebuffer *fb = plane_state->hw.fb;
742 enum plane_id plane_id = plane->id;
744 * |r| | c0 c1 c2 | |cr|
745 * |g| = | c3 c4 c5 | x |y |
746 * |b| | c6 c7 c8 | |cb|
748 * Coefficients are s3.12.
750 * Cb and Cr apparently come in as signed already, and
751 * we always get full range data in on account of CLRC0/1.
753 static const s16 csc_matrix[][9] = {
754 /* BT.601 full range YCbCr -> full range RGB */
755 [DRM_COLOR_YCBCR_BT601] = {
760 /* BT.709 full range YCbCr -> full range RGB */
761 [DRM_COLOR_YCBCR_BT709] = {
767 const s16 *csc = csc_matrix[plane_state->hw.color_encoding];
769 /* Seems RGB data bypasses the CSC always */
770 if (!fb->format->is_yuv)
773 I915_WRITE_FW(SPCSCYGOFF(plane_id), SPCSC_OOFF(0) | SPCSC_IOFF(0));
774 I915_WRITE_FW(SPCSCCBOFF(plane_id), SPCSC_OOFF(0) | SPCSC_IOFF(0));
775 I915_WRITE_FW(SPCSCCROFF(plane_id), SPCSC_OOFF(0) | SPCSC_IOFF(0));
777 I915_WRITE_FW(SPCSCC01(plane_id), SPCSC_C1(csc[1]) | SPCSC_C0(csc[0]));
778 I915_WRITE_FW(SPCSCC23(plane_id), SPCSC_C1(csc[3]) | SPCSC_C0(csc[2]));
779 I915_WRITE_FW(SPCSCC45(plane_id), SPCSC_C1(csc[5]) | SPCSC_C0(csc[4]));
780 I915_WRITE_FW(SPCSCC67(plane_id), SPCSC_C1(csc[7]) | SPCSC_C0(csc[6]));
781 I915_WRITE_FW(SPCSCC8(plane_id), SPCSC_C0(csc[8]));
783 I915_WRITE_FW(SPCSCYGICLAMP(plane_id), SPCSC_IMAX(1023) | SPCSC_IMIN(0));
784 I915_WRITE_FW(SPCSCCBICLAMP(plane_id), SPCSC_IMAX(512) | SPCSC_IMIN(-512));
785 I915_WRITE_FW(SPCSCCRICLAMP(plane_id), SPCSC_IMAX(512) | SPCSC_IMIN(-512));
787 I915_WRITE_FW(SPCSCYGOCLAMP(plane_id), SPCSC_OMAX(1023) | SPCSC_OMIN(0));
788 I915_WRITE_FW(SPCSCCBOCLAMP(plane_id), SPCSC_OMAX(1023) | SPCSC_OMIN(0));
789 I915_WRITE_FW(SPCSCCROCLAMP(plane_id), SPCSC_OMAX(1023) | SPCSC_OMIN(0));
796 vlv_update_clrc(const struct intel_plane_state *plane_state)
798 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
799 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
800 const struct drm_framebuffer *fb = plane_state->hw.fb;
801 enum pipe pipe = plane->pipe;
802 enum plane_id plane_id = plane->id;
803 int contrast, brightness, sh_scale, sh_sin, sh_cos;
805 if (fb->format->is_yuv &&
806 plane_state->hw.color_range == DRM_COLOR_YCBCR_LIMITED_RANGE) {
808 * Expand limited range to full range:
809 * Contrast is applied first and is used to expand Y range.
810 * Brightness is applied second and is used to remove the
811 * offset from Y. Saturation/hue is used to expand CbCr range.
813 contrast = DIV_ROUND_CLOSEST(255 << 6, 235 - 16);
814 brightness = -DIV_ROUND_CLOSEST(16 * 255, 235 - 16);
815 sh_scale = DIV_ROUND_CLOSEST(128 << 7, 240 - 128);
816 sh_sin = SIN_0 * sh_scale;
817 sh_cos = COS_0 * sh_scale;
819 /* Pass-through everything. */
823 sh_sin = SIN_0 * sh_scale;
824 sh_cos = COS_0 * sh_scale;
827 /* FIXME these register are single buffered :( */
828 I915_WRITE_FW(SPCLRC0(pipe, plane_id),
829 SP_CONTRAST(contrast) | SP_BRIGHTNESS(brightness));
830 I915_WRITE_FW(SPCLRC1(pipe, plane_id),
831 SP_SH_SIN(sh_sin) | SP_SH_COS(sh_cos));
835 vlv_plane_ratio(const struct intel_crtc_state *crtc_state,
836 const struct intel_plane_state *plane_state,
837 unsigned int *num, unsigned int *den)
839 u8 active_planes = crtc_state->active_planes & ~BIT(PLANE_CURSOR);
840 const struct drm_framebuffer *fb = plane_state->hw.fb;
841 unsigned int cpp = fb->format->cpp[0];
844 * VLV bspec only considers cases where all three planes are
845 * enabled, and cases where the primary and one sprite is enabled.
846 * Let's assume the case with just two sprites enabled also
847 * maps to the latter case.
849 if (hweight8(active_planes) == 3) {
864 } else if (hweight8(active_planes) == 2) {
893 int vlv_plane_min_cdclk(const struct intel_crtc_state *crtc_state,
894 const struct intel_plane_state *plane_state)
896 unsigned int pixel_rate;
897 unsigned int num, den;
900 * Note that crtc_state->pixel_rate accounts for both
901 * horizontal and vertical panel fitter downscaling factors.
902 * Pre-HSW bspec tells us to only consider the horizontal
903 * downscaling factor here. We ignore that and just consider
904 * both for simplicity.
906 pixel_rate = crtc_state->pixel_rate;
908 vlv_plane_ratio(crtc_state, plane_state, &num, &den);
910 return DIV_ROUND_UP(pixel_rate * num, den);
913 static u32 vlv_sprite_ctl_crtc(const struct intel_crtc_state *crtc_state)
917 if (crtc_state->gamma_enable)
918 sprctl |= SP_GAMMA_ENABLE;
923 static u32 vlv_sprite_ctl(const struct intel_crtc_state *crtc_state,
924 const struct intel_plane_state *plane_state)
926 const struct drm_framebuffer *fb = plane_state->hw.fb;
927 unsigned int rotation = plane_state->hw.rotation;
928 const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
933 switch (fb->format->format) {
934 case DRM_FORMAT_YUYV:
935 sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_YUYV;
937 case DRM_FORMAT_YVYU:
938 sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_YVYU;
940 case DRM_FORMAT_UYVY:
941 sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_UYVY;
943 case DRM_FORMAT_VYUY:
944 sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_VYUY;
947 sprctl |= SP_FORMAT_8BPP;
949 case DRM_FORMAT_RGB565:
950 sprctl |= SP_FORMAT_BGR565;
952 case DRM_FORMAT_XRGB8888:
953 sprctl |= SP_FORMAT_BGRX8888;
955 case DRM_FORMAT_ARGB8888:
956 sprctl |= SP_FORMAT_BGRA8888;
958 case DRM_FORMAT_XBGR2101010:
959 sprctl |= SP_FORMAT_RGBX1010102;
961 case DRM_FORMAT_ABGR2101010:
962 sprctl |= SP_FORMAT_RGBA1010102;
964 case DRM_FORMAT_XRGB2101010:
965 sprctl |= SP_FORMAT_BGRX1010102;
967 case DRM_FORMAT_ARGB2101010:
968 sprctl |= SP_FORMAT_BGRA1010102;
970 case DRM_FORMAT_XBGR8888:
971 sprctl |= SP_FORMAT_RGBX8888;
973 case DRM_FORMAT_ABGR8888:
974 sprctl |= SP_FORMAT_RGBA8888;
977 MISSING_CASE(fb->format->format);
981 if (plane_state->hw.color_encoding == DRM_COLOR_YCBCR_BT709)
982 sprctl |= SP_YUV_FORMAT_BT709;
984 if (fb->modifier == I915_FORMAT_MOD_X_TILED)
987 if (rotation & DRM_MODE_ROTATE_180)
988 sprctl |= SP_ROTATE_180;
990 if (rotation & DRM_MODE_REFLECT_X)
993 if (key->flags & I915_SET_COLORKEY_SOURCE)
994 sprctl |= SP_SOURCE_KEY;
999 static void vlv_update_gamma(const struct intel_plane_state *plane_state)
1001 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
1002 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
1003 const struct drm_framebuffer *fb = plane_state->hw.fb;
1004 enum pipe pipe = plane->pipe;
1005 enum plane_id plane_id = plane->id;
1009 /* Seems RGB data bypasses the gamma always */
1010 if (!fb->format->is_yuv)
1013 i9xx_plane_linear_gamma(gamma);
1015 /* FIXME these register are single buffered :( */
1016 /* The two end points are implicit (0.0 and 1.0) */
1017 for (i = 1; i < 8 - 1; i++)
1018 I915_WRITE_FW(SPGAMC(pipe, plane_id, i - 1),
1025 vlv_update_plane(struct intel_plane *plane,
1026 const struct intel_crtc_state *crtc_state,
1027 const struct intel_plane_state *plane_state)
1029 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
1030 enum pipe pipe = plane->pipe;
1031 enum plane_id plane_id = plane->id;
1032 u32 sprsurf_offset = plane_state->color_plane[0].offset;
1034 const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
1035 int crtc_x = plane_state->uapi.dst.x1;
1036 int crtc_y = plane_state->uapi.dst.y1;
1037 u32 crtc_w = drm_rect_width(&plane_state->uapi.dst);
1038 u32 crtc_h = drm_rect_height(&plane_state->uapi.dst);
1039 u32 x = plane_state->color_plane[0].x;
1040 u32 y = plane_state->color_plane[0].y;
1041 unsigned long irqflags;
1044 sprctl = plane_state->ctl | vlv_sprite_ctl_crtc(crtc_state);
1046 /* Sizes are 0 based */
1050 linear_offset = intel_fb_xy_to_linear(x, y, plane_state, 0);
1052 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
1054 I915_WRITE_FW(SPSTRIDE(pipe, plane_id),
1055 plane_state->color_plane[0].stride);
1056 I915_WRITE_FW(SPPOS(pipe, plane_id), (crtc_y << 16) | crtc_x);
1057 I915_WRITE_FW(SPSIZE(pipe, plane_id), (crtc_h << 16) | crtc_w);
1058 I915_WRITE_FW(SPCONSTALPHA(pipe, plane_id), 0);
1060 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B)
1061 chv_update_csc(plane_state);
1064 I915_WRITE_FW(SPKEYMINVAL(pipe, plane_id), key->min_value);
1065 I915_WRITE_FW(SPKEYMSK(pipe, plane_id), key->channel_mask);
1066 I915_WRITE_FW(SPKEYMAXVAL(pipe, plane_id), key->max_value);
1069 I915_WRITE_FW(SPLINOFF(pipe, plane_id), linear_offset);
1070 I915_WRITE_FW(SPTILEOFF(pipe, plane_id), (y << 16) | x);
1073 * The control register self-arms if the plane was previously
1074 * disabled. Try to make the plane enable atomic by writing
1075 * the control register just before the surface register.
1077 I915_WRITE_FW(SPCNTR(pipe, plane_id), sprctl);
1078 I915_WRITE_FW(SPSURF(pipe, plane_id),
1079 intel_plane_ggtt_offset(plane_state) + sprsurf_offset);
1081 vlv_update_clrc(plane_state);
1082 vlv_update_gamma(plane_state);
1084 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
1088 vlv_disable_plane(struct intel_plane *plane,
1089 const struct intel_crtc_state *crtc_state)
1091 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
1092 enum pipe pipe = plane->pipe;
1093 enum plane_id plane_id = plane->id;
1094 unsigned long irqflags;
1096 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
1098 I915_WRITE_FW(SPCNTR(pipe, plane_id), 0);
1099 I915_WRITE_FW(SPSURF(pipe, plane_id), 0);
1101 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
1105 vlv_plane_get_hw_state(struct intel_plane *plane,
1108 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
1109 enum intel_display_power_domain power_domain;
1110 enum plane_id plane_id = plane->id;
1111 intel_wakeref_t wakeref;
1114 power_domain = POWER_DOMAIN_PIPE(plane->pipe);
1115 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
1119 ret = I915_READ(SPCNTR(plane->pipe, plane_id)) & SP_ENABLE;
1121 *pipe = plane->pipe;
1123 intel_display_power_put(dev_priv, power_domain, wakeref);
1128 static void ivb_plane_ratio(const struct intel_crtc_state *crtc_state,
1129 const struct intel_plane_state *plane_state,
1130 unsigned int *num, unsigned int *den)
1132 u8 active_planes = crtc_state->active_planes & ~BIT(PLANE_CURSOR);
1133 const struct drm_framebuffer *fb = plane_state->hw.fb;
1134 unsigned int cpp = fb->format->cpp[0];
1136 if (hweight8(active_planes) == 2) {
1165 static void ivb_plane_ratio_scaling(const struct intel_crtc_state *crtc_state,
1166 const struct intel_plane_state *plane_state,
1167 unsigned int *num, unsigned int *den)
1169 const struct drm_framebuffer *fb = plane_state->hw.fb;
1170 unsigned int cpp = fb->format->cpp[0];
1192 int ivb_plane_min_cdclk(const struct intel_crtc_state *crtc_state,
1193 const struct intel_plane_state *plane_state)
1195 unsigned int pixel_rate;
1196 unsigned int num, den;
1199 * Note that crtc_state->pixel_rate accounts for both
1200 * horizontal and vertical panel fitter downscaling factors.
1201 * Pre-HSW bspec tells us to only consider the horizontal
1202 * downscaling factor here. We ignore that and just consider
1203 * both for simplicity.
1205 pixel_rate = crtc_state->pixel_rate;
1207 ivb_plane_ratio(crtc_state, plane_state, &num, &den);
1209 return DIV_ROUND_UP(pixel_rate * num, den);
1212 static int ivb_sprite_min_cdclk(const struct intel_crtc_state *crtc_state,
1213 const struct intel_plane_state *plane_state)
1215 unsigned int src_w, dst_w, pixel_rate;
1216 unsigned int num, den;
1219 * Note that crtc_state->pixel_rate accounts for both
1220 * horizontal and vertical panel fitter downscaling factors.
1221 * Pre-HSW bspec tells us to only consider the horizontal
1222 * downscaling factor here. We ignore that and just consider
1223 * both for simplicity.
1225 pixel_rate = crtc_state->pixel_rate;
1227 src_w = drm_rect_width(&plane_state->uapi.src) >> 16;
1228 dst_w = drm_rect_width(&plane_state->uapi.dst);
1231 ivb_plane_ratio_scaling(crtc_state, plane_state, &num, &den);
1233 ivb_plane_ratio(crtc_state, plane_state, &num, &den);
1235 /* Horizontal downscaling limits the maximum pixel rate */
1236 dst_w = min(src_w, dst_w);
1238 return DIV_ROUND_UP_ULL(mul_u32_u32(pixel_rate, num * src_w),
1242 static void hsw_plane_ratio(const struct intel_crtc_state *crtc_state,
1243 const struct intel_plane_state *plane_state,
1244 unsigned int *num, unsigned int *den)
1246 u8 active_planes = crtc_state->active_planes & ~BIT(PLANE_CURSOR);
1247 const struct drm_framebuffer *fb = plane_state->hw.fb;
1248 unsigned int cpp = fb->format->cpp[0];
1250 if (hweight8(active_planes) == 2) {
1275 int hsw_plane_min_cdclk(const struct intel_crtc_state *crtc_state,
1276 const struct intel_plane_state *plane_state)
1278 unsigned int pixel_rate = crtc_state->pixel_rate;
1279 unsigned int num, den;
1281 hsw_plane_ratio(crtc_state, plane_state, &num, &den);
1283 return DIV_ROUND_UP(pixel_rate * num, den);
1286 static u32 ivb_sprite_ctl_crtc(const struct intel_crtc_state *crtc_state)
1290 if (crtc_state->gamma_enable)
1291 sprctl |= SPRITE_GAMMA_ENABLE;
1293 if (crtc_state->csc_enable)
1294 sprctl |= SPRITE_PIPE_CSC_ENABLE;
1299 static bool ivb_need_sprite_gamma(const struct intel_plane_state *plane_state)
1301 struct drm_i915_private *dev_priv =
1302 to_i915(plane_state->uapi.plane->dev);
1303 const struct drm_framebuffer *fb = plane_state->hw.fb;
1305 return fb->format->cpp[0] == 8 &&
1306 (IS_IVYBRIDGE(dev_priv) || IS_HASWELL(dev_priv));
1309 static u32 ivb_sprite_ctl(const struct intel_crtc_state *crtc_state,
1310 const struct intel_plane_state *plane_state)
1312 struct drm_i915_private *dev_priv =
1313 to_i915(plane_state->uapi.plane->dev);
1314 const struct drm_framebuffer *fb = plane_state->hw.fb;
1315 unsigned int rotation = plane_state->hw.rotation;
1316 const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
1319 sprctl = SPRITE_ENABLE;
1321 if (IS_IVYBRIDGE(dev_priv))
1322 sprctl |= SPRITE_TRICKLE_FEED_DISABLE;
1324 switch (fb->format->format) {
1325 case DRM_FORMAT_XBGR8888:
1326 sprctl |= SPRITE_FORMAT_RGBX888 | SPRITE_RGB_ORDER_RGBX;
1328 case DRM_FORMAT_XRGB8888:
1329 sprctl |= SPRITE_FORMAT_RGBX888;
1331 case DRM_FORMAT_XBGR2101010:
1332 sprctl |= SPRITE_FORMAT_RGBX101010 | SPRITE_RGB_ORDER_RGBX;
1334 case DRM_FORMAT_XRGB2101010:
1335 sprctl |= SPRITE_FORMAT_RGBX101010;
1337 case DRM_FORMAT_XBGR16161616F:
1338 sprctl |= SPRITE_FORMAT_RGBX161616 | SPRITE_RGB_ORDER_RGBX;
1340 case DRM_FORMAT_XRGB16161616F:
1341 sprctl |= SPRITE_FORMAT_RGBX161616;
1343 case DRM_FORMAT_YUYV:
1344 sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_YUYV;
1346 case DRM_FORMAT_YVYU:
1347 sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_YVYU;
1349 case DRM_FORMAT_UYVY:
1350 sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_UYVY;
1352 case DRM_FORMAT_VYUY:
1353 sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_VYUY;
1356 MISSING_CASE(fb->format->format);
1360 if (!ivb_need_sprite_gamma(plane_state))
1361 sprctl |= SPRITE_INT_GAMMA_DISABLE;
1363 if (plane_state->hw.color_encoding == DRM_COLOR_YCBCR_BT709)
1364 sprctl |= SPRITE_YUV_TO_RGB_CSC_FORMAT_BT709;
1366 if (plane_state->hw.color_range == DRM_COLOR_YCBCR_FULL_RANGE)
1367 sprctl |= SPRITE_YUV_RANGE_CORRECTION_DISABLE;
1369 if (fb->modifier == I915_FORMAT_MOD_X_TILED)
1370 sprctl |= SPRITE_TILED;
1372 if (rotation & DRM_MODE_ROTATE_180)
1373 sprctl |= SPRITE_ROTATE_180;
1375 if (key->flags & I915_SET_COLORKEY_DESTINATION)
1376 sprctl |= SPRITE_DEST_KEY;
1377 else if (key->flags & I915_SET_COLORKEY_SOURCE)
1378 sprctl |= SPRITE_SOURCE_KEY;
1383 static void ivb_sprite_linear_gamma(const struct intel_plane_state *plane_state,
1389 * WaFP16GammaEnabling:ivb,hsw
1390 * "Workaround : When using the 64-bit format, the sprite output
1391 * on each color channel has one quarter amplitude. It can be
1392 * brought up to full amplitude by using sprite internal gamma
1393 * correction, pipe gamma correction, or pipe color space
1394 * conversion to multiply the sprite output by four."
1398 for (i = 0; i < 16; i++)
1399 gamma[i] = min((scale * i << 10) / 16, (1 << 10) - 1);
1401 gamma[i] = min((scale * i << 10) / 16, 1 << 10);
1408 static void ivb_update_gamma(const struct intel_plane_state *plane_state)
1410 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
1411 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
1412 enum pipe pipe = plane->pipe;
1416 if (!ivb_need_sprite_gamma(plane_state))
1419 ivb_sprite_linear_gamma(plane_state, gamma);
1421 /* FIXME these register are single buffered :( */
1422 for (i = 0; i < 16; i++)
1423 I915_WRITE_FW(SPRGAMC(pipe, i),
1428 I915_WRITE_FW(SPRGAMC16(pipe, 0), gamma[i]);
1429 I915_WRITE_FW(SPRGAMC16(pipe, 1), gamma[i]);
1430 I915_WRITE_FW(SPRGAMC16(pipe, 2), gamma[i]);
1433 I915_WRITE_FW(SPRGAMC17(pipe, 0), gamma[i]);
1434 I915_WRITE_FW(SPRGAMC17(pipe, 1), gamma[i]);
1435 I915_WRITE_FW(SPRGAMC17(pipe, 2), gamma[i]);
1440 ivb_update_plane(struct intel_plane *plane,
1441 const struct intel_crtc_state *crtc_state,
1442 const struct intel_plane_state *plane_state)
1444 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
1445 enum pipe pipe = plane->pipe;
1446 u32 sprsurf_offset = plane_state->color_plane[0].offset;
1448 const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
1449 int crtc_x = plane_state->uapi.dst.x1;
1450 int crtc_y = plane_state->uapi.dst.y1;
1451 u32 crtc_w = drm_rect_width(&plane_state->uapi.dst);
1452 u32 crtc_h = drm_rect_height(&plane_state->uapi.dst);
1453 u32 x = plane_state->color_plane[0].x;
1454 u32 y = plane_state->color_plane[0].y;
1455 u32 src_w = drm_rect_width(&plane_state->uapi.src) >> 16;
1456 u32 src_h = drm_rect_height(&plane_state->uapi.src) >> 16;
1457 u32 sprctl, sprscale = 0;
1458 unsigned long irqflags;
1460 sprctl = plane_state->ctl | ivb_sprite_ctl_crtc(crtc_state);
1462 /* Sizes are 0 based */
1468 if (crtc_w != src_w || crtc_h != src_h)
1469 sprscale = SPRITE_SCALE_ENABLE | (src_w << 16) | src_h;
1471 linear_offset = intel_fb_xy_to_linear(x, y, plane_state, 0);
1473 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
1475 I915_WRITE_FW(SPRSTRIDE(pipe), plane_state->color_plane[0].stride);
1476 I915_WRITE_FW(SPRPOS(pipe), (crtc_y << 16) | crtc_x);
1477 I915_WRITE_FW(SPRSIZE(pipe), (crtc_h << 16) | crtc_w);
1478 if (IS_IVYBRIDGE(dev_priv))
1479 I915_WRITE_FW(SPRSCALE(pipe), sprscale);
1482 I915_WRITE_FW(SPRKEYVAL(pipe), key->min_value);
1483 I915_WRITE_FW(SPRKEYMSK(pipe), key->channel_mask);
1484 I915_WRITE_FW(SPRKEYMAX(pipe), key->max_value);
1487 /* HSW consolidates SPRTILEOFF and SPRLINOFF into a single SPROFFSET
1489 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
1490 I915_WRITE_FW(SPROFFSET(pipe), (y << 16) | x);
1492 I915_WRITE_FW(SPRLINOFF(pipe), linear_offset);
1493 I915_WRITE_FW(SPRTILEOFF(pipe), (y << 16) | x);
1497 * The control register self-arms if the plane was previously
1498 * disabled. Try to make the plane enable atomic by writing
1499 * the control register just before the surface register.
1501 I915_WRITE_FW(SPRCTL(pipe), sprctl);
1502 I915_WRITE_FW(SPRSURF(pipe),
1503 intel_plane_ggtt_offset(plane_state) + sprsurf_offset);
1505 ivb_update_gamma(plane_state);
1507 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
1511 ivb_disable_plane(struct intel_plane *plane,
1512 const struct intel_crtc_state *crtc_state)
1514 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
1515 enum pipe pipe = plane->pipe;
1516 unsigned long irqflags;
1518 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
1520 I915_WRITE_FW(SPRCTL(pipe), 0);
1521 /* Disable the scaler */
1522 if (IS_IVYBRIDGE(dev_priv))
1523 I915_WRITE_FW(SPRSCALE(pipe), 0);
1524 I915_WRITE_FW(SPRSURF(pipe), 0);
1526 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
1530 ivb_plane_get_hw_state(struct intel_plane *plane,
1533 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
1534 enum intel_display_power_domain power_domain;
1535 intel_wakeref_t wakeref;
1538 power_domain = POWER_DOMAIN_PIPE(plane->pipe);
1539 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
1543 ret = I915_READ(SPRCTL(plane->pipe)) & SPRITE_ENABLE;
1545 *pipe = plane->pipe;
1547 intel_display_power_put(dev_priv, power_domain, wakeref);
1552 static int g4x_sprite_min_cdclk(const struct intel_crtc_state *crtc_state,
1553 const struct intel_plane_state *plane_state)
1555 const struct drm_framebuffer *fb = plane_state->hw.fb;
1556 unsigned int hscale, pixel_rate;
1557 unsigned int limit, decimate;
1560 * Note that crtc_state->pixel_rate accounts for both
1561 * horizontal and vertical panel fitter downscaling factors.
1562 * Pre-HSW bspec tells us to only consider the horizontal
1563 * downscaling factor here. We ignore that and just consider
1564 * both for simplicity.
1566 pixel_rate = crtc_state->pixel_rate;
1568 /* Horizontal downscaling limits the maximum pixel rate */
1569 hscale = drm_rect_calc_hscale(&plane_state->uapi.src,
1570 &plane_state->uapi.dst,
1572 if (hscale < 0x10000)
1575 /* Decimation steps at 2x,4x,8x,16x */
1576 decimate = ilog2(hscale >> 16);
1577 hscale >>= decimate;
1579 /* Starting limit is 90% of cdclk */
1582 /* -10% per decimation step */
1586 if (fb->format->cpp[0] >= 4)
1587 limit--; /* -10% for RGB */
1590 * We should also do -10% if sprite scaling is enabled
1591 * on the other pipe, but we can't really check for that,
1595 return DIV_ROUND_UP_ULL(mul_u32_u32(pixel_rate, 10 * hscale),
1600 g4x_sprite_max_stride(struct intel_plane *plane,
1601 u32 pixel_format, u64 modifier,
1602 unsigned int rotation)
1607 static u32 g4x_sprite_ctl_crtc(const struct intel_crtc_state *crtc_state)
1611 if (crtc_state->gamma_enable)
1612 dvscntr |= DVS_GAMMA_ENABLE;
1614 if (crtc_state->csc_enable)
1615 dvscntr |= DVS_PIPE_CSC_ENABLE;
1620 static u32 g4x_sprite_ctl(const struct intel_crtc_state *crtc_state,
1621 const struct intel_plane_state *plane_state)
1623 struct drm_i915_private *dev_priv =
1624 to_i915(plane_state->uapi.plane->dev);
1625 const struct drm_framebuffer *fb = plane_state->hw.fb;
1626 unsigned int rotation = plane_state->hw.rotation;
1627 const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
1630 dvscntr = DVS_ENABLE;
1632 if (IS_GEN(dev_priv, 6))
1633 dvscntr |= DVS_TRICKLE_FEED_DISABLE;
1635 switch (fb->format->format) {
1636 case DRM_FORMAT_XBGR8888:
1637 dvscntr |= DVS_FORMAT_RGBX888 | DVS_RGB_ORDER_XBGR;
1639 case DRM_FORMAT_XRGB8888:
1640 dvscntr |= DVS_FORMAT_RGBX888;
1642 case DRM_FORMAT_XBGR2101010:
1643 dvscntr |= DVS_FORMAT_RGBX101010 | DVS_RGB_ORDER_XBGR;
1645 case DRM_FORMAT_XRGB2101010:
1646 dvscntr |= DVS_FORMAT_RGBX101010;
1648 case DRM_FORMAT_XBGR16161616F:
1649 dvscntr |= DVS_FORMAT_RGBX161616 | DVS_RGB_ORDER_XBGR;
1651 case DRM_FORMAT_XRGB16161616F:
1652 dvscntr |= DVS_FORMAT_RGBX161616;
1654 case DRM_FORMAT_YUYV:
1655 dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_YUYV;
1657 case DRM_FORMAT_YVYU:
1658 dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_YVYU;
1660 case DRM_FORMAT_UYVY:
1661 dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_UYVY;
1663 case DRM_FORMAT_VYUY:
1664 dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_VYUY;
1667 MISSING_CASE(fb->format->format);
1671 if (plane_state->hw.color_encoding == DRM_COLOR_YCBCR_BT709)
1672 dvscntr |= DVS_YUV_FORMAT_BT709;
1674 if (plane_state->hw.color_range == DRM_COLOR_YCBCR_FULL_RANGE)
1675 dvscntr |= DVS_YUV_RANGE_CORRECTION_DISABLE;
1677 if (fb->modifier == I915_FORMAT_MOD_X_TILED)
1678 dvscntr |= DVS_TILED;
1680 if (rotation & DRM_MODE_ROTATE_180)
1681 dvscntr |= DVS_ROTATE_180;
1683 if (key->flags & I915_SET_COLORKEY_DESTINATION)
1684 dvscntr |= DVS_DEST_KEY;
1685 else if (key->flags & I915_SET_COLORKEY_SOURCE)
1686 dvscntr |= DVS_SOURCE_KEY;
1691 static void g4x_update_gamma(const struct intel_plane_state *plane_state)
1693 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
1694 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
1695 const struct drm_framebuffer *fb = plane_state->hw.fb;
1696 enum pipe pipe = plane->pipe;
1700 /* Seems RGB data bypasses the gamma always */
1701 if (!fb->format->is_yuv)
1704 i9xx_plane_linear_gamma(gamma);
1706 /* FIXME these register are single buffered :( */
1707 /* The two end points are implicit (0.0 and 1.0) */
1708 for (i = 1; i < 8 - 1; i++)
1709 I915_WRITE_FW(DVSGAMC_G4X(pipe, i - 1),
1715 static void ilk_sprite_linear_gamma(u16 gamma[17])
1719 for (i = 0; i < 17; i++)
1720 gamma[i] = (i << 10) / 16;
1723 static void ilk_update_gamma(const struct intel_plane_state *plane_state)
1725 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
1726 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
1727 const struct drm_framebuffer *fb = plane_state->hw.fb;
1728 enum pipe pipe = plane->pipe;
1732 /* Seems RGB data bypasses the gamma always */
1733 if (!fb->format->is_yuv)
1736 ilk_sprite_linear_gamma(gamma);
1738 /* FIXME these register are single buffered :( */
1739 for (i = 0; i < 16; i++)
1740 I915_WRITE_FW(DVSGAMC_ILK(pipe, i),
1745 I915_WRITE_FW(DVSGAMCMAX_ILK(pipe, 0), gamma[i]);
1746 I915_WRITE_FW(DVSGAMCMAX_ILK(pipe, 1), gamma[i]);
1747 I915_WRITE_FW(DVSGAMCMAX_ILK(pipe, 2), gamma[i]);
1752 g4x_update_plane(struct intel_plane *plane,
1753 const struct intel_crtc_state *crtc_state,
1754 const struct intel_plane_state *plane_state)
1756 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
1757 enum pipe pipe = plane->pipe;
1758 u32 dvssurf_offset = plane_state->color_plane[0].offset;
1760 const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
1761 int crtc_x = plane_state->uapi.dst.x1;
1762 int crtc_y = plane_state->uapi.dst.y1;
1763 u32 crtc_w = drm_rect_width(&plane_state->uapi.dst);
1764 u32 crtc_h = drm_rect_height(&plane_state->uapi.dst);
1765 u32 x = plane_state->color_plane[0].x;
1766 u32 y = plane_state->color_plane[0].y;
1767 u32 src_w = drm_rect_width(&plane_state->uapi.src) >> 16;
1768 u32 src_h = drm_rect_height(&plane_state->uapi.src) >> 16;
1769 u32 dvscntr, dvsscale = 0;
1770 unsigned long irqflags;
1772 dvscntr = plane_state->ctl | g4x_sprite_ctl_crtc(crtc_state);
1774 /* Sizes are 0 based */
1780 if (crtc_w != src_w || crtc_h != src_h)
1781 dvsscale = DVS_SCALE_ENABLE | (src_w << 16) | src_h;
1783 linear_offset = intel_fb_xy_to_linear(x, y, plane_state, 0);
1785 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
1787 I915_WRITE_FW(DVSSTRIDE(pipe), plane_state->color_plane[0].stride);
1788 I915_WRITE_FW(DVSPOS(pipe), (crtc_y << 16) | crtc_x);
1789 I915_WRITE_FW(DVSSIZE(pipe), (crtc_h << 16) | crtc_w);
1790 I915_WRITE_FW(DVSSCALE(pipe), dvsscale);
1793 I915_WRITE_FW(DVSKEYVAL(pipe), key->min_value);
1794 I915_WRITE_FW(DVSKEYMSK(pipe), key->channel_mask);
1795 I915_WRITE_FW(DVSKEYMAX(pipe), key->max_value);
1798 I915_WRITE_FW(DVSLINOFF(pipe), linear_offset);
1799 I915_WRITE_FW(DVSTILEOFF(pipe), (y << 16) | x);
1802 * The control register self-arms if the plane was previously
1803 * disabled. Try to make the plane enable atomic by writing
1804 * the control register just before the surface register.
1806 I915_WRITE_FW(DVSCNTR(pipe), dvscntr);
1807 I915_WRITE_FW(DVSSURF(pipe),
1808 intel_plane_ggtt_offset(plane_state) + dvssurf_offset);
1810 if (IS_G4X(dev_priv))
1811 g4x_update_gamma(plane_state);
1813 ilk_update_gamma(plane_state);
1815 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
1819 g4x_disable_plane(struct intel_plane *plane,
1820 const struct intel_crtc_state *crtc_state)
1822 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
1823 enum pipe pipe = plane->pipe;
1824 unsigned long irqflags;
1826 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
1828 I915_WRITE_FW(DVSCNTR(pipe), 0);
1829 /* Disable the scaler */
1830 I915_WRITE_FW(DVSSCALE(pipe), 0);
1831 I915_WRITE_FW(DVSSURF(pipe), 0);
1833 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
1837 g4x_plane_get_hw_state(struct intel_plane *plane,
1840 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
1841 enum intel_display_power_domain power_domain;
1842 intel_wakeref_t wakeref;
1845 power_domain = POWER_DOMAIN_PIPE(plane->pipe);
1846 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
1850 ret = I915_READ(DVSCNTR(plane->pipe)) & DVS_ENABLE;
1852 *pipe = plane->pipe;
1854 intel_display_power_put(dev_priv, power_domain, wakeref);
1859 static bool intel_fb_scalable(const struct drm_framebuffer *fb)
1864 switch (fb->format->format) {
1867 case DRM_FORMAT_XRGB16161616F:
1868 case DRM_FORMAT_ARGB16161616F:
1869 case DRM_FORMAT_XBGR16161616F:
1870 case DRM_FORMAT_ABGR16161616F:
1871 return INTEL_GEN(to_i915(fb->dev)) >= 11;
1878 g4x_sprite_check_scaling(struct intel_crtc_state *crtc_state,
1879 struct intel_plane_state *plane_state)
1881 const struct drm_framebuffer *fb = plane_state->hw.fb;
1882 const struct drm_rect *src = &plane_state->uapi.src;
1883 const struct drm_rect *dst = &plane_state->uapi.dst;
1884 int src_x, src_w, src_h, crtc_w, crtc_h;
1885 const struct drm_display_mode *adjusted_mode =
1886 &crtc_state->hw.adjusted_mode;
1887 unsigned int stride = plane_state->color_plane[0].stride;
1888 unsigned int cpp = fb->format->cpp[0];
1889 unsigned int width_bytes;
1890 int min_width, min_height;
1892 crtc_w = drm_rect_width(dst);
1893 crtc_h = drm_rect_height(dst);
1895 src_x = src->x1 >> 16;
1896 src_w = drm_rect_width(src) >> 16;
1897 src_h = drm_rect_height(src) >> 16;
1899 if (src_w == crtc_w && src_h == crtc_h)
1904 if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
1906 DRM_DEBUG_KMS("Source height must be even with interlaced modes\n");
1914 width_bytes = ((src_x * cpp) & 63) + src_w * cpp;
1916 if (src_w < min_width || src_h < min_height ||
1917 src_w > 2048 || src_h > 2048) {
1918 DRM_DEBUG_KMS("Source dimensions (%dx%d) exceed hardware limits (%dx%d - %dx%d)\n",
1919 src_w, src_h, min_width, min_height, 2048, 2048);
1923 if (width_bytes > 4096) {
1924 DRM_DEBUG_KMS("Fetch width (%d) exceeds hardware max with scaling (%u)\n",
1929 if (stride > 4096) {
1930 DRM_DEBUG_KMS("Stride (%u) exceeds hardware max with scaling (%u)\n",
1939 g4x_sprite_check(struct intel_crtc_state *crtc_state,
1940 struct intel_plane_state *plane_state)
1942 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
1943 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
1944 int min_scale = DRM_PLANE_HELPER_NO_SCALING;
1945 int max_scale = DRM_PLANE_HELPER_NO_SCALING;
1948 if (intel_fb_scalable(plane_state->hw.fb)) {
1949 if (INTEL_GEN(dev_priv) < 7) {
1951 max_scale = 16 << 16;
1952 } else if (IS_IVYBRIDGE(dev_priv)) {
1954 max_scale = 2 << 16;
1958 ret = drm_atomic_helper_check_plane_state(&plane_state->uapi,
1960 min_scale, max_scale,
1965 ret = i9xx_check_plane_surface(plane_state);
1969 if (!plane_state->uapi.visible)
1972 ret = intel_plane_check_src_coordinates(plane_state);
1976 ret = g4x_sprite_check_scaling(crtc_state, plane_state);
1980 if (INTEL_GEN(dev_priv) >= 7)
1981 plane_state->ctl = ivb_sprite_ctl(crtc_state, plane_state);
1983 plane_state->ctl = g4x_sprite_ctl(crtc_state, plane_state);
1988 int chv_plane_check_rotation(const struct intel_plane_state *plane_state)
1990 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
1991 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
1992 unsigned int rotation = plane_state->hw.rotation;
1994 /* CHV ignores the mirror bit when the rotate bit is set :( */
1995 if (IS_CHERRYVIEW(dev_priv) &&
1996 rotation & DRM_MODE_ROTATE_180 &&
1997 rotation & DRM_MODE_REFLECT_X) {
1998 DRM_DEBUG_KMS("Cannot rotate and reflect at the same time\n");
2006 vlv_sprite_check(struct intel_crtc_state *crtc_state,
2007 struct intel_plane_state *plane_state)
2011 ret = chv_plane_check_rotation(plane_state);
2015 ret = drm_atomic_helper_check_plane_state(&plane_state->uapi,
2017 DRM_PLANE_HELPER_NO_SCALING,
2018 DRM_PLANE_HELPER_NO_SCALING,
2023 ret = i9xx_check_plane_surface(plane_state);
2027 if (!plane_state->uapi.visible)
2030 ret = intel_plane_check_src_coordinates(plane_state);
2034 plane_state->ctl = vlv_sprite_ctl(crtc_state, plane_state);
2039 static int skl_plane_check_fb(const struct intel_crtc_state *crtc_state,
2040 const struct intel_plane_state *plane_state)
2042 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
2043 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
2044 const struct drm_framebuffer *fb = plane_state->hw.fb;
2045 unsigned int rotation = plane_state->hw.rotation;
2046 struct drm_format_name_buf format_name;
2051 if (rotation & ~(DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180) &&
2052 is_ccs_modifier(fb->modifier)) {
2053 DRM_DEBUG_KMS("RC support only with 0/180 degree rotation (%x)\n",
2058 if (rotation & DRM_MODE_REFLECT_X &&
2059 fb->modifier == DRM_FORMAT_MOD_LINEAR) {
2060 DRM_DEBUG_KMS("horizontal flip is not supported with linear surface formats\n");
2064 if (drm_rotation_90_or_270(rotation)) {
2065 if (fb->modifier != I915_FORMAT_MOD_Y_TILED &&
2066 fb->modifier != I915_FORMAT_MOD_Yf_TILED) {
2067 DRM_DEBUG_KMS("Y/Yf tiling required for 90/270!\n");
2072 * 90/270 is not allowed with RGB64 16:16:16:16 and
2073 * Indexed 8-bit. RGB 16-bit 5:6:5 is allowed gen11 onwards.
2075 switch (fb->format->format) {
2076 case DRM_FORMAT_RGB565:
2077 if (INTEL_GEN(dev_priv) >= 11)
2081 case DRM_FORMAT_XRGB16161616F:
2082 case DRM_FORMAT_XBGR16161616F:
2083 case DRM_FORMAT_ARGB16161616F:
2084 case DRM_FORMAT_ABGR16161616F:
2085 case DRM_FORMAT_Y210:
2086 case DRM_FORMAT_Y212:
2087 case DRM_FORMAT_Y216:
2088 case DRM_FORMAT_XVYU12_16161616:
2089 case DRM_FORMAT_XVYU16161616:
2090 DRM_DEBUG_KMS("Unsupported pixel format %s for 90/270!\n",
2091 drm_get_format_name(fb->format->format,
2099 /* Y-tiling is not supported in IF-ID Interlace mode */
2100 if (crtc_state->hw.enable &&
2101 crtc_state->hw.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE &&
2102 (fb->modifier == I915_FORMAT_MOD_Y_TILED ||
2103 fb->modifier == I915_FORMAT_MOD_Yf_TILED ||
2104 fb->modifier == I915_FORMAT_MOD_Y_TILED_CCS ||
2105 fb->modifier == I915_FORMAT_MOD_Yf_TILED_CCS)) {
2106 DRM_DEBUG_KMS("Y/Yf tiling not supported in IF-ID mode\n");
2113 static int skl_plane_check_dst_coordinates(const struct intel_crtc_state *crtc_state,
2114 const struct intel_plane_state *plane_state)
2116 struct drm_i915_private *dev_priv =
2117 to_i915(plane_state->uapi.plane->dev);
2118 int crtc_x = plane_state->uapi.dst.x1;
2119 int crtc_w = drm_rect_width(&plane_state->uapi.dst);
2120 int pipe_src_w = crtc_state->pipe_src_w;
2123 * Display WA #1175: cnl,glk
2124 * Planes other than the cursor may cause FIFO underflow and display
2125 * corruption if starting less than 4 pixels from the right edge of
2127 * Besides the above WA fix the similar problem, where planes other
2128 * than the cursor ending less than 4 pixels from the left edge of the
2129 * screen may cause FIFO underflow and display corruption.
2131 if ((IS_GEMINILAKE(dev_priv) || IS_CANNONLAKE(dev_priv)) &&
2132 (crtc_x + crtc_w < 4 || crtc_x > pipe_src_w - 4)) {
2133 DRM_DEBUG_KMS("requested plane X %s position %d invalid (valid range %d-%d)\n",
2134 crtc_x + crtc_w < 4 ? "end" : "start",
2135 crtc_x + crtc_w < 4 ? crtc_x + crtc_w : crtc_x,
2143 static int skl_plane_check_nv12_rotation(const struct intel_plane_state *plane_state)
2145 const struct drm_framebuffer *fb = plane_state->hw.fb;
2146 unsigned int rotation = plane_state->hw.rotation;
2147 int src_w = drm_rect_width(&plane_state->uapi.src) >> 16;
2149 /* Display WA #1106 */
2150 if (drm_format_info_is_yuv_semiplanar(fb->format) && src_w & 3 &&
2151 (rotation == DRM_MODE_ROTATE_270 ||
2152 rotation == (DRM_MODE_REFLECT_X | DRM_MODE_ROTATE_90))) {
2153 DRM_DEBUG_KMS("src width must be multiple of 4 for rotated planar YUV\n");
2160 static int skl_plane_max_scale(struct drm_i915_private *dev_priv,
2161 const struct drm_framebuffer *fb)
2164 * We don't yet know the final source width nor
2165 * whether we can use the HQ scaler mode. Assume
2167 * FIXME need to properly check this later.
2169 if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv) ||
2170 !drm_format_info_is_yuv_semiplanar(fb->format))
2176 static int skl_plane_check(struct intel_crtc_state *crtc_state,
2177 struct intel_plane_state *plane_state)
2179 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
2180 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
2181 const struct drm_framebuffer *fb = plane_state->hw.fb;
2182 int min_scale = DRM_PLANE_HELPER_NO_SCALING;
2183 int max_scale = DRM_PLANE_HELPER_NO_SCALING;
2186 ret = skl_plane_check_fb(crtc_state, plane_state);
2190 /* use scaler when colorkey is not required */
2191 if (!plane_state->ckey.flags && intel_fb_scalable(fb)) {
2193 max_scale = skl_plane_max_scale(dev_priv, fb);
2196 ret = drm_atomic_helper_check_plane_state(&plane_state->uapi,
2198 min_scale, max_scale,
2203 ret = skl_check_plane_surface(plane_state);
2207 if (!plane_state->uapi.visible)
2210 ret = skl_plane_check_dst_coordinates(crtc_state, plane_state);
2214 ret = intel_plane_check_src_coordinates(plane_state);
2218 ret = skl_plane_check_nv12_rotation(plane_state);
2222 /* HW only has 8 bits pixel precision, disable plane if invisible */
2223 if (!(plane_state->hw.alpha >> 8))
2224 plane_state->uapi.visible = false;
2226 plane_state->ctl = skl_plane_ctl(crtc_state, plane_state);
2228 if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv))
2229 plane_state->color_ctl = glk_plane_color_ctl(crtc_state,
2232 if (drm_format_info_is_yuv_semiplanar(fb->format) &&
2233 icl_is_hdr_plane(dev_priv, plane->id))
2234 /* Enable and use MPEG-2 chroma siting */
2235 plane_state->cus_ctl = PLANE_CUS_ENABLE |
2236 PLANE_CUS_HPHASE_0 |
2237 PLANE_CUS_VPHASE_SIGN_NEGATIVE | PLANE_CUS_VPHASE_0_25;
2239 plane_state->cus_ctl = 0;
2244 static bool has_dst_key_in_primary_plane(struct drm_i915_private *dev_priv)
2246 return INTEL_GEN(dev_priv) >= 9;
2249 static void intel_plane_set_ckey(struct intel_plane_state *plane_state,
2250 const struct drm_intel_sprite_colorkey *set)
2252 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
2253 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
2254 struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
2259 * We want src key enabled on the
2260 * sprite and not on the primary.
2262 if (plane->id == PLANE_PRIMARY &&
2263 set->flags & I915_SET_COLORKEY_SOURCE)
2267 * On SKL+ we want dst key enabled on
2268 * the primary and not on the sprite.
2270 if (INTEL_GEN(dev_priv) >= 9 && plane->id != PLANE_PRIMARY &&
2271 set->flags & I915_SET_COLORKEY_DESTINATION)
2275 int intel_sprite_set_colorkey_ioctl(struct drm_device *dev, void *data,
2276 struct drm_file *file_priv)
2278 struct drm_i915_private *dev_priv = to_i915(dev);
2279 struct drm_intel_sprite_colorkey *set = data;
2280 struct drm_plane *plane;
2281 struct drm_plane_state *plane_state;
2282 struct drm_atomic_state *state;
2283 struct drm_modeset_acquire_ctx ctx;
2286 /* ignore the pointless "none" flag */
2287 set->flags &= ~I915_SET_COLORKEY_NONE;
2289 if (set->flags & ~(I915_SET_COLORKEY_DESTINATION | I915_SET_COLORKEY_SOURCE))
2292 /* Make sure we don't try to enable both src & dest simultaneously */
2293 if ((set->flags & (I915_SET_COLORKEY_DESTINATION | I915_SET_COLORKEY_SOURCE)) == (I915_SET_COLORKEY_DESTINATION | I915_SET_COLORKEY_SOURCE))
2296 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
2297 set->flags & I915_SET_COLORKEY_DESTINATION)
2300 plane = drm_plane_find(dev, file_priv, set->plane_id);
2301 if (!plane || plane->type != DRM_PLANE_TYPE_OVERLAY)
2305 * SKL+ only plane 2 can do destination keying against plane 1.
2306 * Also multiple planes can't do destination keying on the same
2307 * pipe simultaneously.
2309 if (INTEL_GEN(dev_priv) >= 9 &&
2310 to_intel_plane(plane)->id >= PLANE_SPRITE1 &&
2311 set->flags & I915_SET_COLORKEY_DESTINATION)
2314 drm_modeset_acquire_init(&ctx, 0);
2316 state = drm_atomic_state_alloc(plane->dev);
2321 state->acquire_ctx = &ctx;
2324 plane_state = drm_atomic_get_plane_state(state, plane);
2325 ret = PTR_ERR_OR_ZERO(plane_state);
2327 intel_plane_set_ckey(to_intel_plane_state(plane_state), set);
2330 * On some platforms we have to configure
2331 * the dst colorkey on the primary plane.
2333 if (!ret && has_dst_key_in_primary_plane(dev_priv)) {
2334 struct intel_crtc *crtc =
2335 intel_get_crtc_for_pipe(dev_priv,
2336 to_intel_plane(plane)->pipe);
2338 plane_state = drm_atomic_get_plane_state(state,
2339 crtc->base.primary);
2340 ret = PTR_ERR_OR_ZERO(plane_state);
2342 intel_plane_set_ckey(to_intel_plane_state(plane_state), set);
2346 ret = drm_atomic_commit(state);
2348 if (ret != -EDEADLK)
2351 drm_atomic_state_clear(state);
2352 drm_modeset_backoff(&ctx);
2355 drm_atomic_state_put(state);
2357 drm_modeset_drop_locks(&ctx);
2358 drm_modeset_acquire_fini(&ctx);
2362 static const u32 g4x_plane_formats[] = {
2363 DRM_FORMAT_XRGB8888,
2370 static const u64 i9xx_plane_format_modifiers[] = {
2371 I915_FORMAT_MOD_X_TILED,
2372 DRM_FORMAT_MOD_LINEAR,
2373 DRM_FORMAT_MOD_INVALID
2376 static const u32 snb_plane_formats[] = {
2377 DRM_FORMAT_XRGB8888,
2378 DRM_FORMAT_XBGR8888,
2379 DRM_FORMAT_XRGB2101010,
2380 DRM_FORMAT_XBGR2101010,
2381 DRM_FORMAT_XRGB16161616F,
2382 DRM_FORMAT_XBGR16161616F,
2389 static const u32 vlv_plane_formats[] = {
2392 DRM_FORMAT_ABGR8888,
2393 DRM_FORMAT_ARGB8888,
2394 DRM_FORMAT_XBGR8888,
2395 DRM_FORMAT_XRGB8888,
2396 DRM_FORMAT_XBGR2101010,
2397 DRM_FORMAT_ABGR2101010,
2404 static const u32 chv_pipe_b_sprite_formats[] = {
2407 DRM_FORMAT_XRGB8888,
2408 DRM_FORMAT_XBGR8888,
2409 DRM_FORMAT_ARGB8888,
2410 DRM_FORMAT_ABGR8888,
2411 DRM_FORMAT_XRGB2101010,
2412 DRM_FORMAT_XBGR2101010,
2413 DRM_FORMAT_ARGB2101010,
2414 DRM_FORMAT_ABGR2101010,
2421 static const u32 skl_plane_formats[] = {
2424 DRM_FORMAT_XRGB8888,
2425 DRM_FORMAT_XBGR8888,
2426 DRM_FORMAT_ARGB8888,
2427 DRM_FORMAT_ABGR8888,
2428 DRM_FORMAT_XRGB2101010,
2429 DRM_FORMAT_XBGR2101010,
2430 DRM_FORMAT_XRGB16161616F,
2431 DRM_FORMAT_XBGR16161616F,
2438 static const u32 skl_planar_formats[] = {
2441 DRM_FORMAT_XRGB8888,
2442 DRM_FORMAT_XBGR8888,
2443 DRM_FORMAT_ARGB8888,
2444 DRM_FORMAT_ABGR8888,
2445 DRM_FORMAT_XRGB2101010,
2446 DRM_FORMAT_XBGR2101010,
2447 DRM_FORMAT_XRGB16161616F,
2448 DRM_FORMAT_XBGR16161616F,
2456 static const u32 glk_planar_formats[] = {
2459 DRM_FORMAT_XRGB8888,
2460 DRM_FORMAT_XBGR8888,
2461 DRM_FORMAT_ARGB8888,
2462 DRM_FORMAT_ABGR8888,
2463 DRM_FORMAT_XRGB2101010,
2464 DRM_FORMAT_XBGR2101010,
2465 DRM_FORMAT_XRGB16161616F,
2466 DRM_FORMAT_XBGR16161616F,
2477 static const u32 icl_sdr_y_plane_formats[] = {
2480 DRM_FORMAT_XRGB8888,
2481 DRM_FORMAT_XBGR8888,
2482 DRM_FORMAT_ARGB8888,
2483 DRM_FORMAT_ABGR8888,
2484 DRM_FORMAT_XRGB2101010,
2485 DRM_FORMAT_XBGR2101010,
2493 DRM_FORMAT_XVYU2101010,
2494 DRM_FORMAT_XVYU12_16161616,
2495 DRM_FORMAT_XVYU16161616,
2498 static const u32 icl_sdr_uv_plane_formats[] = {
2501 DRM_FORMAT_XRGB8888,
2502 DRM_FORMAT_XBGR8888,
2503 DRM_FORMAT_ARGB8888,
2504 DRM_FORMAT_ABGR8888,
2505 DRM_FORMAT_XRGB2101010,
2506 DRM_FORMAT_XBGR2101010,
2518 DRM_FORMAT_XVYU2101010,
2519 DRM_FORMAT_XVYU12_16161616,
2520 DRM_FORMAT_XVYU16161616,
2523 static const u32 icl_hdr_plane_formats[] = {
2526 DRM_FORMAT_XRGB8888,
2527 DRM_FORMAT_XBGR8888,
2528 DRM_FORMAT_ARGB8888,
2529 DRM_FORMAT_ABGR8888,
2530 DRM_FORMAT_XRGB2101010,
2531 DRM_FORMAT_XBGR2101010,
2532 DRM_FORMAT_XRGB16161616F,
2533 DRM_FORMAT_XBGR16161616F,
2534 DRM_FORMAT_ARGB16161616F,
2535 DRM_FORMAT_ABGR16161616F,
2547 DRM_FORMAT_XVYU2101010,
2548 DRM_FORMAT_XVYU12_16161616,
2549 DRM_FORMAT_XVYU16161616,
2552 static const u64 skl_plane_format_modifiers_noccs[] = {
2553 I915_FORMAT_MOD_Yf_TILED,
2554 I915_FORMAT_MOD_Y_TILED,
2555 I915_FORMAT_MOD_X_TILED,
2556 DRM_FORMAT_MOD_LINEAR,
2557 DRM_FORMAT_MOD_INVALID
2560 static const u64 skl_plane_format_modifiers_ccs[] = {
2561 I915_FORMAT_MOD_Yf_TILED_CCS,
2562 I915_FORMAT_MOD_Y_TILED_CCS,
2563 I915_FORMAT_MOD_Yf_TILED,
2564 I915_FORMAT_MOD_Y_TILED,
2565 I915_FORMAT_MOD_X_TILED,
2566 DRM_FORMAT_MOD_LINEAR,
2567 DRM_FORMAT_MOD_INVALID
2570 static const u64 gen12_plane_format_modifiers_noccs[] = {
2571 I915_FORMAT_MOD_Y_TILED,
2572 I915_FORMAT_MOD_X_TILED,
2573 DRM_FORMAT_MOD_LINEAR,
2574 DRM_FORMAT_MOD_INVALID
2577 static bool g4x_sprite_format_mod_supported(struct drm_plane *_plane,
2578 u32 format, u64 modifier)
2581 case DRM_FORMAT_MOD_LINEAR:
2582 case I915_FORMAT_MOD_X_TILED:
2589 case DRM_FORMAT_XRGB8888:
2590 case DRM_FORMAT_YUYV:
2591 case DRM_FORMAT_YVYU:
2592 case DRM_FORMAT_UYVY:
2593 case DRM_FORMAT_VYUY:
2594 if (modifier == DRM_FORMAT_MOD_LINEAR ||
2595 modifier == I915_FORMAT_MOD_X_TILED)
2603 static bool snb_sprite_format_mod_supported(struct drm_plane *_plane,
2604 u32 format, u64 modifier)
2607 case DRM_FORMAT_MOD_LINEAR:
2608 case I915_FORMAT_MOD_X_TILED:
2615 case DRM_FORMAT_XRGB8888:
2616 case DRM_FORMAT_XBGR8888:
2617 case DRM_FORMAT_XRGB2101010:
2618 case DRM_FORMAT_XBGR2101010:
2619 case DRM_FORMAT_XRGB16161616F:
2620 case DRM_FORMAT_XBGR16161616F:
2621 case DRM_FORMAT_YUYV:
2622 case DRM_FORMAT_YVYU:
2623 case DRM_FORMAT_UYVY:
2624 case DRM_FORMAT_VYUY:
2625 if (modifier == DRM_FORMAT_MOD_LINEAR ||
2626 modifier == I915_FORMAT_MOD_X_TILED)
2634 static bool vlv_sprite_format_mod_supported(struct drm_plane *_plane,
2635 u32 format, u64 modifier)
2638 case DRM_FORMAT_MOD_LINEAR:
2639 case I915_FORMAT_MOD_X_TILED:
2647 case DRM_FORMAT_RGB565:
2648 case DRM_FORMAT_ABGR8888:
2649 case DRM_FORMAT_ARGB8888:
2650 case DRM_FORMAT_XBGR8888:
2651 case DRM_FORMAT_XRGB8888:
2652 case DRM_FORMAT_XBGR2101010:
2653 case DRM_FORMAT_ABGR2101010:
2654 case DRM_FORMAT_XRGB2101010:
2655 case DRM_FORMAT_ARGB2101010:
2656 case DRM_FORMAT_YUYV:
2657 case DRM_FORMAT_YVYU:
2658 case DRM_FORMAT_UYVY:
2659 case DRM_FORMAT_VYUY:
2660 if (modifier == DRM_FORMAT_MOD_LINEAR ||
2661 modifier == I915_FORMAT_MOD_X_TILED)
2669 static bool skl_plane_format_mod_supported(struct drm_plane *_plane,
2670 u32 format, u64 modifier)
2672 struct intel_plane *plane = to_intel_plane(_plane);
2675 case DRM_FORMAT_MOD_LINEAR:
2676 case I915_FORMAT_MOD_X_TILED:
2677 case I915_FORMAT_MOD_Y_TILED:
2678 case I915_FORMAT_MOD_Yf_TILED:
2680 case I915_FORMAT_MOD_Y_TILED_CCS:
2681 case I915_FORMAT_MOD_Yf_TILED_CCS:
2682 if (!plane->has_ccs)
2690 case DRM_FORMAT_XRGB8888:
2691 case DRM_FORMAT_XBGR8888:
2692 case DRM_FORMAT_ARGB8888:
2693 case DRM_FORMAT_ABGR8888:
2694 if (is_ccs_modifier(modifier))
2697 case DRM_FORMAT_RGB565:
2698 case DRM_FORMAT_XRGB2101010:
2699 case DRM_FORMAT_XBGR2101010:
2700 case DRM_FORMAT_YUYV:
2701 case DRM_FORMAT_YVYU:
2702 case DRM_FORMAT_UYVY:
2703 case DRM_FORMAT_VYUY:
2704 case DRM_FORMAT_NV12:
2705 case DRM_FORMAT_P010:
2706 case DRM_FORMAT_P012:
2707 case DRM_FORMAT_P016:
2708 case DRM_FORMAT_XVYU2101010:
2709 if (modifier == I915_FORMAT_MOD_Yf_TILED)
2713 case DRM_FORMAT_XBGR16161616F:
2714 case DRM_FORMAT_ABGR16161616F:
2715 case DRM_FORMAT_XRGB16161616F:
2716 case DRM_FORMAT_ARGB16161616F:
2717 case DRM_FORMAT_Y210:
2718 case DRM_FORMAT_Y212:
2719 case DRM_FORMAT_Y216:
2720 case DRM_FORMAT_XVYU12_16161616:
2721 case DRM_FORMAT_XVYU16161616:
2722 if (modifier == DRM_FORMAT_MOD_LINEAR ||
2723 modifier == I915_FORMAT_MOD_X_TILED ||
2724 modifier == I915_FORMAT_MOD_Y_TILED)
2732 static bool gen12_plane_format_mod_supported(struct drm_plane *_plane,
2733 u32 format, u64 modifier)
2736 case DRM_FORMAT_MOD_LINEAR:
2737 case I915_FORMAT_MOD_X_TILED:
2738 case I915_FORMAT_MOD_Y_TILED:
2745 case DRM_FORMAT_XRGB8888:
2746 case DRM_FORMAT_XBGR8888:
2747 case DRM_FORMAT_ARGB8888:
2748 case DRM_FORMAT_ABGR8888:
2749 case DRM_FORMAT_RGB565:
2750 case DRM_FORMAT_XRGB2101010:
2751 case DRM_FORMAT_XBGR2101010:
2752 case DRM_FORMAT_YUYV:
2753 case DRM_FORMAT_YVYU:
2754 case DRM_FORMAT_UYVY:
2755 case DRM_FORMAT_VYUY:
2756 case DRM_FORMAT_NV12:
2757 case DRM_FORMAT_P010:
2758 case DRM_FORMAT_P012:
2759 case DRM_FORMAT_P016:
2760 case DRM_FORMAT_XVYU2101010:
2762 case DRM_FORMAT_XBGR16161616F:
2763 case DRM_FORMAT_ABGR16161616F:
2764 case DRM_FORMAT_XRGB16161616F:
2765 case DRM_FORMAT_ARGB16161616F:
2766 case DRM_FORMAT_Y210:
2767 case DRM_FORMAT_Y212:
2768 case DRM_FORMAT_Y216:
2769 case DRM_FORMAT_XVYU12_16161616:
2770 case DRM_FORMAT_XVYU16161616:
2771 if (modifier == DRM_FORMAT_MOD_LINEAR ||
2772 modifier == I915_FORMAT_MOD_X_TILED ||
2773 modifier == I915_FORMAT_MOD_Y_TILED)
2781 static const struct drm_plane_funcs g4x_sprite_funcs = {
2782 .update_plane = drm_atomic_helper_update_plane,
2783 .disable_plane = drm_atomic_helper_disable_plane,
2784 .destroy = intel_plane_destroy,
2785 .atomic_duplicate_state = intel_plane_duplicate_state,
2786 .atomic_destroy_state = intel_plane_destroy_state,
2787 .format_mod_supported = g4x_sprite_format_mod_supported,
2790 static const struct drm_plane_funcs snb_sprite_funcs = {
2791 .update_plane = drm_atomic_helper_update_plane,
2792 .disable_plane = drm_atomic_helper_disable_plane,
2793 .destroy = intel_plane_destroy,
2794 .atomic_duplicate_state = intel_plane_duplicate_state,
2795 .atomic_destroy_state = intel_plane_destroy_state,
2796 .format_mod_supported = snb_sprite_format_mod_supported,
2799 static const struct drm_plane_funcs vlv_sprite_funcs = {
2800 .update_plane = drm_atomic_helper_update_plane,
2801 .disable_plane = drm_atomic_helper_disable_plane,
2802 .destroy = intel_plane_destroy,
2803 .atomic_duplicate_state = intel_plane_duplicate_state,
2804 .atomic_destroy_state = intel_plane_destroy_state,
2805 .format_mod_supported = vlv_sprite_format_mod_supported,
2808 static const struct drm_plane_funcs skl_plane_funcs = {
2809 .update_plane = drm_atomic_helper_update_plane,
2810 .disable_plane = drm_atomic_helper_disable_plane,
2811 .destroy = intel_plane_destroy,
2812 .atomic_duplicate_state = intel_plane_duplicate_state,
2813 .atomic_destroy_state = intel_plane_destroy_state,
2814 .format_mod_supported = skl_plane_format_mod_supported,
2817 static const struct drm_plane_funcs gen12_plane_funcs = {
2818 .update_plane = drm_atomic_helper_update_plane,
2819 .disable_plane = drm_atomic_helper_disable_plane,
2820 .destroy = intel_plane_destroy,
2821 .atomic_duplicate_state = intel_plane_duplicate_state,
2822 .atomic_destroy_state = intel_plane_destroy_state,
2823 .format_mod_supported = gen12_plane_format_mod_supported,
2826 static bool skl_plane_has_fbc(struct drm_i915_private *dev_priv,
2827 enum pipe pipe, enum plane_id plane_id)
2829 if (!HAS_FBC(dev_priv))
2832 return pipe == PIPE_A && plane_id == PLANE_PRIMARY;
2835 static bool skl_plane_has_planar(struct drm_i915_private *dev_priv,
2836 enum pipe pipe, enum plane_id plane_id)
2838 /* Display WA #0870: skl, bxt */
2839 if (IS_SKYLAKE(dev_priv) || IS_BROXTON(dev_priv))
2842 if (IS_GEN(dev_priv, 9) && !IS_GEMINILAKE(dev_priv) && pipe == PIPE_C)
2845 if (plane_id != PLANE_PRIMARY && plane_id != PLANE_SPRITE0)
2851 static const u32 *skl_get_plane_formats(struct drm_i915_private *dev_priv,
2852 enum pipe pipe, enum plane_id plane_id,
2855 if (skl_plane_has_planar(dev_priv, pipe, plane_id)) {
2856 *num_formats = ARRAY_SIZE(skl_planar_formats);
2857 return skl_planar_formats;
2859 *num_formats = ARRAY_SIZE(skl_plane_formats);
2860 return skl_plane_formats;
2864 static const u32 *glk_get_plane_formats(struct drm_i915_private *dev_priv,
2865 enum pipe pipe, enum plane_id plane_id,
2868 if (skl_plane_has_planar(dev_priv, pipe, plane_id)) {
2869 *num_formats = ARRAY_SIZE(glk_planar_formats);
2870 return glk_planar_formats;
2872 *num_formats = ARRAY_SIZE(skl_plane_formats);
2873 return skl_plane_formats;
2877 static const u32 *icl_get_plane_formats(struct drm_i915_private *dev_priv,
2878 enum pipe pipe, enum plane_id plane_id,
2881 if (icl_is_hdr_plane(dev_priv, plane_id)) {
2882 *num_formats = ARRAY_SIZE(icl_hdr_plane_formats);
2883 return icl_hdr_plane_formats;
2884 } else if (icl_is_nv12_y_plane(plane_id)) {
2885 *num_formats = ARRAY_SIZE(icl_sdr_y_plane_formats);
2886 return icl_sdr_y_plane_formats;
2888 *num_formats = ARRAY_SIZE(icl_sdr_uv_plane_formats);
2889 return icl_sdr_uv_plane_formats;
2893 static bool skl_plane_has_ccs(struct drm_i915_private *dev_priv,
2894 enum pipe pipe, enum plane_id plane_id)
2896 if (plane_id == PLANE_CURSOR)
2899 if (INTEL_GEN(dev_priv) >= 10)
2902 if (IS_GEMINILAKE(dev_priv))
2903 return pipe != PIPE_C;
2905 return pipe != PIPE_C &&
2906 (plane_id == PLANE_PRIMARY ||
2907 plane_id == PLANE_SPRITE0);
2910 struct intel_plane *
2911 skl_universal_plane_create(struct drm_i915_private *dev_priv,
2912 enum pipe pipe, enum plane_id plane_id)
2914 static const struct drm_plane_funcs *plane_funcs;
2915 struct intel_plane *plane;
2916 enum drm_plane_type plane_type;
2917 unsigned int supported_rotations;
2918 unsigned int possible_crtcs;
2919 const u64 *modifiers;
2924 plane = intel_plane_alloc();
2929 plane->id = plane_id;
2930 plane->frontbuffer_bit = INTEL_FRONTBUFFER(pipe, plane_id);
2932 plane->has_fbc = skl_plane_has_fbc(dev_priv, pipe, plane_id);
2933 if (plane->has_fbc) {
2934 struct intel_fbc *fbc = &dev_priv->fbc;
2936 fbc->possible_framebuffer_bits |= plane->frontbuffer_bit;
2939 plane->max_stride = skl_plane_max_stride;
2940 plane->update_plane = skl_update_plane;
2941 plane->disable_plane = skl_disable_plane;
2942 plane->get_hw_state = skl_plane_get_hw_state;
2943 plane->check_plane = skl_plane_check;
2944 plane->min_cdclk = skl_plane_min_cdclk;
2946 if (INTEL_GEN(dev_priv) >= 11)
2947 formats = icl_get_plane_formats(dev_priv, pipe,
2948 plane_id, &num_formats);
2949 else if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv))
2950 formats = glk_get_plane_formats(dev_priv, pipe,
2951 plane_id, &num_formats);
2953 formats = skl_get_plane_formats(dev_priv, pipe,
2954 plane_id, &num_formats);
2956 if (INTEL_GEN(dev_priv) >= 12) {
2957 /* TODO: Implement support for gen-12 CCS modifiers */
2958 plane->has_ccs = false;
2959 modifiers = gen12_plane_format_modifiers_noccs;
2960 plane_funcs = &gen12_plane_funcs;
2962 plane->has_ccs = skl_plane_has_ccs(dev_priv, pipe, plane_id);
2964 modifiers = skl_plane_format_modifiers_ccs;
2966 modifiers = skl_plane_format_modifiers_noccs;
2967 plane_funcs = &skl_plane_funcs;
2970 if (plane_id == PLANE_PRIMARY)
2971 plane_type = DRM_PLANE_TYPE_PRIMARY;
2973 plane_type = DRM_PLANE_TYPE_OVERLAY;
2975 possible_crtcs = BIT(pipe);
2977 ret = drm_universal_plane_init(&dev_priv->drm, &plane->base,
2978 possible_crtcs, plane_funcs,
2979 formats, num_formats, modifiers,
2981 "plane %d%c", plane_id + 1,
2986 supported_rotations =
2987 DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_90 |
2988 DRM_MODE_ROTATE_180 | DRM_MODE_ROTATE_270;
2990 if (INTEL_GEN(dev_priv) >= 10)
2991 supported_rotations |= DRM_MODE_REFLECT_X;
2993 drm_plane_create_rotation_property(&plane->base,
2995 supported_rotations);
2997 drm_plane_create_color_properties(&plane->base,
2998 BIT(DRM_COLOR_YCBCR_BT601) |
2999 BIT(DRM_COLOR_YCBCR_BT709),
3000 BIT(DRM_COLOR_YCBCR_LIMITED_RANGE) |
3001 BIT(DRM_COLOR_YCBCR_FULL_RANGE),
3002 DRM_COLOR_YCBCR_BT709,
3003 DRM_COLOR_YCBCR_LIMITED_RANGE);
3005 drm_plane_create_alpha_property(&plane->base);
3006 drm_plane_create_blend_mode_property(&plane->base,
3007 BIT(DRM_MODE_BLEND_PIXEL_NONE) |
3008 BIT(DRM_MODE_BLEND_PREMULTI) |
3009 BIT(DRM_MODE_BLEND_COVERAGE));
3011 drm_plane_create_zpos_immutable_property(&plane->base, plane_id);
3013 drm_plane_helper_add(&plane->base, &intel_plane_helper_funcs);
3018 intel_plane_free(plane);
3020 return ERR_PTR(ret);
3023 struct intel_plane *
3024 intel_sprite_plane_create(struct drm_i915_private *dev_priv,
3025 enum pipe pipe, int sprite)
3027 struct intel_plane *plane;
3028 const struct drm_plane_funcs *plane_funcs;
3029 unsigned long possible_crtcs;
3030 unsigned int supported_rotations;
3031 const u64 *modifiers;
3036 if (INTEL_GEN(dev_priv) >= 9)
3037 return skl_universal_plane_create(dev_priv, pipe,
3038 PLANE_SPRITE0 + sprite);
3040 plane = intel_plane_alloc();
3044 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
3045 plane->max_stride = i9xx_plane_max_stride;
3046 plane->update_plane = vlv_update_plane;
3047 plane->disable_plane = vlv_disable_plane;
3048 plane->get_hw_state = vlv_plane_get_hw_state;
3049 plane->check_plane = vlv_sprite_check;
3050 plane->min_cdclk = vlv_plane_min_cdclk;
3052 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B) {
3053 formats = chv_pipe_b_sprite_formats;
3054 num_formats = ARRAY_SIZE(chv_pipe_b_sprite_formats);
3056 formats = vlv_plane_formats;
3057 num_formats = ARRAY_SIZE(vlv_plane_formats);
3059 modifiers = i9xx_plane_format_modifiers;
3061 plane_funcs = &vlv_sprite_funcs;
3062 } else if (INTEL_GEN(dev_priv) >= 7) {
3063 plane->max_stride = g4x_sprite_max_stride;
3064 plane->update_plane = ivb_update_plane;
3065 plane->disable_plane = ivb_disable_plane;
3066 plane->get_hw_state = ivb_plane_get_hw_state;
3067 plane->check_plane = g4x_sprite_check;
3069 if (IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv))
3070 plane->min_cdclk = hsw_plane_min_cdclk;
3072 plane->min_cdclk = ivb_sprite_min_cdclk;
3074 formats = snb_plane_formats;
3075 num_formats = ARRAY_SIZE(snb_plane_formats);
3076 modifiers = i9xx_plane_format_modifiers;
3078 plane_funcs = &snb_sprite_funcs;
3080 plane->max_stride = g4x_sprite_max_stride;
3081 plane->update_plane = g4x_update_plane;
3082 plane->disable_plane = g4x_disable_plane;
3083 plane->get_hw_state = g4x_plane_get_hw_state;
3084 plane->check_plane = g4x_sprite_check;
3085 plane->min_cdclk = g4x_sprite_min_cdclk;
3087 modifiers = i9xx_plane_format_modifiers;
3088 if (IS_GEN(dev_priv, 6)) {
3089 formats = snb_plane_formats;
3090 num_formats = ARRAY_SIZE(snb_plane_formats);
3092 plane_funcs = &snb_sprite_funcs;
3094 formats = g4x_plane_formats;
3095 num_formats = ARRAY_SIZE(g4x_plane_formats);
3097 plane_funcs = &g4x_sprite_funcs;
3101 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B) {
3102 supported_rotations =
3103 DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180 |
3106 supported_rotations =
3107 DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180;
3111 plane->id = PLANE_SPRITE0 + sprite;
3112 plane->frontbuffer_bit = INTEL_FRONTBUFFER(pipe, plane->id);
3114 possible_crtcs = BIT(pipe);
3116 ret = drm_universal_plane_init(&dev_priv->drm, &plane->base,
3117 possible_crtcs, plane_funcs,
3118 formats, num_formats, modifiers,
3119 DRM_PLANE_TYPE_OVERLAY,
3120 "sprite %c", sprite_name(pipe, sprite));
3124 drm_plane_create_rotation_property(&plane->base,
3126 supported_rotations);
3128 drm_plane_create_color_properties(&plane->base,
3129 BIT(DRM_COLOR_YCBCR_BT601) |
3130 BIT(DRM_COLOR_YCBCR_BT709),
3131 BIT(DRM_COLOR_YCBCR_LIMITED_RANGE) |
3132 BIT(DRM_COLOR_YCBCR_FULL_RANGE),
3133 DRM_COLOR_YCBCR_BT709,
3134 DRM_COLOR_YCBCR_LIMITED_RANGE);
3137 drm_plane_create_zpos_immutable_property(&plane->base, zpos);
3139 drm_plane_helper_add(&plane->base, &intel_plane_helper_funcs);
3144 intel_plane_free(plane);
3146 return ERR_PTR(ret);