1 // SPDX-License-Identifier: MIT
3 * Copyright © 2020 Intel Corporation
6 #include <drm/drm_atomic_helper.h>
7 #include <drm/drm_blend.h>
8 #include <drm/drm_damage_helper.h>
9 #include <drm/drm_fourcc.h>
14 #include "intel_atomic_plane.h"
16 #include "intel_display_types.h"
18 #include "intel_fbc.h"
19 #include "intel_psr.h"
20 #include "intel_sprite.h"
21 #include "skl_scaler.h"
22 #include "skl_universal_plane.h"
23 #include "skl_watermark.h"
24 #include "pxp/intel_pxp.h"
26 static const u32 skl_plane_formats[] = {
33 DRM_FORMAT_XRGB2101010,
34 DRM_FORMAT_XBGR2101010,
35 DRM_FORMAT_XRGB16161616F,
36 DRM_FORMAT_XBGR16161616F,
44 static const u32 skl_planar_formats[] = {
51 DRM_FORMAT_XRGB2101010,
52 DRM_FORMAT_XBGR2101010,
53 DRM_FORMAT_XRGB16161616F,
54 DRM_FORMAT_XBGR16161616F,
63 static const u32 glk_planar_formats[] = {
70 DRM_FORMAT_XRGB2101010,
71 DRM_FORMAT_XBGR2101010,
72 DRM_FORMAT_XRGB16161616F,
73 DRM_FORMAT_XBGR16161616F,
85 static const u32 icl_sdr_y_plane_formats[] = {
92 DRM_FORMAT_XRGB2101010,
93 DRM_FORMAT_XBGR2101010,
94 DRM_FORMAT_ARGB2101010,
95 DRM_FORMAT_ABGR2101010,
104 DRM_FORMAT_XVYU2101010,
105 DRM_FORMAT_XVYU12_16161616,
106 DRM_FORMAT_XVYU16161616,
109 static const u32 icl_sdr_uv_plane_formats[] = {
116 DRM_FORMAT_XRGB2101010,
117 DRM_FORMAT_XBGR2101010,
118 DRM_FORMAT_ARGB2101010,
119 DRM_FORMAT_ABGR2101010,
132 DRM_FORMAT_XVYU2101010,
133 DRM_FORMAT_XVYU12_16161616,
134 DRM_FORMAT_XVYU16161616,
137 static const u32 icl_hdr_plane_formats[] = {
144 DRM_FORMAT_XRGB2101010,
145 DRM_FORMAT_XBGR2101010,
146 DRM_FORMAT_ARGB2101010,
147 DRM_FORMAT_ABGR2101010,
148 DRM_FORMAT_XRGB16161616F,
149 DRM_FORMAT_XBGR16161616F,
150 DRM_FORMAT_ARGB16161616F,
151 DRM_FORMAT_ABGR16161616F,
164 DRM_FORMAT_XVYU2101010,
165 DRM_FORMAT_XVYU12_16161616,
166 DRM_FORMAT_XVYU16161616,
169 int skl_format_to_fourcc(int format, bool rgb_order, bool alpha)
172 case PLANE_CTL_FORMAT_RGB_565:
173 return DRM_FORMAT_RGB565;
174 case PLANE_CTL_FORMAT_NV12:
175 return DRM_FORMAT_NV12;
176 case PLANE_CTL_FORMAT_XYUV:
177 return DRM_FORMAT_XYUV8888;
178 case PLANE_CTL_FORMAT_P010:
179 return DRM_FORMAT_P010;
180 case PLANE_CTL_FORMAT_P012:
181 return DRM_FORMAT_P012;
182 case PLANE_CTL_FORMAT_P016:
183 return DRM_FORMAT_P016;
184 case PLANE_CTL_FORMAT_Y210:
185 return DRM_FORMAT_Y210;
186 case PLANE_CTL_FORMAT_Y212:
187 return DRM_FORMAT_Y212;
188 case PLANE_CTL_FORMAT_Y216:
189 return DRM_FORMAT_Y216;
190 case PLANE_CTL_FORMAT_Y410:
191 return DRM_FORMAT_XVYU2101010;
192 case PLANE_CTL_FORMAT_Y412:
193 return DRM_FORMAT_XVYU12_16161616;
194 case PLANE_CTL_FORMAT_Y416:
195 return DRM_FORMAT_XVYU16161616;
197 case PLANE_CTL_FORMAT_XRGB_8888:
200 return DRM_FORMAT_ABGR8888;
202 return DRM_FORMAT_XBGR8888;
205 return DRM_FORMAT_ARGB8888;
207 return DRM_FORMAT_XRGB8888;
209 case PLANE_CTL_FORMAT_XRGB_2101010:
212 return DRM_FORMAT_ABGR2101010;
214 return DRM_FORMAT_XBGR2101010;
217 return DRM_FORMAT_ARGB2101010;
219 return DRM_FORMAT_XRGB2101010;
221 case PLANE_CTL_FORMAT_XRGB_16161616F:
224 return DRM_FORMAT_ABGR16161616F;
226 return DRM_FORMAT_XBGR16161616F;
229 return DRM_FORMAT_ARGB16161616F;
231 return DRM_FORMAT_XRGB16161616F;
236 static u8 icl_nv12_y_plane_mask(struct drm_i915_private *i915)
238 if (DISPLAY_VER(i915) >= 13 || HAS_D12_PLANE_MINIMIZATION(i915))
239 return BIT(PLANE_SPRITE2) | BIT(PLANE_SPRITE3);
241 return BIT(PLANE_SPRITE4) | BIT(PLANE_SPRITE5);
244 bool icl_is_nv12_y_plane(struct drm_i915_private *dev_priv,
245 enum plane_id plane_id)
247 return DISPLAY_VER(dev_priv) >= 11 &&
248 icl_nv12_y_plane_mask(dev_priv) & BIT(plane_id);
251 u8 icl_hdr_plane_mask(void)
253 return BIT(PLANE_PRIMARY) | BIT(PLANE_SPRITE0) | BIT(PLANE_SPRITE1);
256 bool icl_is_hdr_plane(struct drm_i915_private *dev_priv, enum plane_id plane_id)
258 return DISPLAY_VER(dev_priv) >= 11 &&
259 icl_hdr_plane_mask() & BIT(plane_id);
262 static int icl_plane_min_cdclk(const struct intel_crtc_state *crtc_state,
263 const struct intel_plane_state *plane_state)
265 unsigned int pixel_rate = intel_plane_pixel_rate(crtc_state, plane_state);
267 /* two pixels per clock */
268 return DIV_ROUND_UP(pixel_rate, 2);
272 glk_plane_ratio(const struct intel_plane_state *plane_state,
273 unsigned int *num, unsigned int *den)
275 const struct drm_framebuffer *fb = plane_state->hw.fb;
277 if (fb->format->cpp[0] == 8) {
286 static int glk_plane_min_cdclk(const struct intel_crtc_state *crtc_state,
287 const struct intel_plane_state *plane_state)
289 unsigned int pixel_rate = intel_plane_pixel_rate(crtc_state, plane_state);
290 unsigned int num, den;
292 glk_plane_ratio(plane_state, &num, &den);
294 /* two pixels per clock */
295 return DIV_ROUND_UP(pixel_rate * num, 2 * den);
299 skl_plane_ratio(const struct intel_plane_state *plane_state,
300 unsigned int *num, unsigned int *den)
302 const struct drm_framebuffer *fb = plane_state->hw.fb;
304 if (fb->format->cpp[0] == 8) {
313 static int skl_plane_min_cdclk(const struct intel_crtc_state *crtc_state,
314 const struct intel_plane_state *plane_state)
316 unsigned int pixel_rate = intel_plane_pixel_rate(crtc_state, plane_state);
317 unsigned int num, den;
319 skl_plane_ratio(plane_state, &num, &den);
321 return DIV_ROUND_UP(pixel_rate * num, den);
324 static int skl_plane_max_width(const struct drm_framebuffer *fb,
326 unsigned int rotation)
328 int cpp = fb->format->cpp[color_plane];
330 switch (fb->modifier) {
331 case DRM_FORMAT_MOD_LINEAR:
332 case I915_FORMAT_MOD_X_TILED:
334 * Validated limit is 4k, but has 5k should
335 * work apart from the following features:
336 * - Ytile (already limited to 4k)
337 * - FP16 (already limited to 4k)
338 * - render compression (already limited to 4k)
339 * - KVMR sprite and cursor (don't care)
340 * - horizontal panning (TODO verify this)
341 * - pipe and plane scaling (TODO verify this)
347 case I915_FORMAT_MOD_Y_TILED_CCS:
348 case I915_FORMAT_MOD_Yf_TILED_CCS:
349 case I915_FORMAT_MOD_Y_TILED_GEN12_MC_CCS:
350 /* FIXME AUX plane? */
351 case I915_FORMAT_MOD_Y_TILED:
352 case I915_FORMAT_MOD_Yf_TILED:
358 MISSING_CASE(fb->modifier);
363 static int glk_plane_max_width(const struct drm_framebuffer *fb,
365 unsigned int rotation)
367 int cpp = fb->format->cpp[color_plane];
369 switch (fb->modifier) {
370 case DRM_FORMAT_MOD_LINEAR:
371 case I915_FORMAT_MOD_X_TILED:
376 case I915_FORMAT_MOD_Y_TILED_CCS:
377 case I915_FORMAT_MOD_Yf_TILED_CCS:
378 /* FIXME AUX plane? */
379 case I915_FORMAT_MOD_Y_TILED:
380 case I915_FORMAT_MOD_Yf_TILED:
386 MISSING_CASE(fb->modifier);
391 static int icl_plane_min_width(const struct drm_framebuffer *fb,
393 unsigned int rotation)
395 /* Wa_14011264657, Wa_14011050563: gen11+ */
396 switch (fb->format->format) {
399 case DRM_FORMAT_RGB565:
401 case DRM_FORMAT_XRGB8888:
402 case DRM_FORMAT_XBGR8888:
403 case DRM_FORMAT_ARGB8888:
404 case DRM_FORMAT_ABGR8888:
405 case DRM_FORMAT_XRGB2101010:
406 case DRM_FORMAT_XBGR2101010:
407 case DRM_FORMAT_ARGB2101010:
408 case DRM_FORMAT_ABGR2101010:
409 case DRM_FORMAT_XVYU2101010:
410 case DRM_FORMAT_Y212:
411 case DRM_FORMAT_Y216:
413 case DRM_FORMAT_NV12:
415 case DRM_FORMAT_P010:
416 case DRM_FORMAT_P012:
417 case DRM_FORMAT_P016:
419 case DRM_FORMAT_XRGB16161616F:
420 case DRM_FORMAT_XBGR16161616F:
421 case DRM_FORMAT_ARGB16161616F:
422 case DRM_FORMAT_ABGR16161616F:
423 case DRM_FORMAT_XVYU12_16161616:
424 case DRM_FORMAT_XVYU16161616:
431 static int icl_hdr_plane_max_width(const struct drm_framebuffer *fb,
433 unsigned int rotation)
435 if (intel_format_info_is_yuv_semiplanar(fb->format, fb->modifier))
441 static int icl_sdr_plane_max_width(const struct drm_framebuffer *fb,
443 unsigned int rotation)
448 static int skl_plane_max_height(const struct drm_framebuffer *fb,
450 unsigned int rotation)
455 static int icl_plane_max_height(const struct drm_framebuffer *fb,
457 unsigned int rotation)
463 skl_plane_max_stride(struct intel_plane *plane,
464 u32 pixel_format, u64 modifier,
465 unsigned int rotation)
467 struct drm_i915_private *i915 = to_i915(plane->base.dev);
468 const struct drm_format_info *info = drm_format_info(pixel_format);
469 int cpp = info->cpp[0];
470 int max_horizontal_pixels = 8192;
471 int max_stride_bytes;
473 if (DISPLAY_VER(i915) >= 13) {
475 * The stride in bytes must not exceed of the size
476 * of 128K bytes. For pixel formats of 64bpp will allow
477 * for a 16K pixel surface.
479 max_stride_bytes = 131072;
481 max_horizontal_pixels = 16384;
483 max_horizontal_pixels = 65536;
486 * "The stride in bytes must not exceed the
487 * of the size of 8K pixels and 32K bytes."
489 max_stride_bytes = 32768;
492 if (drm_rotation_90_or_270(rotation))
493 return min(max_horizontal_pixels, max_stride_bytes / cpp);
495 return min(max_horizontal_pixels * cpp, max_stride_bytes);
499 /* Preoffset values for YUV to RGB Conversion */
500 #define PREOFF_YUV_TO_RGB_HI 0x1800
501 #define PREOFF_YUV_TO_RGB_ME 0x0000
502 #define PREOFF_YUV_TO_RGB_LO 0x1800
504 #define ROFF(x) (((x) & 0xffff) << 16)
505 #define GOFF(x) (((x) & 0xffff) << 0)
506 #define BOFF(x) (((x) & 0xffff) << 16)
509 * Programs the input color space conversion stage for ICL HDR planes.
510 * Note that it is assumed that this stage always happens after YUV
511 * range correction. Thus, the input to this stage is assumed to be
512 * in full-range YCbCr.
515 icl_program_input_csc(struct intel_plane *plane,
516 const struct intel_crtc_state *crtc_state,
517 const struct intel_plane_state *plane_state)
519 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
520 enum pipe pipe = plane->pipe;
521 enum plane_id plane_id = plane->id;
523 static const u16 input_csc_matrix[][9] = {
525 * BT.601 full range YCbCr -> full range RGB
526 * The matrix required is :
527 * [1.000, 0.000, 1.371,
528 * 1.000, -0.336, -0.698,
529 * 1.000, 1.732, 0.0000]
531 [DRM_COLOR_YCBCR_BT601] = {
533 0x8B28, 0x7800, 0x9AC0,
537 * BT.709 full range YCbCr -> full range RGB
538 * The matrix required is :
539 * [1.000, 0.000, 1.574,
540 * 1.000, -0.187, -0.468,
541 * 1.000, 1.855, 0.0000]
543 [DRM_COLOR_YCBCR_BT709] = {
545 0x9EF8, 0x7800, 0xAC00,
549 * BT.2020 full range YCbCr -> full range RGB
550 * The matrix required is :
551 * [1.000, 0.000, 1.474,
552 * 1.000, -0.1645, -0.5713,
553 * 1.000, 1.8814, 0.0000]
555 [DRM_COLOR_YCBCR_BT2020] = {
557 0x8928, 0x7800, 0xAA88,
561 const u16 *csc = input_csc_matrix[plane_state->hw.color_encoding];
563 intel_de_write_fw(dev_priv, PLANE_INPUT_CSC_COEFF(pipe, plane_id, 0),
564 ROFF(csc[0]) | GOFF(csc[1]));
565 intel_de_write_fw(dev_priv, PLANE_INPUT_CSC_COEFF(pipe, plane_id, 1),
567 intel_de_write_fw(dev_priv, PLANE_INPUT_CSC_COEFF(pipe, plane_id, 2),
568 ROFF(csc[3]) | GOFF(csc[4]));
569 intel_de_write_fw(dev_priv, PLANE_INPUT_CSC_COEFF(pipe, plane_id, 3),
571 intel_de_write_fw(dev_priv, PLANE_INPUT_CSC_COEFF(pipe, plane_id, 4),
572 ROFF(csc[6]) | GOFF(csc[7]));
573 intel_de_write_fw(dev_priv, PLANE_INPUT_CSC_COEFF(pipe, plane_id, 5),
576 intel_de_write_fw(dev_priv, PLANE_INPUT_CSC_PREOFF(pipe, plane_id, 0),
577 PREOFF_YUV_TO_RGB_HI);
578 intel_de_write_fw(dev_priv, PLANE_INPUT_CSC_PREOFF(pipe, plane_id, 1),
579 PREOFF_YUV_TO_RGB_ME);
580 intel_de_write_fw(dev_priv, PLANE_INPUT_CSC_PREOFF(pipe, plane_id, 2),
581 PREOFF_YUV_TO_RGB_LO);
582 intel_de_write_fw(dev_priv,
583 PLANE_INPUT_CSC_POSTOFF(pipe, plane_id, 0), 0x0);
584 intel_de_write_fw(dev_priv,
585 PLANE_INPUT_CSC_POSTOFF(pipe, plane_id, 1), 0x0);
586 intel_de_write_fw(dev_priv,
587 PLANE_INPUT_CSC_POSTOFF(pipe, plane_id, 2), 0x0);
590 static unsigned int skl_plane_stride_mult(const struct drm_framebuffer *fb,
591 int color_plane, unsigned int rotation)
594 * The stride is either expressed as a multiple of 64 bytes chunks for
595 * linear buffers or in number of tiles for tiled buffers.
597 if (is_surface_linear(fb, color_plane))
599 else if (drm_rotation_90_or_270(rotation))
600 return intel_tile_height(fb, color_plane);
602 return intel_tile_width_bytes(fb, color_plane);
605 static u32 skl_plane_stride(const struct intel_plane_state *plane_state,
608 const struct drm_framebuffer *fb = plane_state->hw.fb;
609 unsigned int rotation = plane_state->hw.rotation;
610 u32 stride = plane_state->view.color_plane[color_plane].scanout_stride;
612 if (color_plane >= fb->format->num_planes)
615 return stride / skl_plane_stride_mult(fb, color_plane, rotation);
619 skl_plane_disable_arm(struct intel_plane *plane,
620 const struct intel_crtc_state *crtc_state)
622 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
623 enum plane_id plane_id = plane->id;
624 enum pipe pipe = plane->pipe;
626 skl_write_plane_wm(plane, crtc_state);
628 intel_de_write_fw(dev_priv, PLANE_CTL(pipe, plane_id), 0);
629 intel_de_write_fw(dev_priv, PLANE_SURF(pipe, plane_id), 0);
633 icl_plane_disable_arm(struct intel_plane *plane,
634 const struct intel_crtc_state *crtc_state)
636 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
637 enum plane_id plane_id = plane->id;
638 enum pipe pipe = plane->pipe;
640 if (icl_is_hdr_plane(dev_priv, plane_id))
641 intel_de_write_fw(dev_priv, PLANE_CUS_CTL(pipe, plane_id), 0);
643 skl_write_plane_wm(plane, crtc_state);
645 intel_psr2_disable_plane_sel_fetch(plane, crtc_state);
646 intel_de_write_fw(dev_priv, PLANE_CTL(pipe, plane_id), 0);
647 intel_de_write_fw(dev_priv, PLANE_SURF(pipe, plane_id), 0);
651 skl_plane_get_hw_state(struct intel_plane *plane,
654 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
655 enum intel_display_power_domain power_domain;
656 enum plane_id plane_id = plane->id;
657 intel_wakeref_t wakeref;
660 power_domain = POWER_DOMAIN_PIPE(plane->pipe);
661 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
665 ret = intel_de_read(dev_priv, PLANE_CTL(plane->pipe, plane_id)) & PLANE_CTL_ENABLE;
669 intel_display_power_put(dev_priv, power_domain, wakeref);
674 static u32 skl_plane_ctl_format(u32 pixel_format)
676 switch (pixel_format) {
678 return PLANE_CTL_FORMAT_INDEXED;
679 case DRM_FORMAT_RGB565:
680 return PLANE_CTL_FORMAT_RGB_565;
681 case DRM_FORMAT_XBGR8888:
682 case DRM_FORMAT_ABGR8888:
683 return PLANE_CTL_FORMAT_XRGB_8888 | PLANE_CTL_ORDER_RGBX;
684 case DRM_FORMAT_XRGB8888:
685 case DRM_FORMAT_ARGB8888:
686 return PLANE_CTL_FORMAT_XRGB_8888;
687 case DRM_FORMAT_XBGR2101010:
688 case DRM_FORMAT_ABGR2101010:
689 return PLANE_CTL_FORMAT_XRGB_2101010 | PLANE_CTL_ORDER_RGBX;
690 case DRM_FORMAT_XRGB2101010:
691 case DRM_FORMAT_ARGB2101010:
692 return PLANE_CTL_FORMAT_XRGB_2101010;
693 case DRM_FORMAT_XBGR16161616F:
694 case DRM_FORMAT_ABGR16161616F:
695 return PLANE_CTL_FORMAT_XRGB_16161616F | PLANE_CTL_ORDER_RGBX;
696 case DRM_FORMAT_XRGB16161616F:
697 case DRM_FORMAT_ARGB16161616F:
698 return PLANE_CTL_FORMAT_XRGB_16161616F;
699 case DRM_FORMAT_XYUV8888:
700 return PLANE_CTL_FORMAT_XYUV;
701 case DRM_FORMAT_YUYV:
702 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_ORDER_YUYV;
703 case DRM_FORMAT_YVYU:
704 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_ORDER_YVYU;
705 case DRM_FORMAT_UYVY:
706 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_ORDER_UYVY;
707 case DRM_FORMAT_VYUY:
708 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_ORDER_VYUY;
709 case DRM_FORMAT_NV12:
710 return PLANE_CTL_FORMAT_NV12;
711 case DRM_FORMAT_P010:
712 return PLANE_CTL_FORMAT_P010;
713 case DRM_FORMAT_P012:
714 return PLANE_CTL_FORMAT_P012;
715 case DRM_FORMAT_P016:
716 return PLANE_CTL_FORMAT_P016;
717 case DRM_FORMAT_Y210:
718 return PLANE_CTL_FORMAT_Y210;
719 case DRM_FORMAT_Y212:
720 return PLANE_CTL_FORMAT_Y212;
721 case DRM_FORMAT_Y216:
722 return PLANE_CTL_FORMAT_Y216;
723 case DRM_FORMAT_XVYU2101010:
724 return PLANE_CTL_FORMAT_Y410;
725 case DRM_FORMAT_XVYU12_16161616:
726 return PLANE_CTL_FORMAT_Y412;
727 case DRM_FORMAT_XVYU16161616:
728 return PLANE_CTL_FORMAT_Y416;
730 MISSING_CASE(pixel_format);
736 static u32 skl_plane_ctl_alpha(const struct intel_plane_state *plane_state)
738 if (!plane_state->hw.fb->format->has_alpha)
739 return PLANE_CTL_ALPHA_DISABLE;
741 switch (plane_state->hw.pixel_blend_mode) {
742 case DRM_MODE_BLEND_PIXEL_NONE:
743 return PLANE_CTL_ALPHA_DISABLE;
744 case DRM_MODE_BLEND_PREMULTI:
745 return PLANE_CTL_ALPHA_SW_PREMULTIPLY;
746 case DRM_MODE_BLEND_COVERAGE:
747 return PLANE_CTL_ALPHA_HW_PREMULTIPLY;
749 MISSING_CASE(plane_state->hw.pixel_blend_mode);
750 return PLANE_CTL_ALPHA_DISABLE;
754 static u32 glk_plane_color_ctl_alpha(const struct intel_plane_state *plane_state)
756 if (!plane_state->hw.fb->format->has_alpha)
757 return PLANE_COLOR_ALPHA_DISABLE;
759 switch (plane_state->hw.pixel_blend_mode) {
760 case DRM_MODE_BLEND_PIXEL_NONE:
761 return PLANE_COLOR_ALPHA_DISABLE;
762 case DRM_MODE_BLEND_PREMULTI:
763 return PLANE_COLOR_ALPHA_SW_PREMULTIPLY;
764 case DRM_MODE_BLEND_COVERAGE:
765 return PLANE_COLOR_ALPHA_HW_PREMULTIPLY;
767 MISSING_CASE(plane_state->hw.pixel_blend_mode);
768 return PLANE_COLOR_ALPHA_DISABLE;
772 static u32 skl_plane_ctl_tiling(u64 fb_modifier)
774 switch (fb_modifier) {
775 case DRM_FORMAT_MOD_LINEAR:
777 case I915_FORMAT_MOD_X_TILED:
778 return PLANE_CTL_TILED_X;
779 case I915_FORMAT_MOD_Y_TILED:
780 return PLANE_CTL_TILED_Y;
781 case I915_FORMAT_MOD_4_TILED:
782 return PLANE_CTL_TILED_4;
783 case I915_FORMAT_MOD_4_TILED_DG2_RC_CCS:
784 return PLANE_CTL_TILED_4 |
785 PLANE_CTL_RENDER_DECOMPRESSION_ENABLE |
786 PLANE_CTL_CLEAR_COLOR_DISABLE;
787 case I915_FORMAT_MOD_4_TILED_DG2_MC_CCS:
788 return PLANE_CTL_TILED_4 |
789 PLANE_CTL_MEDIA_DECOMPRESSION_ENABLE |
790 PLANE_CTL_CLEAR_COLOR_DISABLE;
791 case I915_FORMAT_MOD_4_TILED_DG2_RC_CCS_CC:
792 return PLANE_CTL_TILED_4 | PLANE_CTL_RENDER_DECOMPRESSION_ENABLE;
793 case I915_FORMAT_MOD_Y_TILED_CCS:
794 case I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS_CC:
795 return PLANE_CTL_TILED_Y | PLANE_CTL_RENDER_DECOMPRESSION_ENABLE;
796 case I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS:
797 return PLANE_CTL_TILED_Y |
798 PLANE_CTL_RENDER_DECOMPRESSION_ENABLE |
799 PLANE_CTL_CLEAR_COLOR_DISABLE;
800 case I915_FORMAT_MOD_Y_TILED_GEN12_MC_CCS:
801 return PLANE_CTL_TILED_Y | PLANE_CTL_MEDIA_DECOMPRESSION_ENABLE;
802 case I915_FORMAT_MOD_Yf_TILED:
803 return PLANE_CTL_TILED_YF;
804 case I915_FORMAT_MOD_Yf_TILED_CCS:
805 return PLANE_CTL_TILED_YF | PLANE_CTL_RENDER_DECOMPRESSION_ENABLE;
807 MISSING_CASE(fb_modifier);
813 static u32 skl_plane_ctl_rotate(unsigned int rotate)
816 case DRM_MODE_ROTATE_0:
819 * DRM_MODE_ROTATE_ is counter clockwise to stay compatible with Xrandr
820 * while i915 HW rotation is clockwise, thats why this swapping.
822 case DRM_MODE_ROTATE_90:
823 return PLANE_CTL_ROTATE_270;
824 case DRM_MODE_ROTATE_180:
825 return PLANE_CTL_ROTATE_180;
826 case DRM_MODE_ROTATE_270:
827 return PLANE_CTL_ROTATE_90;
829 MISSING_CASE(rotate);
835 static u32 icl_plane_ctl_flip(unsigned int reflect)
840 case DRM_MODE_REFLECT_X:
841 return PLANE_CTL_FLIP_HORIZONTAL;
842 case DRM_MODE_REFLECT_Y:
844 MISSING_CASE(reflect);
850 static u32 adlp_plane_ctl_arb_slots(const struct intel_plane_state *plane_state)
852 const struct drm_framebuffer *fb = plane_state->hw.fb;
854 if (intel_format_info_is_yuv_semiplanar(fb->format, fb->modifier)) {
855 switch (fb->format->cpp[0]) {
857 return PLANE_CTL_ARB_SLOTS(1);
859 return PLANE_CTL_ARB_SLOTS(0);
862 switch (fb->format->cpp[0]) {
864 return PLANE_CTL_ARB_SLOTS(3);
866 return PLANE_CTL_ARB_SLOTS(1);
868 return PLANE_CTL_ARB_SLOTS(0);
873 static u32 skl_plane_ctl_crtc(const struct intel_crtc_state *crtc_state)
875 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
878 if (DISPLAY_VER(dev_priv) >= 10)
881 if (crtc_state->gamma_enable)
882 plane_ctl |= PLANE_CTL_PIPE_GAMMA_ENABLE;
884 if (crtc_state->csc_enable)
885 plane_ctl |= PLANE_CTL_PIPE_CSC_ENABLE;
890 static u32 skl_plane_ctl(const struct intel_crtc_state *crtc_state,
891 const struct intel_plane_state *plane_state)
893 struct drm_i915_private *dev_priv =
894 to_i915(plane_state->uapi.plane->dev);
895 const struct drm_framebuffer *fb = plane_state->hw.fb;
896 unsigned int rotation = plane_state->hw.rotation;
897 const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
900 plane_ctl = PLANE_CTL_ENABLE;
902 if (DISPLAY_VER(dev_priv) < 10) {
903 plane_ctl |= skl_plane_ctl_alpha(plane_state);
904 plane_ctl |= PLANE_CTL_PLANE_GAMMA_DISABLE;
906 if (plane_state->hw.color_encoding == DRM_COLOR_YCBCR_BT709)
907 plane_ctl |= PLANE_CTL_YUV_TO_RGB_CSC_FORMAT_BT709;
909 if (plane_state->hw.color_range == DRM_COLOR_YCBCR_FULL_RANGE)
910 plane_ctl |= PLANE_CTL_YUV_RANGE_CORRECTION_DISABLE;
913 plane_ctl |= skl_plane_ctl_format(fb->format->format);
914 plane_ctl |= skl_plane_ctl_tiling(fb->modifier);
915 plane_ctl |= skl_plane_ctl_rotate(rotation & DRM_MODE_ROTATE_MASK);
917 if (DISPLAY_VER(dev_priv) >= 11)
918 plane_ctl |= icl_plane_ctl_flip(rotation &
919 DRM_MODE_REFLECT_MASK);
921 if (key->flags & I915_SET_COLORKEY_DESTINATION)
922 plane_ctl |= PLANE_CTL_KEY_ENABLE_DESTINATION;
923 else if (key->flags & I915_SET_COLORKEY_SOURCE)
924 plane_ctl |= PLANE_CTL_KEY_ENABLE_SOURCE;
926 /* Wa_22012358565:adl-p */
927 if (DISPLAY_VER(dev_priv) == 13)
928 plane_ctl |= adlp_plane_ctl_arb_slots(plane_state);
933 static u32 glk_plane_color_ctl_crtc(const struct intel_crtc_state *crtc_state)
935 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
936 u32 plane_color_ctl = 0;
938 if (DISPLAY_VER(dev_priv) >= 11)
939 return plane_color_ctl;
941 if (crtc_state->gamma_enable)
942 plane_color_ctl |= PLANE_COLOR_PIPE_GAMMA_ENABLE;
944 if (crtc_state->csc_enable)
945 plane_color_ctl |= PLANE_COLOR_PIPE_CSC_ENABLE;
947 return plane_color_ctl;
950 static u32 glk_plane_color_ctl(const struct intel_crtc_state *crtc_state,
951 const struct intel_plane_state *plane_state)
953 struct drm_i915_private *dev_priv =
954 to_i915(plane_state->uapi.plane->dev);
955 const struct drm_framebuffer *fb = plane_state->hw.fb;
956 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
957 u32 plane_color_ctl = 0;
959 plane_color_ctl |= PLANE_COLOR_PLANE_GAMMA_DISABLE;
960 plane_color_ctl |= glk_plane_color_ctl_alpha(plane_state);
962 if (fb->format->is_yuv && !icl_is_hdr_plane(dev_priv, plane->id)) {
963 switch (plane_state->hw.color_encoding) {
964 case DRM_COLOR_YCBCR_BT709:
965 plane_color_ctl |= PLANE_COLOR_CSC_MODE_YUV709_TO_RGB709;
967 case DRM_COLOR_YCBCR_BT2020:
969 PLANE_COLOR_CSC_MODE_YUV2020_TO_RGB2020;
973 PLANE_COLOR_CSC_MODE_YUV601_TO_RGB601;
975 if (plane_state->hw.color_range == DRM_COLOR_YCBCR_FULL_RANGE)
976 plane_color_ctl |= PLANE_COLOR_YUV_RANGE_CORRECTION_DISABLE;
977 } else if (fb->format->is_yuv) {
978 plane_color_ctl |= PLANE_COLOR_INPUT_CSC_ENABLE;
979 if (plane_state->hw.color_range == DRM_COLOR_YCBCR_FULL_RANGE)
980 plane_color_ctl |= PLANE_COLOR_YUV_RANGE_CORRECTION_DISABLE;
983 if (plane_state->force_black)
984 plane_color_ctl |= PLANE_COLOR_PLANE_CSC_ENABLE;
986 return plane_color_ctl;
989 static u32 skl_surf_address(const struct intel_plane_state *plane_state,
992 struct drm_i915_private *i915 = to_i915(plane_state->uapi.plane->dev);
993 const struct drm_framebuffer *fb = plane_state->hw.fb;
994 u32 offset = plane_state->view.color_plane[color_plane].offset;
996 if (intel_fb_uses_dpt(fb)) {
998 * The DPT object contains only one vma, so the VMA's offset
999 * within the DPT is always 0.
1001 drm_WARN_ON(&i915->drm, plane_state->dpt_vma->node.start);
1002 drm_WARN_ON(&i915->drm, offset & 0x1fffff);
1005 drm_WARN_ON(&i915->drm, offset & 0xfff);
1010 static u32 skl_plane_surf(const struct intel_plane_state *plane_state,
1015 plane_surf = intel_plane_ggtt_offset(plane_state) +
1016 skl_surf_address(plane_state, color_plane);
1018 if (plane_state->decrypt)
1019 plane_surf |= PLANE_SURF_DECRYPT;
1024 static u32 skl_plane_aux_dist(const struct intel_plane_state *plane_state,
1027 struct drm_i915_private *i915 = to_i915(plane_state->uapi.plane->dev);
1028 const struct drm_framebuffer *fb = plane_state->hw.fb;
1029 int aux_plane = skl_main_to_aux_plane(fb, color_plane);
1035 aux_dist = skl_surf_address(plane_state, aux_plane) -
1036 skl_surf_address(plane_state, color_plane);
1038 if (DISPLAY_VER(i915) < 12)
1039 aux_dist |= PLANE_AUX_STRIDE(skl_plane_stride(plane_state, aux_plane));
1044 static u32 skl_plane_keyval(const struct intel_plane_state *plane_state)
1046 const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
1048 return key->min_value;
1051 static u32 skl_plane_keymax(const struct intel_plane_state *plane_state)
1053 const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
1054 u8 alpha = plane_state->hw.alpha >> 8;
1056 return (key->max_value & 0xffffff) | PLANE_KEYMAX_ALPHA(alpha);
1059 static u32 skl_plane_keymsk(const struct intel_plane_state *plane_state)
1061 const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
1062 u8 alpha = plane_state->hw.alpha >> 8;
1065 keymsk = key->channel_mask & 0x7ffffff;
1067 keymsk |= PLANE_KEYMSK_ALPHA_ENABLE;
1072 static void icl_plane_csc_load_black(struct intel_plane *plane)
1074 struct drm_i915_private *i915 = to_i915(plane->base.dev);
1075 enum plane_id plane_id = plane->id;
1076 enum pipe pipe = plane->pipe;
1078 intel_de_write_fw(i915, PLANE_CSC_COEFF(pipe, plane_id, 0), 0);
1079 intel_de_write_fw(i915, PLANE_CSC_COEFF(pipe, plane_id, 1), 0);
1081 intel_de_write_fw(i915, PLANE_CSC_COEFF(pipe, plane_id, 2), 0);
1082 intel_de_write_fw(i915, PLANE_CSC_COEFF(pipe, plane_id, 3), 0);
1084 intel_de_write_fw(i915, PLANE_CSC_COEFF(pipe, plane_id, 4), 0);
1085 intel_de_write_fw(i915, PLANE_CSC_COEFF(pipe, plane_id, 5), 0);
1087 intel_de_write_fw(i915, PLANE_CSC_PREOFF(pipe, plane_id, 0), 0);
1088 intel_de_write_fw(i915, PLANE_CSC_PREOFF(pipe, plane_id, 1), 0);
1089 intel_de_write_fw(i915, PLANE_CSC_PREOFF(pipe, plane_id, 2), 0);
1091 intel_de_write_fw(i915, PLANE_CSC_POSTOFF(pipe, plane_id, 0), 0);
1092 intel_de_write_fw(i915, PLANE_CSC_POSTOFF(pipe, plane_id, 1), 0);
1093 intel_de_write_fw(i915, PLANE_CSC_POSTOFF(pipe, plane_id, 2), 0);
1096 static int icl_plane_color_plane(const struct intel_plane_state *plane_state)
1098 /* Program the UV plane on planar master */
1099 if (plane_state->planar_linked_plane && !plane_state->planar_slave)
1106 skl_plane_update_noarm(struct intel_plane *plane,
1107 const struct intel_crtc_state *crtc_state,
1108 const struct intel_plane_state *plane_state)
1110 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
1111 enum plane_id plane_id = plane->id;
1112 enum pipe pipe = plane->pipe;
1113 u32 stride = skl_plane_stride(plane_state, 0);
1114 int crtc_x = plane_state->uapi.dst.x1;
1115 int crtc_y = plane_state->uapi.dst.y1;
1116 u32 src_w = drm_rect_width(&plane_state->uapi.src) >> 16;
1117 u32 src_h = drm_rect_height(&plane_state->uapi.src) >> 16;
1119 /* The scaler will handle the output position */
1120 if (plane_state->scaler_id >= 0) {
1125 intel_de_write_fw(dev_priv, PLANE_STRIDE(pipe, plane_id),
1126 PLANE_STRIDE_(stride));
1127 intel_de_write_fw(dev_priv, PLANE_POS(pipe, plane_id),
1128 PLANE_POS_Y(crtc_y) | PLANE_POS_X(crtc_x));
1129 intel_de_write_fw(dev_priv, PLANE_SIZE(pipe, plane_id),
1130 PLANE_HEIGHT(src_h - 1) | PLANE_WIDTH(src_w - 1));
1132 skl_write_plane_wm(plane, crtc_state);
1136 skl_plane_update_arm(struct intel_plane *plane,
1137 const struct intel_crtc_state *crtc_state,
1138 const struct intel_plane_state *plane_state)
1140 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
1141 enum plane_id plane_id = plane->id;
1142 enum pipe pipe = plane->pipe;
1143 u32 x = plane_state->view.color_plane[0].x;
1144 u32 y = plane_state->view.color_plane[0].y;
1145 u32 plane_ctl, plane_color_ctl = 0;
1147 plane_ctl = plane_state->ctl |
1148 skl_plane_ctl_crtc(crtc_state);
1150 if (DISPLAY_VER(dev_priv) >= 10)
1151 plane_color_ctl = plane_state->color_ctl |
1152 glk_plane_color_ctl_crtc(crtc_state);
1154 intel_de_write_fw(dev_priv, PLANE_KEYVAL(pipe, plane_id), skl_plane_keyval(plane_state));
1155 intel_de_write_fw(dev_priv, PLANE_KEYMSK(pipe, plane_id), skl_plane_keymsk(plane_state));
1156 intel_de_write_fw(dev_priv, PLANE_KEYMAX(pipe, plane_id), skl_plane_keymax(plane_state));
1158 intel_de_write_fw(dev_priv, PLANE_OFFSET(pipe, plane_id),
1159 PLANE_OFFSET_Y(y) | PLANE_OFFSET_X(x));
1161 intel_de_write_fw(dev_priv, PLANE_AUX_DIST(pipe, plane_id),
1162 skl_plane_aux_dist(plane_state, 0));
1164 intel_de_write_fw(dev_priv, PLANE_AUX_OFFSET(pipe, plane_id),
1165 PLANE_OFFSET_Y(plane_state->view.color_plane[1].y) |
1166 PLANE_OFFSET_X(plane_state->view.color_plane[1].x));
1168 if (DISPLAY_VER(dev_priv) >= 10)
1169 intel_de_write_fw(dev_priv, PLANE_COLOR_CTL(pipe, plane_id), plane_color_ctl);
1172 * Enable the scaler before the plane so that we don't
1173 * get a catastrophic underrun even if the two operations
1174 * end up happening in two different frames.
1176 * TODO: split into noarm+arm pair
1178 if (plane_state->scaler_id >= 0)
1179 skl_program_plane_scaler(plane, crtc_state, plane_state);
1182 * The control register self-arms if the plane was previously
1183 * disabled. Try to make the plane enable atomic by writing
1184 * the control register just before the surface register.
1186 intel_de_write_fw(dev_priv, PLANE_CTL(pipe, plane_id), plane_ctl);
1187 intel_de_write_fw(dev_priv, PLANE_SURF(pipe, plane_id),
1188 skl_plane_surf(plane_state, 0));
1192 icl_plane_update_noarm(struct intel_plane *plane,
1193 const struct intel_crtc_state *crtc_state,
1194 const struct intel_plane_state *plane_state)
1196 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
1197 enum plane_id plane_id = plane->id;
1198 enum pipe pipe = plane->pipe;
1199 int color_plane = icl_plane_color_plane(plane_state);
1200 u32 stride = skl_plane_stride(plane_state, color_plane);
1201 const struct drm_framebuffer *fb = plane_state->hw.fb;
1202 int crtc_x = plane_state->uapi.dst.x1;
1203 int crtc_y = plane_state->uapi.dst.y1;
1204 int x = plane_state->view.color_plane[color_plane].x;
1205 int y = plane_state->view.color_plane[color_plane].y;
1206 int src_w = drm_rect_width(&plane_state->uapi.src) >> 16;
1207 int src_h = drm_rect_height(&plane_state->uapi.src) >> 16;
1208 u32 plane_color_ctl;
1210 plane_color_ctl = plane_state->color_ctl |
1211 glk_plane_color_ctl_crtc(crtc_state);
1213 /* The scaler will handle the output position */
1214 if (plane_state->scaler_id >= 0) {
1219 intel_de_write_fw(dev_priv, PLANE_STRIDE(pipe, plane_id),
1220 PLANE_STRIDE_(stride));
1221 intel_de_write_fw(dev_priv, PLANE_POS(pipe, plane_id),
1222 PLANE_POS_Y(crtc_y) | PLANE_POS_X(crtc_x));
1223 intel_de_write_fw(dev_priv, PLANE_SIZE(pipe, plane_id),
1224 PLANE_HEIGHT(src_h - 1) | PLANE_WIDTH(src_w - 1));
1226 intel_de_write_fw(dev_priv, PLANE_KEYVAL(pipe, plane_id), skl_plane_keyval(plane_state));
1227 intel_de_write_fw(dev_priv, PLANE_KEYMSK(pipe, plane_id), skl_plane_keymsk(plane_state));
1228 intel_de_write_fw(dev_priv, PLANE_KEYMAX(pipe, plane_id), skl_plane_keymax(plane_state));
1230 intel_de_write_fw(dev_priv, PLANE_OFFSET(pipe, plane_id),
1231 PLANE_OFFSET_Y(y) | PLANE_OFFSET_X(x));
1233 if (intel_fb_is_rc_ccs_cc_modifier(fb->modifier)) {
1234 intel_de_write_fw(dev_priv, PLANE_CC_VAL(pipe, plane_id, 0),
1235 lower_32_bits(plane_state->ccval));
1236 intel_de_write_fw(dev_priv, PLANE_CC_VAL(pipe, plane_id, 1),
1237 upper_32_bits(plane_state->ccval));
1240 /* FLAT CCS doesn't need to program AUX_DIST */
1241 if (!HAS_FLAT_CCS(dev_priv))
1242 intel_de_write_fw(dev_priv, PLANE_AUX_DIST(pipe, plane_id),
1243 skl_plane_aux_dist(plane_state, color_plane));
1245 if (icl_is_hdr_plane(dev_priv, plane_id))
1246 intel_de_write_fw(dev_priv, PLANE_CUS_CTL(pipe, plane_id),
1247 plane_state->cus_ctl);
1249 intel_de_write_fw(dev_priv, PLANE_COLOR_CTL(pipe, plane_id), plane_color_ctl);
1251 if (fb->format->is_yuv && icl_is_hdr_plane(dev_priv, plane_id))
1252 icl_program_input_csc(plane, crtc_state, plane_state);
1254 skl_write_plane_wm(plane, crtc_state);
1257 * FIXME: pxp session invalidation can hit any time even at time of commit
1258 * or after the commit, display content will be garbage.
1260 if (plane_state->force_black)
1261 icl_plane_csc_load_black(plane);
1263 intel_psr2_program_plane_sel_fetch(plane, crtc_state, plane_state, color_plane);
1267 icl_plane_update_arm(struct intel_plane *plane,
1268 const struct intel_crtc_state *crtc_state,
1269 const struct intel_plane_state *plane_state)
1271 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
1272 enum plane_id plane_id = plane->id;
1273 enum pipe pipe = plane->pipe;
1274 int color_plane = icl_plane_color_plane(plane_state);
1277 plane_ctl = plane_state->ctl |
1278 skl_plane_ctl_crtc(crtc_state);
1281 * Enable the scaler before the plane so that we don't
1282 * get a catastrophic underrun even if the two operations
1283 * end up happening in two different frames.
1285 * TODO: split into noarm+arm pair
1287 if (plane_state->scaler_id >= 0)
1288 skl_program_plane_scaler(plane, crtc_state, plane_state);
1291 * The control register self-arms if the plane was previously
1292 * disabled. Try to make the plane enable atomic by writing
1293 * the control register just before the surface register.
1295 intel_de_write_fw(dev_priv, PLANE_CTL(pipe, plane_id), plane_ctl);
1296 intel_de_write_fw(dev_priv, PLANE_SURF(pipe, plane_id),
1297 skl_plane_surf(plane_state, color_plane));
1301 skl_plane_async_flip(struct intel_plane *plane,
1302 const struct intel_crtc_state *crtc_state,
1303 const struct intel_plane_state *plane_state,
1306 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
1307 enum plane_id plane_id = plane->id;
1308 enum pipe pipe = plane->pipe;
1309 u32 plane_ctl = plane_state->ctl;
1311 plane_ctl |= skl_plane_ctl_crtc(crtc_state);
1314 plane_ctl |= PLANE_CTL_ASYNC_FLIP;
1316 intel_de_write_fw(dev_priv, PLANE_CTL(pipe, plane_id), plane_ctl);
1317 intel_de_write_fw(dev_priv, PLANE_SURF(pipe, plane_id),
1318 skl_plane_surf(plane_state, 0));
1321 static bool intel_format_is_p01x(u32 format)
1324 case DRM_FORMAT_P010:
1325 case DRM_FORMAT_P012:
1326 case DRM_FORMAT_P016:
1333 static int skl_plane_check_fb(const struct intel_crtc_state *crtc_state,
1334 const struct intel_plane_state *plane_state)
1336 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
1337 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
1338 const struct drm_framebuffer *fb = plane_state->hw.fb;
1339 unsigned int rotation = plane_state->hw.rotation;
1344 if (rotation & ~(DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180) &&
1345 intel_fb_is_ccs_modifier(fb->modifier)) {
1346 drm_dbg_kms(&dev_priv->drm,
1347 "RC support only with 0/180 degree rotation (%x)\n",
1352 if (rotation & DRM_MODE_REFLECT_X &&
1353 fb->modifier == DRM_FORMAT_MOD_LINEAR) {
1354 drm_dbg_kms(&dev_priv->drm,
1355 "horizontal flip is not supported with linear surface formats\n");
1359 if (drm_rotation_90_or_270(rotation)) {
1360 if (!intel_fb_supports_90_270_rotation(to_intel_framebuffer(fb))) {
1361 drm_dbg_kms(&dev_priv->drm,
1362 "Y/Yf tiling required for 90/270!\n");
1367 * 90/270 is not allowed with RGB64 16:16:16:16 and
1368 * Indexed 8-bit. RGB 16-bit 5:6:5 is allowed gen11 onwards.
1370 switch (fb->format->format) {
1371 case DRM_FORMAT_RGB565:
1372 if (DISPLAY_VER(dev_priv) >= 11)
1376 case DRM_FORMAT_XRGB16161616F:
1377 case DRM_FORMAT_XBGR16161616F:
1378 case DRM_FORMAT_ARGB16161616F:
1379 case DRM_FORMAT_ABGR16161616F:
1380 case DRM_FORMAT_Y210:
1381 case DRM_FORMAT_Y212:
1382 case DRM_FORMAT_Y216:
1383 case DRM_FORMAT_XVYU12_16161616:
1384 case DRM_FORMAT_XVYU16161616:
1385 drm_dbg_kms(&dev_priv->drm,
1386 "Unsupported pixel format %p4cc for 90/270!\n",
1387 &fb->format->format);
1394 /* Y-tiling is not supported in IF-ID Interlace mode */
1395 if (crtc_state->hw.enable &&
1396 crtc_state->hw.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE &&
1397 fb->modifier != DRM_FORMAT_MOD_LINEAR &&
1398 fb->modifier != I915_FORMAT_MOD_X_TILED) {
1399 drm_dbg_kms(&dev_priv->drm,
1400 "Y/Yf tiling not supported in IF-ID mode\n");
1404 /* Wa_1606054188:tgl,adl-s */
1405 if ((IS_ALDERLAKE_S(dev_priv) || IS_TIGERLAKE(dev_priv)) &&
1406 plane_state->ckey.flags & I915_SET_COLORKEY_SOURCE &&
1407 intel_format_is_p01x(fb->format->format)) {
1408 drm_dbg_kms(&dev_priv->drm,
1409 "Source color keying not supported with P01x formats\n");
1416 static int skl_plane_check_dst_coordinates(const struct intel_crtc_state *crtc_state,
1417 const struct intel_plane_state *plane_state)
1419 struct drm_i915_private *dev_priv =
1420 to_i915(plane_state->uapi.plane->dev);
1421 int crtc_x = plane_state->uapi.dst.x1;
1422 int crtc_w = drm_rect_width(&plane_state->uapi.dst);
1423 int pipe_src_w = drm_rect_width(&crtc_state->pipe_src);
1426 * Display WA #1175: glk
1427 * Planes other than the cursor may cause FIFO underflow and display
1428 * corruption if starting less than 4 pixels from the right edge of
1430 * Besides the above WA fix the similar problem, where planes other
1431 * than the cursor ending less than 4 pixels from the left edge of the
1432 * screen may cause FIFO underflow and display corruption.
1434 if (DISPLAY_VER(dev_priv) == 10 &&
1435 (crtc_x + crtc_w < 4 || crtc_x > pipe_src_w - 4)) {
1436 drm_dbg_kms(&dev_priv->drm,
1437 "requested plane X %s position %d invalid (valid range %d-%d)\n",
1438 crtc_x + crtc_w < 4 ? "end" : "start",
1439 crtc_x + crtc_w < 4 ? crtc_x + crtc_w : crtc_x,
1447 static int skl_plane_check_nv12_rotation(const struct intel_plane_state *plane_state)
1449 struct drm_i915_private *i915 = to_i915(plane_state->uapi.plane->dev);
1450 const struct drm_framebuffer *fb = plane_state->hw.fb;
1451 unsigned int rotation = plane_state->hw.rotation;
1452 int src_w = drm_rect_width(&plane_state->uapi.src) >> 16;
1454 /* Display WA #1106 */
1455 if (intel_format_info_is_yuv_semiplanar(fb->format, fb->modifier) &&
1457 (rotation == DRM_MODE_ROTATE_270 ||
1458 rotation == (DRM_MODE_REFLECT_X | DRM_MODE_ROTATE_90))) {
1459 drm_dbg_kms(&i915->drm, "src width must be multiple of 4 for rotated planar YUV\n");
1466 static int skl_plane_max_scale(struct drm_i915_private *dev_priv,
1467 const struct drm_framebuffer *fb)
1470 * We don't yet know the final source width nor
1471 * whether we can use the HQ scaler mode. Assume
1473 * FIXME need to properly check this later.
1475 if (DISPLAY_VER(dev_priv) >= 10 ||
1476 !intel_format_info_is_yuv_semiplanar(fb->format, fb->modifier))
1482 static int intel_plane_min_width(struct intel_plane *plane,
1483 const struct drm_framebuffer *fb,
1485 unsigned int rotation)
1487 if (plane->min_width)
1488 return plane->min_width(fb, color_plane, rotation);
1493 static int intel_plane_max_width(struct intel_plane *plane,
1494 const struct drm_framebuffer *fb,
1496 unsigned int rotation)
1498 if (plane->max_width)
1499 return plane->max_width(fb, color_plane, rotation);
1504 static int intel_plane_max_height(struct intel_plane *plane,
1505 const struct drm_framebuffer *fb,
1507 unsigned int rotation)
1509 if (plane->max_height)
1510 return plane->max_height(fb, color_plane, rotation);
1516 skl_check_main_ccs_coordinates(struct intel_plane_state *plane_state,
1517 int main_x, int main_y, u32 main_offset,
1520 const struct drm_framebuffer *fb = plane_state->hw.fb;
1521 int aux_x = plane_state->view.color_plane[ccs_plane].x;
1522 int aux_y = plane_state->view.color_plane[ccs_plane].y;
1523 u32 aux_offset = plane_state->view.color_plane[ccs_plane].offset;
1524 u32 alignment = intel_surf_alignment(fb, ccs_plane);
1528 intel_fb_plane_get_subsampling(&hsub, &vsub, fb, ccs_plane);
1529 while (aux_offset >= main_offset && aux_y <= main_y) {
1532 if (aux_x == main_x && aux_y == main_y)
1535 if (aux_offset == 0)
1540 aux_offset = intel_plane_adjust_aligned_offset(&x, &y,
1546 aux_x = x * hsub + aux_x % hsub;
1547 aux_y = y * vsub + aux_y % vsub;
1550 if (aux_x != main_x || aux_y != main_y)
1553 plane_state->view.color_plane[ccs_plane].offset = aux_offset;
1554 plane_state->view.color_plane[ccs_plane].x = aux_x;
1555 plane_state->view.color_plane[ccs_plane].y = aux_y;
1561 int skl_calc_main_surface_offset(const struct intel_plane_state *plane_state,
1562 int *x, int *y, u32 *offset)
1564 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
1565 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
1566 const struct drm_framebuffer *fb = plane_state->hw.fb;
1567 const int aux_plane = skl_main_to_aux_plane(fb, 0);
1568 const u32 aux_offset = plane_state->view.color_plane[aux_plane].offset;
1569 const u32 alignment = intel_surf_alignment(fb, 0);
1570 const int w = drm_rect_width(&plane_state->uapi.src) >> 16;
1572 intel_add_fb_offsets(x, y, plane_state, 0);
1573 *offset = intel_plane_compute_aligned_offset(x, y, plane_state, 0);
1574 if (drm_WARN_ON(&dev_priv->drm, alignment && !is_power_of_2(alignment)))
1578 * AUX surface offset is specified as the distance from the
1579 * main surface offset, and it must be non-negative. Make
1580 * sure that is what we will get.
1582 if (aux_plane && *offset > aux_offset)
1583 *offset = intel_plane_adjust_aligned_offset(x, y, plane_state, 0,
1585 aux_offset & ~(alignment - 1));
1588 * When using an X-tiled surface, the plane blows up
1589 * if the x offset + width exceed the stride.
1591 * TODO: linear and Y-tiled seem fine, Yf untested,
1593 if (fb->modifier == I915_FORMAT_MOD_X_TILED) {
1594 int cpp = fb->format->cpp[0];
1596 while ((*x + w) * cpp > plane_state->view.color_plane[0].mapping_stride) {
1598 drm_dbg_kms(&dev_priv->drm,
1599 "Unable to find suitable display surface offset due to X-tiling\n");
1603 *offset = intel_plane_adjust_aligned_offset(x, y, plane_state, 0,
1605 *offset - alignment);
1612 static int skl_check_main_surface(struct intel_plane_state *plane_state)
1614 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
1615 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
1616 const struct drm_framebuffer *fb = plane_state->hw.fb;
1617 const unsigned int rotation = plane_state->hw.rotation;
1618 int x = plane_state->uapi.src.x1 >> 16;
1619 int y = plane_state->uapi.src.y1 >> 16;
1620 const int w = drm_rect_width(&plane_state->uapi.src) >> 16;
1621 const int h = drm_rect_height(&plane_state->uapi.src) >> 16;
1622 const int min_width = intel_plane_min_width(plane, fb, 0, rotation);
1623 const int max_width = intel_plane_max_width(plane, fb, 0, rotation);
1624 const int max_height = intel_plane_max_height(plane, fb, 0, rotation);
1625 const int aux_plane = skl_main_to_aux_plane(fb, 0);
1626 const u32 alignment = intel_surf_alignment(fb, 0);
1630 if (w > max_width || w < min_width || h > max_height) {
1631 drm_dbg_kms(&dev_priv->drm,
1632 "requested Y/RGB source size %dx%d outside limits (min: %dx1 max: %dx%d)\n",
1633 w, h, min_width, max_width, max_height);
1637 ret = skl_calc_main_surface_offset(plane_state, &x, &y, &offset);
1642 * CCS AUX surface doesn't have its own x/y offsets, we must make sure
1643 * they match with the main surface x/y offsets. On DG2
1644 * there's no aux plane on fb so skip this checking.
1646 if (intel_fb_is_ccs_modifier(fb->modifier) && aux_plane) {
1647 while (!skl_check_main_ccs_coordinates(plane_state, x, y,
1648 offset, aux_plane)) {
1652 offset = intel_plane_adjust_aligned_offset(&x, &y, plane_state, 0,
1653 offset, offset - alignment);
1656 if (x != plane_state->view.color_plane[aux_plane].x ||
1657 y != plane_state->view.color_plane[aux_plane].y) {
1658 drm_dbg_kms(&dev_priv->drm,
1659 "Unable to find suitable display surface offset due to CCS\n");
1664 if (DISPLAY_VER(dev_priv) >= 13)
1665 drm_WARN_ON(&dev_priv->drm, x > 65535 || y > 65535);
1667 drm_WARN_ON(&dev_priv->drm, x > 8191 || y > 8191);
1669 plane_state->view.color_plane[0].offset = offset;
1670 plane_state->view.color_plane[0].x = x;
1671 plane_state->view.color_plane[0].y = y;
1674 * Put the final coordinates back so that the src
1675 * coordinate checks will see the right values.
1677 drm_rect_translate_to(&plane_state->uapi.src,
1683 static int skl_check_nv12_aux_surface(struct intel_plane_state *plane_state)
1685 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
1686 struct drm_i915_private *i915 = to_i915(plane->base.dev);
1687 const struct drm_framebuffer *fb = plane_state->hw.fb;
1688 unsigned int rotation = plane_state->hw.rotation;
1690 int ccs_plane = intel_fb_is_ccs_modifier(fb->modifier) ?
1691 skl_main_to_aux_plane(fb, uv_plane) : 0;
1692 int max_width = intel_plane_max_width(plane, fb, uv_plane, rotation);
1693 int max_height = intel_plane_max_height(plane, fb, uv_plane, rotation);
1694 int x = plane_state->uapi.src.x1 >> 17;
1695 int y = plane_state->uapi.src.y1 >> 17;
1696 int w = drm_rect_width(&plane_state->uapi.src) >> 17;
1697 int h = drm_rect_height(&plane_state->uapi.src) >> 17;
1700 /* FIXME not quite sure how/if these apply to the chroma plane */
1701 if (w > max_width || h > max_height) {
1702 drm_dbg_kms(&i915->drm,
1703 "CbCr source size %dx%d too big (limit %dx%d)\n",
1704 w, h, max_width, max_height);
1708 intel_add_fb_offsets(&x, &y, plane_state, uv_plane);
1709 offset = intel_plane_compute_aligned_offset(&x, &y,
1710 plane_state, uv_plane);
1713 u32 aux_offset = plane_state->view.color_plane[ccs_plane].offset;
1714 u32 alignment = intel_surf_alignment(fb, uv_plane);
1716 if (offset > aux_offset)
1717 offset = intel_plane_adjust_aligned_offset(&x, &y,
1721 aux_offset & ~(alignment - 1));
1723 while (!skl_check_main_ccs_coordinates(plane_state, x, y,
1724 offset, ccs_plane)) {
1728 offset = intel_plane_adjust_aligned_offset(&x, &y,
1731 offset, offset - alignment);
1734 if (x != plane_state->view.color_plane[ccs_plane].x ||
1735 y != plane_state->view.color_plane[ccs_plane].y) {
1736 drm_dbg_kms(&i915->drm,
1737 "Unable to find suitable display surface offset due to CCS\n");
1742 if (DISPLAY_VER(i915) >= 13)
1743 drm_WARN_ON(&i915->drm, x > 65535 || y > 65535);
1745 drm_WARN_ON(&i915->drm, x > 8191 || y > 8191);
1747 plane_state->view.color_plane[uv_plane].offset = offset;
1748 plane_state->view.color_plane[uv_plane].x = x;
1749 plane_state->view.color_plane[uv_plane].y = y;
1754 static int skl_check_ccs_aux_surface(struct intel_plane_state *plane_state)
1756 const struct drm_framebuffer *fb = plane_state->hw.fb;
1757 int src_x = plane_state->uapi.src.x1 >> 16;
1758 int src_y = plane_state->uapi.src.y1 >> 16;
1762 for (ccs_plane = 0; ccs_plane < fb->format->num_planes; ccs_plane++) {
1763 int main_hsub, main_vsub;
1767 if (!intel_fb_is_ccs_aux_plane(fb, ccs_plane))
1770 intel_fb_plane_get_subsampling(&main_hsub, &main_vsub, fb,
1771 skl_ccs_to_main_plane(fb, ccs_plane));
1772 intel_fb_plane_get_subsampling(&hsub, &vsub, fb, ccs_plane);
1779 intel_add_fb_offsets(&x, &y, plane_state, ccs_plane);
1781 offset = intel_plane_compute_aligned_offset(&x, &y,
1785 plane_state->view.color_plane[ccs_plane].offset = offset;
1786 plane_state->view.color_plane[ccs_plane].x = (x * hsub + src_x % hsub) / main_hsub;
1787 plane_state->view.color_plane[ccs_plane].y = (y * vsub + src_y % vsub) / main_vsub;
1793 static int skl_check_plane_surface(struct intel_plane_state *plane_state)
1795 const struct drm_framebuffer *fb = plane_state->hw.fb;
1798 ret = intel_plane_compute_gtt(plane_state);
1802 if (!plane_state->uapi.visible)
1806 * Handle the AUX surface first since the main surface setup depends on
1809 if (intel_fb_is_ccs_modifier(fb->modifier)) {
1810 ret = skl_check_ccs_aux_surface(plane_state);
1815 if (intel_format_info_is_yuv_semiplanar(fb->format,
1817 ret = skl_check_nv12_aux_surface(plane_state);
1822 ret = skl_check_main_surface(plane_state);
1829 static bool skl_fb_scalable(const struct drm_framebuffer *fb)
1834 switch (fb->format->format) {
1837 case DRM_FORMAT_XRGB16161616F:
1838 case DRM_FORMAT_ARGB16161616F:
1839 case DRM_FORMAT_XBGR16161616F:
1840 case DRM_FORMAT_ABGR16161616F:
1841 return DISPLAY_VER(to_i915(fb->dev)) >= 11;
1847 static bool bo_has_valid_encryption(struct drm_i915_gem_object *obj)
1849 struct drm_i915_private *i915 = to_i915(obj->base.dev);
1851 return intel_pxp_key_check(i915->pxp, obj, false) == 0;
1854 static bool pxp_is_borked(struct drm_i915_gem_object *obj)
1856 return i915_gem_object_is_protected(obj) && !bo_has_valid_encryption(obj);
1859 static int skl_plane_check(struct intel_crtc_state *crtc_state,
1860 struct intel_plane_state *plane_state)
1862 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
1863 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
1864 const struct drm_framebuffer *fb = plane_state->hw.fb;
1865 int min_scale = DRM_PLANE_NO_SCALING;
1866 int max_scale = DRM_PLANE_NO_SCALING;
1869 ret = skl_plane_check_fb(crtc_state, plane_state);
1873 /* use scaler when colorkey is not required */
1874 if (!plane_state->ckey.flags && skl_fb_scalable(fb)) {
1876 max_scale = skl_plane_max_scale(dev_priv, fb);
1879 ret = intel_atomic_plane_check_clipping(plane_state, crtc_state,
1880 min_scale, max_scale, true);
1884 ret = skl_check_plane_surface(plane_state);
1888 if (!plane_state->uapi.visible)
1891 ret = skl_plane_check_dst_coordinates(crtc_state, plane_state);
1895 ret = intel_plane_check_src_coordinates(plane_state);
1899 ret = skl_plane_check_nv12_rotation(plane_state);
1903 if (DISPLAY_VER(dev_priv) >= 11) {
1904 plane_state->decrypt = bo_has_valid_encryption(intel_fb_obj(fb));
1905 plane_state->force_black = pxp_is_borked(intel_fb_obj(fb));
1908 /* HW only has 8 bits pixel precision, disable plane if invisible */
1909 if (!(plane_state->hw.alpha >> 8))
1910 plane_state->uapi.visible = false;
1912 plane_state->ctl = skl_plane_ctl(crtc_state, plane_state);
1914 if (DISPLAY_VER(dev_priv) >= 10)
1915 plane_state->color_ctl = glk_plane_color_ctl(crtc_state,
1918 if (intel_format_info_is_yuv_semiplanar(fb->format, fb->modifier) &&
1919 icl_is_hdr_plane(dev_priv, plane->id))
1920 /* Enable and use MPEG-2 chroma siting */
1921 plane_state->cus_ctl = PLANE_CUS_ENABLE |
1922 PLANE_CUS_HPHASE_0 |
1923 PLANE_CUS_VPHASE_SIGN_NEGATIVE | PLANE_CUS_VPHASE_0_25;
1925 plane_state->cus_ctl = 0;
1930 static enum intel_fbc_id skl_fbc_id_for_pipe(enum pipe pipe)
1932 return pipe - PIPE_A + INTEL_FBC_A;
1935 static bool skl_plane_has_fbc(struct drm_i915_private *dev_priv,
1936 enum intel_fbc_id fbc_id, enum plane_id plane_id)
1938 if ((RUNTIME_INFO(dev_priv)->fbc_mask & BIT(fbc_id)) == 0)
1941 return plane_id == PLANE_PRIMARY;
1944 static struct intel_fbc *skl_plane_fbc(struct drm_i915_private *dev_priv,
1945 enum pipe pipe, enum plane_id plane_id)
1947 enum intel_fbc_id fbc_id = skl_fbc_id_for_pipe(pipe);
1949 if (skl_plane_has_fbc(dev_priv, fbc_id, plane_id))
1950 return dev_priv->display.fbc[fbc_id];
1955 static bool skl_plane_has_planar(struct drm_i915_private *dev_priv,
1956 enum pipe pipe, enum plane_id plane_id)
1958 /* Display WA #0870: skl, bxt */
1959 if (IS_SKYLAKE(dev_priv) || IS_BROXTON(dev_priv))
1962 if (DISPLAY_VER(dev_priv) == 9 && pipe == PIPE_C)
1965 if (plane_id != PLANE_PRIMARY && plane_id != PLANE_SPRITE0)
1971 static const u32 *skl_get_plane_formats(struct drm_i915_private *dev_priv,
1972 enum pipe pipe, enum plane_id plane_id,
1975 if (skl_plane_has_planar(dev_priv, pipe, plane_id)) {
1976 *num_formats = ARRAY_SIZE(skl_planar_formats);
1977 return skl_planar_formats;
1979 *num_formats = ARRAY_SIZE(skl_plane_formats);
1980 return skl_plane_formats;
1984 static const u32 *glk_get_plane_formats(struct drm_i915_private *dev_priv,
1985 enum pipe pipe, enum plane_id plane_id,
1988 if (skl_plane_has_planar(dev_priv, pipe, plane_id)) {
1989 *num_formats = ARRAY_SIZE(glk_planar_formats);
1990 return glk_planar_formats;
1992 *num_formats = ARRAY_SIZE(skl_plane_formats);
1993 return skl_plane_formats;
1997 static const u32 *icl_get_plane_formats(struct drm_i915_private *dev_priv,
1998 enum pipe pipe, enum plane_id plane_id,
2001 if (icl_is_hdr_plane(dev_priv, plane_id)) {
2002 *num_formats = ARRAY_SIZE(icl_hdr_plane_formats);
2003 return icl_hdr_plane_formats;
2004 } else if (icl_is_nv12_y_plane(dev_priv, plane_id)) {
2005 *num_formats = ARRAY_SIZE(icl_sdr_y_plane_formats);
2006 return icl_sdr_y_plane_formats;
2008 *num_formats = ARRAY_SIZE(icl_sdr_uv_plane_formats);
2009 return icl_sdr_uv_plane_formats;
2013 static bool skl_plane_format_mod_supported(struct drm_plane *_plane,
2014 u32 format, u64 modifier)
2016 struct intel_plane *plane = to_intel_plane(_plane);
2018 if (!intel_fb_plane_supports_modifier(plane, modifier))
2022 case DRM_FORMAT_XRGB8888:
2023 case DRM_FORMAT_XBGR8888:
2024 case DRM_FORMAT_ARGB8888:
2025 case DRM_FORMAT_ABGR8888:
2026 if (intel_fb_is_ccs_modifier(modifier))
2029 case DRM_FORMAT_RGB565:
2030 case DRM_FORMAT_XRGB2101010:
2031 case DRM_FORMAT_XBGR2101010:
2032 case DRM_FORMAT_ARGB2101010:
2033 case DRM_FORMAT_ABGR2101010:
2034 case DRM_FORMAT_YUYV:
2035 case DRM_FORMAT_YVYU:
2036 case DRM_FORMAT_UYVY:
2037 case DRM_FORMAT_VYUY:
2038 case DRM_FORMAT_NV12:
2039 case DRM_FORMAT_XYUV8888:
2040 case DRM_FORMAT_P010:
2041 case DRM_FORMAT_P012:
2042 case DRM_FORMAT_P016:
2043 case DRM_FORMAT_XVYU2101010:
2044 if (modifier == I915_FORMAT_MOD_Yf_TILED)
2048 case DRM_FORMAT_XBGR16161616F:
2049 case DRM_FORMAT_ABGR16161616F:
2050 case DRM_FORMAT_XRGB16161616F:
2051 case DRM_FORMAT_ARGB16161616F:
2052 case DRM_FORMAT_Y210:
2053 case DRM_FORMAT_Y212:
2054 case DRM_FORMAT_Y216:
2055 case DRM_FORMAT_XVYU12_16161616:
2056 case DRM_FORMAT_XVYU16161616:
2057 if (modifier == DRM_FORMAT_MOD_LINEAR ||
2058 modifier == I915_FORMAT_MOD_X_TILED ||
2059 modifier == I915_FORMAT_MOD_Y_TILED)
2067 static bool gen12_plane_format_mod_supported(struct drm_plane *_plane,
2068 u32 format, u64 modifier)
2070 struct intel_plane *plane = to_intel_plane(_plane);
2072 if (!intel_fb_plane_supports_modifier(plane, modifier))
2076 case DRM_FORMAT_XRGB8888:
2077 case DRM_FORMAT_XBGR8888:
2078 case DRM_FORMAT_ARGB8888:
2079 case DRM_FORMAT_ABGR8888:
2080 if (intel_fb_is_ccs_modifier(modifier))
2083 case DRM_FORMAT_YUYV:
2084 case DRM_FORMAT_YVYU:
2085 case DRM_FORMAT_UYVY:
2086 case DRM_FORMAT_VYUY:
2087 case DRM_FORMAT_NV12:
2088 case DRM_FORMAT_XYUV8888:
2089 case DRM_FORMAT_P010:
2090 case DRM_FORMAT_P012:
2091 case DRM_FORMAT_P016:
2092 if (intel_fb_is_mc_ccs_modifier(modifier))
2095 case DRM_FORMAT_RGB565:
2096 case DRM_FORMAT_XRGB2101010:
2097 case DRM_FORMAT_XBGR2101010:
2098 case DRM_FORMAT_ARGB2101010:
2099 case DRM_FORMAT_ABGR2101010:
2100 case DRM_FORMAT_XVYU2101010:
2102 case DRM_FORMAT_XBGR16161616F:
2103 case DRM_FORMAT_ABGR16161616F:
2104 case DRM_FORMAT_XRGB16161616F:
2105 case DRM_FORMAT_ARGB16161616F:
2106 case DRM_FORMAT_Y210:
2107 case DRM_FORMAT_Y212:
2108 case DRM_FORMAT_Y216:
2109 case DRM_FORMAT_XVYU12_16161616:
2110 case DRM_FORMAT_XVYU16161616:
2111 if (!intel_fb_is_ccs_modifier(modifier))
2119 static const struct drm_plane_funcs skl_plane_funcs = {
2120 .update_plane = drm_atomic_helper_update_plane,
2121 .disable_plane = drm_atomic_helper_disable_plane,
2122 .destroy = intel_plane_destroy,
2123 .atomic_duplicate_state = intel_plane_duplicate_state,
2124 .atomic_destroy_state = intel_plane_destroy_state,
2125 .format_mod_supported = skl_plane_format_mod_supported,
2128 static const struct drm_plane_funcs gen12_plane_funcs = {
2129 .update_plane = drm_atomic_helper_update_plane,
2130 .disable_plane = drm_atomic_helper_disable_plane,
2131 .destroy = intel_plane_destroy,
2132 .atomic_duplicate_state = intel_plane_duplicate_state,
2133 .atomic_destroy_state = intel_plane_destroy_state,
2134 .format_mod_supported = gen12_plane_format_mod_supported,
2138 skl_plane_enable_flip_done(struct intel_plane *plane)
2140 struct drm_i915_private *i915 = to_i915(plane->base.dev);
2141 enum pipe pipe = plane->pipe;
2143 spin_lock_irq(&i915->irq_lock);
2144 bdw_enable_pipe_irq(i915, pipe, GEN9_PIPE_PLANE_FLIP_DONE(plane->id));
2145 spin_unlock_irq(&i915->irq_lock);
2149 skl_plane_disable_flip_done(struct intel_plane *plane)
2151 struct drm_i915_private *i915 = to_i915(plane->base.dev);
2152 enum pipe pipe = plane->pipe;
2154 spin_lock_irq(&i915->irq_lock);
2155 bdw_disable_pipe_irq(i915, pipe, GEN9_PIPE_PLANE_FLIP_DONE(plane->id));
2156 spin_unlock_irq(&i915->irq_lock);
2159 static bool skl_plane_has_rc_ccs(struct drm_i915_private *i915,
2160 enum pipe pipe, enum plane_id plane_id)
2162 /* Wa_22011186057 */
2163 if (IS_ADLP_DISPLAY_STEP(i915, STEP_A0, STEP_B0))
2166 if (DISPLAY_VER(i915) >= 11)
2169 if (IS_GEMINILAKE(i915))
2170 return pipe != PIPE_C;
2172 return pipe != PIPE_C &&
2173 (plane_id == PLANE_PRIMARY ||
2174 plane_id == PLANE_SPRITE0);
2177 static bool gen12_plane_has_mc_ccs(struct drm_i915_private *i915,
2178 enum plane_id plane_id)
2180 if (DISPLAY_VER(i915) < 12)
2183 /* Wa_14010477008:tgl[a0..c0],rkl[all],dg1[all] */
2184 if (IS_DG1(i915) || IS_ROCKETLAKE(i915) ||
2185 IS_TGL_DISPLAY_STEP(i915, STEP_A0, STEP_D0))
2188 /* Wa_22011186057 */
2189 if (IS_ADLP_DISPLAY_STEP(i915, STEP_A0, STEP_B0))
2192 /* Wa_14013215631 */
2193 if (IS_DG2_DISPLAY_STEP(i915, STEP_A0, STEP_C0))
2196 return plane_id < PLANE_SPRITE4;
2199 static u8 skl_get_plane_caps(struct drm_i915_private *i915,
2200 enum pipe pipe, enum plane_id plane_id)
2202 u8 caps = INTEL_PLANE_CAP_TILING_X;
2204 if (DISPLAY_VER(i915) < 13 || IS_ALDERLAKE_P(i915))
2205 caps |= INTEL_PLANE_CAP_TILING_Y;
2206 if (DISPLAY_VER(i915) < 12)
2207 caps |= INTEL_PLANE_CAP_TILING_Yf;
2208 if (HAS_4TILE(i915))
2209 caps |= INTEL_PLANE_CAP_TILING_4;
2211 if (skl_plane_has_rc_ccs(i915, pipe, plane_id)) {
2212 caps |= INTEL_PLANE_CAP_CCS_RC;
2213 if (DISPLAY_VER(i915) >= 12)
2214 caps |= INTEL_PLANE_CAP_CCS_RC_CC;
2217 if (gen12_plane_has_mc_ccs(i915, plane_id))
2218 caps |= INTEL_PLANE_CAP_CCS_MC;
2223 struct intel_plane *
2224 skl_universal_plane_create(struct drm_i915_private *dev_priv,
2225 enum pipe pipe, enum plane_id plane_id)
2227 const struct drm_plane_funcs *plane_funcs;
2228 struct intel_plane *plane;
2229 enum drm_plane_type plane_type;
2230 unsigned int supported_rotations;
2231 unsigned int supported_csc;
2232 const u64 *modifiers;
2237 plane = intel_plane_alloc();
2242 plane->id = plane_id;
2243 plane->frontbuffer_bit = INTEL_FRONTBUFFER(pipe, plane_id);
2245 intel_fbc_add_plane(skl_plane_fbc(dev_priv, pipe, plane_id), plane);
2247 if (DISPLAY_VER(dev_priv) >= 11) {
2248 plane->min_width = icl_plane_min_width;
2249 if (icl_is_hdr_plane(dev_priv, plane_id))
2250 plane->max_width = icl_hdr_plane_max_width;
2252 plane->max_width = icl_sdr_plane_max_width;
2253 plane->max_height = icl_plane_max_height;
2254 plane->min_cdclk = icl_plane_min_cdclk;
2255 } else if (DISPLAY_VER(dev_priv) >= 10) {
2256 plane->max_width = glk_plane_max_width;
2257 plane->max_height = skl_plane_max_height;
2258 plane->min_cdclk = glk_plane_min_cdclk;
2260 plane->max_width = skl_plane_max_width;
2261 plane->max_height = skl_plane_max_height;
2262 plane->min_cdclk = skl_plane_min_cdclk;
2265 plane->max_stride = skl_plane_max_stride;
2266 if (DISPLAY_VER(dev_priv) >= 11) {
2267 plane->update_noarm = icl_plane_update_noarm;
2268 plane->update_arm = icl_plane_update_arm;
2269 plane->disable_arm = icl_plane_disable_arm;
2271 plane->update_noarm = skl_plane_update_noarm;
2272 plane->update_arm = skl_plane_update_arm;
2273 plane->disable_arm = skl_plane_disable_arm;
2275 plane->get_hw_state = skl_plane_get_hw_state;
2276 plane->check_plane = skl_plane_check;
2278 if (plane_id == PLANE_PRIMARY) {
2279 plane->need_async_flip_disable_wa = IS_DISPLAY_VER(dev_priv,
2281 plane->async_flip = skl_plane_async_flip;
2282 plane->enable_flip_done = skl_plane_enable_flip_done;
2283 plane->disable_flip_done = skl_plane_disable_flip_done;
2286 if (DISPLAY_VER(dev_priv) >= 11)
2287 formats = icl_get_plane_formats(dev_priv, pipe,
2288 plane_id, &num_formats);
2289 else if (DISPLAY_VER(dev_priv) >= 10)
2290 formats = glk_get_plane_formats(dev_priv, pipe,
2291 plane_id, &num_formats);
2293 formats = skl_get_plane_formats(dev_priv, pipe,
2294 plane_id, &num_formats);
2296 if (DISPLAY_VER(dev_priv) >= 12)
2297 plane_funcs = &gen12_plane_funcs;
2299 plane_funcs = &skl_plane_funcs;
2301 if (plane_id == PLANE_PRIMARY)
2302 plane_type = DRM_PLANE_TYPE_PRIMARY;
2304 plane_type = DRM_PLANE_TYPE_OVERLAY;
2306 modifiers = intel_fb_plane_get_modifiers(dev_priv,
2307 skl_get_plane_caps(dev_priv, pipe, plane_id));
2309 ret = drm_universal_plane_init(&dev_priv->drm, &plane->base,
2311 formats, num_formats, modifiers,
2313 "plane %d%c", plane_id + 1,
2321 if (DISPLAY_VER(dev_priv) >= 13)
2322 supported_rotations = DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180;
2324 supported_rotations =
2325 DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_90 |
2326 DRM_MODE_ROTATE_180 | DRM_MODE_ROTATE_270;
2328 if (DISPLAY_VER(dev_priv) >= 11)
2329 supported_rotations |= DRM_MODE_REFLECT_X;
2331 drm_plane_create_rotation_property(&plane->base,
2333 supported_rotations);
2335 supported_csc = BIT(DRM_COLOR_YCBCR_BT601) | BIT(DRM_COLOR_YCBCR_BT709);
2337 if (DISPLAY_VER(dev_priv) >= 10)
2338 supported_csc |= BIT(DRM_COLOR_YCBCR_BT2020);
2340 drm_plane_create_color_properties(&plane->base,
2342 BIT(DRM_COLOR_YCBCR_LIMITED_RANGE) |
2343 BIT(DRM_COLOR_YCBCR_FULL_RANGE),
2344 DRM_COLOR_YCBCR_BT709,
2345 DRM_COLOR_YCBCR_LIMITED_RANGE);
2347 drm_plane_create_alpha_property(&plane->base);
2348 drm_plane_create_blend_mode_property(&plane->base,
2349 BIT(DRM_MODE_BLEND_PIXEL_NONE) |
2350 BIT(DRM_MODE_BLEND_PREMULTI) |
2351 BIT(DRM_MODE_BLEND_COVERAGE));
2353 drm_plane_create_zpos_immutable_property(&plane->base, plane_id);
2355 if (DISPLAY_VER(dev_priv) >= 12)
2356 drm_plane_enable_fb_damage_clips(&plane->base);
2358 if (DISPLAY_VER(dev_priv) >= 11)
2359 drm_plane_create_scaling_filter_property(&plane->base,
2360 BIT(DRM_SCALING_FILTER_DEFAULT) |
2361 BIT(DRM_SCALING_FILTER_NEAREST_NEIGHBOR));
2363 intel_plane_helper_add(plane);
2368 intel_plane_free(plane);
2370 return ERR_PTR(ret);
2374 skl_get_initial_plane_config(struct intel_crtc *crtc,
2375 struct intel_initial_plane_config *plane_config)
2377 struct intel_crtc_state *crtc_state = to_intel_crtc_state(crtc->base.state);
2378 struct drm_device *dev = crtc->base.dev;
2379 struct drm_i915_private *dev_priv = to_i915(dev);
2380 struct intel_plane *plane = to_intel_plane(crtc->base.primary);
2381 enum plane_id plane_id = plane->id;
2383 u32 val, base, offset, stride_mult, tiling, alpha;
2384 int fourcc, pixel_format;
2385 unsigned int aligned_height;
2386 struct drm_framebuffer *fb;
2387 struct intel_framebuffer *intel_fb;
2388 static_assert(PLANE_CTL_TILED_YF == PLANE_CTL_TILED_4);
2390 if (!plane->get_hw_state(plane, &pipe))
2393 drm_WARN_ON(dev, pipe != crtc->pipe);
2395 if (crtc_state->bigjoiner_pipes) {
2396 drm_dbg_kms(&dev_priv->drm,
2397 "Unsupported bigjoiner configuration for initial FB\n");
2401 intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
2403 drm_dbg_kms(&dev_priv->drm, "failed to alloc fb\n");
2407 fb = &intel_fb->base;
2411 val = intel_de_read(dev_priv, PLANE_CTL(pipe, plane_id));
2413 if (DISPLAY_VER(dev_priv) >= 11)
2414 pixel_format = val & PLANE_CTL_FORMAT_MASK_ICL;
2416 pixel_format = val & PLANE_CTL_FORMAT_MASK_SKL;
2418 if (DISPLAY_VER(dev_priv) >= 10) {
2421 color_ctl = intel_de_read(dev_priv, PLANE_COLOR_CTL(pipe, plane_id));
2422 alpha = REG_FIELD_GET(PLANE_COLOR_ALPHA_MASK, color_ctl);
2424 alpha = REG_FIELD_GET(PLANE_CTL_ALPHA_MASK, val);
2427 fourcc = skl_format_to_fourcc(pixel_format,
2428 val & PLANE_CTL_ORDER_RGBX, alpha);
2429 fb->format = drm_format_info(fourcc);
2431 tiling = val & PLANE_CTL_TILED_MASK;
2433 case PLANE_CTL_TILED_LINEAR:
2434 fb->modifier = DRM_FORMAT_MOD_LINEAR;
2436 case PLANE_CTL_TILED_X:
2437 plane_config->tiling = I915_TILING_X;
2438 fb->modifier = I915_FORMAT_MOD_X_TILED;
2440 case PLANE_CTL_TILED_Y:
2441 plane_config->tiling = I915_TILING_Y;
2442 if (val & PLANE_CTL_RENDER_DECOMPRESSION_ENABLE)
2443 if (DISPLAY_VER(dev_priv) >= 12)
2444 fb->modifier = I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS;
2446 fb->modifier = I915_FORMAT_MOD_Y_TILED_CCS;
2447 else if (val & PLANE_CTL_MEDIA_DECOMPRESSION_ENABLE)
2448 fb->modifier = I915_FORMAT_MOD_Y_TILED_GEN12_MC_CCS;
2450 fb->modifier = I915_FORMAT_MOD_Y_TILED;
2452 case PLANE_CTL_TILED_YF: /* aka PLANE_CTL_TILED_4 on XE_LPD+ */
2453 if (HAS_4TILE(dev_priv)) {
2454 u32 rc_mask = PLANE_CTL_RENDER_DECOMPRESSION_ENABLE |
2455 PLANE_CTL_CLEAR_COLOR_DISABLE;
2457 if ((val & rc_mask) == rc_mask)
2458 fb->modifier = I915_FORMAT_MOD_4_TILED_DG2_RC_CCS;
2459 else if (val & PLANE_CTL_MEDIA_DECOMPRESSION_ENABLE)
2460 fb->modifier = I915_FORMAT_MOD_4_TILED_DG2_MC_CCS;
2461 else if (val & PLANE_CTL_RENDER_DECOMPRESSION_ENABLE)
2462 fb->modifier = I915_FORMAT_MOD_4_TILED_DG2_RC_CCS_CC;
2464 fb->modifier = I915_FORMAT_MOD_4_TILED;
2466 if (val & PLANE_CTL_RENDER_DECOMPRESSION_ENABLE)
2467 fb->modifier = I915_FORMAT_MOD_Yf_TILED_CCS;
2469 fb->modifier = I915_FORMAT_MOD_Yf_TILED;
2473 MISSING_CASE(tiling);
2478 * DRM_MODE_ROTATE_ is counter clockwise to stay compatible with Xrandr
2479 * while i915 HW rotation is clockwise, thats why this swapping.
2481 switch (val & PLANE_CTL_ROTATE_MASK) {
2482 case PLANE_CTL_ROTATE_0:
2483 plane_config->rotation = DRM_MODE_ROTATE_0;
2485 case PLANE_CTL_ROTATE_90:
2486 plane_config->rotation = DRM_MODE_ROTATE_270;
2488 case PLANE_CTL_ROTATE_180:
2489 plane_config->rotation = DRM_MODE_ROTATE_180;
2491 case PLANE_CTL_ROTATE_270:
2492 plane_config->rotation = DRM_MODE_ROTATE_90;
2496 if (DISPLAY_VER(dev_priv) >= 11 && val & PLANE_CTL_FLIP_HORIZONTAL)
2497 plane_config->rotation |= DRM_MODE_REFLECT_X;
2499 /* 90/270 degree rotation would require extra work */
2500 if (drm_rotation_90_or_270(plane_config->rotation))
2503 base = intel_de_read(dev_priv, PLANE_SURF(pipe, plane_id)) & PLANE_SURF_ADDR_MASK;
2504 plane_config->base = base;
2506 offset = intel_de_read(dev_priv, PLANE_OFFSET(pipe, plane_id));
2508 val = intel_de_read(dev_priv, PLANE_SIZE(pipe, plane_id));
2509 fb->height = REG_FIELD_GET(PLANE_HEIGHT_MASK, val) + 1;
2510 fb->width = REG_FIELD_GET(PLANE_WIDTH_MASK, val) + 1;
2512 val = intel_de_read(dev_priv, PLANE_STRIDE(pipe, plane_id));
2513 stride_mult = skl_plane_stride_mult(fb, 0, DRM_MODE_ROTATE_0);
2515 fb->pitches[0] = REG_FIELD_GET(PLANE_STRIDE__MASK, val) * stride_mult;
2517 aligned_height = intel_fb_align_height(fb, 0, fb->height);
2519 plane_config->size = fb->pitches[0] * aligned_height;
2521 drm_dbg_kms(&dev_priv->drm,
2522 "%s/%s with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
2523 crtc->base.name, plane->base.name, fb->width, fb->height,
2524 fb->format->cpp[0] * 8, base, fb->pitches[0],
2525 plane_config->size);
2527 plane_config->fb = intel_fb;