1 // SPDX-License-Identifier: MIT
3 * Copyright © 2020 Intel Corporation
5 #include <linux/kernel.h>
7 #include <drm/drm_atomic_helper.h>
8 #include <drm/drm_fourcc.h>
9 #include <drm/drm_plane_helper.h>
11 #include "intel_atomic.h"
12 #include "intel_atomic_plane.h"
14 #include "intel_display_types.h"
16 #include "intel_sprite.h"
17 #include "i9xx_plane.h"
19 /* Primary plane formats for gen <= 3 */
20 static const u32 i8xx_primary_formats[] = {
27 /* Primary plane formats for ivb (no fp16 due to hw issue) */
28 static const u32 ivb_primary_formats[] = {
33 DRM_FORMAT_XRGB2101010,
34 DRM_FORMAT_XBGR2101010,
37 /* Primary plane formats for gen >= 4, except ivb */
38 static const u32 i965_primary_formats[] = {
43 DRM_FORMAT_XRGB2101010,
44 DRM_FORMAT_XBGR2101010,
45 DRM_FORMAT_XBGR16161616F,
48 /* Primary plane formats for vlv/chv */
49 static const u32 vlv_primary_formats[] = {
56 DRM_FORMAT_XRGB2101010,
57 DRM_FORMAT_XBGR2101010,
58 DRM_FORMAT_ARGB2101010,
59 DRM_FORMAT_ABGR2101010,
60 DRM_FORMAT_XBGR16161616F,
63 static const u64 i9xx_format_modifiers[] = {
64 I915_FORMAT_MOD_X_TILED,
65 DRM_FORMAT_MOD_LINEAR,
66 DRM_FORMAT_MOD_INVALID
69 static bool i8xx_plane_format_mod_supported(struct drm_plane *_plane,
70 u32 format, u64 modifier)
73 case DRM_FORMAT_MOD_LINEAR:
74 case I915_FORMAT_MOD_X_TILED:
82 case DRM_FORMAT_RGB565:
83 case DRM_FORMAT_XRGB1555:
84 case DRM_FORMAT_XRGB8888:
85 return modifier == DRM_FORMAT_MOD_LINEAR ||
86 modifier == I915_FORMAT_MOD_X_TILED;
92 static bool i965_plane_format_mod_supported(struct drm_plane *_plane,
93 u32 format, u64 modifier)
96 case DRM_FORMAT_MOD_LINEAR:
97 case I915_FORMAT_MOD_X_TILED:
105 case DRM_FORMAT_RGB565:
106 case DRM_FORMAT_XRGB8888:
107 case DRM_FORMAT_XBGR8888:
108 case DRM_FORMAT_ARGB8888:
109 case DRM_FORMAT_ABGR8888:
110 case DRM_FORMAT_XRGB2101010:
111 case DRM_FORMAT_XBGR2101010:
112 case DRM_FORMAT_ARGB2101010:
113 case DRM_FORMAT_ABGR2101010:
114 case DRM_FORMAT_XBGR16161616F:
115 return modifier == DRM_FORMAT_MOD_LINEAR ||
116 modifier == I915_FORMAT_MOD_X_TILED;
122 static bool i9xx_plane_has_fbc(struct drm_i915_private *dev_priv,
123 enum i9xx_plane_id i9xx_plane)
125 if (!HAS_FBC(dev_priv))
128 if (IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv))
129 return i9xx_plane == PLANE_A; /* tied to pipe A */
130 else if (IS_IVYBRIDGE(dev_priv))
131 return i9xx_plane == PLANE_A || i9xx_plane == PLANE_B ||
132 i9xx_plane == PLANE_C;
133 else if (DISPLAY_VER(dev_priv) >= 4)
134 return i9xx_plane == PLANE_A || i9xx_plane == PLANE_B;
136 return i9xx_plane == PLANE_A;
139 static bool i9xx_plane_has_windowing(struct intel_plane *plane)
141 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
142 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
144 if (IS_CHERRYVIEW(dev_priv))
145 return i9xx_plane == PLANE_B;
146 else if (DISPLAY_VER(dev_priv) >= 5 || IS_G4X(dev_priv))
148 else if (DISPLAY_VER(dev_priv) == 4)
149 return i9xx_plane == PLANE_C;
151 return i9xx_plane == PLANE_B ||
152 i9xx_plane == PLANE_C;
155 static u32 i9xx_plane_ctl(const struct intel_crtc_state *crtc_state,
156 const struct intel_plane_state *plane_state)
158 struct drm_i915_private *dev_priv =
159 to_i915(plane_state->uapi.plane->dev);
160 const struct drm_framebuffer *fb = plane_state->hw.fb;
161 unsigned int rotation = plane_state->hw.rotation;
164 dspcntr = DISPLAY_PLANE_ENABLE;
166 if (IS_G4X(dev_priv) || IS_IRONLAKE(dev_priv) ||
167 IS_SANDYBRIDGE(dev_priv) || IS_IVYBRIDGE(dev_priv))
168 dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE;
170 switch (fb->format->format) {
172 dspcntr |= DISPPLANE_8BPP;
174 case DRM_FORMAT_XRGB1555:
175 dspcntr |= DISPPLANE_BGRX555;
177 case DRM_FORMAT_ARGB1555:
178 dspcntr |= DISPPLANE_BGRA555;
180 case DRM_FORMAT_RGB565:
181 dspcntr |= DISPPLANE_BGRX565;
183 case DRM_FORMAT_XRGB8888:
184 dspcntr |= DISPPLANE_BGRX888;
186 case DRM_FORMAT_XBGR8888:
187 dspcntr |= DISPPLANE_RGBX888;
189 case DRM_FORMAT_ARGB8888:
190 dspcntr |= DISPPLANE_BGRA888;
192 case DRM_FORMAT_ABGR8888:
193 dspcntr |= DISPPLANE_RGBA888;
195 case DRM_FORMAT_XRGB2101010:
196 dspcntr |= DISPPLANE_BGRX101010;
198 case DRM_FORMAT_XBGR2101010:
199 dspcntr |= DISPPLANE_RGBX101010;
201 case DRM_FORMAT_ARGB2101010:
202 dspcntr |= DISPPLANE_BGRA101010;
204 case DRM_FORMAT_ABGR2101010:
205 dspcntr |= DISPPLANE_RGBA101010;
207 case DRM_FORMAT_XBGR16161616F:
208 dspcntr |= DISPPLANE_RGBX161616;
211 MISSING_CASE(fb->format->format);
215 if (DISPLAY_VER(dev_priv) >= 4 &&
216 fb->modifier == I915_FORMAT_MOD_X_TILED)
217 dspcntr |= DISPPLANE_TILED;
219 if (rotation & DRM_MODE_ROTATE_180)
220 dspcntr |= DISPPLANE_ROTATE_180;
222 if (rotation & DRM_MODE_REFLECT_X)
223 dspcntr |= DISPPLANE_MIRROR;
228 int i9xx_check_plane_surface(struct intel_plane_state *plane_state)
230 struct drm_i915_private *dev_priv =
231 to_i915(plane_state->uapi.plane->dev);
232 const struct drm_framebuffer *fb = plane_state->hw.fb;
233 int src_x, src_y, src_w;
237 ret = intel_plane_compute_gtt(plane_state);
241 if (!plane_state->uapi.visible)
244 src_w = drm_rect_width(&plane_state->uapi.src) >> 16;
245 src_x = plane_state->uapi.src.x1 >> 16;
246 src_y = plane_state->uapi.src.y1 >> 16;
248 /* Undocumented hardware limit on i965/g4x/vlv/chv */
249 if (HAS_GMCH(dev_priv) && fb->format->cpp[0] == 8 && src_w > 2048)
252 intel_add_fb_offsets(&src_x, &src_y, plane_state, 0);
254 if (DISPLAY_VER(dev_priv) >= 4)
255 offset = intel_plane_compute_aligned_offset(&src_x, &src_y,
261 * When using an X-tiled surface the plane starts to
262 * misbehave if the x offset + width exceeds the stride.
263 * hsw/bdw: underrun galore
264 * ilk/snb/ivb: wrap to the next tile row mid scanout
265 * i965/g4x: so far appear immune to this
266 * vlv/chv: TODO check
268 * Linear surfaces seem to work just fine, even on hsw/bdw
269 * despite them not using the linear offset anymore.
271 if (DISPLAY_VER(dev_priv) >= 4 && fb->modifier == I915_FORMAT_MOD_X_TILED) {
272 u32 alignment = intel_surf_alignment(fb, 0);
273 int cpp = fb->format->cpp[0];
275 while ((src_x + src_w) * cpp > plane_state->view.color_plane[0].stride) {
277 drm_dbg_kms(&dev_priv->drm,
278 "Unable to find suitable display surface offset due to X-tiling\n");
282 offset = intel_plane_adjust_aligned_offset(&src_x, &src_y, plane_state, 0,
283 offset, offset - alignment);
288 * Put the final coordinates back so that the src
289 * coordinate checks will see the right values.
291 drm_rect_translate_to(&plane_state->uapi.src,
292 src_x << 16, src_y << 16);
294 /* HSW/BDW do this automagically in hardware */
295 if (!IS_HASWELL(dev_priv) && !IS_BROADWELL(dev_priv)) {
296 unsigned int rotation = plane_state->hw.rotation;
297 int src_w = drm_rect_width(&plane_state->uapi.src) >> 16;
298 int src_h = drm_rect_height(&plane_state->uapi.src) >> 16;
300 if (rotation & DRM_MODE_ROTATE_180) {
303 } else if (rotation & DRM_MODE_REFLECT_X) {
308 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
309 drm_WARN_ON(&dev_priv->drm, src_x > 8191 || src_y > 4095);
310 } else if (DISPLAY_VER(dev_priv) >= 4 &&
311 fb->modifier == I915_FORMAT_MOD_X_TILED) {
312 drm_WARN_ON(&dev_priv->drm, src_x > 4095 || src_y > 4095);
315 plane_state->view.color_plane[0].offset = offset;
316 plane_state->view.color_plane[0].x = src_x;
317 plane_state->view.color_plane[0].y = src_y;
323 i9xx_plane_check(struct intel_crtc_state *crtc_state,
324 struct intel_plane_state *plane_state)
326 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
329 ret = chv_plane_check_rotation(plane_state);
333 ret = intel_atomic_plane_check_clipping(plane_state, crtc_state,
334 DRM_PLANE_HELPER_NO_SCALING,
335 DRM_PLANE_HELPER_NO_SCALING,
336 i9xx_plane_has_windowing(plane));
340 ret = i9xx_check_plane_surface(plane_state);
344 if (!plane_state->uapi.visible)
347 ret = intel_plane_check_src_coordinates(plane_state);
351 plane_state->ctl = i9xx_plane_ctl(crtc_state, plane_state);
356 static u32 i9xx_plane_ctl_crtc(const struct intel_crtc_state *crtc_state)
358 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
359 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
362 if (crtc_state->gamma_enable)
363 dspcntr |= DISPPLANE_GAMMA_ENABLE;
365 if (crtc_state->csc_enable)
366 dspcntr |= DISPPLANE_PIPE_CSC_ENABLE;
368 if (DISPLAY_VER(dev_priv) < 5)
369 dspcntr |= DISPPLANE_SEL_PIPE(crtc->pipe);
374 static void i9xx_plane_ratio(const struct intel_crtc_state *crtc_state,
375 const struct intel_plane_state *plane_state,
376 unsigned int *num, unsigned int *den)
378 const struct drm_framebuffer *fb = plane_state->hw.fb;
379 unsigned int cpp = fb->format->cpp[0];
382 * g4x bspec says 64bpp pixel rate can't exceed 80%
383 * of cdclk when the sprite plane is enabled on the
384 * same pipe. ilk/snb bspec says 64bpp pixel rate is
385 * never allowed to exceed 80% of cdclk. Let's just go
386 * with the ilk/snb limit always.
397 static int i9xx_plane_min_cdclk(const struct intel_crtc_state *crtc_state,
398 const struct intel_plane_state *plane_state)
400 unsigned int pixel_rate;
401 unsigned int num, den;
404 * Note that crtc_state->pixel_rate accounts for both
405 * horizontal and vertical panel fitter downscaling factors.
406 * Pre-HSW bspec tells us to only consider the horizontal
407 * downscaling factor here. We ignore that and just consider
408 * both for simplicity.
410 pixel_rate = crtc_state->pixel_rate;
412 i9xx_plane_ratio(crtc_state, plane_state, &num, &den);
414 /* two pixels per clock with double wide pipe */
415 if (crtc_state->double_wide)
418 return DIV_ROUND_UP(pixel_rate * num, den);
421 static void i9xx_update_plane(struct intel_plane *plane,
422 const struct intel_crtc_state *crtc_state,
423 const struct intel_plane_state *plane_state)
425 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
426 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
428 int x = plane_state->view.color_plane[0].x;
429 int y = plane_state->view.color_plane[0].y;
430 int crtc_x = plane_state->uapi.dst.x1;
431 int crtc_y = plane_state->uapi.dst.y1;
432 int crtc_w = drm_rect_width(&plane_state->uapi.dst);
433 int crtc_h = drm_rect_height(&plane_state->uapi.dst);
434 unsigned long irqflags;
438 dspcntr = plane_state->ctl | i9xx_plane_ctl_crtc(crtc_state);
440 linear_offset = intel_fb_xy_to_linear(x, y, plane_state, 0);
442 if (DISPLAY_VER(dev_priv) >= 4)
443 dspaddr_offset = plane_state->view.color_plane[0].offset;
445 dspaddr_offset = linear_offset;
447 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
449 intel_de_write_fw(dev_priv, DSPSTRIDE(i9xx_plane),
450 plane_state->view.color_plane[0].stride);
452 if (DISPLAY_VER(dev_priv) < 4) {
454 * PLANE_A doesn't actually have a full window
455 * generator but let's assume we still need to
456 * program whatever is there.
458 intel_de_write_fw(dev_priv, DSPPOS(i9xx_plane),
459 (crtc_y << 16) | crtc_x);
460 intel_de_write_fw(dev_priv, DSPSIZE(i9xx_plane),
461 ((crtc_h - 1) << 16) | (crtc_w - 1));
462 } else if (IS_CHERRYVIEW(dev_priv) && i9xx_plane == PLANE_B) {
463 intel_de_write_fw(dev_priv, PRIMPOS(i9xx_plane),
464 (crtc_y << 16) | crtc_x);
465 intel_de_write_fw(dev_priv, PRIMSIZE(i9xx_plane),
466 ((crtc_h - 1) << 16) | (crtc_w - 1));
467 intel_de_write_fw(dev_priv, PRIMCNSTALPHA(i9xx_plane), 0);
470 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
471 intel_de_write_fw(dev_priv, DSPOFFSET(i9xx_plane),
473 } else if (DISPLAY_VER(dev_priv) >= 4) {
474 intel_de_write_fw(dev_priv, DSPLINOFF(i9xx_plane),
476 intel_de_write_fw(dev_priv, DSPTILEOFF(i9xx_plane),
481 * The control register self-arms if the plane was previously
482 * disabled. Try to make the plane enable atomic by writing
483 * the control register just before the surface register.
485 intel_de_write_fw(dev_priv, DSPCNTR(i9xx_plane), dspcntr);
486 if (DISPLAY_VER(dev_priv) >= 4)
487 intel_de_write_fw(dev_priv, DSPSURF(i9xx_plane),
488 intel_plane_ggtt_offset(plane_state) + dspaddr_offset);
490 intel_de_write_fw(dev_priv, DSPADDR(i9xx_plane),
491 intel_plane_ggtt_offset(plane_state) + dspaddr_offset);
493 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
496 static void i9xx_disable_plane(struct intel_plane *plane,
497 const struct intel_crtc_state *crtc_state)
499 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
500 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
501 unsigned long irqflags;
505 * DSPCNTR pipe gamma enable on g4x+ and pipe csc
506 * enable on ilk+ affect the pipe bottom color as
507 * well, so we must configure them even if the plane
510 * On pre-g4x there is no way to gamma correct the
511 * pipe bottom color but we'll keep on doing this
512 * anyway so that the crtc state readout works correctly.
514 dspcntr = i9xx_plane_ctl_crtc(crtc_state);
516 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
518 intel_de_write_fw(dev_priv, DSPCNTR(i9xx_plane), dspcntr);
519 if (DISPLAY_VER(dev_priv) >= 4)
520 intel_de_write_fw(dev_priv, DSPSURF(i9xx_plane), 0);
522 intel_de_write_fw(dev_priv, DSPADDR(i9xx_plane), 0);
524 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
528 g4x_primary_async_flip(struct intel_plane *plane,
529 const struct intel_crtc_state *crtc_state,
530 const struct intel_plane_state *plane_state,
533 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
534 u32 dspcntr = plane_state->ctl | i9xx_plane_ctl_crtc(crtc_state);
535 u32 dspaddr_offset = plane_state->view.color_plane[0].offset;
536 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
537 unsigned long irqflags;
540 dspcntr |= DISPPLANE_ASYNC_FLIP;
542 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
543 intel_de_write_fw(dev_priv, DSPCNTR(i9xx_plane), dspcntr);
544 intel_de_write_fw(dev_priv, DSPSURF(i9xx_plane),
545 intel_plane_ggtt_offset(plane_state) + dspaddr_offset);
546 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
550 vlv_primary_async_flip(struct intel_plane *plane,
551 const struct intel_crtc_state *crtc_state,
552 const struct intel_plane_state *plane_state,
555 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
556 u32 dspaddr_offset = plane_state->view.color_plane[0].offset;
557 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
558 unsigned long irqflags;
560 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
561 intel_de_write_fw(dev_priv, DSPADDR_VLV(i9xx_plane),
562 intel_plane_ggtt_offset(plane_state) + dspaddr_offset);
563 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
567 bdw_primary_enable_flip_done(struct intel_plane *plane)
569 struct drm_i915_private *i915 = to_i915(plane->base.dev);
570 enum pipe pipe = plane->pipe;
572 spin_lock_irq(&i915->irq_lock);
573 bdw_enable_pipe_irq(i915, pipe, GEN8_PIPE_PRIMARY_FLIP_DONE);
574 spin_unlock_irq(&i915->irq_lock);
578 bdw_primary_disable_flip_done(struct intel_plane *plane)
580 struct drm_i915_private *i915 = to_i915(plane->base.dev);
581 enum pipe pipe = plane->pipe;
583 spin_lock_irq(&i915->irq_lock);
584 bdw_disable_pipe_irq(i915, pipe, GEN8_PIPE_PRIMARY_FLIP_DONE);
585 spin_unlock_irq(&i915->irq_lock);
589 ivb_primary_enable_flip_done(struct intel_plane *plane)
591 struct drm_i915_private *i915 = to_i915(plane->base.dev);
593 spin_lock_irq(&i915->irq_lock);
594 ilk_enable_display_irq(i915, DE_PLANE_FLIP_DONE_IVB(plane->i9xx_plane));
595 spin_unlock_irq(&i915->irq_lock);
599 ivb_primary_disable_flip_done(struct intel_plane *plane)
601 struct drm_i915_private *i915 = to_i915(plane->base.dev);
603 spin_lock_irq(&i915->irq_lock);
604 ilk_disable_display_irq(i915, DE_PLANE_FLIP_DONE_IVB(plane->i9xx_plane));
605 spin_unlock_irq(&i915->irq_lock);
609 ilk_primary_enable_flip_done(struct intel_plane *plane)
611 struct drm_i915_private *i915 = to_i915(plane->base.dev);
613 spin_lock_irq(&i915->irq_lock);
614 ilk_enable_display_irq(i915, DE_PLANE_FLIP_DONE(plane->i9xx_plane));
615 spin_unlock_irq(&i915->irq_lock);
619 ilk_primary_disable_flip_done(struct intel_plane *plane)
621 struct drm_i915_private *i915 = to_i915(plane->base.dev);
623 spin_lock_irq(&i915->irq_lock);
624 ilk_disable_display_irq(i915, DE_PLANE_FLIP_DONE(plane->i9xx_plane));
625 spin_unlock_irq(&i915->irq_lock);
629 vlv_primary_enable_flip_done(struct intel_plane *plane)
631 struct drm_i915_private *i915 = to_i915(plane->base.dev);
632 enum pipe pipe = plane->pipe;
634 spin_lock_irq(&i915->irq_lock);
635 i915_enable_pipestat(i915, pipe, PLANE_FLIP_DONE_INT_STATUS_VLV);
636 spin_unlock_irq(&i915->irq_lock);
640 vlv_primary_disable_flip_done(struct intel_plane *plane)
642 struct drm_i915_private *i915 = to_i915(plane->base.dev);
643 enum pipe pipe = plane->pipe;
645 spin_lock_irq(&i915->irq_lock);
646 i915_disable_pipestat(i915, pipe, PLANE_FLIP_DONE_INT_STATUS_VLV);
647 spin_unlock_irq(&i915->irq_lock);
650 static bool i9xx_plane_get_hw_state(struct intel_plane *plane,
653 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
654 enum intel_display_power_domain power_domain;
655 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
656 intel_wakeref_t wakeref;
661 * Not 100% correct for planes that can move between pipes,
662 * but that's only the case for gen2-4 which don't have any
663 * display power wells.
665 power_domain = POWER_DOMAIN_PIPE(plane->pipe);
666 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
670 val = intel_de_read(dev_priv, DSPCNTR(i9xx_plane));
672 ret = val & DISPLAY_PLANE_ENABLE;
674 if (DISPLAY_VER(dev_priv) >= 5)
677 *pipe = (val & DISPPLANE_SEL_PIPE_MASK) >>
678 DISPPLANE_SEL_PIPE_SHIFT;
680 intel_display_power_put(dev_priv, power_domain, wakeref);
686 hsw_primary_max_stride(struct intel_plane *plane,
687 u32 pixel_format, u64 modifier,
688 unsigned int rotation)
690 const struct drm_format_info *info = drm_format_info(pixel_format);
691 int cpp = info->cpp[0];
693 /* Limit to 8k pixels to guarantee OFFSET.x doesn't get too big. */
694 return min(8192 * cpp, 32 * 1024);
698 ilk_primary_max_stride(struct intel_plane *plane,
699 u32 pixel_format, u64 modifier,
700 unsigned int rotation)
702 const struct drm_format_info *info = drm_format_info(pixel_format);
703 int cpp = info->cpp[0];
705 /* Limit to 4k pixels to guarantee TILEOFF.x doesn't get too big. */
706 if (modifier == I915_FORMAT_MOD_X_TILED)
707 return min(4096 * cpp, 32 * 1024);
713 i965_plane_max_stride(struct intel_plane *plane,
714 u32 pixel_format, u64 modifier,
715 unsigned int rotation)
717 const struct drm_format_info *info = drm_format_info(pixel_format);
718 int cpp = info->cpp[0];
720 /* Limit to 4k pixels to guarantee TILEOFF.x doesn't get too big. */
721 if (modifier == I915_FORMAT_MOD_X_TILED)
722 return min(4096 * cpp, 16 * 1024);
728 i9xx_plane_max_stride(struct intel_plane *plane,
729 u32 pixel_format, u64 modifier,
730 unsigned int rotation)
732 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
734 if (DISPLAY_VER(dev_priv) >= 3) {
735 if (modifier == I915_FORMAT_MOD_X_TILED)
740 if (plane->i9xx_plane == PLANE_C)
747 static const struct drm_plane_funcs i965_plane_funcs = {
748 .update_plane = drm_atomic_helper_update_plane,
749 .disable_plane = drm_atomic_helper_disable_plane,
750 .destroy = intel_plane_destroy,
751 .atomic_duplicate_state = intel_plane_duplicate_state,
752 .atomic_destroy_state = intel_plane_destroy_state,
753 .format_mod_supported = i965_plane_format_mod_supported,
756 static const struct drm_plane_funcs i8xx_plane_funcs = {
757 .update_plane = drm_atomic_helper_update_plane,
758 .disable_plane = drm_atomic_helper_disable_plane,
759 .destroy = intel_plane_destroy,
760 .atomic_duplicate_state = intel_plane_duplicate_state,
761 .atomic_destroy_state = intel_plane_destroy_state,
762 .format_mod_supported = i8xx_plane_format_mod_supported,
766 intel_primary_plane_create(struct drm_i915_private *dev_priv, enum pipe pipe)
768 struct intel_plane *plane;
769 const struct drm_plane_funcs *plane_funcs;
770 unsigned int supported_rotations;
775 plane = intel_plane_alloc();
781 * On gen2/3 only plane A can do FBC, but the panel fitter and LVDS
782 * port is hooked to pipe B. Hence we want plane A feeding pipe B.
784 if (HAS_FBC(dev_priv) && DISPLAY_VER(dev_priv) < 4 &&
785 INTEL_NUM_PIPES(dev_priv) == 2)
786 plane->i9xx_plane = (enum i9xx_plane_id) !pipe;
788 plane->i9xx_plane = (enum i9xx_plane_id) pipe;
789 plane->id = PLANE_PRIMARY;
790 plane->frontbuffer_bit = INTEL_FRONTBUFFER(pipe, plane->id);
792 plane->has_fbc = i9xx_plane_has_fbc(dev_priv, plane->i9xx_plane);
793 if (plane->has_fbc) {
794 struct intel_fbc *fbc = &dev_priv->fbc;
796 fbc->possible_framebuffer_bits |= plane->frontbuffer_bit;
799 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
800 formats = vlv_primary_formats;
801 num_formats = ARRAY_SIZE(vlv_primary_formats);
802 } else if (DISPLAY_VER(dev_priv) >= 4) {
804 * WaFP16GammaEnabling:ivb
805 * "Workaround : When using the 64-bit format, the plane
806 * output on each color channel has one quarter amplitude.
807 * It can be brought up to full amplitude by using pipe
808 * gamma correction or pipe color space conversion to
809 * multiply the plane output by four."
811 * There is no dedicated plane gamma for the primary plane,
812 * and using the pipe gamma/csc could conflict with other
813 * planes, so we choose not to expose fp16 on IVB primary
814 * planes. HSW primary planes no longer have this problem.
816 if (IS_IVYBRIDGE(dev_priv)) {
817 formats = ivb_primary_formats;
818 num_formats = ARRAY_SIZE(ivb_primary_formats);
820 formats = i965_primary_formats;
821 num_formats = ARRAY_SIZE(i965_primary_formats);
824 formats = i8xx_primary_formats;
825 num_formats = ARRAY_SIZE(i8xx_primary_formats);
828 if (DISPLAY_VER(dev_priv) >= 4)
829 plane_funcs = &i965_plane_funcs;
831 plane_funcs = &i8xx_plane_funcs;
833 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
834 plane->min_cdclk = vlv_plane_min_cdclk;
835 else if (IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv))
836 plane->min_cdclk = hsw_plane_min_cdclk;
837 else if (IS_IVYBRIDGE(dev_priv))
838 plane->min_cdclk = ivb_plane_min_cdclk;
840 plane->min_cdclk = i9xx_plane_min_cdclk;
842 if (HAS_GMCH(dev_priv)) {
843 if (DISPLAY_VER(dev_priv) >= 4)
844 plane->max_stride = i965_plane_max_stride;
846 plane->max_stride = i9xx_plane_max_stride;
848 if (IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv))
849 plane->max_stride = hsw_primary_max_stride;
851 plane->max_stride = ilk_primary_max_stride;
854 plane->update_plane = i9xx_update_plane;
855 plane->disable_plane = i9xx_disable_plane;
856 plane->get_hw_state = i9xx_plane_get_hw_state;
857 plane->check_plane = i9xx_plane_check;
859 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
860 plane->async_flip = vlv_primary_async_flip;
861 plane->enable_flip_done = vlv_primary_enable_flip_done;
862 plane->disable_flip_done = vlv_primary_disable_flip_done;
863 } else if (IS_BROADWELL(dev_priv)) {
864 plane->need_async_flip_disable_wa = true;
865 plane->async_flip = g4x_primary_async_flip;
866 plane->enable_flip_done = bdw_primary_enable_flip_done;
867 plane->disable_flip_done = bdw_primary_disable_flip_done;
868 } else if (DISPLAY_VER(dev_priv) >= 7) {
869 plane->async_flip = g4x_primary_async_flip;
870 plane->enable_flip_done = ivb_primary_enable_flip_done;
871 plane->disable_flip_done = ivb_primary_disable_flip_done;
872 } else if (DISPLAY_VER(dev_priv) >= 5) {
873 plane->async_flip = g4x_primary_async_flip;
874 plane->enable_flip_done = ilk_primary_enable_flip_done;
875 plane->disable_flip_done = ilk_primary_disable_flip_done;
878 if (DISPLAY_VER(dev_priv) >= 5 || IS_G4X(dev_priv))
879 ret = drm_universal_plane_init(&dev_priv->drm, &plane->base,
881 formats, num_formats,
882 i9xx_format_modifiers,
883 DRM_PLANE_TYPE_PRIMARY,
884 "primary %c", pipe_name(pipe));
886 ret = drm_universal_plane_init(&dev_priv->drm, &plane->base,
888 formats, num_formats,
889 i9xx_format_modifiers,
890 DRM_PLANE_TYPE_PRIMARY,
892 plane_name(plane->i9xx_plane));
896 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B) {
897 supported_rotations =
898 DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180 |
900 } else if (DISPLAY_VER(dev_priv) >= 4) {
901 supported_rotations =
902 DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180;
904 supported_rotations = DRM_MODE_ROTATE_0;
907 if (DISPLAY_VER(dev_priv) >= 4)
908 drm_plane_create_rotation_property(&plane->base,
910 supported_rotations);
913 drm_plane_create_zpos_immutable_property(&plane->base, zpos);
915 intel_plane_helper_add(plane);
920 intel_plane_free(plane);
925 static int i9xx_format_to_fourcc(int format)
929 return DRM_FORMAT_C8;
930 case DISPPLANE_BGRA555:
931 return DRM_FORMAT_ARGB1555;
932 case DISPPLANE_BGRX555:
933 return DRM_FORMAT_XRGB1555;
934 case DISPPLANE_BGRX565:
935 return DRM_FORMAT_RGB565;
937 case DISPPLANE_BGRX888:
938 return DRM_FORMAT_XRGB8888;
939 case DISPPLANE_RGBX888:
940 return DRM_FORMAT_XBGR8888;
941 case DISPPLANE_BGRA888:
942 return DRM_FORMAT_ARGB8888;
943 case DISPPLANE_RGBA888:
944 return DRM_FORMAT_ABGR8888;
945 case DISPPLANE_BGRX101010:
946 return DRM_FORMAT_XRGB2101010;
947 case DISPPLANE_RGBX101010:
948 return DRM_FORMAT_XBGR2101010;
949 case DISPPLANE_BGRA101010:
950 return DRM_FORMAT_ARGB2101010;
951 case DISPPLANE_RGBA101010:
952 return DRM_FORMAT_ABGR2101010;
953 case DISPPLANE_RGBX161616:
954 return DRM_FORMAT_XBGR16161616F;
959 i9xx_get_initial_plane_config(struct intel_crtc *crtc,
960 struct intel_initial_plane_config *plane_config)
962 struct drm_device *dev = crtc->base.dev;
963 struct drm_i915_private *dev_priv = to_i915(dev);
964 struct intel_plane *plane = to_intel_plane(crtc->base.primary);
965 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
967 u32 val, base, offset;
968 int fourcc, pixel_format;
969 unsigned int aligned_height;
970 struct drm_framebuffer *fb;
971 struct intel_framebuffer *intel_fb;
973 if (!plane->get_hw_state(plane, &pipe))
976 drm_WARN_ON(dev, pipe != crtc->pipe);
978 intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
980 drm_dbg_kms(&dev_priv->drm, "failed to alloc fb\n");
984 fb = &intel_fb->base;
988 val = intel_de_read(dev_priv, DSPCNTR(i9xx_plane));
990 if (DISPLAY_VER(dev_priv) >= 4) {
991 if (val & DISPPLANE_TILED) {
992 plane_config->tiling = I915_TILING_X;
993 fb->modifier = I915_FORMAT_MOD_X_TILED;
996 if (val & DISPPLANE_ROTATE_180)
997 plane_config->rotation = DRM_MODE_ROTATE_180;
1000 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B &&
1001 val & DISPPLANE_MIRROR)
1002 plane_config->rotation |= DRM_MODE_REFLECT_X;
1004 pixel_format = val & DISPPLANE_PIXFORMAT_MASK;
1005 fourcc = i9xx_format_to_fourcc(pixel_format);
1006 fb->format = drm_format_info(fourcc);
1008 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
1009 offset = intel_de_read(dev_priv, DSPOFFSET(i9xx_plane));
1010 base = intel_de_read(dev_priv, DSPSURF(i9xx_plane)) & 0xfffff000;
1011 } else if (DISPLAY_VER(dev_priv) >= 4) {
1012 if (plane_config->tiling)
1013 offset = intel_de_read(dev_priv,
1014 DSPTILEOFF(i9xx_plane));
1016 offset = intel_de_read(dev_priv,
1017 DSPLINOFF(i9xx_plane));
1018 base = intel_de_read(dev_priv, DSPSURF(i9xx_plane)) & 0xfffff000;
1020 base = intel_de_read(dev_priv, DSPADDR(i9xx_plane));
1022 plane_config->base = base;
1024 val = intel_de_read(dev_priv, PIPESRC(pipe));
1025 fb->width = ((val >> 16) & 0xfff) + 1;
1026 fb->height = ((val >> 0) & 0xfff) + 1;
1028 val = intel_de_read(dev_priv, DSPSTRIDE(i9xx_plane));
1029 fb->pitches[0] = val & 0xffffffc0;
1031 aligned_height = intel_fb_align_height(fb, 0, fb->height);
1033 plane_config->size = fb->pitches[0] * aligned_height;
1035 drm_dbg_kms(&dev_priv->drm,
1036 "%s/%s with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
1037 crtc->base.name, plane->base.name, fb->width, fb->height,
1038 fb->format->cpp[0] * 8, base, fb->pitches[0],
1039 plane_config->size);
1041 plane_config->fb = intel_fb;