1 // SPDX-License-Identifier: MIT
3 * Copyright © 2020 Intel Corporation
6 #include <drm/drm_atomic_helper.h>
7 #include <drm/drm_damage_helper.h>
8 #include <drm/drm_fourcc.h>
9 #include <drm/drm_plane_helper.h>
12 #include "intel_atomic_plane.h"
14 #include "intel_display_types.h"
17 #include "intel_psr.h"
18 #include "intel_sprite.h"
19 #include "skl_scaler.h"
20 #include "skl_universal_plane.h"
21 #include "pxp/intel_pxp.h"
23 static const u32 skl_plane_formats[] = {
30 DRM_FORMAT_XRGB2101010,
31 DRM_FORMAT_XBGR2101010,
32 DRM_FORMAT_XRGB16161616F,
33 DRM_FORMAT_XBGR16161616F,
41 static const u32 skl_planar_formats[] = {
48 DRM_FORMAT_XRGB2101010,
49 DRM_FORMAT_XBGR2101010,
50 DRM_FORMAT_XRGB16161616F,
51 DRM_FORMAT_XBGR16161616F,
60 static const u32 glk_planar_formats[] = {
67 DRM_FORMAT_XRGB2101010,
68 DRM_FORMAT_XBGR2101010,
69 DRM_FORMAT_XRGB16161616F,
70 DRM_FORMAT_XBGR16161616F,
82 static const u32 icl_sdr_y_plane_formats[] = {
89 DRM_FORMAT_XRGB2101010,
90 DRM_FORMAT_XBGR2101010,
91 DRM_FORMAT_ARGB2101010,
92 DRM_FORMAT_ABGR2101010,
101 DRM_FORMAT_XVYU2101010,
102 DRM_FORMAT_XVYU12_16161616,
103 DRM_FORMAT_XVYU16161616,
106 static const u32 icl_sdr_uv_plane_formats[] = {
113 DRM_FORMAT_XRGB2101010,
114 DRM_FORMAT_XBGR2101010,
115 DRM_FORMAT_ARGB2101010,
116 DRM_FORMAT_ABGR2101010,
129 DRM_FORMAT_XVYU2101010,
130 DRM_FORMAT_XVYU12_16161616,
131 DRM_FORMAT_XVYU16161616,
134 static const u32 icl_hdr_plane_formats[] = {
141 DRM_FORMAT_XRGB2101010,
142 DRM_FORMAT_XBGR2101010,
143 DRM_FORMAT_ARGB2101010,
144 DRM_FORMAT_ABGR2101010,
145 DRM_FORMAT_XRGB16161616F,
146 DRM_FORMAT_XBGR16161616F,
147 DRM_FORMAT_ARGB16161616F,
148 DRM_FORMAT_ABGR16161616F,
161 DRM_FORMAT_XVYU2101010,
162 DRM_FORMAT_XVYU12_16161616,
163 DRM_FORMAT_XVYU16161616,
166 int skl_format_to_fourcc(int format, bool rgb_order, bool alpha)
169 case PLANE_CTL_FORMAT_RGB_565:
170 return DRM_FORMAT_RGB565;
171 case PLANE_CTL_FORMAT_NV12:
172 return DRM_FORMAT_NV12;
173 case PLANE_CTL_FORMAT_XYUV:
174 return DRM_FORMAT_XYUV8888;
175 case PLANE_CTL_FORMAT_P010:
176 return DRM_FORMAT_P010;
177 case PLANE_CTL_FORMAT_P012:
178 return DRM_FORMAT_P012;
179 case PLANE_CTL_FORMAT_P016:
180 return DRM_FORMAT_P016;
181 case PLANE_CTL_FORMAT_Y210:
182 return DRM_FORMAT_Y210;
183 case PLANE_CTL_FORMAT_Y212:
184 return DRM_FORMAT_Y212;
185 case PLANE_CTL_FORMAT_Y216:
186 return DRM_FORMAT_Y216;
187 case PLANE_CTL_FORMAT_Y410:
188 return DRM_FORMAT_XVYU2101010;
189 case PLANE_CTL_FORMAT_Y412:
190 return DRM_FORMAT_XVYU12_16161616;
191 case PLANE_CTL_FORMAT_Y416:
192 return DRM_FORMAT_XVYU16161616;
194 case PLANE_CTL_FORMAT_XRGB_8888:
197 return DRM_FORMAT_ABGR8888;
199 return DRM_FORMAT_XBGR8888;
202 return DRM_FORMAT_ARGB8888;
204 return DRM_FORMAT_XRGB8888;
206 case PLANE_CTL_FORMAT_XRGB_2101010:
209 return DRM_FORMAT_ABGR2101010;
211 return DRM_FORMAT_XBGR2101010;
214 return DRM_FORMAT_ARGB2101010;
216 return DRM_FORMAT_XRGB2101010;
218 case PLANE_CTL_FORMAT_XRGB_16161616F:
221 return DRM_FORMAT_ABGR16161616F;
223 return DRM_FORMAT_XBGR16161616F;
226 return DRM_FORMAT_ARGB16161616F;
228 return DRM_FORMAT_XRGB16161616F;
233 static u8 icl_nv12_y_plane_mask(struct drm_i915_private *i915)
235 if (DISPLAY_VER(i915) >= 13 || HAS_D12_PLANE_MINIMIZATION(i915))
236 return BIT(PLANE_SPRITE2) | BIT(PLANE_SPRITE3);
238 return BIT(PLANE_SPRITE4) | BIT(PLANE_SPRITE5);
241 bool icl_is_nv12_y_plane(struct drm_i915_private *dev_priv,
242 enum plane_id plane_id)
244 return DISPLAY_VER(dev_priv) >= 11 &&
245 icl_nv12_y_plane_mask(dev_priv) & BIT(plane_id);
248 bool icl_is_hdr_plane(struct drm_i915_private *dev_priv, enum plane_id plane_id)
250 return DISPLAY_VER(dev_priv) >= 11 &&
251 icl_hdr_plane_mask() & BIT(plane_id);
254 static int icl_plane_min_cdclk(const struct intel_crtc_state *crtc_state,
255 const struct intel_plane_state *plane_state)
257 unsigned int pixel_rate = intel_plane_pixel_rate(crtc_state, plane_state);
259 /* two pixels per clock */
260 return DIV_ROUND_UP(pixel_rate, 2);
264 glk_plane_ratio(const struct intel_plane_state *plane_state,
265 unsigned int *num, unsigned int *den)
267 const struct drm_framebuffer *fb = plane_state->hw.fb;
269 if (fb->format->cpp[0] == 8) {
278 static int glk_plane_min_cdclk(const struct intel_crtc_state *crtc_state,
279 const struct intel_plane_state *plane_state)
281 unsigned int pixel_rate = intel_plane_pixel_rate(crtc_state, plane_state);
282 unsigned int num, den;
284 glk_plane_ratio(plane_state, &num, &den);
286 /* two pixels per clock */
287 return DIV_ROUND_UP(pixel_rate * num, 2 * den);
291 skl_plane_ratio(const struct intel_plane_state *plane_state,
292 unsigned int *num, unsigned int *den)
294 const struct drm_framebuffer *fb = plane_state->hw.fb;
296 if (fb->format->cpp[0] == 8) {
305 static int skl_plane_min_cdclk(const struct intel_crtc_state *crtc_state,
306 const struct intel_plane_state *plane_state)
308 unsigned int pixel_rate = intel_plane_pixel_rate(crtc_state, plane_state);
309 unsigned int num, den;
311 skl_plane_ratio(plane_state, &num, &den);
313 return DIV_ROUND_UP(pixel_rate * num, den);
316 static int skl_plane_max_width(const struct drm_framebuffer *fb,
318 unsigned int rotation)
320 int cpp = fb->format->cpp[color_plane];
322 switch (fb->modifier) {
323 case DRM_FORMAT_MOD_LINEAR:
324 case I915_FORMAT_MOD_X_TILED:
326 * Validated limit is 4k, but has 5k should
327 * work apart from the following features:
328 * - Ytile (already limited to 4k)
329 * - FP16 (already limited to 4k)
330 * - render compression (already limited to 4k)
331 * - KVMR sprite and cursor (don't care)
332 * - horizontal panning (TODO verify this)
333 * - pipe and plane scaling (TODO verify this)
339 case I915_FORMAT_MOD_Y_TILED_CCS:
340 case I915_FORMAT_MOD_Yf_TILED_CCS:
341 case I915_FORMAT_MOD_Y_TILED_GEN12_MC_CCS:
342 /* FIXME AUX plane? */
343 case I915_FORMAT_MOD_Y_TILED:
344 case I915_FORMAT_MOD_Yf_TILED:
350 MISSING_CASE(fb->modifier);
355 static int glk_plane_max_width(const struct drm_framebuffer *fb,
357 unsigned int rotation)
359 int cpp = fb->format->cpp[color_plane];
361 switch (fb->modifier) {
362 case DRM_FORMAT_MOD_LINEAR:
363 case I915_FORMAT_MOD_X_TILED:
368 case I915_FORMAT_MOD_Y_TILED_CCS:
369 case I915_FORMAT_MOD_Yf_TILED_CCS:
370 /* FIXME AUX plane? */
371 case I915_FORMAT_MOD_Y_TILED:
372 case I915_FORMAT_MOD_Yf_TILED:
378 MISSING_CASE(fb->modifier);
383 static int icl_plane_min_width(const struct drm_framebuffer *fb,
385 unsigned int rotation)
387 /* Wa_14011264657, Wa_14011050563: gen11+ */
388 switch (fb->format->format) {
391 case DRM_FORMAT_RGB565:
393 case DRM_FORMAT_XRGB8888:
394 case DRM_FORMAT_XBGR8888:
395 case DRM_FORMAT_ARGB8888:
396 case DRM_FORMAT_ABGR8888:
397 case DRM_FORMAT_XRGB2101010:
398 case DRM_FORMAT_XBGR2101010:
399 case DRM_FORMAT_ARGB2101010:
400 case DRM_FORMAT_ABGR2101010:
401 case DRM_FORMAT_XVYU2101010:
402 case DRM_FORMAT_Y212:
403 case DRM_FORMAT_Y216:
405 case DRM_FORMAT_NV12:
407 case DRM_FORMAT_P010:
408 case DRM_FORMAT_P012:
409 case DRM_FORMAT_P016:
411 case DRM_FORMAT_XRGB16161616F:
412 case DRM_FORMAT_XBGR16161616F:
413 case DRM_FORMAT_ARGB16161616F:
414 case DRM_FORMAT_ABGR16161616F:
415 case DRM_FORMAT_XVYU12_16161616:
416 case DRM_FORMAT_XVYU16161616:
423 static int icl_plane_max_width(const struct drm_framebuffer *fb,
425 unsigned int rotation)
430 static int skl_plane_max_height(const struct drm_framebuffer *fb,
432 unsigned int rotation)
437 static int icl_plane_max_height(const struct drm_framebuffer *fb,
439 unsigned int rotation)
445 skl_plane_max_stride(struct intel_plane *plane,
446 u32 pixel_format, u64 modifier,
447 unsigned int rotation)
449 struct drm_i915_private *i915 = to_i915(plane->base.dev);
450 const struct drm_format_info *info = drm_format_info(pixel_format);
451 int cpp = info->cpp[0];
452 int max_horizontal_pixels = 8192;
453 int max_stride_bytes;
455 if (DISPLAY_VER(i915) >= 13) {
457 * The stride in bytes must not exceed of the size
458 * of 128K bytes. For pixel formats of 64bpp will allow
459 * for a 16K pixel surface.
461 max_stride_bytes = 131072;
463 max_horizontal_pixels = 16384;
465 max_horizontal_pixels = 65536;
468 * "The stride in bytes must not exceed the
469 * of the size of 8K pixels and 32K bytes."
471 max_stride_bytes = 32768;
474 if (drm_rotation_90_or_270(rotation))
475 return min(max_horizontal_pixels, max_stride_bytes / cpp);
477 return min(max_horizontal_pixels * cpp, max_stride_bytes);
481 /* Preoffset values for YUV to RGB Conversion */
482 #define PREOFF_YUV_TO_RGB_HI 0x1800
483 #define PREOFF_YUV_TO_RGB_ME 0x0000
484 #define PREOFF_YUV_TO_RGB_LO 0x1800
486 #define ROFF(x) (((x) & 0xffff) << 16)
487 #define GOFF(x) (((x) & 0xffff) << 0)
488 #define BOFF(x) (((x) & 0xffff) << 16)
491 * Programs the input color space conversion stage for ICL HDR planes.
492 * Note that it is assumed that this stage always happens after YUV
493 * range correction. Thus, the input to this stage is assumed to be
494 * in full-range YCbCr.
497 icl_program_input_csc(struct intel_plane *plane,
498 const struct intel_crtc_state *crtc_state,
499 const struct intel_plane_state *plane_state)
501 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
502 enum pipe pipe = plane->pipe;
503 enum plane_id plane_id = plane->id;
505 static const u16 input_csc_matrix[][9] = {
507 * BT.601 full range YCbCr -> full range RGB
508 * The matrix required is :
509 * [1.000, 0.000, 1.371,
510 * 1.000, -0.336, -0.698,
511 * 1.000, 1.732, 0.0000]
513 [DRM_COLOR_YCBCR_BT601] = {
515 0x8B28, 0x7800, 0x9AC0,
519 * BT.709 full range YCbCr -> full range RGB
520 * The matrix required is :
521 * [1.000, 0.000, 1.574,
522 * 1.000, -0.187, -0.468,
523 * 1.000, 1.855, 0.0000]
525 [DRM_COLOR_YCBCR_BT709] = {
527 0x9EF8, 0x7800, 0xAC00,
531 * BT.2020 full range YCbCr -> full range RGB
532 * The matrix required is :
533 * [1.000, 0.000, 1.474,
534 * 1.000, -0.1645, -0.5713,
535 * 1.000, 1.8814, 0.0000]
537 [DRM_COLOR_YCBCR_BT2020] = {
539 0x8928, 0x7800, 0xAA88,
543 const u16 *csc = input_csc_matrix[plane_state->hw.color_encoding];
545 intel_de_write_fw(dev_priv, PLANE_INPUT_CSC_COEFF(pipe, plane_id, 0),
546 ROFF(csc[0]) | GOFF(csc[1]));
547 intel_de_write_fw(dev_priv, PLANE_INPUT_CSC_COEFF(pipe, plane_id, 1),
549 intel_de_write_fw(dev_priv, PLANE_INPUT_CSC_COEFF(pipe, plane_id, 2),
550 ROFF(csc[3]) | GOFF(csc[4]));
551 intel_de_write_fw(dev_priv, PLANE_INPUT_CSC_COEFF(pipe, plane_id, 3),
553 intel_de_write_fw(dev_priv, PLANE_INPUT_CSC_COEFF(pipe, plane_id, 4),
554 ROFF(csc[6]) | GOFF(csc[7]));
555 intel_de_write_fw(dev_priv, PLANE_INPUT_CSC_COEFF(pipe, plane_id, 5),
558 intel_de_write_fw(dev_priv, PLANE_INPUT_CSC_PREOFF(pipe, plane_id, 0),
559 PREOFF_YUV_TO_RGB_HI);
560 intel_de_write_fw(dev_priv, PLANE_INPUT_CSC_PREOFF(pipe, plane_id, 1),
561 PREOFF_YUV_TO_RGB_ME);
562 intel_de_write_fw(dev_priv, PLANE_INPUT_CSC_PREOFF(pipe, plane_id, 2),
563 PREOFF_YUV_TO_RGB_LO);
564 intel_de_write_fw(dev_priv,
565 PLANE_INPUT_CSC_POSTOFF(pipe, plane_id, 0), 0x0);
566 intel_de_write_fw(dev_priv,
567 PLANE_INPUT_CSC_POSTOFF(pipe, plane_id, 1), 0x0);
568 intel_de_write_fw(dev_priv,
569 PLANE_INPUT_CSC_POSTOFF(pipe, plane_id, 2), 0x0);
572 static unsigned int skl_plane_stride_mult(const struct drm_framebuffer *fb,
573 int color_plane, unsigned int rotation)
576 * The stride is either expressed as a multiple of 64 bytes chunks for
577 * linear buffers or in number of tiles for tiled buffers.
579 if (is_surface_linear(fb, color_plane))
581 else if (drm_rotation_90_or_270(rotation))
582 return intel_tile_height(fb, color_plane);
584 return intel_tile_width_bytes(fb, color_plane);
587 static u32 skl_plane_stride(const struct intel_plane_state *plane_state,
590 const struct drm_framebuffer *fb = plane_state->hw.fb;
591 unsigned int rotation = plane_state->hw.rotation;
592 u32 stride = plane_state->view.color_plane[color_plane].scanout_stride;
594 if (color_plane >= fb->format->num_planes)
597 return stride / skl_plane_stride_mult(fb, color_plane, rotation);
601 skl_plane_disable_arm(struct intel_plane *plane,
602 const struct intel_crtc_state *crtc_state)
604 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
605 enum plane_id plane_id = plane->id;
606 enum pipe pipe = plane->pipe;
607 unsigned long irqflags;
609 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
611 if (icl_is_hdr_plane(dev_priv, plane_id))
612 intel_de_write_fw(dev_priv, PLANE_CUS_CTL(pipe, plane_id), 0);
614 skl_write_plane_wm(plane, crtc_state);
616 intel_psr2_disable_plane_sel_fetch(plane, crtc_state);
617 intel_de_write_fw(dev_priv, PLANE_CTL(pipe, plane_id), 0);
618 intel_de_write_fw(dev_priv, PLANE_SURF(pipe, plane_id), 0);
620 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
624 skl_plane_get_hw_state(struct intel_plane *plane,
627 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
628 enum intel_display_power_domain power_domain;
629 enum plane_id plane_id = plane->id;
630 intel_wakeref_t wakeref;
633 power_domain = POWER_DOMAIN_PIPE(plane->pipe);
634 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
638 ret = intel_de_read(dev_priv, PLANE_CTL(plane->pipe, plane_id)) & PLANE_CTL_ENABLE;
642 intel_display_power_put(dev_priv, power_domain, wakeref);
647 static u32 skl_plane_ctl_format(u32 pixel_format)
649 switch (pixel_format) {
651 return PLANE_CTL_FORMAT_INDEXED;
652 case DRM_FORMAT_RGB565:
653 return PLANE_CTL_FORMAT_RGB_565;
654 case DRM_FORMAT_XBGR8888:
655 case DRM_FORMAT_ABGR8888:
656 return PLANE_CTL_FORMAT_XRGB_8888 | PLANE_CTL_ORDER_RGBX;
657 case DRM_FORMAT_XRGB8888:
658 case DRM_FORMAT_ARGB8888:
659 return PLANE_CTL_FORMAT_XRGB_8888;
660 case DRM_FORMAT_XBGR2101010:
661 case DRM_FORMAT_ABGR2101010:
662 return PLANE_CTL_FORMAT_XRGB_2101010 | PLANE_CTL_ORDER_RGBX;
663 case DRM_FORMAT_XRGB2101010:
664 case DRM_FORMAT_ARGB2101010:
665 return PLANE_CTL_FORMAT_XRGB_2101010;
666 case DRM_FORMAT_XBGR16161616F:
667 case DRM_FORMAT_ABGR16161616F:
668 return PLANE_CTL_FORMAT_XRGB_16161616F | PLANE_CTL_ORDER_RGBX;
669 case DRM_FORMAT_XRGB16161616F:
670 case DRM_FORMAT_ARGB16161616F:
671 return PLANE_CTL_FORMAT_XRGB_16161616F;
672 case DRM_FORMAT_XYUV8888:
673 return PLANE_CTL_FORMAT_XYUV;
674 case DRM_FORMAT_YUYV:
675 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YUYV;
676 case DRM_FORMAT_YVYU:
677 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YVYU;
678 case DRM_FORMAT_UYVY:
679 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_UYVY;
680 case DRM_FORMAT_VYUY:
681 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_VYUY;
682 case DRM_FORMAT_NV12:
683 return PLANE_CTL_FORMAT_NV12;
684 case DRM_FORMAT_P010:
685 return PLANE_CTL_FORMAT_P010;
686 case DRM_FORMAT_P012:
687 return PLANE_CTL_FORMAT_P012;
688 case DRM_FORMAT_P016:
689 return PLANE_CTL_FORMAT_P016;
690 case DRM_FORMAT_Y210:
691 return PLANE_CTL_FORMAT_Y210;
692 case DRM_FORMAT_Y212:
693 return PLANE_CTL_FORMAT_Y212;
694 case DRM_FORMAT_Y216:
695 return PLANE_CTL_FORMAT_Y216;
696 case DRM_FORMAT_XVYU2101010:
697 return PLANE_CTL_FORMAT_Y410;
698 case DRM_FORMAT_XVYU12_16161616:
699 return PLANE_CTL_FORMAT_Y412;
700 case DRM_FORMAT_XVYU16161616:
701 return PLANE_CTL_FORMAT_Y416;
703 MISSING_CASE(pixel_format);
709 static u32 skl_plane_ctl_alpha(const struct intel_plane_state *plane_state)
711 if (!plane_state->hw.fb->format->has_alpha)
712 return PLANE_CTL_ALPHA_DISABLE;
714 switch (plane_state->hw.pixel_blend_mode) {
715 case DRM_MODE_BLEND_PIXEL_NONE:
716 return PLANE_CTL_ALPHA_DISABLE;
717 case DRM_MODE_BLEND_PREMULTI:
718 return PLANE_CTL_ALPHA_SW_PREMULTIPLY;
719 case DRM_MODE_BLEND_COVERAGE:
720 return PLANE_CTL_ALPHA_HW_PREMULTIPLY;
722 MISSING_CASE(plane_state->hw.pixel_blend_mode);
723 return PLANE_CTL_ALPHA_DISABLE;
727 static u32 glk_plane_color_ctl_alpha(const struct intel_plane_state *plane_state)
729 if (!plane_state->hw.fb->format->has_alpha)
730 return PLANE_COLOR_ALPHA_DISABLE;
732 switch (plane_state->hw.pixel_blend_mode) {
733 case DRM_MODE_BLEND_PIXEL_NONE:
734 return PLANE_COLOR_ALPHA_DISABLE;
735 case DRM_MODE_BLEND_PREMULTI:
736 return PLANE_COLOR_ALPHA_SW_PREMULTIPLY;
737 case DRM_MODE_BLEND_COVERAGE:
738 return PLANE_COLOR_ALPHA_HW_PREMULTIPLY;
740 MISSING_CASE(plane_state->hw.pixel_blend_mode);
741 return PLANE_COLOR_ALPHA_DISABLE;
745 static u32 skl_plane_ctl_tiling(u64 fb_modifier)
747 switch (fb_modifier) {
748 case DRM_FORMAT_MOD_LINEAR:
750 case I915_FORMAT_MOD_X_TILED:
751 return PLANE_CTL_TILED_X;
752 case I915_FORMAT_MOD_Y_TILED:
753 return PLANE_CTL_TILED_Y;
754 case I915_FORMAT_MOD_4_TILED:
755 return PLANE_CTL_TILED_4;
756 case I915_FORMAT_MOD_Y_TILED_CCS:
757 case I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS_CC:
758 return PLANE_CTL_TILED_Y | PLANE_CTL_RENDER_DECOMPRESSION_ENABLE;
759 case I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS:
760 return PLANE_CTL_TILED_Y |
761 PLANE_CTL_RENDER_DECOMPRESSION_ENABLE |
762 PLANE_CTL_CLEAR_COLOR_DISABLE;
763 case I915_FORMAT_MOD_Y_TILED_GEN12_MC_CCS:
764 return PLANE_CTL_TILED_Y | PLANE_CTL_MEDIA_DECOMPRESSION_ENABLE;
765 case I915_FORMAT_MOD_Yf_TILED:
766 return PLANE_CTL_TILED_YF;
767 case I915_FORMAT_MOD_Yf_TILED_CCS:
768 return PLANE_CTL_TILED_YF | PLANE_CTL_RENDER_DECOMPRESSION_ENABLE;
770 MISSING_CASE(fb_modifier);
776 static u32 skl_plane_ctl_rotate(unsigned int rotate)
779 case DRM_MODE_ROTATE_0:
782 * DRM_MODE_ROTATE_ is counter clockwise to stay compatible with Xrandr
783 * while i915 HW rotation is clockwise, thats why this swapping.
785 case DRM_MODE_ROTATE_90:
786 return PLANE_CTL_ROTATE_270;
787 case DRM_MODE_ROTATE_180:
788 return PLANE_CTL_ROTATE_180;
789 case DRM_MODE_ROTATE_270:
790 return PLANE_CTL_ROTATE_90;
792 MISSING_CASE(rotate);
798 static u32 icl_plane_ctl_flip(unsigned int reflect)
803 case DRM_MODE_REFLECT_X:
804 return PLANE_CTL_FLIP_HORIZONTAL;
805 case DRM_MODE_REFLECT_Y:
807 MISSING_CASE(reflect);
813 static u32 adlp_plane_ctl_arb_slots(const struct intel_plane_state *plane_state)
815 const struct drm_framebuffer *fb = plane_state->hw.fb;
817 if (intel_format_info_is_yuv_semiplanar(fb->format, fb->modifier)) {
818 switch (fb->format->cpp[0]) {
820 return PLANE_CTL_ARB_SLOTS(1);
822 return PLANE_CTL_ARB_SLOTS(0);
825 switch (fb->format->cpp[0]) {
827 return PLANE_CTL_ARB_SLOTS(3);
829 return PLANE_CTL_ARB_SLOTS(1);
831 return PLANE_CTL_ARB_SLOTS(0);
836 static u32 skl_plane_ctl_crtc(const struct intel_crtc_state *crtc_state)
838 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
841 if (DISPLAY_VER(dev_priv) >= 10)
844 if (crtc_state->gamma_enable)
845 plane_ctl |= PLANE_CTL_PIPE_GAMMA_ENABLE;
847 if (crtc_state->csc_enable)
848 plane_ctl |= PLANE_CTL_PIPE_CSC_ENABLE;
853 static u32 skl_plane_ctl(const struct intel_crtc_state *crtc_state,
854 const struct intel_plane_state *plane_state)
856 struct drm_i915_private *dev_priv =
857 to_i915(plane_state->uapi.plane->dev);
858 const struct drm_framebuffer *fb = plane_state->hw.fb;
859 unsigned int rotation = plane_state->hw.rotation;
860 const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
863 plane_ctl = PLANE_CTL_ENABLE;
865 if (DISPLAY_VER(dev_priv) < 10) {
866 plane_ctl |= skl_plane_ctl_alpha(plane_state);
867 plane_ctl |= PLANE_CTL_PLANE_GAMMA_DISABLE;
869 if (plane_state->hw.color_encoding == DRM_COLOR_YCBCR_BT709)
870 plane_ctl |= PLANE_CTL_YUV_TO_RGB_CSC_FORMAT_BT709;
872 if (plane_state->hw.color_range == DRM_COLOR_YCBCR_FULL_RANGE)
873 plane_ctl |= PLANE_CTL_YUV_RANGE_CORRECTION_DISABLE;
876 plane_ctl |= skl_plane_ctl_format(fb->format->format);
877 plane_ctl |= skl_plane_ctl_tiling(fb->modifier);
878 plane_ctl |= skl_plane_ctl_rotate(rotation & DRM_MODE_ROTATE_MASK);
880 if (DISPLAY_VER(dev_priv) >= 11)
881 plane_ctl |= icl_plane_ctl_flip(rotation &
882 DRM_MODE_REFLECT_MASK);
884 if (key->flags & I915_SET_COLORKEY_DESTINATION)
885 plane_ctl |= PLANE_CTL_KEY_ENABLE_DESTINATION;
886 else if (key->flags & I915_SET_COLORKEY_SOURCE)
887 plane_ctl |= PLANE_CTL_KEY_ENABLE_SOURCE;
889 /* Wa_22012358565:adl-p */
890 if (DISPLAY_VER(dev_priv) == 13)
891 plane_ctl |= adlp_plane_ctl_arb_slots(plane_state);
896 static u32 glk_plane_color_ctl_crtc(const struct intel_crtc_state *crtc_state)
898 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
899 u32 plane_color_ctl = 0;
901 if (DISPLAY_VER(dev_priv) >= 11)
902 return plane_color_ctl;
904 if (crtc_state->gamma_enable)
905 plane_color_ctl |= PLANE_COLOR_PIPE_GAMMA_ENABLE;
907 if (crtc_state->csc_enable)
908 plane_color_ctl |= PLANE_COLOR_PIPE_CSC_ENABLE;
910 return plane_color_ctl;
913 static u32 glk_plane_color_ctl(const struct intel_crtc_state *crtc_state,
914 const struct intel_plane_state *plane_state)
916 struct drm_i915_private *dev_priv =
917 to_i915(plane_state->uapi.plane->dev);
918 const struct drm_framebuffer *fb = plane_state->hw.fb;
919 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
920 u32 plane_color_ctl = 0;
922 plane_color_ctl |= PLANE_COLOR_PLANE_GAMMA_DISABLE;
923 plane_color_ctl |= glk_plane_color_ctl_alpha(plane_state);
925 if (fb->format->is_yuv && !icl_is_hdr_plane(dev_priv, plane->id)) {
926 switch (plane_state->hw.color_encoding) {
927 case DRM_COLOR_YCBCR_BT709:
928 plane_color_ctl |= PLANE_COLOR_CSC_MODE_YUV709_TO_RGB709;
930 case DRM_COLOR_YCBCR_BT2020:
932 PLANE_COLOR_CSC_MODE_YUV2020_TO_RGB2020;
936 PLANE_COLOR_CSC_MODE_YUV601_TO_RGB601;
938 if (plane_state->hw.color_range == DRM_COLOR_YCBCR_FULL_RANGE)
939 plane_color_ctl |= PLANE_COLOR_YUV_RANGE_CORRECTION_DISABLE;
940 } else if (fb->format->is_yuv) {
941 plane_color_ctl |= PLANE_COLOR_INPUT_CSC_ENABLE;
942 if (plane_state->hw.color_range == DRM_COLOR_YCBCR_FULL_RANGE)
943 plane_color_ctl |= PLANE_COLOR_YUV_RANGE_CORRECTION_DISABLE;
946 if (plane_state->force_black)
947 plane_color_ctl |= PLANE_COLOR_PLANE_CSC_ENABLE;
949 return plane_color_ctl;
952 static u32 skl_surf_address(const struct intel_plane_state *plane_state,
955 const struct drm_framebuffer *fb = plane_state->hw.fb;
956 u32 offset = plane_state->view.color_plane[color_plane].offset;
958 if (intel_fb_uses_dpt(fb)) {
960 * The DPT object contains only one vma, so the VMA's offset
961 * within the DPT is always 0.
963 WARN_ON(plane_state->dpt_vma->node.start);
964 WARN_ON(offset & 0x1fffff);
967 WARN_ON(offset & 0xfff);
972 static u32 skl_plane_surf(const struct intel_plane_state *plane_state,
977 plane_surf = intel_plane_ggtt_offset(plane_state) +
978 skl_surf_address(plane_state, color_plane);
980 if (plane_state->decrypt)
981 plane_surf |= PLANE_SURF_DECRYPT;
986 static void icl_plane_csc_load_black(struct intel_plane *plane)
988 struct drm_i915_private *i915 = to_i915(plane->base.dev);
989 enum plane_id plane_id = plane->id;
990 enum pipe pipe = plane->pipe;
992 intel_de_write_fw(i915, PLANE_CSC_COEFF(pipe, plane_id, 0), 0);
993 intel_de_write_fw(i915, PLANE_CSC_COEFF(pipe, plane_id, 1), 0);
995 intel_de_write_fw(i915, PLANE_CSC_COEFF(pipe, plane_id, 2), 0);
996 intel_de_write_fw(i915, PLANE_CSC_COEFF(pipe, plane_id, 3), 0);
998 intel_de_write_fw(i915, PLANE_CSC_COEFF(pipe, plane_id, 4), 0);
999 intel_de_write_fw(i915, PLANE_CSC_COEFF(pipe, plane_id, 5), 0);
1001 intel_de_write_fw(i915, PLANE_CSC_PREOFF(pipe, plane_id, 0), 0);
1002 intel_de_write_fw(i915, PLANE_CSC_PREOFF(pipe, plane_id, 1), 0);
1003 intel_de_write_fw(i915, PLANE_CSC_PREOFF(pipe, plane_id, 2), 0);
1005 intel_de_write_fw(i915, PLANE_CSC_POSTOFF(pipe, plane_id, 0), 0);
1006 intel_de_write_fw(i915, PLANE_CSC_POSTOFF(pipe, plane_id, 1), 0);
1007 intel_de_write_fw(i915, PLANE_CSC_POSTOFF(pipe, plane_id, 2), 0);
1011 skl_program_plane_noarm(struct intel_plane *plane,
1012 const struct intel_crtc_state *crtc_state,
1013 const struct intel_plane_state *plane_state,
1016 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
1017 enum plane_id plane_id = plane->id;
1018 enum pipe pipe = plane->pipe;
1019 u32 stride = skl_plane_stride(plane_state, color_plane);
1020 const struct drm_framebuffer *fb = plane_state->hw.fb;
1021 int crtc_x = plane_state->uapi.dst.x1;
1022 int crtc_y = plane_state->uapi.dst.y1;
1023 u32 src_w = drm_rect_width(&plane_state->uapi.src) >> 16;
1024 u32 src_h = drm_rect_height(&plane_state->uapi.src) >> 16;
1025 unsigned long irqflags;
1027 /* Sizes are 0 based */
1031 /* The scaler will handle the output position */
1032 if (plane_state->scaler_id >= 0) {
1037 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
1040 * FIXME: pxp session invalidation can hit any time even at time of commit
1041 * or after the commit, display content will be garbage.
1043 if (plane_state->force_black)
1044 icl_plane_csc_load_black(plane);
1046 intel_de_write_fw(dev_priv, PLANE_STRIDE(pipe, plane_id), stride);
1047 intel_de_write_fw(dev_priv, PLANE_POS(pipe, plane_id),
1048 (crtc_y << 16) | crtc_x);
1049 intel_de_write_fw(dev_priv, PLANE_SIZE(pipe, plane_id),
1050 (src_h << 16) | src_w);
1052 if (icl_is_hdr_plane(dev_priv, plane_id))
1053 intel_de_write_fw(dev_priv, PLANE_CUS_CTL(pipe, plane_id),
1054 plane_state->cus_ctl);
1056 if (fb->format->is_yuv && icl_is_hdr_plane(dev_priv, plane_id))
1057 icl_program_input_csc(plane, crtc_state, plane_state);
1059 if (intel_fb_is_rc_ccs_cc_modifier(fb->modifier))
1060 intel_uncore_write64_fw(&dev_priv->uncore,
1061 PLANE_CC_VAL(pipe, plane_id), plane_state->ccval);
1063 skl_write_plane_wm(plane, crtc_state);
1065 intel_psr2_program_plane_sel_fetch(plane, crtc_state, plane_state, color_plane);
1067 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
1071 skl_program_plane_arm(struct intel_plane *plane,
1072 const struct intel_crtc_state *crtc_state,
1073 const struct intel_plane_state *plane_state,
1076 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
1077 enum plane_id plane_id = plane->id;
1078 enum pipe pipe = plane->pipe;
1079 const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
1080 const struct drm_framebuffer *fb = plane_state->hw.fb;
1081 int aux_plane = skl_main_to_aux_plane(fb, color_plane);
1082 u32 x = plane_state->view.color_plane[color_plane].x;
1083 u32 y = plane_state->view.color_plane[color_plane].y;
1084 u32 keymsk, keymax, aux_dist = 0, plane_color_ctl = 0;
1085 u8 alpha = plane_state->hw.alpha >> 8;
1086 u32 plane_ctl = plane_state->ctl;
1087 unsigned long irqflags;
1089 plane_ctl |= skl_plane_ctl_crtc(crtc_state);
1091 if (DISPLAY_VER(dev_priv) >= 10)
1092 plane_color_ctl = plane_state->color_ctl |
1093 glk_plane_color_ctl_crtc(crtc_state);
1095 keymax = (key->max_value & 0xffffff) | PLANE_KEYMAX_ALPHA(alpha);
1097 keymsk = key->channel_mask & 0x7ffffff;
1099 keymsk |= PLANE_KEYMSK_ALPHA_ENABLE;
1102 aux_dist = skl_surf_address(plane_state, aux_plane) -
1103 skl_surf_address(plane_state, color_plane);
1105 if (DISPLAY_VER(dev_priv) < 12)
1106 aux_dist |= skl_plane_stride(plane_state, aux_plane);
1109 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
1111 intel_de_write_fw(dev_priv, PLANE_KEYVAL(pipe, plane_id),
1113 intel_de_write_fw(dev_priv, PLANE_KEYMSK(pipe, plane_id), keymsk);
1114 intel_de_write_fw(dev_priv, PLANE_KEYMAX(pipe, plane_id), keymax);
1116 intel_de_write_fw(dev_priv, PLANE_OFFSET(pipe, plane_id),
1119 intel_de_write_fw(dev_priv, PLANE_AUX_DIST(pipe, plane_id), aux_dist);
1121 if (DISPLAY_VER(dev_priv) < 11)
1122 intel_de_write_fw(dev_priv, PLANE_AUX_OFFSET(pipe, plane_id),
1123 (plane_state->view.color_plane[1].y << 16) |
1124 plane_state->view.color_plane[1].x);
1126 if (DISPLAY_VER(dev_priv) >= 10)
1127 intel_de_write_fw(dev_priv, PLANE_COLOR_CTL(pipe, plane_id), plane_color_ctl);
1130 * Enable the scaler before the plane so that we don't
1131 * get a catastrophic underrun even if the two operations
1132 * end up happening in two different frames.
1134 * TODO: split into noarm+arm pair
1136 if (plane_state->scaler_id >= 0)
1137 skl_program_plane_scaler(plane, crtc_state, plane_state);
1140 * The control register self-arms if the plane was previously
1141 * disabled. Try to make the plane enable atomic by writing
1142 * the control register just before the surface register.
1144 intel_de_write_fw(dev_priv, PLANE_CTL(pipe, plane_id), plane_ctl);
1145 intel_de_write_fw(dev_priv, PLANE_SURF(pipe, plane_id),
1146 skl_plane_surf(plane_state, color_plane));
1148 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
1152 skl_plane_async_flip(struct intel_plane *plane,
1153 const struct intel_crtc_state *crtc_state,
1154 const struct intel_plane_state *plane_state,
1157 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
1158 unsigned long irqflags;
1159 enum plane_id plane_id = plane->id;
1160 enum pipe pipe = plane->pipe;
1161 u32 plane_ctl = plane_state->ctl;
1163 plane_ctl |= skl_plane_ctl_crtc(crtc_state);
1166 plane_ctl |= PLANE_CTL_ASYNC_FLIP;
1168 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
1170 intel_de_write_fw(dev_priv, PLANE_CTL(pipe, plane_id), plane_ctl);
1171 intel_de_write_fw(dev_priv, PLANE_SURF(pipe, plane_id),
1172 skl_plane_surf(plane_state, 0));
1174 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
1178 skl_plane_update_noarm(struct intel_plane *plane,
1179 const struct intel_crtc_state *crtc_state,
1180 const struct intel_plane_state *plane_state)
1182 int color_plane = 0;
1184 if (plane_state->planar_linked_plane && !plane_state->planar_slave)
1185 /* Program the UV plane on planar master */
1188 skl_program_plane_noarm(plane, crtc_state, plane_state, color_plane);
1192 skl_plane_update_arm(struct intel_plane *plane,
1193 const struct intel_crtc_state *crtc_state,
1194 const struct intel_plane_state *plane_state)
1196 int color_plane = 0;
1198 if (plane_state->planar_linked_plane && !plane_state->planar_slave)
1199 /* Program the UV plane on planar master */
1202 skl_program_plane_arm(plane, crtc_state, plane_state, color_plane);
1205 static bool intel_format_is_p01x(u32 format)
1208 case DRM_FORMAT_P010:
1209 case DRM_FORMAT_P012:
1210 case DRM_FORMAT_P016:
1217 static int skl_plane_check_fb(const struct intel_crtc_state *crtc_state,
1218 const struct intel_plane_state *plane_state)
1220 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
1221 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
1222 const struct drm_framebuffer *fb = plane_state->hw.fb;
1223 unsigned int rotation = plane_state->hw.rotation;
1228 if (rotation & ~(DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180) &&
1229 intel_fb_is_ccs_modifier(fb->modifier)) {
1230 drm_dbg_kms(&dev_priv->drm,
1231 "RC support only with 0/180 degree rotation (%x)\n",
1236 if (rotation & DRM_MODE_REFLECT_X &&
1237 fb->modifier == DRM_FORMAT_MOD_LINEAR) {
1238 drm_dbg_kms(&dev_priv->drm,
1239 "horizontal flip is not supported with linear surface formats\n");
1243 if (drm_rotation_90_or_270(rotation)) {
1244 if (!intel_fb_supports_90_270_rotation(to_intel_framebuffer(fb))) {
1245 drm_dbg_kms(&dev_priv->drm,
1246 "Y/Yf tiling required for 90/270!\n");
1251 * 90/270 is not allowed with RGB64 16:16:16:16 and
1252 * Indexed 8-bit. RGB 16-bit 5:6:5 is allowed gen11 onwards.
1254 switch (fb->format->format) {
1255 case DRM_FORMAT_RGB565:
1256 if (DISPLAY_VER(dev_priv) >= 11)
1260 case DRM_FORMAT_XRGB16161616F:
1261 case DRM_FORMAT_XBGR16161616F:
1262 case DRM_FORMAT_ARGB16161616F:
1263 case DRM_FORMAT_ABGR16161616F:
1264 case DRM_FORMAT_Y210:
1265 case DRM_FORMAT_Y212:
1266 case DRM_FORMAT_Y216:
1267 case DRM_FORMAT_XVYU12_16161616:
1268 case DRM_FORMAT_XVYU16161616:
1269 drm_dbg_kms(&dev_priv->drm,
1270 "Unsupported pixel format %p4cc for 90/270!\n",
1271 &fb->format->format);
1278 /* Y-tiling is not supported in IF-ID Interlace mode */
1279 if (crtc_state->hw.enable &&
1280 crtc_state->hw.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE &&
1281 fb->modifier != DRM_FORMAT_MOD_LINEAR &&
1282 fb->modifier != I915_FORMAT_MOD_X_TILED) {
1283 drm_dbg_kms(&dev_priv->drm,
1284 "Y/Yf tiling not supported in IF-ID mode\n");
1288 /* Wa_1606054188:tgl,adl-s */
1289 if ((IS_ALDERLAKE_S(dev_priv) || IS_TIGERLAKE(dev_priv)) &&
1290 plane_state->ckey.flags & I915_SET_COLORKEY_SOURCE &&
1291 intel_format_is_p01x(fb->format->format)) {
1292 drm_dbg_kms(&dev_priv->drm,
1293 "Source color keying not supported with P01x formats\n");
1300 static int skl_plane_check_dst_coordinates(const struct intel_crtc_state *crtc_state,
1301 const struct intel_plane_state *plane_state)
1303 struct drm_i915_private *dev_priv =
1304 to_i915(plane_state->uapi.plane->dev);
1305 int crtc_x = plane_state->uapi.dst.x1;
1306 int crtc_w = drm_rect_width(&plane_state->uapi.dst);
1307 int pipe_src_w = crtc_state->pipe_src_w;
1310 * Display WA #1175: glk
1311 * Planes other than the cursor may cause FIFO underflow and display
1312 * corruption if starting less than 4 pixels from the right edge of
1314 * Besides the above WA fix the similar problem, where planes other
1315 * than the cursor ending less than 4 pixels from the left edge of the
1316 * screen may cause FIFO underflow and display corruption.
1318 if (DISPLAY_VER(dev_priv) == 10 &&
1319 (crtc_x + crtc_w < 4 || crtc_x > pipe_src_w - 4)) {
1320 drm_dbg_kms(&dev_priv->drm,
1321 "requested plane X %s position %d invalid (valid range %d-%d)\n",
1322 crtc_x + crtc_w < 4 ? "end" : "start",
1323 crtc_x + crtc_w < 4 ? crtc_x + crtc_w : crtc_x,
1331 static int skl_plane_check_nv12_rotation(const struct intel_plane_state *plane_state)
1333 const struct drm_framebuffer *fb = plane_state->hw.fb;
1334 unsigned int rotation = plane_state->hw.rotation;
1335 int src_w = drm_rect_width(&plane_state->uapi.src) >> 16;
1337 /* Display WA #1106 */
1338 if (intel_format_info_is_yuv_semiplanar(fb->format, fb->modifier) &&
1340 (rotation == DRM_MODE_ROTATE_270 ||
1341 rotation == (DRM_MODE_REFLECT_X | DRM_MODE_ROTATE_90))) {
1342 DRM_DEBUG_KMS("src width must be multiple of 4 for rotated planar YUV\n");
1349 static int skl_plane_max_scale(struct drm_i915_private *dev_priv,
1350 const struct drm_framebuffer *fb)
1353 * We don't yet know the final source width nor
1354 * whether we can use the HQ scaler mode. Assume
1356 * FIXME need to properly check this later.
1358 if (DISPLAY_VER(dev_priv) >= 10 ||
1359 !intel_format_info_is_yuv_semiplanar(fb->format, fb->modifier))
1365 static int intel_plane_min_width(struct intel_plane *plane,
1366 const struct drm_framebuffer *fb,
1368 unsigned int rotation)
1370 if (plane->min_width)
1371 return plane->min_width(fb, color_plane, rotation);
1376 static int intel_plane_max_width(struct intel_plane *plane,
1377 const struct drm_framebuffer *fb,
1379 unsigned int rotation)
1381 if (plane->max_width)
1382 return plane->max_width(fb, color_plane, rotation);
1387 static int intel_plane_max_height(struct intel_plane *plane,
1388 const struct drm_framebuffer *fb,
1390 unsigned int rotation)
1392 if (plane->max_height)
1393 return plane->max_height(fb, color_plane, rotation);
1399 skl_check_main_ccs_coordinates(struct intel_plane_state *plane_state,
1400 int main_x, int main_y, u32 main_offset,
1403 const struct drm_framebuffer *fb = plane_state->hw.fb;
1404 int aux_x = plane_state->view.color_plane[ccs_plane].x;
1405 int aux_y = plane_state->view.color_plane[ccs_plane].y;
1406 u32 aux_offset = plane_state->view.color_plane[ccs_plane].offset;
1407 u32 alignment = intel_surf_alignment(fb, ccs_plane);
1411 intel_fb_plane_get_subsampling(&hsub, &vsub, fb, ccs_plane);
1412 while (aux_offset >= main_offset && aux_y <= main_y) {
1415 if (aux_x == main_x && aux_y == main_y)
1418 if (aux_offset == 0)
1423 aux_offset = intel_plane_adjust_aligned_offset(&x, &y,
1429 aux_x = x * hsub + aux_x % hsub;
1430 aux_y = y * vsub + aux_y % vsub;
1433 if (aux_x != main_x || aux_y != main_y)
1436 plane_state->view.color_plane[ccs_plane].offset = aux_offset;
1437 plane_state->view.color_plane[ccs_plane].x = aux_x;
1438 plane_state->view.color_plane[ccs_plane].y = aux_y;
1444 int skl_calc_main_surface_offset(const struct intel_plane_state *plane_state,
1445 int *x, int *y, u32 *offset)
1447 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
1448 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
1449 const struct drm_framebuffer *fb = plane_state->hw.fb;
1450 const int aux_plane = skl_main_to_aux_plane(fb, 0);
1451 const u32 aux_offset = plane_state->view.color_plane[aux_plane].offset;
1452 const u32 alignment = intel_surf_alignment(fb, 0);
1453 const int w = drm_rect_width(&plane_state->uapi.src) >> 16;
1455 intel_add_fb_offsets(x, y, plane_state, 0);
1456 *offset = intel_plane_compute_aligned_offset(x, y, plane_state, 0);
1457 if (drm_WARN_ON(&dev_priv->drm, alignment && !is_power_of_2(alignment)))
1461 * AUX surface offset is specified as the distance from the
1462 * main surface offset, and it must be non-negative. Make
1463 * sure that is what we will get.
1465 if (aux_plane && *offset > aux_offset)
1466 *offset = intel_plane_adjust_aligned_offset(x, y, plane_state, 0,
1468 aux_offset & ~(alignment - 1));
1471 * When using an X-tiled surface, the plane blows up
1472 * if the x offset + width exceed the stride.
1474 * TODO: linear and Y-tiled seem fine, Yf untested,
1476 if (fb->modifier == I915_FORMAT_MOD_X_TILED) {
1477 int cpp = fb->format->cpp[0];
1479 while ((*x + w) * cpp > plane_state->view.color_plane[0].mapping_stride) {
1481 drm_dbg_kms(&dev_priv->drm,
1482 "Unable to find suitable display surface offset due to X-tiling\n");
1486 *offset = intel_plane_adjust_aligned_offset(x, y, plane_state, 0,
1488 *offset - alignment);
1495 static int skl_check_main_surface(struct intel_plane_state *plane_state)
1497 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
1498 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
1499 const struct drm_framebuffer *fb = plane_state->hw.fb;
1500 const unsigned int rotation = plane_state->hw.rotation;
1501 int x = plane_state->uapi.src.x1 >> 16;
1502 int y = plane_state->uapi.src.y1 >> 16;
1503 const int w = drm_rect_width(&plane_state->uapi.src) >> 16;
1504 const int h = drm_rect_height(&plane_state->uapi.src) >> 16;
1505 const int min_width = intel_plane_min_width(plane, fb, 0, rotation);
1506 const int max_width = intel_plane_max_width(plane, fb, 0, rotation);
1507 const int max_height = intel_plane_max_height(plane, fb, 0, rotation);
1508 const int aux_plane = skl_main_to_aux_plane(fb, 0);
1509 const u32 alignment = intel_surf_alignment(fb, 0);
1513 if (w > max_width || w < min_width || h > max_height) {
1514 drm_dbg_kms(&dev_priv->drm,
1515 "requested Y/RGB source size %dx%d outside limits (min: %dx1 max: %dx%d)\n",
1516 w, h, min_width, max_width, max_height);
1520 ret = skl_calc_main_surface_offset(plane_state, &x, &y, &offset);
1525 * CCS AUX surface doesn't have its own x/y offsets, we must make sure
1526 * they match with the main surface x/y offsets.
1528 if (intel_fb_is_ccs_modifier(fb->modifier)) {
1529 while (!skl_check_main_ccs_coordinates(plane_state, x, y,
1530 offset, aux_plane)) {
1534 offset = intel_plane_adjust_aligned_offset(&x, &y, plane_state, 0,
1535 offset, offset - alignment);
1538 if (x != plane_state->view.color_plane[aux_plane].x ||
1539 y != plane_state->view.color_plane[aux_plane].y) {
1540 drm_dbg_kms(&dev_priv->drm,
1541 "Unable to find suitable display surface offset due to CCS\n");
1546 if (DISPLAY_VER(dev_priv) >= 13)
1547 drm_WARN_ON(&dev_priv->drm, x > 65535 || y > 65535);
1549 drm_WARN_ON(&dev_priv->drm, x > 8191 || y > 8191);
1551 plane_state->view.color_plane[0].offset = offset;
1552 plane_state->view.color_plane[0].x = x;
1553 plane_state->view.color_plane[0].y = y;
1556 * Put the final coordinates back so that the src
1557 * coordinate checks will see the right values.
1559 drm_rect_translate_to(&plane_state->uapi.src,
1565 static int skl_check_nv12_aux_surface(struct intel_plane_state *plane_state)
1567 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
1568 struct drm_i915_private *i915 = to_i915(plane->base.dev);
1569 const struct drm_framebuffer *fb = plane_state->hw.fb;
1570 unsigned int rotation = plane_state->hw.rotation;
1572 int max_width = intel_plane_max_width(plane, fb, uv_plane, rotation);
1573 int max_height = intel_plane_max_height(plane, fb, uv_plane, rotation);
1574 int x = plane_state->uapi.src.x1 >> 17;
1575 int y = plane_state->uapi.src.y1 >> 17;
1576 int w = drm_rect_width(&plane_state->uapi.src) >> 17;
1577 int h = drm_rect_height(&plane_state->uapi.src) >> 17;
1580 /* FIXME not quite sure how/if these apply to the chroma plane */
1581 if (w > max_width || h > max_height) {
1582 drm_dbg_kms(&i915->drm,
1583 "CbCr source size %dx%d too big (limit %dx%d)\n",
1584 w, h, max_width, max_height);
1588 intel_add_fb_offsets(&x, &y, plane_state, uv_plane);
1589 offset = intel_plane_compute_aligned_offset(&x, &y,
1590 plane_state, uv_plane);
1592 if (intel_fb_is_ccs_modifier(fb->modifier)) {
1593 int ccs_plane = main_to_ccs_plane(fb, uv_plane);
1594 u32 aux_offset = plane_state->view.color_plane[ccs_plane].offset;
1595 u32 alignment = intel_surf_alignment(fb, uv_plane);
1597 if (offset > aux_offset)
1598 offset = intel_plane_adjust_aligned_offset(&x, &y,
1602 aux_offset & ~(alignment - 1));
1604 while (!skl_check_main_ccs_coordinates(plane_state, x, y,
1605 offset, ccs_plane)) {
1609 offset = intel_plane_adjust_aligned_offset(&x, &y,
1612 offset, offset - alignment);
1615 if (x != plane_state->view.color_plane[ccs_plane].x ||
1616 y != plane_state->view.color_plane[ccs_plane].y) {
1617 drm_dbg_kms(&i915->drm,
1618 "Unable to find suitable display surface offset due to CCS\n");
1623 if (DISPLAY_VER(i915) >= 13)
1624 drm_WARN_ON(&i915->drm, x > 65535 || y > 65535);
1626 drm_WARN_ON(&i915->drm, x > 8191 || y > 8191);
1628 plane_state->view.color_plane[uv_plane].offset = offset;
1629 plane_state->view.color_plane[uv_plane].x = x;
1630 plane_state->view.color_plane[uv_plane].y = y;
1635 static int skl_check_ccs_aux_surface(struct intel_plane_state *plane_state)
1637 const struct drm_framebuffer *fb = plane_state->hw.fb;
1638 int src_x = plane_state->uapi.src.x1 >> 16;
1639 int src_y = plane_state->uapi.src.y1 >> 16;
1643 for (ccs_plane = 0; ccs_plane < fb->format->num_planes; ccs_plane++) {
1644 int main_hsub, main_vsub;
1648 if (!intel_fb_is_ccs_aux_plane(fb, ccs_plane))
1651 intel_fb_plane_get_subsampling(&main_hsub, &main_vsub, fb,
1652 skl_ccs_to_main_plane(fb, ccs_plane));
1653 intel_fb_plane_get_subsampling(&hsub, &vsub, fb, ccs_plane);
1660 intel_add_fb_offsets(&x, &y, plane_state, ccs_plane);
1662 offset = intel_plane_compute_aligned_offset(&x, &y,
1666 plane_state->view.color_plane[ccs_plane].offset = offset;
1667 plane_state->view.color_plane[ccs_plane].x = (x * hsub + src_x % hsub) / main_hsub;
1668 plane_state->view.color_plane[ccs_plane].y = (y * vsub + src_y % vsub) / main_vsub;
1674 static int skl_check_plane_surface(struct intel_plane_state *plane_state)
1676 const struct drm_framebuffer *fb = plane_state->hw.fb;
1679 ret = intel_plane_compute_gtt(plane_state);
1683 if (!plane_state->uapi.visible)
1687 * Handle the AUX surface first since the main surface setup depends on
1690 if (intel_fb_is_ccs_modifier(fb->modifier)) {
1691 ret = skl_check_ccs_aux_surface(plane_state);
1696 if (intel_format_info_is_yuv_semiplanar(fb->format,
1698 ret = skl_check_nv12_aux_surface(plane_state);
1703 ret = skl_check_main_surface(plane_state);
1710 static bool skl_fb_scalable(const struct drm_framebuffer *fb)
1715 switch (fb->format->format) {
1718 case DRM_FORMAT_XRGB16161616F:
1719 case DRM_FORMAT_ARGB16161616F:
1720 case DRM_FORMAT_XBGR16161616F:
1721 case DRM_FORMAT_ABGR16161616F:
1722 return DISPLAY_VER(to_i915(fb->dev)) >= 11;
1728 static bool bo_has_valid_encryption(struct drm_i915_gem_object *obj)
1730 struct drm_i915_private *i915 = to_i915(obj->base.dev);
1732 return intel_pxp_key_check(&i915->gt.pxp, obj, false) == 0;
1735 static bool pxp_is_borked(struct drm_i915_gem_object *obj)
1737 return i915_gem_object_is_protected(obj) && !bo_has_valid_encryption(obj);
1740 static int skl_plane_check(struct intel_crtc_state *crtc_state,
1741 struct intel_plane_state *plane_state)
1743 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
1744 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
1745 const struct drm_framebuffer *fb = plane_state->hw.fb;
1746 int min_scale = DRM_PLANE_HELPER_NO_SCALING;
1747 int max_scale = DRM_PLANE_HELPER_NO_SCALING;
1750 ret = skl_plane_check_fb(crtc_state, plane_state);
1754 /* use scaler when colorkey is not required */
1755 if (!plane_state->ckey.flags && skl_fb_scalable(fb)) {
1757 max_scale = skl_plane_max_scale(dev_priv, fb);
1760 ret = intel_atomic_plane_check_clipping(plane_state, crtc_state,
1761 min_scale, max_scale, true);
1765 ret = skl_check_plane_surface(plane_state);
1769 if (!plane_state->uapi.visible)
1772 ret = skl_plane_check_dst_coordinates(crtc_state, plane_state);
1776 ret = intel_plane_check_src_coordinates(plane_state);
1780 ret = skl_plane_check_nv12_rotation(plane_state);
1784 if (DISPLAY_VER(dev_priv) >= 11) {
1785 plane_state->decrypt = bo_has_valid_encryption(intel_fb_obj(fb));
1786 plane_state->force_black = pxp_is_borked(intel_fb_obj(fb));
1789 /* HW only has 8 bits pixel precision, disable plane if invisible */
1790 if (!(plane_state->hw.alpha >> 8))
1791 plane_state->uapi.visible = false;
1793 plane_state->ctl = skl_plane_ctl(crtc_state, plane_state);
1795 if (DISPLAY_VER(dev_priv) >= 10)
1796 plane_state->color_ctl = glk_plane_color_ctl(crtc_state,
1799 if (intel_format_info_is_yuv_semiplanar(fb->format, fb->modifier) &&
1800 icl_is_hdr_plane(dev_priv, plane->id))
1801 /* Enable and use MPEG-2 chroma siting */
1802 plane_state->cus_ctl = PLANE_CUS_ENABLE |
1803 PLANE_CUS_HPHASE_0 |
1804 PLANE_CUS_VPHASE_SIGN_NEGATIVE | PLANE_CUS_VPHASE_0_25;
1806 plane_state->cus_ctl = 0;
1811 static bool skl_plane_has_fbc(struct drm_i915_private *dev_priv,
1812 enum pipe pipe, enum plane_id plane_id)
1814 if (!HAS_FBC(dev_priv))
1817 return pipe == PIPE_A && plane_id == PLANE_PRIMARY;
1820 static bool skl_plane_has_planar(struct drm_i915_private *dev_priv,
1821 enum pipe pipe, enum plane_id plane_id)
1823 /* Display WA #0870: skl, bxt */
1824 if (IS_SKYLAKE(dev_priv) || IS_BROXTON(dev_priv))
1827 if (DISPLAY_VER(dev_priv) == 9 && pipe == PIPE_C)
1830 if (plane_id != PLANE_PRIMARY && plane_id != PLANE_SPRITE0)
1836 static const u32 *skl_get_plane_formats(struct drm_i915_private *dev_priv,
1837 enum pipe pipe, enum plane_id plane_id,
1840 if (skl_plane_has_planar(dev_priv, pipe, plane_id)) {
1841 *num_formats = ARRAY_SIZE(skl_planar_formats);
1842 return skl_planar_formats;
1844 *num_formats = ARRAY_SIZE(skl_plane_formats);
1845 return skl_plane_formats;
1849 static const u32 *glk_get_plane_formats(struct drm_i915_private *dev_priv,
1850 enum pipe pipe, enum plane_id plane_id,
1853 if (skl_plane_has_planar(dev_priv, pipe, plane_id)) {
1854 *num_formats = ARRAY_SIZE(glk_planar_formats);
1855 return glk_planar_formats;
1857 *num_formats = ARRAY_SIZE(skl_plane_formats);
1858 return skl_plane_formats;
1862 static const u32 *icl_get_plane_formats(struct drm_i915_private *dev_priv,
1863 enum pipe pipe, enum plane_id plane_id,
1866 if (icl_is_hdr_plane(dev_priv, plane_id)) {
1867 *num_formats = ARRAY_SIZE(icl_hdr_plane_formats);
1868 return icl_hdr_plane_formats;
1869 } else if (icl_is_nv12_y_plane(dev_priv, plane_id)) {
1870 *num_formats = ARRAY_SIZE(icl_sdr_y_plane_formats);
1871 return icl_sdr_y_plane_formats;
1873 *num_formats = ARRAY_SIZE(icl_sdr_uv_plane_formats);
1874 return icl_sdr_uv_plane_formats;
1878 static bool skl_plane_format_mod_supported(struct drm_plane *_plane,
1879 u32 format, u64 modifier)
1881 struct intel_plane *plane = to_intel_plane(_plane);
1883 if (!intel_fb_plane_supports_modifier(plane, modifier))
1887 case DRM_FORMAT_XRGB8888:
1888 case DRM_FORMAT_XBGR8888:
1889 case DRM_FORMAT_ARGB8888:
1890 case DRM_FORMAT_ABGR8888:
1891 if (intel_fb_is_ccs_modifier(modifier))
1894 case DRM_FORMAT_RGB565:
1895 case DRM_FORMAT_XRGB2101010:
1896 case DRM_FORMAT_XBGR2101010:
1897 case DRM_FORMAT_ARGB2101010:
1898 case DRM_FORMAT_ABGR2101010:
1899 case DRM_FORMAT_YUYV:
1900 case DRM_FORMAT_YVYU:
1901 case DRM_FORMAT_UYVY:
1902 case DRM_FORMAT_VYUY:
1903 case DRM_FORMAT_NV12:
1904 case DRM_FORMAT_XYUV8888:
1905 case DRM_FORMAT_P010:
1906 case DRM_FORMAT_P012:
1907 case DRM_FORMAT_P016:
1908 case DRM_FORMAT_XVYU2101010:
1909 if (modifier == I915_FORMAT_MOD_Yf_TILED)
1913 case DRM_FORMAT_XBGR16161616F:
1914 case DRM_FORMAT_ABGR16161616F:
1915 case DRM_FORMAT_XRGB16161616F:
1916 case DRM_FORMAT_ARGB16161616F:
1917 case DRM_FORMAT_Y210:
1918 case DRM_FORMAT_Y212:
1919 case DRM_FORMAT_Y216:
1920 case DRM_FORMAT_XVYU12_16161616:
1921 case DRM_FORMAT_XVYU16161616:
1922 if (modifier == DRM_FORMAT_MOD_LINEAR ||
1923 modifier == I915_FORMAT_MOD_X_TILED ||
1924 modifier == I915_FORMAT_MOD_Y_TILED)
1932 static bool gen12_plane_format_mod_supported(struct drm_plane *_plane,
1933 u32 format, u64 modifier)
1935 struct intel_plane *plane = to_intel_plane(_plane);
1937 if (!intel_fb_plane_supports_modifier(plane, modifier))
1941 case DRM_FORMAT_XRGB8888:
1942 case DRM_FORMAT_XBGR8888:
1943 case DRM_FORMAT_ARGB8888:
1944 case DRM_FORMAT_ABGR8888:
1945 if (intel_fb_is_ccs_modifier(modifier))
1948 case DRM_FORMAT_YUYV:
1949 case DRM_FORMAT_YVYU:
1950 case DRM_FORMAT_UYVY:
1951 case DRM_FORMAT_VYUY:
1952 case DRM_FORMAT_NV12:
1953 case DRM_FORMAT_XYUV8888:
1954 case DRM_FORMAT_P010:
1955 case DRM_FORMAT_P012:
1956 case DRM_FORMAT_P016:
1957 if (intel_fb_is_mc_ccs_modifier(modifier))
1960 case DRM_FORMAT_RGB565:
1961 case DRM_FORMAT_XRGB2101010:
1962 case DRM_FORMAT_XBGR2101010:
1963 case DRM_FORMAT_ARGB2101010:
1964 case DRM_FORMAT_ABGR2101010:
1965 case DRM_FORMAT_XVYU2101010:
1967 case DRM_FORMAT_XBGR16161616F:
1968 case DRM_FORMAT_ABGR16161616F:
1969 case DRM_FORMAT_XRGB16161616F:
1970 case DRM_FORMAT_ARGB16161616F:
1971 case DRM_FORMAT_Y210:
1972 case DRM_FORMAT_Y212:
1973 case DRM_FORMAT_Y216:
1974 case DRM_FORMAT_XVYU12_16161616:
1975 case DRM_FORMAT_XVYU16161616:
1976 if (!intel_fb_is_ccs_modifier(modifier))
1984 static const struct drm_plane_funcs skl_plane_funcs = {
1985 .update_plane = drm_atomic_helper_update_plane,
1986 .disable_plane = drm_atomic_helper_disable_plane,
1987 .destroy = intel_plane_destroy,
1988 .atomic_duplicate_state = intel_plane_duplicate_state,
1989 .atomic_destroy_state = intel_plane_destroy_state,
1990 .format_mod_supported = skl_plane_format_mod_supported,
1993 static const struct drm_plane_funcs gen12_plane_funcs = {
1994 .update_plane = drm_atomic_helper_update_plane,
1995 .disable_plane = drm_atomic_helper_disable_plane,
1996 .destroy = intel_plane_destroy,
1997 .atomic_duplicate_state = intel_plane_duplicate_state,
1998 .atomic_destroy_state = intel_plane_destroy_state,
1999 .format_mod_supported = gen12_plane_format_mod_supported,
2003 skl_plane_enable_flip_done(struct intel_plane *plane)
2005 struct drm_i915_private *i915 = to_i915(plane->base.dev);
2006 enum pipe pipe = plane->pipe;
2008 spin_lock_irq(&i915->irq_lock);
2009 bdw_enable_pipe_irq(i915, pipe, GEN9_PIPE_PLANE_FLIP_DONE(plane->id));
2010 spin_unlock_irq(&i915->irq_lock);
2014 skl_plane_disable_flip_done(struct intel_plane *plane)
2016 struct drm_i915_private *i915 = to_i915(plane->base.dev);
2017 enum pipe pipe = plane->pipe;
2019 spin_lock_irq(&i915->irq_lock);
2020 bdw_disable_pipe_irq(i915, pipe, GEN9_PIPE_PLANE_FLIP_DONE(plane->id));
2021 spin_unlock_irq(&i915->irq_lock);
2024 static bool skl_plane_has_rc_ccs(struct drm_i915_private *i915,
2025 enum pipe pipe, enum plane_id plane_id)
2027 /* Wa_22011186057 */
2028 if (IS_ADLP_DISPLAY_STEP(i915, STEP_A0, STEP_B0))
2031 if (DISPLAY_VER(i915) >= 11)
2034 if (IS_GEMINILAKE(i915))
2035 return pipe != PIPE_C;
2037 return pipe != PIPE_C &&
2038 (plane_id == PLANE_PRIMARY ||
2039 plane_id == PLANE_SPRITE0);
2042 static bool gen12_plane_has_mc_ccs(struct drm_i915_private *i915,
2043 enum plane_id plane_id)
2045 if (DISPLAY_VER(i915) < 12)
2048 /* Wa_14010477008:tgl[a0..c0],rkl[all],dg1[all] */
2049 if (IS_DG1(i915) || IS_ROCKETLAKE(i915) ||
2050 IS_TGL_DISPLAY_STEP(i915, STEP_A0, STEP_D0))
2053 /* Wa_22011186057 */
2054 if (IS_ADLP_DISPLAY_STEP(i915, STEP_A0, STEP_B0))
2057 return plane_id < PLANE_SPRITE4;
2060 static u8 skl_get_plane_caps(struct drm_i915_private *i915,
2061 enum pipe pipe, enum plane_id plane_id)
2063 u8 caps = INTEL_PLANE_CAP_TILING_X;
2065 if (DISPLAY_VER(i915) < 13 || IS_ALDERLAKE_P(i915))
2066 caps |= INTEL_PLANE_CAP_TILING_Y;
2067 if (DISPLAY_VER(i915) < 12)
2068 caps |= INTEL_PLANE_CAP_TILING_Yf;
2070 if (skl_plane_has_rc_ccs(i915, pipe, plane_id)) {
2071 caps |= INTEL_PLANE_CAP_CCS_RC;
2072 if (DISPLAY_VER(i915) >= 12)
2073 caps |= INTEL_PLANE_CAP_CCS_RC_CC;
2076 if (gen12_plane_has_mc_ccs(i915, plane_id))
2077 caps |= INTEL_PLANE_CAP_CCS_MC;
2082 struct intel_plane *
2083 skl_universal_plane_create(struct drm_i915_private *dev_priv,
2084 enum pipe pipe, enum plane_id plane_id)
2086 const struct drm_plane_funcs *plane_funcs;
2087 struct intel_plane *plane;
2088 enum drm_plane_type plane_type;
2089 unsigned int supported_rotations;
2090 unsigned int supported_csc;
2091 const u64 *modifiers;
2096 plane = intel_plane_alloc();
2101 plane->id = plane_id;
2102 plane->frontbuffer_bit = INTEL_FRONTBUFFER(pipe, plane_id);
2104 if (skl_plane_has_fbc(dev_priv, pipe, plane_id))
2105 plane->fbc = &dev_priv->fbc;
2107 plane->fbc->possible_framebuffer_bits |= plane->frontbuffer_bit;
2109 if (DISPLAY_VER(dev_priv) >= 11) {
2110 plane->min_width = icl_plane_min_width;
2111 plane->max_width = icl_plane_max_width;
2112 plane->max_height = icl_plane_max_height;
2113 plane->min_cdclk = icl_plane_min_cdclk;
2114 } else if (DISPLAY_VER(dev_priv) >= 10) {
2115 plane->max_width = glk_plane_max_width;
2116 plane->max_height = skl_plane_max_height;
2117 plane->min_cdclk = glk_plane_min_cdclk;
2119 plane->max_width = skl_plane_max_width;
2120 plane->max_height = skl_plane_max_height;
2121 plane->min_cdclk = skl_plane_min_cdclk;
2124 plane->max_stride = skl_plane_max_stride;
2125 plane->update_noarm = skl_plane_update_noarm;
2126 plane->update_arm = skl_plane_update_arm;
2127 plane->disable_arm = skl_plane_disable_arm;
2128 plane->get_hw_state = skl_plane_get_hw_state;
2129 plane->check_plane = skl_plane_check;
2131 if (plane_id == PLANE_PRIMARY) {
2132 plane->need_async_flip_disable_wa = IS_DISPLAY_VER(dev_priv,
2134 plane->async_flip = skl_plane_async_flip;
2135 plane->enable_flip_done = skl_plane_enable_flip_done;
2136 plane->disable_flip_done = skl_plane_disable_flip_done;
2139 if (DISPLAY_VER(dev_priv) >= 11)
2140 formats = icl_get_plane_formats(dev_priv, pipe,
2141 plane_id, &num_formats);
2142 else if (DISPLAY_VER(dev_priv) >= 10)
2143 formats = glk_get_plane_formats(dev_priv, pipe,
2144 plane_id, &num_formats);
2146 formats = skl_get_plane_formats(dev_priv, pipe,
2147 plane_id, &num_formats);
2149 if (DISPLAY_VER(dev_priv) >= 12)
2150 plane_funcs = &gen12_plane_funcs;
2152 plane_funcs = &skl_plane_funcs;
2154 if (plane_id == PLANE_PRIMARY)
2155 plane_type = DRM_PLANE_TYPE_PRIMARY;
2157 plane_type = DRM_PLANE_TYPE_OVERLAY;
2159 modifiers = intel_fb_plane_get_modifiers(dev_priv,
2160 skl_get_plane_caps(dev_priv, pipe, plane_id));
2162 ret = drm_universal_plane_init(&dev_priv->drm, &plane->base,
2164 formats, num_formats, modifiers,
2166 "plane %d%c", plane_id + 1,
2174 if (DISPLAY_VER(dev_priv) >= 13)
2175 supported_rotations = DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180;
2177 supported_rotations =
2178 DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_90 |
2179 DRM_MODE_ROTATE_180 | DRM_MODE_ROTATE_270;
2181 if (DISPLAY_VER(dev_priv) >= 11)
2182 supported_rotations |= DRM_MODE_REFLECT_X;
2184 drm_plane_create_rotation_property(&plane->base,
2186 supported_rotations);
2188 supported_csc = BIT(DRM_COLOR_YCBCR_BT601) | BIT(DRM_COLOR_YCBCR_BT709);
2190 if (DISPLAY_VER(dev_priv) >= 10)
2191 supported_csc |= BIT(DRM_COLOR_YCBCR_BT2020);
2193 drm_plane_create_color_properties(&plane->base,
2195 BIT(DRM_COLOR_YCBCR_LIMITED_RANGE) |
2196 BIT(DRM_COLOR_YCBCR_FULL_RANGE),
2197 DRM_COLOR_YCBCR_BT709,
2198 DRM_COLOR_YCBCR_LIMITED_RANGE);
2200 drm_plane_create_alpha_property(&plane->base);
2201 drm_plane_create_blend_mode_property(&plane->base,
2202 BIT(DRM_MODE_BLEND_PIXEL_NONE) |
2203 BIT(DRM_MODE_BLEND_PREMULTI) |
2204 BIT(DRM_MODE_BLEND_COVERAGE));
2206 drm_plane_create_zpos_immutable_property(&plane->base, plane_id);
2208 if (DISPLAY_VER(dev_priv) >= 12)
2209 drm_plane_enable_fb_damage_clips(&plane->base);
2211 if (DISPLAY_VER(dev_priv) >= 11)
2212 drm_plane_create_scaling_filter_property(&plane->base,
2213 BIT(DRM_SCALING_FILTER_DEFAULT) |
2214 BIT(DRM_SCALING_FILTER_NEAREST_NEIGHBOR));
2216 intel_plane_helper_add(plane);
2221 intel_plane_free(plane);
2223 return ERR_PTR(ret);
2227 skl_get_initial_plane_config(struct intel_crtc *crtc,
2228 struct intel_initial_plane_config *plane_config)
2230 struct intel_crtc_state *crtc_state = to_intel_crtc_state(crtc->base.state);
2231 struct drm_device *dev = crtc->base.dev;
2232 struct drm_i915_private *dev_priv = to_i915(dev);
2233 struct intel_plane *plane = to_intel_plane(crtc->base.primary);
2234 enum plane_id plane_id = plane->id;
2236 u32 val, base, offset, stride_mult, tiling, alpha;
2237 int fourcc, pixel_format;
2238 unsigned int aligned_height;
2239 struct drm_framebuffer *fb;
2240 struct intel_framebuffer *intel_fb;
2242 if (!plane->get_hw_state(plane, &pipe))
2245 drm_WARN_ON(dev, pipe != crtc->pipe);
2247 if (crtc_state->bigjoiner) {
2248 drm_dbg_kms(&dev_priv->drm,
2249 "Unsupported bigjoiner configuration for initial FB\n");
2253 intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
2255 drm_dbg_kms(&dev_priv->drm, "failed to alloc fb\n");
2259 fb = &intel_fb->base;
2263 val = intel_de_read(dev_priv, PLANE_CTL(pipe, plane_id));
2265 if (DISPLAY_VER(dev_priv) >= 11)
2266 pixel_format = val & ICL_PLANE_CTL_FORMAT_MASK;
2268 pixel_format = val & PLANE_CTL_FORMAT_MASK;
2270 if (DISPLAY_VER(dev_priv) >= 10) {
2271 alpha = intel_de_read(dev_priv,
2272 PLANE_COLOR_CTL(pipe, plane_id));
2273 alpha &= PLANE_COLOR_ALPHA_MASK;
2275 alpha = val & PLANE_CTL_ALPHA_MASK;
2278 fourcc = skl_format_to_fourcc(pixel_format,
2279 val & PLANE_CTL_ORDER_RGBX, alpha);
2280 fb->format = drm_format_info(fourcc);
2282 tiling = val & PLANE_CTL_TILED_MASK;
2284 case PLANE_CTL_TILED_LINEAR:
2285 fb->modifier = DRM_FORMAT_MOD_LINEAR;
2287 case PLANE_CTL_TILED_X:
2288 plane_config->tiling = I915_TILING_X;
2289 fb->modifier = I915_FORMAT_MOD_X_TILED;
2291 case PLANE_CTL_TILED_Y:
2292 plane_config->tiling = I915_TILING_Y;
2293 if (val & PLANE_CTL_RENDER_DECOMPRESSION_ENABLE)
2294 fb->modifier = DISPLAY_VER(dev_priv) >= 12 ?
2295 I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS :
2296 I915_FORMAT_MOD_Y_TILED_CCS;
2297 else if (val & PLANE_CTL_MEDIA_DECOMPRESSION_ENABLE)
2298 fb->modifier = I915_FORMAT_MOD_Y_TILED_GEN12_MC_CCS;
2300 fb->modifier = I915_FORMAT_MOD_Y_TILED;
2302 case PLANE_CTL_TILED_YF: /* aka PLANE_CTL_TILED_4 on XE_LPD+ */
2303 if (HAS_4TILE(dev_priv)) {
2304 fb->modifier = I915_FORMAT_MOD_4_TILED;
2306 if (val & PLANE_CTL_RENDER_DECOMPRESSION_ENABLE)
2307 fb->modifier = I915_FORMAT_MOD_Yf_TILED_CCS;
2309 fb->modifier = I915_FORMAT_MOD_Yf_TILED;
2313 MISSING_CASE(tiling);
2318 * DRM_MODE_ROTATE_ is counter clockwise to stay compatible with Xrandr
2319 * while i915 HW rotation is clockwise, thats why this swapping.
2321 switch (val & PLANE_CTL_ROTATE_MASK) {
2322 case PLANE_CTL_ROTATE_0:
2323 plane_config->rotation = DRM_MODE_ROTATE_0;
2325 case PLANE_CTL_ROTATE_90:
2326 plane_config->rotation = DRM_MODE_ROTATE_270;
2328 case PLANE_CTL_ROTATE_180:
2329 plane_config->rotation = DRM_MODE_ROTATE_180;
2331 case PLANE_CTL_ROTATE_270:
2332 plane_config->rotation = DRM_MODE_ROTATE_90;
2336 if (DISPLAY_VER(dev_priv) >= 11 && val & PLANE_CTL_FLIP_HORIZONTAL)
2337 plane_config->rotation |= DRM_MODE_REFLECT_X;
2339 /* 90/270 degree rotation would require extra work */
2340 if (drm_rotation_90_or_270(plane_config->rotation))
2343 base = intel_de_read(dev_priv, PLANE_SURF(pipe, plane_id)) & 0xfffff000;
2344 plane_config->base = base;
2346 offset = intel_de_read(dev_priv, PLANE_OFFSET(pipe, plane_id));
2348 val = intel_de_read(dev_priv, PLANE_SIZE(pipe, plane_id));
2349 fb->height = ((val >> 16) & 0xffff) + 1;
2350 fb->width = ((val >> 0) & 0xffff) + 1;
2352 val = intel_de_read(dev_priv, PLANE_STRIDE(pipe, plane_id));
2353 stride_mult = skl_plane_stride_mult(fb, 0, DRM_MODE_ROTATE_0);
2355 if (DISPLAY_VER(dev_priv) >= 13)
2356 fb->pitches[0] = (val & PLANE_STRIDE_MASK_XELPD) * stride_mult;
2358 fb->pitches[0] = (val & PLANE_STRIDE_MASK) * stride_mult;
2360 aligned_height = intel_fb_align_height(fb, 0, fb->height);
2362 plane_config->size = fb->pitches[0] * aligned_height;
2364 drm_dbg_kms(&dev_priv->drm,
2365 "%s/%s with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
2366 crtc->base.name, plane->base.name, fb->width, fb->height,
2367 fb->format->cpp[0] * 8, base, fb->pitches[0],
2368 plane_config->size);
2370 plane_config->fb = intel_fb;