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"
13 #include "intel_display_types.h"
15 #include "intel_sprite.h"
16 #include "i9xx_plane.h"
18 /* Primary plane formats for gen <= 3 */
19 static const u32 i8xx_primary_formats[] = {
26 /* Primary plane formats for ivb (no fp16 due to hw issue) */
27 static const u32 ivb_primary_formats[] = {
32 DRM_FORMAT_XRGB2101010,
33 DRM_FORMAT_XBGR2101010,
36 /* Primary plane formats for gen >= 4, except ivb */
37 static const u32 i965_primary_formats[] = {
42 DRM_FORMAT_XRGB2101010,
43 DRM_FORMAT_XBGR2101010,
44 DRM_FORMAT_XBGR16161616F,
47 /* Primary plane formats for vlv/chv */
48 static const u32 vlv_primary_formats[] = {
55 DRM_FORMAT_XRGB2101010,
56 DRM_FORMAT_XBGR2101010,
57 DRM_FORMAT_ARGB2101010,
58 DRM_FORMAT_ABGR2101010,
59 DRM_FORMAT_XBGR16161616F,
62 static const u64 i9xx_format_modifiers[] = {
63 I915_FORMAT_MOD_X_TILED,
64 DRM_FORMAT_MOD_LINEAR,
65 DRM_FORMAT_MOD_INVALID
68 static bool i8xx_plane_format_mod_supported(struct drm_plane *_plane,
69 u32 format, u64 modifier)
72 case DRM_FORMAT_MOD_LINEAR:
73 case I915_FORMAT_MOD_X_TILED:
81 case DRM_FORMAT_RGB565:
82 case DRM_FORMAT_XRGB1555:
83 case DRM_FORMAT_XRGB8888:
84 return modifier == DRM_FORMAT_MOD_LINEAR ||
85 modifier == I915_FORMAT_MOD_X_TILED;
91 static bool i965_plane_format_mod_supported(struct drm_plane *_plane,
92 u32 format, u64 modifier)
95 case DRM_FORMAT_MOD_LINEAR:
96 case I915_FORMAT_MOD_X_TILED:
104 case DRM_FORMAT_RGB565:
105 case DRM_FORMAT_XRGB8888:
106 case DRM_FORMAT_XBGR8888:
107 case DRM_FORMAT_ARGB8888:
108 case DRM_FORMAT_ABGR8888:
109 case DRM_FORMAT_XRGB2101010:
110 case DRM_FORMAT_XBGR2101010:
111 case DRM_FORMAT_ARGB2101010:
112 case DRM_FORMAT_ABGR2101010:
113 case DRM_FORMAT_XBGR16161616F:
114 return modifier == DRM_FORMAT_MOD_LINEAR ||
115 modifier == I915_FORMAT_MOD_X_TILED;
121 static bool i9xx_plane_has_fbc(struct drm_i915_private *dev_priv,
122 enum i9xx_plane_id i9xx_plane)
124 if (!HAS_FBC(dev_priv))
127 if (IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv))
128 return i9xx_plane == PLANE_A; /* tied to pipe A */
129 else if (IS_IVYBRIDGE(dev_priv))
130 return i9xx_plane == PLANE_A || i9xx_plane == PLANE_B ||
131 i9xx_plane == PLANE_C;
132 else if (DISPLAY_VER(dev_priv) >= 4)
133 return i9xx_plane == PLANE_A || i9xx_plane == PLANE_B;
135 return i9xx_plane == PLANE_A;
138 static bool i9xx_plane_has_windowing(struct intel_plane *plane)
140 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
141 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
143 if (IS_CHERRYVIEW(dev_priv))
144 return i9xx_plane == PLANE_B;
145 else if (DISPLAY_VER(dev_priv) >= 5 || IS_G4X(dev_priv))
147 else if (DISPLAY_VER(dev_priv) == 4)
148 return i9xx_plane == PLANE_C;
150 return i9xx_plane == PLANE_B ||
151 i9xx_plane == PLANE_C;
154 static u32 i9xx_plane_ctl(const struct intel_crtc_state *crtc_state,
155 const struct intel_plane_state *plane_state)
157 struct drm_i915_private *dev_priv =
158 to_i915(plane_state->uapi.plane->dev);
159 const struct drm_framebuffer *fb = plane_state->hw.fb;
160 unsigned int rotation = plane_state->hw.rotation;
163 dspcntr = DISPLAY_PLANE_ENABLE;
165 if (IS_G4X(dev_priv) || IS_IRONLAKE(dev_priv) ||
166 IS_SANDYBRIDGE(dev_priv) || IS_IVYBRIDGE(dev_priv))
167 dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE;
169 switch (fb->format->format) {
171 dspcntr |= DISPPLANE_8BPP;
173 case DRM_FORMAT_XRGB1555:
174 dspcntr |= DISPPLANE_BGRX555;
176 case DRM_FORMAT_ARGB1555:
177 dspcntr |= DISPPLANE_BGRA555;
179 case DRM_FORMAT_RGB565:
180 dspcntr |= DISPPLANE_BGRX565;
182 case DRM_FORMAT_XRGB8888:
183 dspcntr |= DISPPLANE_BGRX888;
185 case DRM_FORMAT_XBGR8888:
186 dspcntr |= DISPPLANE_RGBX888;
188 case DRM_FORMAT_ARGB8888:
189 dspcntr |= DISPPLANE_BGRA888;
191 case DRM_FORMAT_ABGR8888:
192 dspcntr |= DISPPLANE_RGBA888;
194 case DRM_FORMAT_XRGB2101010:
195 dspcntr |= DISPPLANE_BGRX101010;
197 case DRM_FORMAT_XBGR2101010:
198 dspcntr |= DISPPLANE_RGBX101010;
200 case DRM_FORMAT_ARGB2101010:
201 dspcntr |= DISPPLANE_BGRA101010;
203 case DRM_FORMAT_ABGR2101010:
204 dspcntr |= DISPPLANE_RGBA101010;
206 case DRM_FORMAT_XBGR16161616F:
207 dspcntr |= DISPPLANE_RGBX161616;
210 MISSING_CASE(fb->format->format);
214 if (DISPLAY_VER(dev_priv) >= 4 &&
215 fb->modifier == I915_FORMAT_MOD_X_TILED)
216 dspcntr |= DISPPLANE_TILED;
218 if (rotation & DRM_MODE_ROTATE_180)
219 dspcntr |= DISPPLANE_ROTATE_180;
221 if (rotation & DRM_MODE_REFLECT_X)
222 dspcntr |= DISPPLANE_MIRROR;
227 int i9xx_check_plane_surface(struct intel_plane_state *plane_state)
229 struct drm_i915_private *dev_priv =
230 to_i915(plane_state->uapi.plane->dev);
231 const struct drm_framebuffer *fb = plane_state->hw.fb;
232 int src_x, src_y, src_w;
236 ret = intel_plane_compute_gtt(plane_state);
240 if (!plane_state->uapi.visible)
243 src_w = drm_rect_width(&plane_state->uapi.src) >> 16;
244 src_x = plane_state->uapi.src.x1 >> 16;
245 src_y = plane_state->uapi.src.y1 >> 16;
247 /* Undocumented hardware limit on i965/g4x/vlv/chv */
248 if (HAS_GMCH(dev_priv) && fb->format->cpp[0] == 8 && src_w > 2048)
251 intel_add_fb_offsets(&src_x, &src_y, plane_state, 0);
253 if (DISPLAY_VER(dev_priv) >= 4)
254 offset = intel_plane_compute_aligned_offset(&src_x, &src_y,
260 * When using an X-tiled surface the plane starts to
261 * misbehave if the x offset + width exceeds the stride.
262 * hsw/bdw: underrun galore
263 * ilk/snb/ivb: wrap to the next tile row mid scanout
264 * i965/g4x: so far appear immune to this
265 * vlv/chv: TODO check
267 * Linear surfaces seem to work just fine, even on hsw/bdw
268 * despite them not using the linear offset anymore.
270 if (DISPLAY_VER(dev_priv) >= 4 && fb->modifier == I915_FORMAT_MOD_X_TILED) {
271 u32 alignment = intel_surf_alignment(fb, 0);
272 int cpp = fb->format->cpp[0];
274 while ((src_x + src_w) * cpp > plane_state->view.color_plane[0].stride) {
276 drm_dbg_kms(&dev_priv->drm,
277 "Unable to find suitable display surface offset due to X-tiling\n");
281 offset = intel_plane_adjust_aligned_offset(&src_x, &src_y, plane_state, 0,
282 offset, offset - alignment);
287 * Put the final coordinates back so that the src
288 * coordinate checks will see the right values.
290 drm_rect_translate_to(&plane_state->uapi.src,
291 src_x << 16, src_y << 16);
293 /* HSW/BDW do this automagically in hardware */
294 if (!IS_HASWELL(dev_priv) && !IS_BROADWELL(dev_priv)) {
295 unsigned int rotation = plane_state->hw.rotation;
296 int src_w = drm_rect_width(&plane_state->uapi.src) >> 16;
297 int src_h = drm_rect_height(&plane_state->uapi.src) >> 16;
299 if (rotation & DRM_MODE_ROTATE_180) {
302 } else if (rotation & DRM_MODE_REFLECT_X) {
307 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
308 drm_WARN_ON(&dev_priv->drm, src_x > 8191 || src_y > 4095);
309 } else if (DISPLAY_VER(dev_priv) >= 4 &&
310 fb->modifier == I915_FORMAT_MOD_X_TILED) {
311 drm_WARN_ON(&dev_priv->drm, src_x > 4095 || src_y > 4095);
314 plane_state->view.color_plane[0].offset = offset;
315 plane_state->view.color_plane[0].x = src_x;
316 plane_state->view.color_plane[0].y = src_y;
322 i9xx_plane_check(struct intel_crtc_state *crtc_state,
323 struct intel_plane_state *plane_state)
325 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
328 ret = chv_plane_check_rotation(plane_state);
332 ret = intel_atomic_plane_check_clipping(plane_state, crtc_state,
333 DRM_PLANE_HELPER_NO_SCALING,
334 DRM_PLANE_HELPER_NO_SCALING,
335 i9xx_plane_has_windowing(plane));
339 ret = i9xx_check_plane_surface(plane_state);
343 if (!plane_state->uapi.visible)
346 ret = intel_plane_check_src_coordinates(plane_state);
350 plane_state->ctl = i9xx_plane_ctl(crtc_state, plane_state);
355 static u32 i9xx_plane_ctl_crtc(const struct intel_crtc_state *crtc_state)
357 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
358 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
361 if (crtc_state->gamma_enable)
362 dspcntr |= DISPPLANE_GAMMA_ENABLE;
364 if (crtc_state->csc_enable)
365 dspcntr |= DISPPLANE_PIPE_CSC_ENABLE;
367 if (DISPLAY_VER(dev_priv) < 5)
368 dspcntr |= DISPPLANE_SEL_PIPE(crtc->pipe);
373 static void i9xx_plane_ratio(const struct intel_crtc_state *crtc_state,
374 const struct intel_plane_state *plane_state,
375 unsigned int *num, unsigned int *den)
377 const struct drm_framebuffer *fb = plane_state->hw.fb;
378 unsigned int cpp = fb->format->cpp[0];
381 * g4x bspec says 64bpp pixel rate can't exceed 80%
382 * of cdclk when the sprite plane is enabled on the
383 * same pipe. ilk/snb bspec says 64bpp pixel rate is
384 * never allowed to exceed 80% of cdclk. Let's just go
385 * with the ilk/snb limit always.
396 static int i9xx_plane_min_cdclk(const struct intel_crtc_state *crtc_state,
397 const struct intel_plane_state *plane_state)
399 unsigned int pixel_rate;
400 unsigned int num, den;
403 * Note that crtc_state->pixel_rate accounts for both
404 * horizontal and vertical panel fitter downscaling factors.
405 * Pre-HSW bspec tells us to only consider the horizontal
406 * downscaling factor here. We ignore that and just consider
407 * both for simplicity.
409 pixel_rate = crtc_state->pixel_rate;
411 i9xx_plane_ratio(crtc_state, plane_state, &num, &den);
413 /* two pixels per clock with double wide pipe */
414 if (crtc_state->double_wide)
417 return DIV_ROUND_UP(pixel_rate * num, den);
420 static void i9xx_update_plane(struct intel_plane *plane,
421 const struct intel_crtc_state *crtc_state,
422 const struct intel_plane_state *plane_state)
424 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
425 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
427 int x = plane_state->view.color_plane[0].x;
428 int y = plane_state->view.color_plane[0].y;
429 int crtc_x = plane_state->uapi.dst.x1;
430 int crtc_y = plane_state->uapi.dst.y1;
431 int crtc_w = drm_rect_width(&plane_state->uapi.dst);
432 int crtc_h = drm_rect_height(&plane_state->uapi.dst);
433 unsigned long irqflags;
437 dspcntr = plane_state->ctl | i9xx_plane_ctl_crtc(crtc_state);
439 linear_offset = intel_fb_xy_to_linear(x, y, plane_state, 0);
441 if (DISPLAY_VER(dev_priv) >= 4)
442 dspaddr_offset = plane_state->view.color_plane[0].offset;
444 dspaddr_offset = linear_offset;
446 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
448 intel_de_write_fw(dev_priv, DSPSTRIDE(i9xx_plane),
449 plane_state->view.color_plane[0].stride);
451 if (DISPLAY_VER(dev_priv) < 4) {
453 * PLANE_A doesn't actually have a full window
454 * generator but let's assume we still need to
455 * program whatever is there.
457 intel_de_write_fw(dev_priv, DSPPOS(i9xx_plane),
458 (crtc_y << 16) | crtc_x);
459 intel_de_write_fw(dev_priv, DSPSIZE(i9xx_plane),
460 ((crtc_h - 1) << 16) | (crtc_w - 1));
461 } else if (IS_CHERRYVIEW(dev_priv) && i9xx_plane == PLANE_B) {
462 intel_de_write_fw(dev_priv, PRIMPOS(i9xx_plane),
463 (crtc_y << 16) | crtc_x);
464 intel_de_write_fw(dev_priv, PRIMSIZE(i9xx_plane),
465 ((crtc_h - 1) << 16) | (crtc_w - 1));
466 intel_de_write_fw(dev_priv, PRIMCNSTALPHA(i9xx_plane), 0);
469 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
470 intel_de_write_fw(dev_priv, DSPOFFSET(i9xx_plane),
472 } else if (DISPLAY_VER(dev_priv) >= 4) {
473 intel_de_write_fw(dev_priv, DSPLINOFF(i9xx_plane),
475 intel_de_write_fw(dev_priv, DSPTILEOFF(i9xx_plane),
480 * The control register self-arms if the plane was previously
481 * disabled. Try to make the plane enable atomic by writing
482 * the control register just before the surface register.
484 intel_de_write_fw(dev_priv, DSPCNTR(i9xx_plane), dspcntr);
485 if (DISPLAY_VER(dev_priv) >= 4)
486 intel_de_write_fw(dev_priv, DSPSURF(i9xx_plane),
487 intel_plane_ggtt_offset(plane_state) + dspaddr_offset);
489 intel_de_write_fw(dev_priv, DSPADDR(i9xx_plane),
490 intel_plane_ggtt_offset(plane_state) + dspaddr_offset);
492 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
495 static void i9xx_disable_plane(struct intel_plane *plane,
496 const struct intel_crtc_state *crtc_state)
498 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
499 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
500 unsigned long irqflags;
504 * DSPCNTR pipe gamma enable on g4x+ and pipe csc
505 * enable on ilk+ affect the pipe bottom color as
506 * well, so we must configure them even if the plane
509 * On pre-g4x there is no way to gamma correct the
510 * pipe bottom color but we'll keep on doing this
511 * anyway so that the crtc state readout works correctly.
513 dspcntr = i9xx_plane_ctl_crtc(crtc_state);
515 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
517 intel_de_write_fw(dev_priv, DSPCNTR(i9xx_plane), dspcntr);
518 if (DISPLAY_VER(dev_priv) >= 4)
519 intel_de_write_fw(dev_priv, DSPSURF(i9xx_plane), 0);
521 intel_de_write_fw(dev_priv, DSPADDR(i9xx_plane), 0);
523 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
527 g4x_primary_async_flip(struct intel_plane *plane,
528 const struct intel_crtc_state *crtc_state,
529 const struct intel_plane_state *plane_state,
532 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
533 u32 dspcntr = plane_state->ctl | i9xx_plane_ctl_crtc(crtc_state);
534 u32 dspaddr_offset = plane_state->view.color_plane[0].offset;
535 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
536 unsigned long irqflags;
539 dspcntr |= DISPPLANE_ASYNC_FLIP;
541 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
542 intel_de_write_fw(dev_priv, DSPCNTR(i9xx_plane), dspcntr);
543 intel_de_write_fw(dev_priv, DSPSURF(i9xx_plane),
544 intel_plane_ggtt_offset(plane_state) + dspaddr_offset);
545 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
549 vlv_primary_async_flip(struct intel_plane *plane,
550 const struct intel_crtc_state *crtc_state,
551 const struct intel_plane_state *plane_state,
554 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
555 u32 dspaddr_offset = plane_state->view.color_plane[0].offset;
556 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
557 unsigned long irqflags;
559 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
560 intel_de_write_fw(dev_priv, DSPADDR_VLV(i9xx_plane),
561 intel_plane_ggtt_offset(plane_state) + dspaddr_offset);
562 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
566 bdw_primary_enable_flip_done(struct intel_plane *plane)
568 struct drm_i915_private *i915 = to_i915(plane->base.dev);
569 enum pipe pipe = plane->pipe;
571 spin_lock_irq(&i915->irq_lock);
572 bdw_enable_pipe_irq(i915, pipe, GEN8_PIPE_PRIMARY_FLIP_DONE);
573 spin_unlock_irq(&i915->irq_lock);
577 bdw_primary_disable_flip_done(struct intel_plane *plane)
579 struct drm_i915_private *i915 = to_i915(plane->base.dev);
580 enum pipe pipe = plane->pipe;
582 spin_lock_irq(&i915->irq_lock);
583 bdw_disable_pipe_irq(i915, pipe, GEN8_PIPE_PRIMARY_FLIP_DONE);
584 spin_unlock_irq(&i915->irq_lock);
588 ivb_primary_enable_flip_done(struct intel_plane *plane)
590 struct drm_i915_private *i915 = to_i915(plane->base.dev);
592 spin_lock_irq(&i915->irq_lock);
593 ilk_enable_display_irq(i915, DE_PLANE_FLIP_DONE_IVB(plane->i9xx_plane));
594 spin_unlock_irq(&i915->irq_lock);
598 ivb_primary_disable_flip_done(struct intel_plane *plane)
600 struct drm_i915_private *i915 = to_i915(plane->base.dev);
602 spin_lock_irq(&i915->irq_lock);
603 ilk_disable_display_irq(i915, DE_PLANE_FLIP_DONE_IVB(plane->i9xx_plane));
604 spin_unlock_irq(&i915->irq_lock);
608 ilk_primary_enable_flip_done(struct intel_plane *plane)
610 struct drm_i915_private *i915 = to_i915(plane->base.dev);
612 spin_lock_irq(&i915->irq_lock);
613 ilk_enable_display_irq(i915, DE_PLANE_FLIP_DONE(plane->i9xx_plane));
614 spin_unlock_irq(&i915->irq_lock);
618 ilk_primary_disable_flip_done(struct intel_plane *plane)
620 struct drm_i915_private *i915 = to_i915(plane->base.dev);
622 spin_lock_irq(&i915->irq_lock);
623 ilk_disable_display_irq(i915, DE_PLANE_FLIP_DONE(plane->i9xx_plane));
624 spin_unlock_irq(&i915->irq_lock);
628 vlv_primary_enable_flip_done(struct intel_plane *plane)
630 struct drm_i915_private *i915 = to_i915(plane->base.dev);
631 enum pipe pipe = plane->pipe;
633 spin_lock_irq(&i915->irq_lock);
634 i915_enable_pipestat(i915, pipe, PLANE_FLIP_DONE_INT_STATUS_VLV);
635 spin_unlock_irq(&i915->irq_lock);
639 vlv_primary_disable_flip_done(struct intel_plane *plane)
641 struct drm_i915_private *i915 = to_i915(plane->base.dev);
642 enum pipe pipe = plane->pipe;
644 spin_lock_irq(&i915->irq_lock);
645 i915_disable_pipestat(i915, pipe, PLANE_FLIP_DONE_INT_STATUS_VLV);
646 spin_unlock_irq(&i915->irq_lock);
649 static bool i9xx_plane_get_hw_state(struct intel_plane *plane,
652 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
653 enum intel_display_power_domain power_domain;
654 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
655 intel_wakeref_t wakeref;
660 * Not 100% correct for planes that can move between pipes,
661 * but that's only the case for gen2-4 which don't have any
662 * display power wells.
664 power_domain = POWER_DOMAIN_PIPE(plane->pipe);
665 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
669 val = intel_de_read(dev_priv, DSPCNTR(i9xx_plane));
671 ret = val & DISPLAY_PLANE_ENABLE;
673 if (DISPLAY_VER(dev_priv) >= 5)
676 *pipe = (val & DISPPLANE_SEL_PIPE_MASK) >>
677 DISPPLANE_SEL_PIPE_SHIFT;
679 intel_display_power_put(dev_priv, power_domain, wakeref);
685 hsw_primary_max_stride(struct intel_plane *plane,
686 u32 pixel_format, u64 modifier,
687 unsigned int rotation)
689 const struct drm_format_info *info = drm_format_info(pixel_format);
690 int cpp = info->cpp[0];
692 /* Limit to 8k pixels to guarantee OFFSET.x doesn't get too big. */
693 return min(8192 * cpp, 32 * 1024);
697 ilk_primary_max_stride(struct intel_plane *plane,
698 u32 pixel_format, u64 modifier,
699 unsigned int rotation)
701 const struct drm_format_info *info = drm_format_info(pixel_format);
702 int cpp = info->cpp[0];
704 /* Limit to 4k pixels to guarantee TILEOFF.x doesn't get too big. */
705 if (modifier == I915_FORMAT_MOD_X_TILED)
706 return min(4096 * cpp, 32 * 1024);
712 i965_plane_max_stride(struct intel_plane *plane,
713 u32 pixel_format, u64 modifier,
714 unsigned int rotation)
716 const struct drm_format_info *info = drm_format_info(pixel_format);
717 int cpp = info->cpp[0];
719 /* Limit to 4k pixels to guarantee TILEOFF.x doesn't get too big. */
720 if (modifier == I915_FORMAT_MOD_X_TILED)
721 return min(4096 * cpp, 16 * 1024);
727 i9xx_plane_max_stride(struct intel_plane *plane,
728 u32 pixel_format, u64 modifier,
729 unsigned int rotation)
731 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
733 if (DISPLAY_VER(dev_priv) >= 3) {
734 if (modifier == I915_FORMAT_MOD_X_TILED)
739 if (plane->i9xx_plane == PLANE_C)
746 static const struct drm_plane_funcs i965_plane_funcs = {
747 .update_plane = drm_atomic_helper_update_plane,
748 .disable_plane = drm_atomic_helper_disable_plane,
749 .destroy = intel_plane_destroy,
750 .atomic_duplicate_state = intel_plane_duplicate_state,
751 .atomic_destroy_state = intel_plane_destroy_state,
752 .format_mod_supported = i965_plane_format_mod_supported,
755 static const struct drm_plane_funcs i8xx_plane_funcs = {
756 .update_plane = drm_atomic_helper_update_plane,
757 .disable_plane = drm_atomic_helper_disable_plane,
758 .destroy = intel_plane_destroy,
759 .atomic_duplicate_state = intel_plane_duplicate_state,
760 .atomic_destroy_state = intel_plane_destroy_state,
761 .format_mod_supported = i8xx_plane_format_mod_supported,
765 intel_primary_plane_create(struct drm_i915_private *dev_priv, enum pipe pipe)
767 struct intel_plane *plane;
768 const struct drm_plane_funcs *plane_funcs;
769 unsigned int supported_rotations;
774 plane = intel_plane_alloc();
780 * On gen2/3 only plane A can do FBC, but the panel fitter and LVDS
781 * port is hooked to pipe B. Hence we want plane A feeding pipe B.
783 if (HAS_FBC(dev_priv) && DISPLAY_VER(dev_priv) < 4 &&
784 INTEL_NUM_PIPES(dev_priv) == 2)
785 plane->i9xx_plane = (enum i9xx_plane_id) !pipe;
787 plane->i9xx_plane = (enum i9xx_plane_id) pipe;
788 plane->id = PLANE_PRIMARY;
789 plane->frontbuffer_bit = INTEL_FRONTBUFFER(pipe, plane->id);
791 plane->has_fbc = i9xx_plane_has_fbc(dev_priv, plane->i9xx_plane);
792 if (plane->has_fbc) {
793 struct intel_fbc *fbc = &dev_priv->fbc;
795 fbc->possible_framebuffer_bits |= plane->frontbuffer_bit;
798 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
799 formats = vlv_primary_formats;
800 num_formats = ARRAY_SIZE(vlv_primary_formats);
801 } else if (DISPLAY_VER(dev_priv) >= 4) {
803 * WaFP16GammaEnabling:ivb
804 * "Workaround : When using the 64-bit format, the plane
805 * output on each color channel has one quarter amplitude.
806 * It can be brought up to full amplitude by using pipe
807 * gamma correction or pipe color space conversion to
808 * multiply the plane output by four."
810 * There is no dedicated plane gamma for the primary plane,
811 * and using the pipe gamma/csc could conflict with other
812 * planes, so we choose not to expose fp16 on IVB primary
813 * planes. HSW primary planes no longer have this problem.
815 if (IS_IVYBRIDGE(dev_priv)) {
816 formats = ivb_primary_formats;
817 num_formats = ARRAY_SIZE(ivb_primary_formats);
819 formats = i965_primary_formats;
820 num_formats = ARRAY_SIZE(i965_primary_formats);
823 formats = i8xx_primary_formats;
824 num_formats = ARRAY_SIZE(i8xx_primary_formats);
827 if (DISPLAY_VER(dev_priv) >= 4)
828 plane_funcs = &i965_plane_funcs;
830 plane_funcs = &i8xx_plane_funcs;
832 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
833 plane->min_cdclk = vlv_plane_min_cdclk;
834 else if (IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv))
835 plane->min_cdclk = hsw_plane_min_cdclk;
836 else if (IS_IVYBRIDGE(dev_priv))
837 plane->min_cdclk = ivb_plane_min_cdclk;
839 plane->min_cdclk = i9xx_plane_min_cdclk;
841 if (HAS_GMCH(dev_priv)) {
842 if (DISPLAY_VER(dev_priv) >= 4)
843 plane->max_stride = i965_plane_max_stride;
845 plane->max_stride = i9xx_plane_max_stride;
847 if (IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv))
848 plane->max_stride = hsw_primary_max_stride;
850 plane->max_stride = ilk_primary_max_stride;
853 plane->update_plane = i9xx_update_plane;
854 plane->disable_plane = i9xx_disable_plane;
855 plane->get_hw_state = i9xx_plane_get_hw_state;
856 plane->check_plane = i9xx_plane_check;
858 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
859 plane->async_flip = vlv_primary_async_flip;
860 plane->enable_flip_done = vlv_primary_enable_flip_done;
861 plane->disable_flip_done = vlv_primary_disable_flip_done;
862 } else if (IS_BROADWELL(dev_priv)) {
863 plane->need_async_flip_disable_wa = true;
864 plane->async_flip = g4x_primary_async_flip;
865 plane->enable_flip_done = bdw_primary_enable_flip_done;
866 plane->disable_flip_done = bdw_primary_disable_flip_done;
867 } else if (DISPLAY_VER(dev_priv) >= 7) {
868 plane->async_flip = g4x_primary_async_flip;
869 plane->enable_flip_done = ivb_primary_enable_flip_done;
870 plane->disable_flip_done = ivb_primary_disable_flip_done;
871 } else if (DISPLAY_VER(dev_priv) >= 5) {
872 plane->async_flip = g4x_primary_async_flip;
873 plane->enable_flip_done = ilk_primary_enable_flip_done;
874 plane->disable_flip_done = ilk_primary_disable_flip_done;
877 if (DISPLAY_VER(dev_priv) >= 5 || IS_G4X(dev_priv))
878 ret = drm_universal_plane_init(&dev_priv->drm, &plane->base,
880 formats, num_formats,
881 i9xx_format_modifiers,
882 DRM_PLANE_TYPE_PRIMARY,
883 "primary %c", pipe_name(pipe));
885 ret = drm_universal_plane_init(&dev_priv->drm, &plane->base,
887 formats, num_formats,
888 i9xx_format_modifiers,
889 DRM_PLANE_TYPE_PRIMARY,
891 plane_name(plane->i9xx_plane));
895 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B) {
896 supported_rotations =
897 DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180 |
899 } else if (DISPLAY_VER(dev_priv) >= 4) {
900 supported_rotations =
901 DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180;
903 supported_rotations = DRM_MODE_ROTATE_0;
906 if (DISPLAY_VER(dev_priv) >= 4)
907 drm_plane_create_rotation_property(&plane->base,
909 supported_rotations);
912 drm_plane_create_zpos_immutable_property(&plane->base, zpos);
914 drm_plane_helper_add(&plane->base, &intel_plane_helper_funcs);
919 intel_plane_free(plane);
924 static int i9xx_format_to_fourcc(int format)
928 return DRM_FORMAT_C8;
929 case DISPPLANE_BGRA555:
930 return DRM_FORMAT_ARGB1555;
931 case DISPPLANE_BGRX555:
932 return DRM_FORMAT_XRGB1555;
933 case DISPPLANE_BGRX565:
934 return DRM_FORMAT_RGB565;
936 case DISPPLANE_BGRX888:
937 return DRM_FORMAT_XRGB8888;
938 case DISPPLANE_RGBX888:
939 return DRM_FORMAT_XBGR8888;
940 case DISPPLANE_BGRA888:
941 return DRM_FORMAT_ARGB8888;
942 case DISPPLANE_RGBA888:
943 return DRM_FORMAT_ABGR8888;
944 case DISPPLANE_BGRX101010:
945 return DRM_FORMAT_XRGB2101010;
946 case DISPPLANE_RGBX101010:
947 return DRM_FORMAT_XBGR2101010;
948 case DISPPLANE_BGRA101010:
949 return DRM_FORMAT_ARGB2101010;
950 case DISPPLANE_RGBA101010:
951 return DRM_FORMAT_ABGR2101010;
952 case DISPPLANE_RGBX161616:
953 return DRM_FORMAT_XBGR16161616F;
958 i9xx_get_initial_plane_config(struct intel_crtc *crtc,
959 struct intel_initial_plane_config *plane_config)
961 struct drm_device *dev = crtc->base.dev;
962 struct drm_i915_private *dev_priv = to_i915(dev);
963 struct intel_plane *plane = to_intel_plane(crtc->base.primary);
964 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
966 u32 val, base, offset;
967 int fourcc, pixel_format;
968 unsigned int aligned_height;
969 struct drm_framebuffer *fb;
970 struct intel_framebuffer *intel_fb;
972 if (!plane->get_hw_state(plane, &pipe))
975 drm_WARN_ON(dev, pipe != crtc->pipe);
977 intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
979 drm_dbg_kms(&dev_priv->drm, "failed to alloc fb\n");
983 fb = &intel_fb->base;
987 val = intel_de_read(dev_priv, DSPCNTR(i9xx_plane));
989 if (DISPLAY_VER(dev_priv) >= 4) {
990 if (val & DISPPLANE_TILED) {
991 plane_config->tiling = I915_TILING_X;
992 fb->modifier = I915_FORMAT_MOD_X_TILED;
995 if (val & DISPPLANE_ROTATE_180)
996 plane_config->rotation = DRM_MODE_ROTATE_180;
999 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B &&
1000 val & DISPPLANE_MIRROR)
1001 plane_config->rotation |= DRM_MODE_REFLECT_X;
1003 pixel_format = val & DISPPLANE_PIXFORMAT_MASK;
1004 fourcc = i9xx_format_to_fourcc(pixel_format);
1005 fb->format = drm_format_info(fourcc);
1007 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
1008 offset = intel_de_read(dev_priv, DSPOFFSET(i9xx_plane));
1009 base = intel_de_read(dev_priv, DSPSURF(i9xx_plane)) & 0xfffff000;
1010 } else if (DISPLAY_VER(dev_priv) >= 4) {
1011 if (plane_config->tiling)
1012 offset = intel_de_read(dev_priv,
1013 DSPTILEOFF(i9xx_plane));
1015 offset = intel_de_read(dev_priv,
1016 DSPLINOFF(i9xx_plane));
1017 base = intel_de_read(dev_priv, DSPSURF(i9xx_plane)) & 0xfffff000;
1019 base = intel_de_read(dev_priv, DSPADDR(i9xx_plane));
1021 plane_config->base = base;
1023 val = intel_de_read(dev_priv, PIPESRC(pipe));
1024 fb->width = ((val >> 16) & 0xfff) + 1;
1025 fb->height = ((val >> 0) & 0xfff) + 1;
1027 val = intel_de_read(dev_priv, DSPSTRIDE(i9xx_plane));
1028 fb->pitches[0] = val & 0xffffffc0;
1030 aligned_height = intel_fb_align_height(fb, 0, fb->height);
1032 plane_config->size = fb->pitches[0] * aligned_height;
1034 drm_dbg_kms(&dev_priv->drm,
1035 "%s/%s with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
1036 crtc->base.name, plane->base.name, fb->width, fb->height,
1037 fb->format->cpp[0] * 8, base, fb->pitches[0],
1038 plane_config->size);
1040 plane_config->fb = intel_fb;