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_intel_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_intel_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_intel_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 (intel_format_info_is_yuv_semiplanar(fb->format, fb->modifier) &&
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_dist = plane_state->color_plane[1].offset - surf_addr;
587 u32 aux_stride = skl_plane_stride(plane_state, 1);
588 int crtc_x = plane_state->uapi.dst.x1;
589 int crtc_y = plane_state->uapi.dst.y1;
590 u32 x = plane_state->color_plane[color_plane].x;
591 u32 y = plane_state->color_plane[color_plane].y;
592 u32 src_w = drm_rect_width(&plane_state->uapi.src) >> 16;
593 u32 src_h = drm_rect_height(&plane_state->uapi.src) >> 16;
594 const struct drm_framebuffer *fb = plane_state->hw.fb;
595 u8 alpha = plane_state->hw.alpha >> 8;
596 u32 plane_color_ctl = 0;
597 unsigned long irqflags;
599 u32 plane_ctl = plane_state->ctl;
601 plane_ctl |= skl_plane_ctl_crtc(crtc_state);
603 if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv))
604 plane_color_ctl = plane_state->color_ctl |
605 glk_plane_color_ctl_crtc(crtc_state);
607 /* Sizes are 0 based */
611 keymax = (key->max_value & 0xffffff) | PLANE_KEYMAX_ALPHA(alpha);
613 keymsk = key->channel_mask & 0x7ffffff;
615 keymsk |= PLANE_KEYMSK_ALPHA_ENABLE;
617 /* The scaler will handle the output position */
618 if (plane_state->scaler_id >= 0) {
623 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
625 I915_WRITE_FW(PLANE_STRIDE(pipe, plane_id), stride);
626 I915_WRITE_FW(PLANE_POS(pipe, plane_id), (crtc_y << 16) | crtc_x);
627 I915_WRITE_FW(PLANE_SIZE(pipe, plane_id), (src_h << 16) | src_w);
629 if (INTEL_GEN(dev_priv) < 12)
630 aux_dist |= aux_stride;
631 I915_WRITE_FW(PLANE_AUX_DIST(pipe, plane_id), aux_dist);
633 if (icl_is_hdr_plane(dev_priv, plane_id))
634 I915_WRITE_FW(PLANE_CUS_CTL(pipe, plane_id), plane_state->cus_ctl);
636 if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv))
637 I915_WRITE_FW(PLANE_COLOR_CTL(pipe, plane_id), plane_color_ctl);
639 if (fb->format->is_yuv && icl_is_hdr_plane(dev_priv, plane_id))
640 icl_program_input_csc(plane, crtc_state, plane_state);
642 skl_write_plane_wm(plane, crtc_state);
644 I915_WRITE_FW(PLANE_KEYVAL(pipe, plane_id), key->min_value);
645 I915_WRITE_FW(PLANE_KEYMSK(pipe, plane_id), keymsk);
646 I915_WRITE_FW(PLANE_KEYMAX(pipe, plane_id), keymax);
648 I915_WRITE_FW(PLANE_OFFSET(pipe, plane_id), (y << 16) | x);
650 if (INTEL_GEN(dev_priv) < 11)
651 I915_WRITE_FW(PLANE_AUX_OFFSET(pipe, plane_id),
652 (plane_state->color_plane[1].y << 16) |
653 plane_state->color_plane[1].x);
656 * The control register self-arms if the plane was previously
657 * disabled. Try to make the plane enable atomic by writing
658 * the control register just before the surface register.
660 I915_WRITE_FW(PLANE_CTL(pipe, plane_id), plane_ctl);
661 I915_WRITE_FW(PLANE_SURF(pipe, plane_id),
662 intel_plane_ggtt_offset(plane_state) + surf_addr);
664 if (plane_state->scaler_id >= 0)
665 skl_program_scaler(plane, crtc_state, plane_state);
667 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
671 skl_update_plane(struct intel_plane *plane,
672 const struct intel_crtc_state *crtc_state,
673 const struct intel_plane_state *plane_state)
677 if (plane_state->planar_linked_plane && !plane_state->planar_slave)
678 /* Program the UV plane on planar master */
681 skl_program_plane(plane, crtc_state, plane_state, color_plane);
684 skl_disable_plane(struct intel_plane *plane,
685 const struct intel_crtc_state *crtc_state)
687 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
688 enum plane_id plane_id = plane->id;
689 enum pipe pipe = plane->pipe;
690 unsigned long irqflags;
692 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
694 if (icl_is_hdr_plane(dev_priv, plane_id))
695 I915_WRITE_FW(PLANE_CUS_CTL(pipe, plane_id), 0);
697 skl_write_plane_wm(plane, crtc_state);
699 I915_WRITE_FW(PLANE_CTL(pipe, plane_id), 0);
700 I915_WRITE_FW(PLANE_SURF(pipe, plane_id), 0);
702 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
706 skl_plane_get_hw_state(struct intel_plane *plane,
709 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
710 enum intel_display_power_domain power_domain;
711 enum plane_id plane_id = plane->id;
712 intel_wakeref_t wakeref;
715 power_domain = POWER_DOMAIN_PIPE(plane->pipe);
716 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
720 ret = I915_READ(PLANE_CTL(plane->pipe, plane_id)) & PLANE_CTL_ENABLE;
724 intel_display_power_put(dev_priv, power_domain, wakeref);
729 static void i9xx_plane_linear_gamma(u16 gamma[8])
731 /* The points are not evenly spaced. */
732 static const u8 in[8] = { 0, 1, 2, 4, 8, 16, 24, 32 };
735 for (i = 0; i < 8; i++)
736 gamma[i] = (in[i] << 8) / 32;
740 chv_update_csc(const struct intel_plane_state *plane_state)
742 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
743 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
744 const struct drm_framebuffer *fb = plane_state->hw.fb;
745 enum plane_id plane_id = plane->id;
747 * |r| | c0 c1 c2 | |cr|
748 * |g| = | c3 c4 c5 | x |y |
749 * |b| | c6 c7 c8 | |cb|
751 * Coefficients are s3.12.
753 * Cb and Cr apparently come in as signed already, and
754 * we always get full range data in on account of CLRC0/1.
756 static const s16 csc_matrix[][9] = {
757 /* BT.601 full range YCbCr -> full range RGB */
758 [DRM_COLOR_YCBCR_BT601] = {
763 /* BT.709 full range YCbCr -> full range RGB */
764 [DRM_COLOR_YCBCR_BT709] = {
770 const s16 *csc = csc_matrix[plane_state->hw.color_encoding];
772 /* Seems RGB data bypasses the CSC always */
773 if (!fb->format->is_yuv)
776 I915_WRITE_FW(SPCSCYGOFF(plane_id), SPCSC_OOFF(0) | SPCSC_IOFF(0));
777 I915_WRITE_FW(SPCSCCBOFF(plane_id), SPCSC_OOFF(0) | SPCSC_IOFF(0));
778 I915_WRITE_FW(SPCSCCROFF(plane_id), SPCSC_OOFF(0) | SPCSC_IOFF(0));
780 I915_WRITE_FW(SPCSCC01(plane_id), SPCSC_C1(csc[1]) | SPCSC_C0(csc[0]));
781 I915_WRITE_FW(SPCSCC23(plane_id), SPCSC_C1(csc[3]) | SPCSC_C0(csc[2]));
782 I915_WRITE_FW(SPCSCC45(plane_id), SPCSC_C1(csc[5]) | SPCSC_C0(csc[4]));
783 I915_WRITE_FW(SPCSCC67(plane_id), SPCSC_C1(csc[7]) | SPCSC_C0(csc[6]));
784 I915_WRITE_FW(SPCSCC8(plane_id), SPCSC_C0(csc[8]));
786 I915_WRITE_FW(SPCSCYGICLAMP(plane_id), SPCSC_IMAX(1023) | SPCSC_IMIN(0));
787 I915_WRITE_FW(SPCSCCBICLAMP(plane_id), SPCSC_IMAX(512) | SPCSC_IMIN(-512));
788 I915_WRITE_FW(SPCSCCRICLAMP(plane_id), SPCSC_IMAX(512) | SPCSC_IMIN(-512));
790 I915_WRITE_FW(SPCSCYGOCLAMP(plane_id), SPCSC_OMAX(1023) | SPCSC_OMIN(0));
791 I915_WRITE_FW(SPCSCCBOCLAMP(plane_id), SPCSC_OMAX(1023) | SPCSC_OMIN(0));
792 I915_WRITE_FW(SPCSCCROCLAMP(plane_id), SPCSC_OMAX(1023) | SPCSC_OMIN(0));
799 vlv_update_clrc(const struct intel_plane_state *plane_state)
801 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
802 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
803 const struct drm_framebuffer *fb = plane_state->hw.fb;
804 enum pipe pipe = plane->pipe;
805 enum plane_id plane_id = plane->id;
806 int contrast, brightness, sh_scale, sh_sin, sh_cos;
808 if (fb->format->is_yuv &&
809 plane_state->hw.color_range == DRM_COLOR_YCBCR_LIMITED_RANGE) {
811 * Expand limited range to full range:
812 * Contrast is applied first and is used to expand Y range.
813 * Brightness is applied second and is used to remove the
814 * offset from Y. Saturation/hue is used to expand CbCr range.
816 contrast = DIV_ROUND_CLOSEST(255 << 6, 235 - 16);
817 brightness = -DIV_ROUND_CLOSEST(16 * 255, 235 - 16);
818 sh_scale = DIV_ROUND_CLOSEST(128 << 7, 240 - 128);
819 sh_sin = SIN_0 * sh_scale;
820 sh_cos = COS_0 * sh_scale;
822 /* Pass-through everything. */
826 sh_sin = SIN_0 * sh_scale;
827 sh_cos = COS_0 * sh_scale;
830 /* FIXME these register are single buffered :( */
831 I915_WRITE_FW(SPCLRC0(pipe, plane_id),
832 SP_CONTRAST(contrast) | SP_BRIGHTNESS(brightness));
833 I915_WRITE_FW(SPCLRC1(pipe, plane_id),
834 SP_SH_SIN(sh_sin) | SP_SH_COS(sh_cos));
838 vlv_plane_ratio(const struct intel_crtc_state *crtc_state,
839 const struct intel_plane_state *plane_state,
840 unsigned int *num, unsigned int *den)
842 u8 active_planes = crtc_state->active_planes & ~BIT(PLANE_CURSOR);
843 const struct drm_framebuffer *fb = plane_state->hw.fb;
844 unsigned int cpp = fb->format->cpp[0];
847 * VLV bspec only considers cases where all three planes are
848 * enabled, and cases where the primary and one sprite is enabled.
849 * Let's assume the case with just two sprites enabled also
850 * maps to the latter case.
852 if (hweight8(active_planes) == 3) {
867 } else if (hweight8(active_planes) == 2) {
896 int vlv_plane_min_cdclk(const struct intel_crtc_state *crtc_state,
897 const struct intel_plane_state *plane_state)
899 unsigned int pixel_rate;
900 unsigned int num, den;
903 * Note that crtc_state->pixel_rate accounts for both
904 * horizontal and vertical panel fitter downscaling factors.
905 * Pre-HSW bspec tells us to only consider the horizontal
906 * downscaling factor here. We ignore that and just consider
907 * both for simplicity.
909 pixel_rate = crtc_state->pixel_rate;
911 vlv_plane_ratio(crtc_state, plane_state, &num, &den);
913 return DIV_ROUND_UP(pixel_rate * num, den);
916 static u32 vlv_sprite_ctl_crtc(const struct intel_crtc_state *crtc_state)
920 if (crtc_state->gamma_enable)
921 sprctl |= SP_GAMMA_ENABLE;
926 static u32 vlv_sprite_ctl(const struct intel_crtc_state *crtc_state,
927 const struct intel_plane_state *plane_state)
929 const struct drm_framebuffer *fb = plane_state->hw.fb;
930 unsigned int rotation = plane_state->hw.rotation;
931 const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
936 switch (fb->format->format) {
937 case DRM_FORMAT_YUYV:
938 sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_YUYV;
940 case DRM_FORMAT_YVYU:
941 sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_YVYU;
943 case DRM_FORMAT_UYVY:
944 sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_UYVY;
946 case DRM_FORMAT_VYUY:
947 sprctl |= SP_FORMAT_YUV422 | SP_YUV_ORDER_VYUY;
950 sprctl |= SP_FORMAT_8BPP;
952 case DRM_FORMAT_RGB565:
953 sprctl |= SP_FORMAT_BGR565;
955 case DRM_FORMAT_XRGB8888:
956 sprctl |= SP_FORMAT_BGRX8888;
958 case DRM_FORMAT_ARGB8888:
959 sprctl |= SP_FORMAT_BGRA8888;
961 case DRM_FORMAT_XBGR2101010:
962 sprctl |= SP_FORMAT_RGBX1010102;
964 case DRM_FORMAT_ABGR2101010:
965 sprctl |= SP_FORMAT_RGBA1010102;
967 case DRM_FORMAT_XRGB2101010:
968 sprctl |= SP_FORMAT_BGRX1010102;
970 case DRM_FORMAT_ARGB2101010:
971 sprctl |= SP_FORMAT_BGRA1010102;
973 case DRM_FORMAT_XBGR8888:
974 sprctl |= SP_FORMAT_RGBX8888;
976 case DRM_FORMAT_ABGR8888:
977 sprctl |= SP_FORMAT_RGBA8888;
980 MISSING_CASE(fb->format->format);
984 if (plane_state->hw.color_encoding == DRM_COLOR_YCBCR_BT709)
985 sprctl |= SP_YUV_FORMAT_BT709;
987 if (fb->modifier == I915_FORMAT_MOD_X_TILED)
990 if (rotation & DRM_MODE_ROTATE_180)
991 sprctl |= SP_ROTATE_180;
993 if (rotation & DRM_MODE_REFLECT_X)
996 if (key->flags & I915_SET_COLORKEY_SOURCE)
997 sprctl |= SP_SOURCE_KEY;
1002 static void vlv_update_gamma(const struct intel_plane_state *plane_state)
1004 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
1005 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
1006 const struct drm_framebuffer *fb = plane_state->hw.fb;
1007 enum pipe pipe = plane->pipe;
1008 enum plane_id plane_id = plane->id;
1012 /* Seems RGB data bypasses the gamma always */
1013 if (!fb->format->is_yuv)
1016 i9xx_plane_linear_gamma(gamma);
1018 /* FIXME these register are single buffered :( */
1019 /* The two end points are implicit (0.0 and 1.0) */
1020 for (i = 1; i < 8 - 1; i++)
1021 I915_WRITE_FW(SPGAMC(pipe, plane_id, i - 1),
1028 vlv_update_plane(struct intel_plane *plane,
1029 const struct intel_crtc_state *crtc_state,
1030 const struct intel_plane_state *plane_state)
1032 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
1033 enum pipe pipe = plane->pipe;
1034 enum plane_id plane_id = plane->id;
1035 u32 sprsurf_offset = plane_state->color_plane[0].offset;
1037 const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
1038 int crtc_x = plane_state->uapi.dst.x1;
1039 int crtc_y = plane_state->uapi.dst.y1;
1040 u32 crtc_w = drm_rect_width(&plane_state->uapi.dst);
1041 u32 crtc_h = drm_rect_height(&plane_state->uapi.dst);
1042 u32 x = plane_state->color_plane[0].x;
1043 u32 y = plane_state->color_plane[0].y;
1044 unsigned long irqflags;
1047 sprctl = plane_state->ctl | vlv_sprite_ctl_crtc(crtc_state);
1049 /* Sizes are 0 based */
1053 linear_offset = intel_fb_xy_to_linear(x, y, plane_state, 0);
1055 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
1057 I915_WRITE_FW(SPSTRIDE(pipe, plane_id),
1058 plane_state->color_plane[0].stride);
1059 I915_WRITE_FW(SPPOS(pipe, plane_id), (crtc_y << 16) | crtc_x);
1060 I915_WRITE_FW(SPSIZE(pipe, plane_id), (crtc_h << 16) | crtc_w);
1061 I915_WRITE_FW(SPCONSTALPHA(pipe, plane_id), 0);
1063 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B)
1064 chv_update_csc(plane_state);
1067 I915_WRITE_FW(SPKEYMINVAL(pipe, plane_id), key->min_value);
1068 I915_WRITE_FW(SPKEYMSK(pipe, plane_id), key->channel_mask);
1069 I915_WRITE_FW(SPKEYMAXVAL(pipe, plane_id), key->max_value);
1072 I915_WRITE_FW(SPLINOFF(pipe, plane_id), linear_offset);
1073 I915_WRITE_FW(SPTILEOFF(pipe, plane_id), (y << 16) | x);
1076 * The control register self-arms if the plane was previously
1077 * disabled. Try to make the plane enable atomic by writing
1078 * the control register just before the surface register.
1080 I915_WRITE_FW(SPCNTR(pipe, plane_id), sprctl);
1081 I915_WRITE_FW(SPSURF(pipe, plane_id),
1082 intel_plane_ggtt_offset(plane_state) + sprsurf_offset);
1084 vlv_update_clrc(plane_state);
1085 vlv_update_gamma(plane_state);
1087 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
1091 vlv_disable_plane(struct intel_plane *plane,
1092 const struct intel_crtc_state *crtc_state)
1094 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
1095 enum pipe pipe = plane->pipe;
1096 enum plane_id plane_id = plane->id;
1097 unsigned long irqflags;
1099 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
1101 I915_WRITE_FW(SPCNTR(pipe, plane_id), 0);
1102 I915_WRITE_FW(SPSURF(pipe, plane_id), 0);
1104 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
1108 vlv_plane_get_hw_state(struct intel_plane *plane,
1111 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
1112 enum intel_display_power_domain power_domain;
1113 enum plane_id plane_id = plane->id;
1114 intel_wakeref_t wakeref;
1117 power_domain = POWER_DOMAIN_PIPE(plane->pipe);
1118 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
1122 ret = I915_READ(SPCNTR(plane->pipe, plane_id)) & SP_ENABLE;
1124 *pipe = plane->pipe;
1126 intel_display_power_put(dev_priv, power_domain, wakeref);
1131 static void ivb_plane_ratio(const struct intel_crtc_state *crtc_state,
1132 const struct intel_plane_state *plane_state,
1133 unsigned int *num, unsigned int *den)
1135 u8 active_planes = crtc_state->active_planes & ~BIT(PLANE_CURSOR);
1136 const struct drm_framebuffer *fb = plane_state->hw.fb;
1137 unsigned int cpp = fb->format->cpp[0];
1139 if (hweight8(active_planes) == 2) {
1168 static void ivb_plane_ratio_scaling(const struct intel_crtc_state *crtc_state,
1169 const struct intel_plane_state *plane_state,
1170 unsigned int *num, unsigned int *den)
1172 const struct drm_framebuffer *fb = plane_state->hw.fb;
1173 unsigned int cpp = fb->format->cpp[0];
1195 int ivb_plane_min_cdclk(const struct intel_crtc_state *crtc_state,
1196 const struct intel_plane_state *plane_state)
1198 unsigned int pixel_rate;
1199 unsigned int num, den;
1202 * Note that crtc_state->pixel_rate accounts for both
1203 * horizontal and vertical panel fitter downscaling factors.
1204 * Pre-HSW bspec tells us to only consider the horizontal
1205 * downscaling factor here. We ignore that and just consider
1206 * both for simplicity.
1208 pixel_rate = crtc_state->pixel_rate;
1210 ivb_plane_ratio(crtc_state, plane_state, &num, &den);
1212 return DIV_ROUND_UP(pixel_rate * num, den);
1215 static int ivb_sprite_min_cdclk(const struct intel_crtc_state *crtc_state,
1216 const struct intel_plane_state *plane_state)
1218 unsigned int src_w, dst_w, pixel_rate;
1219 unsigned int num, den;
1222 * Note that crtc_state->pixel_rate accounts for both
1223 * horizontal and vertical panel fitter downscaling factors.
1224 * Pre-HSW bspec tells us to only consider the horizontal
1225 * downscaling factor here. We ignore that and just consider
1226 * both for simplicity.
1228 pixel_rate = crtc_state->pixel_rate;
1230 src_w = drm_rect_width(&plane_state->uapi.src) >> 16;
1231 dst_w = drm_rect_width(&plane_state->uapi.dst);
1234 ivb_plane_ratio_scaling(crtc_state, plane_state, &num, &den);
1236 ivb_plane_ratio(crtc_state, plane_state, &num, &den);
1238 /* Horizontal downscaling limits the maximum pixel rate */
1239 dst_w = min(src_w, dst_w);
1241 return DIV_ROUND_UP_ULL(mul_u32_u32(pixel_rate, num * src_w),
1245 static void hsw_plane_ratio(const struct intel_crtc_state *crtc_state,
1246 const struct intel_plane_state *plane_state,
1247 unsigned int *num, unsigned int *den)
1249 u8 active_planes = crtc_state->active_planes & ~BIT(PLANE_CURSOR);
1250 const struct drm_framebuffer *fb = plane_state->hw.fb;
1251 unsigned int cpp = fb->format->cpp[0];
1253 if (hweight8(active_planes) == 2) {
1278 int hsw_plane_min_cdclk(const struct intel_crtc_state *crtc_state,
1279 const struct intel_plane_state *plane_state)
1281 unsigned int pixel_rate = crtc_state->pixel_rate;
1282 unsigned int num, den;
1284 hsw_plane_ratio(crtc_state, plane_state, &num, &den);
1286 return DIV_ROUND_UP(pixel_rate * num, den);
1289 static u32 ivb_sprite_ctl_crtc(const struct intel_crtc_state *crtc_state)
1293 if (crtc_state->gamma_enable)
1294 sprctl |= SPRITE_GAMMA_ENABLE;
1296 if (crtc_state->csc_enable)
1297 sprctl |= SPRITE_PIPE_CSC_ENABLE;
1302 static bool ivb_need_sprite_gamma(const struct intel_plane_state *plane_state)
1304 struct drm_i915_private *dev_priv =
1305 to_i915(plane_state->uapi.plane->dev);
1306 const struct drm_framebuffer *fb = plane_state->hw.fb;
1308 return fb->format->cpp[0] == 8 &&
1309 (IS_IVYBRIDGE(dev_priv) || IS_HASWELL(dev_priv));
1312 static u32 ivb_sprite_ctl(const struct intel_crtc_state *crtc_state,
1313 const struct intel_plane_state *plane_state)
1315 struct drm_i915_private *dev_priv =
1316 to_i915(plane_state->uapi.plane->dev);
1317 const struct drm_framebuffer *fb = plane_state->hw.fb;
1318 unsigned int rotation = plane_state->hw.rotation;
1319 const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
1322 sprctl = SPRITE_ENABLE;
1324 if (IS_IVYBRIDGE(dev_priv))
1325 sprctl |= SPRITE_TRICKLE_FEED_DISABLE;
1327 switch (fb->format->format) {
1328 case DRM_FORMAT_XBGR8888:
1329 sprctl |= SPRITE_FORMAT_RGBX888 | SPRITE_RGB_ORDER_RGBX;
1331 case DRM_FORMAT_XRGB8888:
1332 sprctl |= SPRITE_FORMAT_RGBX888;
1334 case DRM_FORMAT_XBGR2101010:
1335 sprctl |= SPRITE_FORMAT_RGBX101010 | SPRITE_RGB_ORDER_RGBX;
1337 case DRM_FORMAT_XRGB2101010:
1338 sprctl |= SPRITE_FORMAT_RGBX101010;
1340 case DRM_FORMAT_XBGR16161616F:
1341 sprctl |= SPRITE_FORMAT_RGBX161616 | SPRITE_RGB_ORDER_RGBX;
1343 case DRM_FORMAT_XRGB16161616F:
1344 sprctl |= SPRITE_FORMAT_RGBX161616;
1346 case DRM_FORMAT_YUYV:
1347 sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_YUYV;
1349 case DRM_FORMAT_YVYU:
1350 sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_YVYU;
1352 case DRM_FORMAT_UYVY:
1353 sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_UYVY;
1355 case DRM_FORMAT_VYUY:
1356 sprctl |= SPRITE_FORMAT_YUV422 | SPRITE_YUV_ORDER_VYUY;
1359 MISSING_CASE(fb->format->format);
1363 if (!ivb_need_sprite_gamma(plane_state))
1364 sprctl |= SPRITE_INT_GAMMA_DISABLE;
1366 if (plane_state->hw.color_encoding == DRM_COLOR_YCBCR_BT709)
1367 sprctl |= SPRITE_YUV_TO_RGB_CSC_FORMAT_BT709;
1369 if (plane_state->hw.color_range == DRM_COLOR_YCBCR_FULL_RANGE)
1370 sprctl |= SPRITE_YUV_RANGE_CORRECTION_DISABLE;
1372 if (fb->modifier == I915_FORMAT_MOD_X_TILED)
1373 sprctl |= SPRITE_TILED;
1375 if (rotation & DRM_MODE_ROTATE_180)
1376 sprctl |= SPRITE_ROTATE_180;
1378 if (key->flags & I915_SET_COLORKEY_DESTINATION)
1379 sprctl |= SPRITE_DEST_KEY;
1380 else if (key->flags & I915_SET_COLORKEY_SOURCE)
1381 sprctl |= SPRITE_SOURCE_KEY;
1386 static void ivb_sprite_linear_gamma(const struct intel_plane_state *plane_state,
1392 * WaFP16GammaEnabling:ivb,hsw
1393 * "Workaround : When using the 64-bit format, the sprite output
1394 * on each color channel has one quarter amplitude. It can be
1395 * brought up to full amplitude by using sprite internal gamma
1396 * correction, pipe gamma correction, or pipe color space
1397 * conversion to multiply the sprite output by four."
1401 for (i = 0; i < 16; i++)
1402 gamma[i] = min((scale * i << 10) / 16, (1 << 10) - 1);
1404 gamma[i] = min((scale * i << 10) / 16, 1 << 10);
1411 static void ivb_update_gamma(const struct intel_plane_state *plane_state)
1413 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
1414 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
1415 enum pipe pipe = plane->pipe;
1419 if (!ivb_need_sprite_gamma(plane_state))
1422 ivb_sprite_linear_gamma(plane_state, gamma);
1424 /* FIXME these register are single buffered :( */
1425 for (i = 0; i < 16; i++)
1426 I915_WRITE_FW(SPRGAMC(pipe, i),
1431 I915_WRITE_FW(SPRGAMC16(pipe, 0), gamma[i]);
1432 I915_WRITE_FW(SPRGAMC16(pipe, 1), gamma[i]);
1433 I915_WRITE_FW(SPRGAMC16(pipe, 2), gamma[i]);
1436 I915_WRITE_FW(SPRGAMC17(pipe, 0), gamma[i]);
1437 I915_WRITE_FW(SPRGAMC17(pipe, 1), gamma[i]);
1438 I915_WRITE_FW(SPRGAMC17(pipe, 2), gamma[i]);
1443 ivb_update_plane(struct intel_plane *plane,
1444 const struct intel_crtc_state *crtc_state,
1445 const struct intel_plane_state *plane_state)
1447 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
1448 enum pipe pipe = plane->pipe;
1449 u32 sprsurf_offset = plane_state->color_plane[0].offset;
1451 const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
1452 int crtc_x = plane_state->uapi.dst.x1;
1453 int crtc_y = plane_state->uapi.dst.y1;
1454 u32 crtc_w = drm_rect_width(&plane_state->uapi.dst);
1455 u32 crtc_h = drm_rect_height(&plane_state->uapi.dst);
1456 u32 x = plane_state->color_plane[0].x;
1457 u32 y = plane_state->color_plane[0].y;
1458 u32 src_w = drm_rect_width(&plane_state->uapi.src) >> 16;
1459 u32 src_h = drm_rect_height(&plane_state->uapi.src) >> 16;
1460 u32 sprctl, sprscale = 0;
1461 unsigned long irqflags;
1463 sprctl = plane_state->ctl | ivb_sprite_ctl_crtc(crtc_state);
1465 /* Sizes are 0 based */
1471 if (crtc_w != src_w || crtc_h != src_h)
1472 sprscale = SPRITE_SCALE_ENABLE | (src_w << 16) | src_h;
1474 linear_offset = intel_fb_xy_to_linear(x, y, plane_state, 0);
1476 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
1478 I915_WRITE_FW(SPRSTRIDE(pipe), plane_state->color_plane[0].stride);
1479 I915_WRITE_FW(SPRPOS(pipe), (crtc_y << 16) | crtc_x);
1480 I915_WRITE_FW(SPRSIZE(pipe), (crtc_h << 16) | crtc_w);
1481 if (IS_IVYBRIDGE(dev_priv))
1482 I915_WRITE_FW(SPRSCALE(pipe), sprscale);
1485 I915_WRITE_FW(SPRKEYVAL(pipe), key->min_value);
1486 I915_WRITE_FW(SPRKEYMSK(pipe), key->channel_mask);
1487 I915_WRITE_FW(SPRKEYMAX(pipe), key->max_value);
1490 /* HSW consolidates SPRTILEOFF and SPRLINOFF into a single SPROFFSET
1492 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
1493 I915_WRITE_FW(SPROFFSET(pipe), (y << 16) | x);
1495 I915_WRITE_FW(SPRLINOFF(pipe), linear_offset);
1496 I915_WRITE_FW(SPRTILEOFF(pipe), (y << 16) | x);
1500 * The control register self-arms if the plane was previously
1501 * disabled. Try to make the plane enable atomic by writing
1502 * the control register just before the surface register.
1504 I915_WRITE_FW(SPRCTL(pipe), sprctl);
1505 I915_WRITE_FW(SPRSURF(pipe),
1506 intel_plane_ggtt_offset(plane_state) + sprsurf_offset);
1508 ivb_update_gamma(plane_state);
1510 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
1514 ivb_disable_plane(struct intel_plane *plane,
1515 const struct intel_crtc_state *crtc_state)
1517 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
1518 enum pipe pipe = plane->pipe;
1519 unsigned long irqflags;
1521 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
1523 I915_WRITE_FW(SPRCTL(pipe), 0);
1524 /* Disable the scaler */
1525 if (IS_IVYBRIDGE(dev_priv))
1526 I915_WRITE_FW(SPRSCALE(pipe), 0);
1527 I915_WRITE_FW(SPRSURF(pipe), 0);
1529 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
1533 ivb_plane_get_hw_state(struct intel_plane *plane,
1536 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
1537 enum intel_display_power_domain power_domain;
1538 intel_wakeref_t wakeref;
1541 power_domain = POWER_DOMAIN_PIPE(plane->pipe);
1542 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
1546 ret = I915_READ(SPRCTL(plane->pipe)) & SPRITE_ENABLE;
1548 *pipe = plane->pipe;
1550 intel_display_power_put(dev_priv, power_domain, wakeref);
1555 static int g4x_sprite_min_cdclk(const struct intel_crtc_state *crtc_state,
1556 const struct intel_plane_state *plane_state)
1558 const struct drm_framebuffer *fb = plane_state->hw.fb;
1559 unsigned int hscale, pixel_rate;
1560 unsigned int limit, decimate;
1563 * Note that crtc_state->pixel_rate accounts for both
1564 * horizontal and vertical panel fitter downscaling factors.
1565 * Pre-HSW bspec tells us to only consider the horizontal
1566 * downscaling factor here. We ignore that and just consider
1567 * both for simplicity.
1569 pixel_rate = crtc_state->pixel_rate;
1571 /* Horizontal downscaling limits the maximum pixel rate */
1572 hscale = drm_rect_calc_hscale(&plane_state->uapi.src,
1573 &plane_state->uapi.dst,
1575 if (hscale < 0x10000)
1578 /* Decimation steps at 2x,4x,8x,16x */
1579 decimate = ilog2(hscale >> 16);
1580 hscale >>= decimate;
1582 /* Starting limit is 90% of cdclk */
1585 /* -10% per decimation step */
1589 if (fb->format->cpp[0] >= 4)
1590 limit--; /* -10% for RGB */
1593 * We should also do -10% if sprite scaling is enabled
1594 * on the other pipe, but we can't really check for that,
1598 return DIV_ROUND_UP_ULL(mul_u32_u32(pixel_rate, 10 * hscale),
1603 g4x_sprite_max_stride(struct intel_plane *plane,
1604 u32 pixel_format, u64 modifier,
1605 unsigned int rotation)
1610 static u32 g4x_sprite_ctl_crtc(const struct intel_crtc_state *crtc_state)
1614 if (crtc_state->gamma_enable)
1615 dvscntr |= DVS_GAMMA_ENABLE;
1617 if (crtc_state->csc_enable)
1618 dvscntr |= DVS_PIPE_CSC_ENABLE;
1623 static u32 g4x_sprite_ctl(const struct intel_crtc_state *crtc_state,
1624 const struct intel_plane_state *plane_state)
1626 struct drm_i915_private *dev_priv =
1627 to_i915(plane_state->uapi.plane->dev);
1628 const struct drm_framebuffer *fb = plane_state->hw.fb;
1629 unsigned int rotation = plane_state->hw.rotation;
1630 const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
1633 dvscntr = DVS_ENABLE;
1635 if (IS_GEN(dev_priv, 6))
1636 dvscntr |= DVS_TRICKLE_FEED_DISABLE;
1638 switch (fb->format->format) {
1639 case DRM_FORMAT_XBGR8888:
1640 dvscntr |= DVS_FORMAT_RGBX888 | DVS_RGB_ORDER_XBGR;
1642 case DRM_FORMAT_XRGB8888:
1643 dvscntr |= DVS_FORMAT_RGBX888;
1645 case DRM_FORMAT_XBGR2101010:
1646 dvscntr |= DVS_FORMAT_RGBX101010 | DVS_RGB_ORDER_XBGR;
1648 case DRM_FORMAT_XRGB2101010:
1649 dvscntr |= DVS_FORMAT_RGBX101010;
1651 case DRM_FORMAT_XBGR16161616F:
1652 dvscntr |= DVS_FORMAT_RGBX161616 | DVS_RGB_ORDER_XBGR;
1654 case DRM_FORMAT_XRGB16161616F:
1655 dvscntr |= DVS_FORMAT_RGBX161616;
1657 case DRM_FORMAT_YUYV:
1658 dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_YUYV;
1660 case DRM_FORMAT_YVYU:
1661 dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_YVYU;
1663 case DRM_FORMAT_UYVY:
1664 dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_UYVY;
1666 case DRM_FORMAT_VYUY:
1667 dvscntr |= DVS_FORMAT_YUV422 | DVS_YUV_ORDER_VYUY;
1670 MISSING_CASE(fb->format->format);
1674 if (plane_state->hw.color_encoding == DRM_COLOR_YCBCR_BT709)
1675 dvscntr |= DVS_YUV_FORMAT_BT709;
1677 if (plane_state->hw.color_range == DRM_COLOR_YCBCR_FULL_RANGE)
1678 dvscntr |= DVS_YUV_RANGE_CORRECTION_DISABLE;
1680 if (fb->modifier == I915_FORMAT_MOD_X_TILED)
1681 dvscntr |= DVS_TILED;
1683 if (rotation & DRM_MODE_ROTATE_180)
1684 dvscntr |= DVS_ROTATE_180;
1686 if (key->flags & I915_SET_COLORKEY_DESTINATION)
1687 dvscntr |= DVS_DEST_KEY;
1688 else if (key->flags & I915_SET_COLORKEY_SOURCE)
1689 dvscntr |= DVS_SOURCE_KEY;
1694 static void g4x_update_gamma(const struct intel_plane_state *plane_state)
1696 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
1697 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
1698 const struct drm_framebuffer *fb = plane_state->hw.fb;
1699 enum pipe pipe = plane->pipe;
1703 /* Seems RGB data bypasses the gamma always */
1704 if (!fb->format->is_yuv)
1707 i9xx_plane_linear_gamma(gamma);
1709 /* FIXME these register are single buffered :( */
1710 /* The two end points are implicit (0.0 and 1.0) */
1711 for (i = 1; i < 8 - 1; i++)
1712 I915_WRITE_FW(DVSGAMC_G4X(pipe, i - 1),
1718 static void ilk_sprite_linear_gamma(u16 gamma[17])
1722 for (i = 0; i < 17; i++)
1723 gamma[i] = (i << 10) / 16;
1726 static void ilk_update_gamma(const struct intel_plane_state *plane_state)
1728 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
1729 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
1730 const struct drm_framebuffer *fb = plane_state->hw.fb;
1731 enum pipe pipe = plane->pipe;
1735 /* Seems RGB data bypasses the gamma always */
1736 if (!fb->format->is_yuv)
1739 ilk_sprite_linear_gamma(gamma);
1741 /* FIXME these register are single buffered :( */
1742 for (i = 0; i < 16; i++)
1743 I915_WRITE_FW(DVSGAMC_ILK(pipe, i),
1748 I915_WRITE_FW(DVSGAMCMAX_ILK(pipe, 0), gamma[i]);
1749 I915_WRITE_FW(DVSGAMCMAX_ILK(pipe, 1), gamma[i]);
1750 I915_WRITE_FW(DVSGAMCMAX_ILK(pipe, 2), gamma[i]);
1755 g4x_update_plane(struct intel_plane *plane,
1756 const struct intel_crtc_state *crtc_state,
1757 const struct intel_plane_state *plane_state)
1759 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
1760 enum pipe pipe = plane->pipe;
1761 u32 dvssurf_offset = plane_state->color_plane[0].offset;
1763 const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
1764 int crtc_x = plane_state->uapi.dst.x1;
1765 int crtc_y = plane_state->uapi.dst.y1;
1766 u32 crtc_w = drm_rect_width(&plane_state->uapi.dst);
1767 u32 crtc_h = drm_rect_height(&plane_state->uapi.dst);
1768 u32 x = plane_state->color_plane[0].x;
1769 u32 y = plane_state->color_plane[0].y;
1770 u32 src_w = drm_rect_width(&plane_state->uapi.src) >> 16;
1771 u32 src_h = drm_rect_height(&plane_state->uapi.src) >> 16;
1772 u32 dvscntr, dvsscale = 0;
1773 unsigned long irqflags;
1775 dvscntr = plane_state->ctl | g4x_sprite_ctl_crtc(crtc_state);
1777 /* Sizes are 0 based */
1783 if (crtc_w != src_w || crtc_h != src_h)
1784 dvsscale = DVS_SCALE_ENABLE | (src_w << 16) | src_h;
1786 linear_offset = intel_fb_xy_to_linear(x, y, plane_state, 0);
1788 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
1790 I915_WRITE_FW(DVSSTRIDE(pipe), plane_state->color_plane[0].stride);
1791 I915_WRITE_FW(DVSPOS(pipe), (crtc_y << 16) | crtc_x);
1792 I915_WRITE_FW(DVSSIZE(pipe), (crtc_h << 16) | crtc_w);
1793 I915_WRITE_FW(DVSSCALE(pipe), dvsscale);
1796 I915_WRITE_FW(DVSKEYVAL(pipe), key->min_value);
1797 I915_WRITE_FW(DVSKEYMSK(pipe), key->channel_mask);
1798 I915_WRITE_FW(DVSKEYMAX(pipe), key->max_value);
1801 I915_WRITE_FW(DVSLINOFF(pipe), linear_offset);
1802 I915_WRITE_FW(DVSTILEOFF(pipe), (y << 16) | x);
1805 * The control register self-arms if the plane was previously
1806 * disabled. Try to make the plane enable atomic by writing
1807 * the control register just before the surface register.
1809 I915_WRITE_FW(DVSCNTR(pipe), dvscntr);
1810 I915_WRITE_FW(DVSSURF(pipe),
1811 intel_plane_ggtt_offset(plane_state) + dvssurf_offset);
1813 if (IS_G4X(dev_priv))
1814 g4x_update_gamma(plane_state);
1816 ilk_update_gamma(plane_state);
1818 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
1822 g4x_disable_plane(struct intel_plane *plane,
1823 const struct intel_crtc_state *crtc_state)
1825 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
1826 enum pipe pipe = plane->pipe;
1827 unsigned long irqflags;
1829 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
1831 I915_WRITE_FW(DVSCNTR(pipe), 0);
1832 /* Disable the scaler */
1833 I915_WRITE_FW(DVSSCALE(pipe), 0);
1834 I915_WRITE_FW(DVSSURF(pipe), 0);
1836 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
1840 g4x_plane_get_hw_state(struct intel_plane *plane,
1843 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
1844 enum intel_display_power_domain power_domain;
1845 intel_wakeref_t wakeref;
1848 power_domain = POWER_DOMAIN_PIPE(plane->pipe);
1849 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
1853 ret = I915_READ(DVSCNTR(plane->pipe)) & DVS_ENABLE;
1855 *pipe = plane->pipe;
1857 intel_display_power_put(dev_priv, power_domain, wakeref);
1862 static bool intel_fb_scalable(const struct drm_framebuffer *fb)
1867 switch (fb->format->format) {
1870 case DRM_FORMAT_XRGB16161616F:
1871 case DRM_FORMAT_ARGB16161616F:
1872 case DRM_FORMAT_XBGR16161616F:
1873 case DRM_FORMAT_ABGR16161616F:
1874 return INTEL_GEN(to_i915(fb->dev)) >= 11;
1881 g4x_sprite_check_scaling(struct intel_crtc_state *crtc_state,
1882 struct intel_plane_state *plane_state)
1884 const struct drm_framebuffer *fb = plane_state->hw.fb;
1885 const struct drm_rect *src = &plane_state->uapi.src;
1886 const struct drm_rect *dst = &plane_state->uapi.dst;
1887 int src_x, src_w, src_h, crtc_w, crtc_h;
1888 const struct drm_display_mode *adjusted_mode =
1889 &crtc_state->hw.adjusted_mode;
1890 unsigned int stride = plane_state->color_plane[0].stride;
1891 unsigned int cpp = fb->format->cpp[0];
1892 unsigned int width_bytes;
1893 int min_width, min_height;
1895 crtc_w = drm_rect_width(dst);
1896 crtc_h = drm_rect_height(dst);
1898 src_x = src->x1 >> 16;
1899 src_w = drm_rect_width(src) >> 16;
1900 src_h = drm_rect_height(src) >> 16;
1902 if (src_w == crtc_w && src_h == crtc_h)
1907 if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
1909 DRM_DEBUG_KMS("Source height must be even with interlaced modes\n");
1917 width_bytes = ((src_x * cpp) & 63) + src_w * cpp;
1919 if (src_w < min_width || src_h < min_height ||
1920 src_w > 2048 || src_h > 2048) {
1921 DRM_DEBUG_KMS("Source dimensions (%dx%d) exceed hardware limits (%dx%d - %dx%d)\n",
1922 src_w, src_h, min_width, min_height, 2048, 2048);
1926 if (width_bytes > 4096) {
1927 DRM_DEBUG_KMS("Fetch width (%d) exceeds hardware max with scaling (%u)\n",
1932 if (stride > 4096) {
1933 DRM_DEBUG_KMS("Stride (%u) exceeds hardware max with scaling (%u)\n",
1942 g4x_sprite_check(struct intel_crtc_state *crtc_state,
1943 struct intel_plane_state *plane_state)
1945 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
1946 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
1947 int min_scale = DRM_PLANE_HELPER_NO_SCALING;
1948 int max_scale = DRM_PLANE_HELPER_NO_SCALING;
1951 if (intel_fb_scalable(plane_state->hw.fb)) {
1952 if (INTEL_GEN(dev_priv) < 7) {
1954 max_scale = 16 << 16;
1955 } else if (IS_IVYBRIDGE(dev_priv)) {
1957 max_scale = 2 << 16;
1961 ret = drm_atomic_helper_check_plane_state(&plane_state->uapi,
1963 min_scale, max_scale,
1968 ret = i9xx_check_plane_surface(plane_state);
1972 if (!plane_state->uapi.visible)
1975 ret = intel_plane_check_src_coordinates(plane_state);
1979 ret = g4x_sprite_check_scaling(crtc_state, plane_state);
1983 if (INTEL_GEN(dev_priv) >= 7)
1984 plane_state->ctl = ivb_sprite_ctl(crtc_state, plane_state);
1986 plane_state->ctl = g4x_sprite_ctl(crtc_state, plane_state);
1991 int chv_plane_check_rotation(const struct intel_plane_state *plane_state)
1993 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
1994 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
1995 unsigned int rotation = plane_state->hw.rotation;
1997 /* CHV ignores the mirror bit when the rotate bit is set :( */
1998 if (IS_CHERRYVIEW(dev_priv) &&
1999 rotation & DRM_MODE_ROTATE_180 &&
2000 rotation & DRM_MODE_REFLECT_X) {
2001 DRM_DEBUG_KMS("Cannot rotate and reflect at the same time\n");
2009 vlv_sprite_check(struct intel_crtc_state *crtc_state,
2010 struct intel_plane_state *plane_state)
2014 ret = chv_plane_check_rotation(plane_state);
2018 ret = drm_atomic_helper_check_plane_state(&plane_state->uapi,
2020 DRM_PLANE_HELPER_NO_SCALING,
2021 DRM_PLANE_HELPER_NO_SCALING,
2026 ret = i9xx_check_plane_surface(plane_state);
2030 if (!plane_state->uapi.visible)
2033 ret = intel_plane_check_src_coordinates(plane_state);
2037 plane_state->ctl = vlv_sprite_ctl(crtc_state, plane_state);
2042 static int skl_plane_check_fb(const struct intel_crtc_state *crtc_state,
2043 const struct intel_plane_state *plane_state)
2045 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
2046 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
2047 const struct drm_framebuffer *fb = plane_state->hw.fb;
2048 unsigned int rotation = plane_state->hw.rotation;
2049 struct drm_format_name_buf format_name;
2054 if (rotation & ~(DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180) &&
2055 is_ccs_modifier(fb->modifier)) {
2056 DRM_DEBUG_KMS("RC support only with 0/180 degree rotation (%x)\n",
2061 if (rotation & DRM_MODE_REFLECT_X &&
2062 fb->modifier == DRM_FORMAT_MOD_LINEAR) {
2063 DRM_DEBUG_KMS("horizontal flip is not supported with linear surface formats\n");
2067 if (drm_rotation_90_or_270(rotation)) {
2068 if (fb->modifier != I915_FORMAT_MOD_Y_TILED &&
2069 fb->modifier != I915_FORMAT_MOD_Yf_TILED) {
2070 DRM_DEBUG_KMS("Y/Yf tiling required for 90/270!\n");
2075 * 90/270 is not allowed with RGB64 16:16:16:16 and
2076 * Indexed 8-bit. RGB 16-bit 5:6:5 is allowed gen11 onwards.
2078 switch (fb->format->format) {
2079 case DRM_FORMAT_RGB565:
2080 if (INTEL_GEN(dev_priv) >= 11)
2084 case DRM_FORMAT_XRGB16161616F:
2085 case DRM_FORMAT_XBGR16161616F:
2086 case DRM_FORMAT_ARGB16161616F:
2087 case DRM_FORMAT_ABGR16161616F:
2088 case DRM_FORMAT_Y210:
2089 case DRM_FORMAT_Y212:
2090 case DRM_FORMAT_Y216:
2091 case DRM_FORMAT_XVYU12_16161616:
2092 case DRM_FORMAT_XVYU16161616:
2093 DRM_DEBUG_KMS("Unsupported pixel format %s for 90/270!\n",
2094 drm_get_format_name(fb->format->format,
2102 /* Y-tiling is not supported in IF-ID Interlace mode */
2103 if (crtc_state->hw.enable &&
2104 crtc_state->hw.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE &&
2105 (fb->modifier == I915_FORMAT_MOD_Y_TILED ||
2106 fb->modifier == I915_FORMAT_MOD_Yf_TILED ||
2107 fb->modifier == I915_FORMAT_MOD_Y_TILED_CCS ||
2108 fb->modifier == I915_FORMAT_MOD_Yf_TILED_CCS ||
2109 fb->modifier == I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS)) {
2110 DRM_DEBUG_KMS("Y/Yf tiling not supported in IF-ID mode\n");
2117 static int skl_plane_check_dst_coordinates(const struct intel_crtc_state *crtc_state,
2118 const struct intel_plane_state *plane_state)
2120 struct drm_i915_private *dev_priv =
2121 to_i915(plane_state->uapi.plane->dev);
2122 int crtc_x = plane_state->uapi.dst.x1;
2123 int crtc_w = drm_rect_width(&plane_state->uapi.dst);
2124 int pipe_src_w = crtc_state->pipe_src_w;
2127 * Display WA #1175: cnl,glk
2128 * Planes other than the cursor may cause FIFO underflow and display
2129 * corruption if starting less than 4 pixels from the right edge of
2131 * Besides the above WA fix the similar problem, where planes other
2132 * than the cursor ending less than 4 pixels from the left edge of the
2133 * screen may cause FIFO underflow and display corruption.
2135 if ((IS_GEMINILAKE(dev_priv) || IS_CANNONLAKE(dev_priv)) &&
2136 (crtc_x + crtc_w < 4 || crtc_x > pipe_src_w - 4)) {
2137 DRM_DEBUG_KMS("requested plane X %s position %d invalid (valid range %d-%d)\n",
2138 crtc_x + crtc_w < 4 ? "end" : "start",
2139 crtc_x + crtc_w < 4 ? crtc_x + crtc_w : crtc_x,
2147 static int skl_plane_check_nv12_rotation(const struct intel_plane_state *plane_state)
2149 const struct drm_framebuffer *fb = plane_state->hw.fb;
2150 unsigned int rotation = plane_state->hw.rotation;
2151 int src_w = drm_rect_width(&plane_state->uapi.src) >> 16;
2153 /* Display WA #1106 */
2154 if (intel_format_info_is_yuv_semiplanar(fb->format, fb->modifier) &&
2156 (rotation == DRM_MODE_ROTATE_270 ||
2157 rotation == (DRM_MODE_REFLECT_X | DRM_MODE_ROTATE_90))) {
2158 DRM_DEBUG_KMS("src width must be multiple of 4 for rotated planar YUV\n");
2165 static int skl_plane_max_scale(struct drm_i915_private *dev_priv,
2166 const struct drm_framebuffer *fb)
2169 * We don't yet know the final source width nor
2170 * whether we can use the HQ scaler mode. Assume
2172 * FIXME need to properly check this later.
2174 if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv) ||
2175 !intel_format_info_is_yuv_semiplanar(fb->format, fb->modifier))
2181 static int skl_plane_check(struct intel_crtc_state *crtc_state,
2182 struct intel_plane_state *plane_state)
2184 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
2185 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
2186 const struct drm_framebuffer *fb = plane_state->hw.fb;
2187 int min_scale = DRM_PLANE_HELPER_NO_SCALING;
2188 int max_scale = DRM_PLANE_HELPER_NO_SCALING;
2191 ret = skl_plane_check_fb(crtc_state, plane_state);
2195 /* use scaler when colorkey is not required */
2196 if (!plane_state->ckey.flags && intel_fb_scalable(fb)) {
2198 max_scale = skl_plane_max_scale(dev_priv, fb);
2201 ret = drm_atomic_helper_check_plane_state(&plane_state->uapi,
2203 min_scale, max_scale,
2208 ret = skl_check_plane_surface(plane_state);
2212 if (!plane_state->uapi.visible)
2215 ret = skl_plane_check_dst_coordinates(crtc_state, plane_state);
2219 ret = intel_plane_check_src_coordinates(plane_state);
2223 ret = skl_plane_check_nv12_rotation(plane_state);
2227 /* HW only has 8 bits pixel precision, disable plane if invisible */
2228 if (!(plane_state->hw.alpha >> 8))
2229 plane_state->uapi.visible = false;
2231 plane_state->ctl = skl_plane_ctl(crtc_state, plane_state);
2233 if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv))
2234 plane_state->color_ctl = glk_plane_color_ctl(crtc_state,
2237 if (intel_format_info_is_yuv_semiplanar(fb->format, fb->modifier) &&
2238 icl_is_hdr_plane(dev_priv, plane->id))
2239 /* Enable and use MPEG-2 chroma siting */
2240 plane_state->cus_ctl = PLANE_CUS_ENABLE |
2241 PLANE_CUS_HPHASE_0 |
2242 PLANE_CUS_VPHASE_SIGN_NEGATIVE | PLANE_CUS_VPHASE_0_25;
2244 plane_state->cus_ctl = 0;
2249 static bool has_dst_key_in_primary_plane(struct drm_i915_private *dev_priv)
2251 return INTEL_GEN(dev_priv) >= 9;
2254 static void intel_plane_set_ckey(struct intel_plane_state *plane_state,
2255 const struct drm_intel_sprite_colorkey *set)
2257 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
2258 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
2259 struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
2264 * We want src key enabled on the
2265 * sprite and not on the primary.
2267 if (plane->id == PLANE_PRIMARY &&
2268 set->flags & I915_SET_COLORKEY_SOURCE)
2272 * On SKL+ we want dst key enabled on
2273 * the primary and not on the sprite.
2275 if (INTEL_GEN(dev_priv) >= 9 && plane->id != PLANE_PRIMARY &&
2276 set->flags & I915_SET_COLORKEY_DESTINATION)
2280 int intel_sprite_set_colorkey_ioctl(struct drm_device *dev, void *data,
2281 struct drm_file *file_priv)
2283 struct drm_i915_private *dev_priv = to_i915(dev);
2284 struct drm_intel_sprite_colorkey *set = data;
2285 struct drm_plane *plane;
2286 struct drm_plane_state *plane_state;
2287 struct drm_atomic_state *state;
2288 struct drm_modeset_acquire_ctx ctx;
2291 /* ignore the pointless "none" flag */
2292 set->flags &= ~I915_SET_COLORKEY_NONE;
2294 if (set->flags & ~(I915_SET_COLORKEY_DESTINATION | I915_SET_COLORKEY_SOURCE))
2297 /* Make sure we don't try to enable both src & dest simultaneously */
2298 if ((set->flags & (I915_SET_COLORKEY_DESTINATION | I915_SET_COLORKEY_SOURCE)) == (I915_SET_COLORKEY_DESTINATION | I915_SET_COLORKEY_SOURCE))
2301 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
2302 set->flags & I915_SET_COLORKEY_DESTINATION)
2305 plane = drm_plane_find(dev, file_priv, set->plane_id);
2306 if (!plane || plane->type != DRM_PLANE_TYPE_OVERLAY)
2310 * SKL+ only plane 2 can do destination keying against plane 1.
2311 * Also multiple planes can't do destination keying on the same
2312 * pipe simultaneously.
2314 if (INTEL_GEN(dev_priv) >= 9 &&
2315 to_intel_plane(plane)->id >= PLANE_SPRITE1 &&
2316 set->flags & I915_SET_COLORKEY_DESTINATION)
2319 drm_modeset_acquire_init(&ctx, 0);
2321 state = drm_atomic_state_alloc(plane->dev);
2326 state->acquire_ctx = &ctx;
2329 plane_state = drm_atomic_get_plane_state(state, plane);
2330 ret = PTR_ERR_OR_ZERO(plane_state);
2332 intel_plane_set_ckey(to_intel_plane_state(plane_state), set);
2335 * On some platforms we have to configure
2336 * the dst colorkey on the primary plane.
2338 if (!ret && has_dst_key_in_primary_plane(dev_priv)) {
2339 struct intel_crtc *crtc =
2340 intel_get_crtc_for_pipe(dev_priv,
2341 to_intel_plane(plane)->pipe);
2343 plane_state = drm_atomic_get_plane_state(state,
2344 crtc->base.primary);
2345 ret = PTR_ERR_OR_ZERO(plane_state);
2347 intel_plane_set_ckey(to_intel_plane_state(plane_state), set);
2351 ret = drm_atomic_commit(state);
2353 if (ret != -EDEADLK)
2356 drm_atomic_state_clear(state);
2357 drm_modeset_backoff(&ctx);
2360 drm_atomic_state_put(state);
2362 drm_modeset_drop_locks(&ctx);
2363 drm_modeset_acquire_fini(&ctx);
2367 static const u32 g4x_plane_formats[] = {
2368 DRM_FORMAT_XRGB8888,
2375 static const u64 i9xx_plane_format_modifiers[] = {
2376 I915_FORMAT_MOD_X_TILED,
2377 DRM_FORMAT_MOD_LINEAR,
2378 DRM_FORMAT_MOD_INVALID
2381 static const u32 snb_plane_formats[] = {
2382 DRM_FORMAT_XRGB8888,
2383 DRM_FORMAT_XBGR8888,
2384 DRM_FORMAT_XRGB2101010,
2385 DRM_FORMAT_XBGR2101010,
2386 DRM_FORMAT_XRGB16161616F,
2387 DRM_FORMAT_XBGR16161616F,
2394 static const u32 vlv_plane_formats[] = {
2397 DRM_FORMAT_XRGB8888,
2398 DRM_FORMAT_XBGR8888,
2399 DRM_FORMAT_ARGB8888,
2400 DRM_FORMAT_ABGR8888,
2401 DRM_FORMAT_XBGR2101010,
2402 DRM_FORMAT_ABGR2101010,
2409 static const u32 chv_pipe_b_sprite_formats[] = {
2412 DRM_FORMAT_XRGB8888,
2413 DRM_FORMAT_XBGR8888,
2414 DRM_FORMAT_ARGB8888,
2415 DRM_FORMAT_ABGR8888,
2416 DRM_FORMAT_XRGB2101010,
2417 DRM_FORMAT_XBGR2101010,
2418 DRM_FORMAT_ARGB2101010,
2419 DRM_FORMAT_ABGR2101010,
2426 static const u32 skl_plane_formats[] = {
2429 DRM_FORMAT_XRGB8888,
2430 DRM_FORMAT_XBGR8888,
2431 DRM_FORMAT_ARGB8888,
2432 DRM_FORMAT_ABGR8888,
2433 DRM_FORMAT_XRGB2101010,
2434 DRM_FORMAT_XBGR2101010,
2435 DRM_FORMAT_XRGB16161616F,
2436 DRM_FORMAT_XBGR16161616F,
2443 static const u32 skl_planar_formats[] = {
2446 DRM_FORMAT_XRGB8888,
2447 DRM_FORMAT_XBGR8888,
2448 DRM_FORMAT_ARGB8888,
2449 DRM_FORMAT_ABGR8888,
2450 DRM_FORMAT_XRGB2101010,
2451 DRM_FORMAT_XBGR2101010,
2452 DRM_FORMAT_XRGB16161616F,
2453 DRM_FORMAT_XBGR16161616F,
2461 static const u32 glk_planar_formats[] = {
2464 DRM_FORMAT_XRGB8888,
2465 DRM_FORMAT_XBGR8888,
2466 DRM_FORMAT_ARGB8888,
2467 DRM_FORMAT_ABGR8888,
2468 DRM_FORMAT_XRGB2101010,
2469 DRM_FORMAT_XBGR2101010,
2470 DRM_FORMAT_XRGB16161616F,
2471 DRM_FORMAT_XBGR16161616F,
2482 static const u32 icl_sdr_y_plane_formats[] = {
2485 DRM_FORMAT_XRGB8888,
2486 DRM_FORMAT_XBGR8888,
2487 DRM_FORMAT_ARGB8888,
2488 DRM_FORMAT_ABGR8888,
2489 DRM_FORMAT_XRGB2101010,
2490 DRM_FORMAT_XBGR2101010,
2491 DRM_FORMAT_ARGB2101010,
2492 DRM_FORMAT_ABGR2101010,
2500 DRM_FORMAT_XVYU2101010,
2501 DRM_FORMAT_XVYU12_16161616,
2502 DRM_FORMAT_XVYU16161616,
2505 static const u32 icl_sdr_uv_plane_formats[] = {
2508 DRM_FORMAT_XRGB8888,
2509 DRM_FORMAT_XBGR8888,
2510 DRM_FORMAT_ARGB8888,
2511 DRM_FORMAT_ABGR8888,
2512 DRM_FORMAT_XRGB2101010,
2513 DRM_FORMAT_XBGR2101010,
2514 DRM_FORMAT_ARGB2101010,
2515 DRM_FORMAT_ABGR2101010,
2527 DRM_FORMAT_XVYU2101010,
2528 DRM_FORMAT_XVYU12_16161616,
2529 DRM_FORMAT_XVYU16161616,
2532 static const u32 icl_hdr_plane_formats[] = {
2535 DRM_FORMAT_XRGB8888,
2536 DRM_FORMAT_XBGR8888,
2537 DRM_FORMAT_ARGB8888,
2538 DRM_FORMAT_ABGR8888,
2539 DRM_FORMAT_XRGB2101010,
2540 DRM_FORMAT_XBGR2101010,
2541 DRM_FORMAT_ARGB2101010,
2542 DRM_FORMAT_ABGR2101010,
2543 DRM_FORMAT_XRGB16161616F,
2544 DRM_FORMAT_XBGR16161616F,
2545 DRM_FORMAT_ARGB16161616F,
2546 DRM_FORMAT_ABGR16161616F,
2558 DRM_FORMAT_XVYU2101010,
2559 DRM_FORMAT_XVYU12_16161616,
2560 DRM_FORMAT_XVYU16161616,
2563 static const u64 skl_plane_format_modifiers_noccs[] = {
2564 I915_FORMAT_MOD_Yf_TILED,
2565 I915_FORMAT_MOD_Y_TILED,
2566 I915_FORMAT_MOD_X_TILED,
2567 DRM_FORMAT_MOD_LINEAR,
2568 DRM_FORMAT_MOD_INVALID
2571 static const u64 skl_plane_format_modifiers_ccs[] = {
2572 I915_FORMAT_MOD_Yf_TILED_CCS,
2573 I915_FORMAT_MOD_Y_TILED_CCS,
2574 I915_FORMAT_MOD_Yf_TILED,
2575 I915_FORMAT_MOD_Y_TILED,
2576 I915_FORMAT_MOD_X_TILED,
2577 DRM_FORMAT_MOD_LINEAR,
2578 DRM_FORMAT_MOD_INVALID
2581 static const u64 gen12_plane_format_modifiers_ccs[] = {
2582 I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS,
2583 I915_FORMAT_MOD_Y_TILED,
2584 I915_FORMAT_MOD_X_TILED,
2585 DRM_FORMAT_MOD_LINEAR,
2586 DRM_FORMAT_MOD_INVALID
2589 static bool g4x_sprite_format_mod_supported(struct drm_plane *_plane,
2590 u32 format, u64 modifier)
2593 case DRM_FORMAT_MOD_LINEAR:
2594 case I915_FORMAT_MOD_X_TILED:
2601 case DRM_FORMAT_XRGB8888:
2602 case DRM_FORMAT_YUYV:
2603 case DRM_FORMAT_YVYU:
2604 case DRM_FORMAT_UYVY:
2605 case DRM_FORMAT_VYUY:
2606 if (modifier == DRM_FORMAT_MOD_LINEAR ||
2607 modifier == I915_FORMAT_MOD_X_TILED)
2615 static bool snb_sprite_format_mod_supported(struct drm_plane *_plane,
2616 u32 format, u64 modifier)
2619 case DRM_FORMAT_MOD_LINEAR:
2620 case I915_FORMAT_MOD_X_TILED:
2627 case DRM_FORMAT_XRGB8888:
2628 case DRM_FORMAT_XBGR8888:
2629 case DRM_FORMAT_XRGB2101010:
2630 case DRM_FORMAT_XBGR2101010:
2631 case DRM_FORMAT_XRGB16161616F:
2632 case DRM_FORMAT_XBGR16161616F:
2633 case DRM_FORMAT_YUYV:
2634 case DRM_FORMAT_YVYU:
2635 case DRM_FORMAT_UYVY:
2636 case DRM_FORMAT_VYUY:
2637 if (modifier == DRM_FORMAT_MOD_LINEAR ||
2638 modifier == I915_FORMAT_MOD_X_TILED)
2646 static bool vlv_sprite_format_mod_supported(struct drm_plane *_plane,
2647 u32 format, u64 modifier)
2650 case DRM_FORMAT_MOD_LINEAR:
2651 case I915_FORMAT_MOD_X_TILED:
2659 case DRM_FORMAT_RGB565:
2660 case DRM_FORMAT_ABGR8888:
2661 case DRM_FORMAT_ARGB8888:
2662 case DRM_FORMAT_XBGR8888:
2663 case DRM_FORMAT_XRGB8888:
2664 case DRM_FORMAT_XBGR2101010:
2665 case DRM_FORMAT_ABGR2101010:
2666 case DRM_FORMAT_XRGB2101010:
2667 case DRM_FORMAT_ARGB2101010:
2668 case DRM_FORMAT_YUYV:
2669 case DRM_FORMAT_YVYU:
2670 case DRM_FORMAT_UYVY:
2671 case DRM_FORMAT_VYUY:
2672 if (modifier == DRM_FORMAT_MOD_LINEAR ||
2673 modifier == I915_FORMAT_MOD_X_TILED)
2681 static bool skl_plane_format_mod_supported(struct drm_plane *_plane,
2682 u32 format, u64 modifier)
2684 struct intel_plane *plane = to_intel_plane(_plane);
2687 case DRM_FORMAT_MOD_LINEAR:
2688 case I915_FORMAT_MOD_X_TILED:
2689 case I915_FORMAT_MOD_Y_TILED:
2690 case I915_FORMAT_MOD_Yf_TILED:
2692 case I915_FORMAT_MOD_Y_TILED_CCS:
2693 case I915_FORMAT_MOD_Yf_TILED_CCS:
2694 if (!plane->has_ccs)
2702 case DRM_FORMAT_XRGB8888:
2703 case DRM_FORMAT_XBGR8888:
2704 case DRM_FORMAT_ARGB8888:
2705 case DRM_FORMAT_ABGR8888:
2706 if (is_ccs_modifier(modifier))
2709 case DRM_FORMAT_RGB565:
2710 case DRM_FORMAT_XRGB2101010:
2711 case DRM_FORMAT_XBGR2101010:
2712 case DRM_FORMAT_ARGB2101010:
2713 case DRM_FORMAT_ABGR2101010:
2714 case DRM_FORMAT_YUYV:
2715 case DRM_FORMAT_YVYU:
2716 case DRM_FORMAT_UYVY:
2717 case DRM_FORMAT_VYUY:
2718 case DRM_FORMAT_NV12:
2719 case DRM_FORMAT_P010:
2720 case DRM_FORMAT_P012:
2721 case DRM_FORMAT_P016:
2722 case DRM_FORMAT_XVYU2101010:
2723 if (modifier == I915_FORMAT_MOD_Yf_TILED)
2727 case DRM_FORMAT_XBGR16161616F:
2728 case DRM_FORMAT_ABGR16161616F:
2729 case DRM_FORMAT_XRGB16161616F:
2730 case DRM_FORMAT_ARGB16161616F:
2731 case DRM_FORMAT_Y210:
2732 case DRM_FORMAT_Y212:
2733 case DRM_FORMAT_Y216:
2734 case DRM_FORMAT_XVYU12_16161616:
2735 case DRM_FORMAT_XVYU16161616:
2736 if (modifier == DRM_FORMAT_MOD_LINEAR ||
2737 modifier == I915_FORMAT_MOD_X_TILED ||
2738 modifier == I915_FORMAT_MOD_Y_TILED)
2746 static bool gen12_plane_format_mod_supported(struct drm_plane *_plane,
2747 u32 format, u64 modifier)
2750 case DRM_FORMAT_MOD_LINEAR:
2751 case I915_FORMAT_MOD_X_TILED:
2752 case I915_FORMAT_MOD_Y_TILED:
2753 case I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS:
2760 case DRM_FORMAT_XRGB8888:
2761 case DRM_FORMAT_XBGR8888:
2762 case DRM_FORMAT_ARGB8888:
2763 case DRM_FORMAT_ABGR8888:
2764 if (is_ccs_modifier(modifier))
2767 case DRM_FORMAT_RGB565:
2768 case DRM_FORMAT_XRGB2101010:
2769 case DRM_FORMAT_XBGR2101010:
2770 case DRM_FORMAT_ARGB2101010:
2771 case DRM_FORMAT_ABGR2101010:
2772 case DRM_FORMAT_YUYV:
2773 case DRM_FORMAT_YVYU:
2774 case DRM_FORMAT_UYVY:
2775 case DRM_FORMAT_VYUY:
2776 case DRM_FORMAT_NV12:
2777 case DRM_FORMAT_P010:
2778 case DRM_FORMAT_P012:
2779 case DRM_FORMAT_P016:
2780 case DRM_FORMAT_XVYU2101010:
2782 case DRM_FORMAT_XBGR16161616F:
2783 case DRM_FORMAT_ABGR16161616F:
2784 case DRM_FORMAT_XRGB16161616F:
2785 case DRM_FORMAT_ARGB16161616F:
2786 case DRM_FORMAT_Y210:
2787 case DRM_FORMAT_Y212:
2788 case DRM_FORMAT_Y216:
2789 case DRM_FORMAT_XVYU12_16161616:
2790 case DRM_FORMAT_XVYU16161616:
2791 if (modifier == DRM_FORMAT_MOD_LINEAR ||
2792 modifier == I915_FORMAT_MOD_X_TILED ||
2793 modifier == I915_FORMAT_MOD_Y_TILED)
2801 static const struct drm_plane_funcs g4x_sprite_funcs = {
2802 .update_plane = drm_atomic_helper_update_plane,
2803 .disable_plane = drm_atomic_helper_disable_plane,
2804 .destroy = intel_plane_destroy,
2805 .atomic_duplicate_state = intel_plane_duplicate_state,
2806 .atomic_destroy_state = intel_plane_destroy_state,
2807 .format_mod_supported = g4x_sprite_format_mod_supported,
2810 static const struct drm_plane_funcs snb_sprite_funcs = {
2811 .update_plane = drm_atomic_helper_update_plane,
2812 .disable_plane = drm_atomic_helper_disable_plane,
2813 .destroy = intel_plane_destroy,
2814 .atomic_duplicate_state = intel_plane_duplicate_state,
2815 .atomic_destroy_state = intel_plane_destroy_state,
2816 .format_mod_supported = snb_sprite_format_mod_supported,
2819 static const struct drm_plane_funcs vlv_sprite_funcs = {
2820 .update_plane = drm_atomic_helper_update_plane,
2821 .disable_plane = drm_atomic_helper_disable_plane,
2822 .destroy = intel_plane_destroy,
2823 .atomic_duplicate_state = intel_plane_duplicate_state,
2824 .atomic_destroy_state = intel_plane_destroy_state,
2825 .format_mod_supported = vlv_sprite_format_mod_supported,
2828 static const struct drm_plane_funcs skl_plane_funcs = {
2829 .update_plane = drm_atomic_helper_update_plane,
2830 .disable_plane = drm_atomic_helper_disable_plane,
2831 .destroy = intel_plane_destroy,
2832 .atomic_duplicate_state = intel_plane_duplicate_state,
2833 .atomic_destroy_state = intel_plane_destroy_state,
2834 .format_mod_supported = skl_plane_format_mod_supported,
2837 static const struct drm_plane_funcs gen12_plane_funcs = {
2838 .update_plane = drm_atomic_helper_update_plane,
2839 .disable_plane = drm_atomic_helper_disable_plane,
2840 .destroy = intel_plane_destroy,
2841 .atomic_duplicate_state = intel_plane_duplicate_state,
2842 .atomic_destroy_state = intel_plane_destroy_state,
2843 .format_mod_supported = gen12_plane_format_mod_supported,
2846 static bool skl_plane_has_fbc(struct drm_i915_private *dev_priv,
2847 enum pipe pipe, enum plane_id plane_id)
2849 if (!HAS_FBC(dev_priv))
2852 return pipe == PIPE_A && plane_id == PLANE_PRIMARY;
2855 static bool skl_plane_has_planar(struct drm_i915_private *dev_priv,
2856 enum pipe pipe, enum plane_id plane_id)
2858 /* Display WA #0870: skl, bxt */
2859 if (IS_SKYLAKE(dev_priv) || IS_BROXTON(dev_priv))
2862 if (IS_GEN(dev_priv, 9) && !IS_GEMINILAKE(dev_priv) && pipe == PIPE_C)
2865 if (plane_id != PLANE_PRIMARY && plane_id != PLANE_SPRITE0)
2871 static const u32 *skl_get_plane_formats(struct drm_i915_private *dev_priv,
2872 enum pipe pipe, enum plane_id plane_id,
2875 if (skl_plane_has_planar(dev_priv, pipe, plane_id)) {
2876 *num_formats = ARRAY_SIZE(skl_planar_formats);
2877 return skl_planar_formats;
2879 *num_formats = ARRAY_SIZE(skl_plane_formats);
2880 return skl_plane_formats;
2884 static const u32 *glk_get_plane_formats(struct drm_i915_private *dev_priv,
2885 enum pipe pipe, enum plane_id plane_id,
2888 if (skl_plane_has_planar(dev_priv, pipe, plane_id)) {
2889 *num_formats = ARRAY_SIZE(glk_planar_formats);
2890 return glk_planar_formats;
2892 *num_formats = ARRAY_SIZE(skl_plane_formats);
2893 return skl_plane_formats;
2897 static const u32 *icl_get_plane_formats(struct drm_i915_private *dev_priv,
2898 enum pipe pipe, enum plane_id plane_id,
2901 if (icl_is_hdr_plane(dev_priv, plane_id)) {
2902 *num_formats = ARRAY_SIZE(icl_hdr_plane_formats);
2903 return icl_hdr_plane_formats;
2904 } else if (icl_is_nv12_y_plane(plane_id)) {
2905 *num_formats = ARRAY_SIZE(icl_sdr_y_plane_formats);
2906 return icl_sdr_y_plane_formats;
2908 *num_formats = ARRAY_SIZE(icl_sdr_uv_plane_formats);
2909 return icl_sdr_uv_plane_formats;
2913 static bool skl_plane_has_ccs(struct drm_i915_private *dev_priv,
2914 enum pipe pipe, enum plane_id plane_id)
2916 if (plane_id == PLANE_CURSOR)
2919 if (INTEL_GEN(dev_priv) >= 10)
2922 if (IS_GEMINILAKE(dev_priv))
2923 return pipe != PIPE_C;
2925 return pipe != PIPE_C &&
2926 (plane_id == PLANE_PRIMARY ||
2927 plane_id == PLANE_SPRITE0);
2930 struct intel_plane *
2931 skl_universal_plane_create(struct drm_i915_private *dev_priv,
2932 enum pipe pipe, enum plane_id plane_id)
2934 const struct drm_plane_funcs *plane_funcs;
2935 struct intel_plane *plane;
2936 enum drm_plane_type plane_type;
2937 unsigned int supported_rotations;
2938 unsigned int possible_crtcs;
2939 const u64 *modifiers;
2944 plane = intel_plane_alloc();
2949 plane->id = plane_id;
2950 plane->frontbuffer_bit = INTEL_FRONTBUFFER(pipe, plane_id);
2952 plane->has_fbc = skl_plane_has_fbc(dev_priv, pipe, plane_id);
2953 if (plane->has_fbc) {
2954 struct intel_fbc *fbc = &dev_priv->fbc;
2956 fbc->possible_framebuffer_bits |= plane->frontbuffer_bit;
2959 plane->max_stride = skl_plane_max_stride;
2960 plane->update_plane = skl_update_plane;
2961 plane->disable_plane = skl_disable_plane;
2962 plane->get_hw_state = skl_plane_get_hw_state;
2963 plane->check_plane = skl_plane_check;
2964 plane->min_cdclk = skl_plane_min_cdclk;
2966 if (INTEL_GEN(dev_priv) >= 11)
2967 formats = icl_get_plane_formats(dev_priv, pipe,
2968 plane_id, &num_formats);
2969 else if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv))
2970 formats = glk_get_plane_formats(dev_priv, pipe,
2971 plane_id, &num_formats);
2973 formats = skl_get_plane_formats(dev_priv, pipe,
2974 plane_id, &num_formats);
2976 plane->has_ccs = skl_plane_has_ccs(dev_priv, pipe, plane_id);
2977 if (INTEL_GEN(dev_priv) >= 12) {
2978 modifiers = gen12_plane_format_modifiers_ccs;
2979 plane_funcs = &gen12_plane_funcs;
2982 modifiers = skl_plane_format_modifiers_ccs;
2984 modifiers = skl_plane_format_modifiers_noccs;
2985 plane_funcs = &skl_plane_funcs;
2988 if (plane_id == PLANE_PRIMARY)
2989 plane_type = DRM_PLANE_TYPE_PRIMARY;
2991 plane_type = DRM_PLANE_TYPE_OVERLAY;
2993 possible_crtcs = BIT(pipe);
2995 ret = drm_universal_plane_init(&dev_priv->drm, &plane->base,
2996 possible_crtcs, plane_funcs,
2997 formats, num_formats, modifiers,
2999 "plane %d%c", plane_id + 1,
3004 supported_rotations =
3005 DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_90 |
3006 DRM_MODE_ROTATE_180 | DRM_MODE_ROTATE_270;
3008 if (INTEL_GEN(dev_priv) >= 10)
3009 supported_rotations |= DRM_MODE_REFLECT_X;
3011 drm_plane_create_rotation_property(&plane->base,
3013 supported_rotations);
3015 drm_plane_create_color_properties(&plane->base,
3016 BIT(DRM_COLOR_YCBCR_BT601) |
3017 BIT(DRM_COLOR_YCBCR_BT709),
3018 BIT(DRM_COLOR_YCBCR_LIMITED_RANGE) |
3019 BIT(DRM_COLOR_YCBCR_FULL_RANGE),
3020 DRM_COLOR_YCBCR_BT709,
3021 DRM_COLOR_YCBCR_LIMITED_RANGE);
3023 drm_plane_create_alpha_property(&plane->base);
3024 drm_plane_create_blend_mode_property(&plane->base,
3025 BIT(DRM_MODE_BLEND_PIXEL_NONE) |
3026 BIT(DRM_MODE_BLEND_PREMULTI) |
3027 BIT(DRM_MODE_BLEND_COVERAGE));
3029 drm_plane_create_zpos_immutable_property(&plane->base, plane_id);
3031 drm_plane_helper_add(&plane->base, &intel_plane_helper_funcs);
3036 intel_plane_free(plane);
3038 return ERR_PTR(ret);
3041 struct intel_plane *
3042 intel_sprite_plane_create(struct drm_i915_private *dev_priv,
3043 enum pipe pipe, int sprite)
3045 struct intel_plane *plane;
3046 const struct drm_plane_funcs *plane_funcs;
3047 unsigned long possible_crtcs;
3048 unsigned int supported_rotations;
3049 const u64 *modifiers;
3054 if (INTEL_GEN(dev_priv) >= 9)
3055 return skl_universal_plane_create(dev_priv, pipe,
3056 PLANE_SPRITE0 + sprite);
3058 plane = intel_plane_alloc();
3062 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
3063 plane->max_stride = i9xx_plane_max_stride;
3064 plane->update_plane = vlv_update_plane;
3065 plane->disable_plane = vlv_disable_plane;
3066 plane->get_hw_state = vlv_plane_get_hw_state;
3067 plane->check_plane = vlv_sprite_check;
3068 plane->min_cdclk = vlv_plane_min_cdclk;
3070 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B) {
3071 formats = chv_pipe_b_sprite_formats;
3072 num_formats = ARRAY_SIZE(chv_pipe_b_sprite_formats);
3074 formats = vlv_plane_formats;
3075 num_formats = ARRAY_SIZE(vlv_plane_formats);
3077 modifiers = i9xx_plane_format_modifiers;
3079 plane_funcs = &vlv_sprite_funcs;
3080 } else if (INTEL_GEN(dev_priv) >= 7) {
3081 plane->max_stride = g4x_sprite_max_stride;
3082 plane->update_plane = ivb_update_plane;
3083 plane->disable_plane = ivb_disable_plane;
3084 plane->get_hw_state = ivb_plane_get_hw_state;
3085 plane->check_plane = g4x_sprite_check;
3087 if (IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv))
3088 plane->min_cdclk = hsw_plane_min_cdclk;
3090 plane->min_cdclk = ivb_sprite_min_cdclk;
3092 formats = snb_plane_formats;
3093 num_formats = ARRAY_SIZE(snb_plane_formats);
3094 modifiers = i9xx_plane_format_modifiers;
3096 plane_funcs = &snb_sprite_funcs;
3098 plane->max_stride = g4x_sprite_max_stride;
3099 plane->update_plane = g4x_update_plane;
3100 plane->disable_plane = g4x_disable_plane;
3101 plane->get_hw_state = g4x_plane_get_hw_state;
3102 plane->check_plane = g4x_sprite_check;
3103 plane->min_cdclk = g4x_sprite_min_cdclk;
3105 modifiers = i9xx_plane_format_modifiers;
3106 if (IS_GEN(dev_priv, 6)) {
3107 formats = snb_plane_formats;
3108 num_formats = ARRAY_SIZE(snb_plane_formats);
3110 plane_funcs = &snb_sprite_funcs;
3112 formats = g4x_plane_formats;
3113 num_formats = ARRAY_SIZE(g4x_plane_formats);
3115 plane_funcs = &g4x_sprite_funcs;
3119 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B) {
3120 supported_rotations =
3121 DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180 |
3124 supported_rotations =
3125 DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180;
3129 plane->id = PLANE_SPRITE0 + sprite;
3130 plane->frontbuffer_bit = INTEL_FRONTBUFFER(pipe, plane->id);
3132 possible_crtcs = BIT(pipe);
3134 ret = drm_universal_plane_init(&dev_priv->drm, &plane->base,
3135 possible_crtcs, plane_funcs,
3136 formats, num_formats, modifiers,
3137 DRM_PLANE_TYPE_OVERLAY,
3138 "sprite %c", sprite_name(pipe, sprite));
3142 drm_plane_create_rotation_property(&plane->base,
3144 supported_rotations);
3146 drm_plane_create_color_properties(&plane->base,
3147 BIT(DRM_COLOR_YCBCR_BT601) |
3148 BIT(DRM_COLOR_YCBCR_BT709),
3149 BIT(DRM_COLOR_YCBCR_LIMITED_RANGE) |
3150 BIT(DRM_COLOR_YCBCR_FULL_RANGE),
3151 DRM_COLOR_YCBCR_BT709,
3152 DRM_COLOR_YCBCR_LIMITED_RANGE);
3155 drm_plane_create_zpos_immutable_property(&plane->base, zpos);
3157 drm_plane_helper_add(&plane->base, &intel_plane_helper_funcs);
3162 intel_plane_free(plane);
3164 return ERR_PTR(ret);