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_blend.h>
9 #include <drm/drm_fourcc.h>
13 #include "i9xx_plane.h"
14 #include "i9xx_plane_regs.h"
15 #include "intel_atomic.h"
16 #include "intel_atomic_plane.h"
18 #include "intel_display_irq.h"
19 #include "intel_display_types.h"
21 #include "intel_fbc.h"
22 #include "intel_frontbuffer.h"
23 #include "intel_sprite.h"
25 /* Primary plane formats for gen <= 3 */
26 static const u32 i8xx_primary_formats[] = {
33 /* Primary plane formats for ivb (no fp16 due to hw issue) */
34 static const u32 ivb_primary_formats[] = {
39 DRM_FORMAT_XRGB2101010,
40 DRM_FORMAT_XBGR2101010,
43 /* Primary plane formats for gen >= 4, except ivb */
44 static const u32 i965_primary_formats[] = {
49 DRM_FORMAT_XRGB2101010,
50 DRM_FORMAT_XBGR2101010,
51 DRM_FORMAT_XBGR16161616F,
54 /* Primary plane formats for vlv/chv */
55 static const u32 vlv_primary_formats[] = {
62 DRM_FORMAT_XRGB2101010,
63 DRM_FORMAT_XBGR2101010,
64 DRM_FORMAT_ARGB2101010,
65 DRM_FORMAT_ABGR2101010,
66 DRM_FORMAT_XBGR16161616F,
69 static bool i8xx_plane_format_mod_supported(struct drm_plane *_plane,
70 u32 format, u64 modifier)
72 if (!intel_fb_plane_supports_modifier(to_intel_plane(_plane), modifier))
77 case DRM_FORMAT_RGB565:
78 case DRM_FORMAT_XRGB1555:
79 case DRM_FORMAT_XRGB8888:
80 return modifier == DRM_FORMAT_MOD_LINEAR ||
81 modifier == I915_FORMAT_MOD_X_TILED;
87 static bool i965_plane_format_mod_supported(struct drm_plane *_plane,
88 u32 format, u64 modifier)
90 if (!intel_fb_plane_supports_modifier(to_intel_plane(_plane), modifier))
95 case DRM_FORMAT_RGB565:
96 case DRM_FORMAT_XRGB8888:
97 case DRM_FORMAT_XBGR8888:
98 case DRM_FORMAT_ARGB8888:
99 case DRM_FORMAT_ABGR8888:
100 case DRM_FORMAT_XRGB2101010:
101 case DRM_FORMAT_XBGR2101010:
102 case DRM_FORMAT_ARGB2101010:
103 case DRM_FORMAT_ABGR2101010:
104 case DRM_FORMAT_XBGR16161616F:
105 return modifier == DRM_FORMAT_MOD_LINEAR ||
106 modifier == I915_FORMAT_MOD_X_TILED;
112 static bool i9xx_plane_has_fbc(struct drm_i915_private *dev_priv,
113 enum i9xx_plane_id i9xx_plane)
115 if (!HAS_FBC(dev_priv))
118 if (IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv))
119 return i9xx_plane == PLANE_A; /* tied to pipe A */
120 else if (IS_IVYBRIDGE(dev_priv))
121 return i9xx_plane == PLANE_A || i9xx_plane == PLANE_B ||
122 i9xx_plane == PLANE_C;
123 else if (DISPLAY_VER(dev_priv) >= 4)
124 return i9xx_plane == PLANE_A || i9xx_plane == PLANE_B;
126 return i9xx_plane == PLANE_A;
129 static struct intel_fbc *i9xx_plane_fbc(struct drm_i915_private *dev_priv,
130 enum i9xx_plane_id i9xx_plane)
132 if (i9xx_plane_has_fbc(dev_priv, i9xx_plane))
133 return dev_priv->display.fbc[INTEL_FBC_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 = DISP_ENABLE;
165 if (IS_G4X(dev_priv) || IS_IRONLAKE(dev_priv) ||
166 IS_SANDYBRIDGE(dev_priv) || IS_IVYBRIDGE(dev_priv))
167 dspcntr |= DISP_TRICKLE_FEED_DISABLE;
169 switch (fb->format->format) {
171 dspcntr |= DISP_FORMAT_8BPP;
173 case DRM_FORMAT_XRGB1555:
174 dspcntr |= DISP_FORMAT_BGRX555;
176 case DRM_FORMAT_ARGB1555:
177 dspcntr |= DISP_FORMAT_BGRA555;
179 case DRM_FORMAT_RGB565:
180 dspcntr |= DISP_FORMAT_BGRX565;
182 case DRM_FORMAT_XRGB8888:
183 dspcntr |= DISP_FORMAT_BGRX888;
185 case DRM_FORMAT_XBGR8888:
186 dspcntr |= DISP_FORMAT_RGBX888;
188 case DRM_FORMAT_ARGB8888:
189 dspcntr |= DISP_FORMAT_BGRA888;
191 case DRM_FORMAT_ABGR8888:
192 dspcntr |= DISP_FORMAT_RGBA888;
194 case DRM_FORMAT_XRGB2101010:
195 dspcntr |= DISP_FORMAT_BGRX101010;
197 case DRM_FORMAT_XBGR2101010:
198 dspcntr |= DISP_FORMAT_RGBX101010;
200 case DRM_FORMAT_ARGB2101010:
201 dspcntr |= DISP_FORMAT_BGRA101010;
203 case DRM_FORMAT_ABGR2101010:
204 dspcntr |= DISP_FORMAT_RGBA101010;
206 case DRM_FORMAT_XBGR16161616F:
207 dspcntr |= DISP_FORMAT_RGBX161616;
210 MISSING_CASE(fb->format->format);
214 if (DISPLAY_VER(dev_priv) >= 4 &&
215 fb->modifier == I915_FORMAT_MOD_X_TILED)
216 dspcntr |= DISP_TILED;
218 if (rotation & DRM_MODE_ROTATE_180)
219 dspcntr |= DISP_ROTATE_180;
221 if (rotation & DRM_MODE_REFLECT_X)
222 dspcntr |= DISP_MIRROR;
227 int i9xx_check_plane_surface(struct intel_plane_state *plane_state)
229 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
230 struct drm_i915_private *dev_priv = to_i915(plane->base.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 unsigned int alignment = plane->min_alignment(plane, fb, 0);
272 int cpp = fb->format->cpp[0];
274 while ((src_x + src_w) * cpp > plane_state->view.color_plane[0].mapping_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_NO_SCALING,
334 DRM_PLANE_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 |= DISP_PIPE_GAMMA_ENABLE;
364 if (crtc_state->csc_enable)
365 dspcntr |= DISP_PIPE_CSC_ENABLE;
367 if (DISPLAY_VER(dev_priv) < 5)
368 dspcntr |= DISP_PIPE_SEL(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_plane_update_noarm(struct intel_dsb *dsb,
421 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 intel_de_write_fw(dev_priv, DSPSTRIDE(dev_priv, i9xx_plane),
429 plane_state->view.color_plane[0].mapping_stride);
431 if (DISPLAY_VER(dev_priv) < 4) {
432 int crtc_x = plane_state->uapi.dst.x1;
433 int crtc_y = plane_state->uapi.dst.y1;
434 int crtc_w = drm_rect_width(&plane_state->uapi.dst);
435 int crtc_h = drm_rect_height(&plane_state->uapi.dst);
438 * PLANE_A doesn't actually have a full window
439 * generator but let's assume we still need to
440 * program whatever is there.
442 intel_de_write_fw(dev_priv, DSPPOS(dev_priv, i9xx_plane),
443 DISP_POS_Y(crtc_y) | DISP_POS_X(crtc_x));
444 intel_de_write_fw(dev_priv, DSPSIZE(dev_priv, i9xx_plane),
445 DISP_HEIGHT(crtc_h - 1) | DISP_WIDTH(crtc_w - 1));
449 static void i9xx_plane_update_arm(struct intel_dsb *dsb,
450 struct intel_plane *plane,
451 const struct intel_crtc_state *crtc_state,
452 const struct intel_plane_state *plane_state)
454 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
455 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
456 int x = plane_state->view.color_plane[0].x;
457 int y = plane_state->view.color_plane[0].y;
458 u32 dspcntr, dspaddr_offset, linear_offset;
460 dspcntr = plane_state->ctl | i9xx_plane_ctl_crtc(crtc_state);
462 /* see intel_plane_atomic_calc_changes() */
463 if (plane->need_async_flip_toggle_wa &&
464 crtc_state->async_flip_planes & BIT(plane->id))
465 dspcntr |= DISP_ASYNC_FLIP;
467 linear_offset = intel_fb_xy_to_linear(x, y, plane_state, 0);
469 if (DISPLAY_VER(dev_priv) >= 4)
470 dspaddr_offset = plane_state->view.color_plane[0].offset;
472 dspaddr_offset = linear_offset;
474 if (IS_CHERRYVIEW(dev_priv) && i9xx_plane == PLANE_B) {
475 int crtc_x = plane_state->uapi.dst.x1;
476 int crtc_y = plane_state->uapi.dst.y1;
477 int crtc_w = drm_rect_width(&plane_state->uapi.dst);
478 int crtc_h = drm_rect_height(&plane_state->uapi.dst);
480 intel_de_write_fw(dev_priv, PRIMPOS(dev_priv, i9xx_plane),
481 PRIM_POS_Y(crtc_y) | PRIM_POS_X(crtc_x));
482 intel_de_write_fw(dev_priv, PRIMSIZE(dev_priv, i9xx_plane),
483 PRIM_HEIGHT(crtc_h - 1) | PRIM_WIDTH(crtc_w - 1));
484 intel_de_write_fw(dev_priv,
485 PRIMCNSTALPHA(dev_priv, i9xx_plane), 0);
488 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
489 intel_de_write_fw(dev_priv, DSPOFFSET(dev_priv, i9xx_plane),
490 DISP_OFFSET_Y(y) | DISP_OFFSET_X(x));
491 } else if (DISPLAY_VER(dev_priv) >= 4) {
492 intel_de_write_fw(dev_priv, DSPLINOFF(dev_priv, i9xx_plane),
494 intel_de_write_fw(dev_priv, DSPTILEOFF(dev_priv, i9xx_plane),
495 DISP_OFFSET_Y(y) | DISP_OFFSET_X(x));
499 * The control register self-arms if the plane was previously
500 * disabled. Try to make the plane enable atomic by writing
501 * the control register just before the surface register.
503 intel_de_write_fw(dev_priv, DSPCNTR(dev_priv, i9xx_plane), dspcntr);
505 if (DISPLAY_VER(dev_priv) >= 4)
506 intel_de_write_fw(dev_priv, DSPSURF(dev_priv, i9xx_plane),
507 intel_plane_ggtt_offset(plane_state) + dspaddr_offset);
509 intel_de_write_fw(dev_priv, DSPADDR(dev_priv, i9xx_plane),
510 intel_plane_ggtt_offset(plane_state) + dspaddr_offset);
513 static void i830_plane_update_arm(struct intel_dsb *dsb,
514 struct intel_plane *plane,
515 const struct intel_crtc_state *crtc_state,
516 const struct intel_plane_state *plane_state)
519 * On i830/i845 all registers are self-arming [ALM040].
521 * Additional breakage on i830 causes register reads to return
522 * the last latched value instead of the last written value [ALM026].
524 i9xx_plane_update_noarm(dsb, plane, crtc_state, plane_state);
525 i9xx_plane_update_arm(dsb, plane, crtc_state, plane_state);
528 static void i9xx_plane_disable_arm(struct intel_dsb *dsb,
529 struct intel_plane *plane,
530 const struct intel_crtc_state *crtc_state)
532 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
533 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
537 * DSPCNTR pipe gamma enable on g4x+ and pipe csc
538 * enable on ilk+ affect the pipe bottom color as
539 * well, so we must configure them even if the plane
542 * On pre-g4x there is no way to gamma correct the
543 * pipe bottom color but we'll keep on doing this
544 * anyway so that the crtc state readout works correctly.
546 dspcntr = i9xx_plane_ctl_crtc(crtc_state);
548 intel_de_write_fw(dev_priv, DSPCNTR(dev_priv, i9xx_plane), dspcntr);
550 if (DISPLAY_VER(dev_priv) >= 4)
551 intel_de_write_fw(dev_priv, DSPSURF(dev_priv, i9xx_plane), 0);
553 intel_de_write_fw(dev_priv, DSPADDR(dev_priv, i9xx_plane), 0);
557 g4x_primary_async_flip(struct intel_dsb *dsb,
558 struct intel_plane *plane,
559 const struct intel_crtc_state *crtc_state,
560 const struct intel_plane_state *plane_state,
563 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
564 u32 dspcntr = plane_state->ctl | i9xx_plane_ctl_crtc(crtc_state);
565 u32 dspaddr_offset = plane_state->view.color_plane[0].offset;
566 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
569 dspcntr |= DISP_ASYNC_FLIP;
571 intel_de_write_fw(dev_priv, DSPCNTR(dev_priv, i9xx_plane), dspcntr);
573 intel_de_write_fw(dev_priv, DSPSURF(dev_priv, i9xx_plane),
574 intel_plane_ggtt_offset(plane_state) + dspaddr_offset);
578 vlv_primary_async_flip(struct intel_dsb *dsb,
579 struct intel_plane *plane,
580 const struct intel_crtc_state *crtc_state,
581 const struct intel_plane_state *plane_state,
584 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
585 u32 dspaddr_offset = plane_state->view.color_plane[0].offset;
586 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
588 intel_de_write_fw(dev_priv, DSPADDR_VLV(dev_priv, i9xx_plane),
589 intel_plane_ggtt_offset(plane_state) + dspaddr_offset);
593 bdw_primary_enable_flip_done(struct intel_plane *plane)
595 struct drm_i915_private *i915 = to_i915(plane->base.dev);
596 enum pipe pipe = plane->pipe;
598 spin_lock_irq(&i915->irq_lock);
599 bdw_enable_pipe_irq(i915, pipe, GEN8_PIPE_PRIMARY_FLIP_DONE);
600 spin_unlock_irq(&i915->irq_lock);
604 bdw_primary_disable_flip_done(struct intel_plane *plane)
606 struct drm_i915_private *i915 = to_i915(plane->base.dev);
607 enum pipe pipe = plane->pipe;
609 spin_lock_irq(&i915->irq_lock);
610 bdw_disable_pipe_irq(i915, pipe, GEN8_PIPE_PRIMARY_FLIP_DONE);
611 spin_unlock_irq(&i915->irq_lock);
615 ivb_primary_enable_flip_done(struct intel_plane *plane)
617 struct drm_i915_private *i915 = to_i915(plane->base.dev);
619 spin_lock_irq(&i915->irq_lock);
620 ilk_enable_display_irq(i915, DE_PLANE_FLIP_DONE_IVB(plane->i9xx_plane));
621 spin_unlock_irq(&i915->irq_lock);
625 ivb_primary_disable_flip_done(struct intel_plane *plane)
627 struct drm_i915_private *i915 = to_i915(plane->base.dev);
629 spin_lock_irq(&i915->irq_lock);
630 ilk_disable_display_irq(i915, DE_PLANE_FLIP_DONE_IVB(plane->i9xx_plane));
631 spin_unlock_irq(&i915->irq_lock);
635 ilk_primary_enable_flip_done(struct intel_plane *plane)
637 struct drm_i915_private *i915 = to_i915(plane->base.dev);
639 spin_lock_irq(&i915->irq_lock);
640 ilk_enable_display_irq(i915, DE_PLANE_FLIP_DONE(plane->i9xx_plane));
641 spin_unlock_irq(&i915->irq_lock);
645 ilk_primary_disable_flip_done(struct intel_plane *plane)
647 struct drm_i915_private *i915 = to_i915(plane->base.dev);
649 spin_lock_irq(&i915->irq_lock);
650 ilk_disable_display_irq(i915, DE_PLANE_FLIP_DONE(plane->i9xx_plane));
651 spin_unlock_irq(&i915->irq_lock);
655 vlv_primary_enable_flip_done(struct intel_plane *plane)
657 struct drm_i915_private *i915 = to_i915(plane->base.dev);
658 enum pipe pipe = plane->pipe;
660 spin_lock_irq(&i915->irq_lock);
661 i915_enable_pipestat(i915, pipe, PLANE_FLIP_DONE_INT_STATUS_VLV);
662 spin_unlock_irq(&i915->irq_lock);
666 vlv_primary_disable_flip_done(struct intel_plane *plane)
668 struct drm_i915_private *i915 = to_i915(plane->base.dev);
669 enum pipe pipe = plane->pipe;
671 spin_lock_irq(&i915->irq_lock);
672 i915_disable_pipestat(i915, pipe, PLANE_FLIP_DONE_INT_STATUS_VLV);
673 spin_unlock_irq(&i915->irq_lock);
676 static bool i9xx_plane_get_hw_state(struct intel_plane *plane,
679 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
680 enum intel_display_power_domain power_domain;
681 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
682 intel_wakeref_t wakeref;
687 * Not 100% correct for planes that can move between pipes,
688 * but that's only the case for gen2-4 which don't have any
689 * display power wells.
691 power_domain = POWER_DOMAIN_PIPE(plane->pipe);
692 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
696 val = intel_de_read(dev_priv, DSPCNTR(dev_priv, i9xx_plane));
698 ret = val & DISP_ENABLE;
700 if (DISPLAY_VER(dev_priv) >= 5)
703 *pipe = REG_FIELD_GET(DISP_PIPE_SEL_MASK, val);
705 intel_display_power_put(dev_priv, power_domain, wakeref);
711 hsw_primary_max_stride(struct intel_plane *plane,
712 u32 pixel_format, u64 modifier,
713 unsigned int rotation)
715 const struct drm_format_info *info = drm_format_info(pixel_format);
716 int cpp = info->cpp[0];
718 /* Limit to 8k pixels to guarantee OFFSET.x doesn't get too big. */
719 return min(8192 * cpp, 32 * 1024);
723 ilk_primary_max_stride(struct intel_plane *plane,
724 u32 pixel_format, u64 modifier,
725 unsigned int rotation)
727 const struct drm_format_info *info = drm_format_info(pixel_format);
728 int cpp = info->cpp[0];
730 /* Limit to 4k pixels to guarantee TILEOFF.x doesn't get too big. */
731 if (modifier == I915_FORMAT_MOD_X_TILED)
732 return min(4096 * cpp, 32 * 1024);
738 i965_plane_max_stride(struct intel_plane *plane,
739 u32 pixel_format, u64 modifier,
740 unsigned int rotation)
742 const struct drm_format_info *info = drm_format_info(pixel_format);
743 int cpp = info->cpp[0];
745 /* Limit to 4k pixels to guarantee TILEOFF.x doesn't get too big. */
746 if (modifier == I915_FORMAT_MOD_X_TILED)
747 return min(4096 * cpp, 16 * 1024);
753 i915_plane_max_stride(struct intel_plane *plane,
754 u32 pixel_format, u64 modifier,
755 unsigned int rotation)
757 if (modifier == I915_FORMAT_MOD_X_TILED)
764 i8xx_plane_max_stride(struct intel_plane *plane,
765 u32 pixel_format, u64 modifier,
766 unsigned int rotation)
768 if (plane->i9xx_plane == PLANE_C)
774 static unsigned int vlv_primary_min_alignment(struct intel_plane *plane,
775 const struct drm_framebuffer *fb,
778 struct drm_i915_private *i915 = to_i915(plane->base.dev);
780 switch (fb->modifier) {
781 case I915_FORMAT_MOD_X_TILED:
782 if (HAS_ASYNC_FLIPS(i915))
785 case DRM_FORMAT_MOD_LINEAR:
788 MISSING_CASE(fb->modifier);
793 static unsigned int g4x_primary_min_alignment(struct intel_plane *plane,
794 const struct drm_framebuffer *fb,
797 struct drm_i915_private *i915 = to_i915(plane->base.dev);
799 switch (fb->modifier) {
800 case I915_FORMAT_MOD_X_TILED:
801 if (HAS_ASYNC_FLIPS(i915))
804 case DRM_FORMAT_MOD_LINEAR:
807 MISSING_CASE(fb->modifier);
812 static unsigned int i965_plane_min_alignment(struct intel_plane *plane,
813 const struct drm_framebuffer *fb,
816 switch (fb->modifier) {
817 case I915_FORMAT_MOD_X_TILED:
819 case DRM_FORMAT_MOD_LINEAR:
822 MISSING_CASE(fb->modifier);
827 static unsigned int i9xx_plane_min_alignment(struct intel_plane *plane,
828 const struct drm_framebuffer *fb,
834 static const struct drm_plane_funcs i965_plane_funcs = {
835 .update_plane = drm_atomic_helper_update_plane,
836 .disable_plane = drm_atomic_helper_disable_plane,
837 .destroy = intel_plane_destroy,
838 .atomic_duplicate_state = intel_plane_duplicate_state,
839 .atomic_destroy_state = intel_plane_destroy_state,
840 .format_mod_supported = i965_plane_format_mod_supported,
843 static const struct drm_plane_funcs i8xx_plane_funcs = {
844 .update_plane = drm_atomic_helper_update_plane,
845 .disable_plane = drm_atomic_helper_disable_plane,
846 .destroy = intel_plane_destroy,
847 .atomic_duplicate_state = intel_plane_duplicate_state,
848 .atomic_destroy_state = intel_plane_destroy_state,
849 .format_mod_supported = i8xx_plane_format_mod_supported,
853 intel_primary_plane_create(struct drm_i915_private *dev_priv, enum pipe pipe)
855 struct intel_plane *plane;
856 const struct drm_plane_funcs *plane_funcs;
857 unsigned int supported_rotations;
858 const u64 *modifiers;
863 plane = intel_plane_alloc();
869 * On gen2/3 only plane A can do FBC, but the panel fitter and LVDS
870 * port is hooked to pipe B. Hence we want plane A feeding pipe B.
872 if (HAS_FBC(dev_priv) && DISPLAY_VER(dev_priv) < 4 &&
873 INTEL_NUM_PIPES(dev_priv) == 2)
874 plane->i9xx_plane = (enum i9xx_plane_id) !pipe;
876 plane->i9xx_plane = (enum i9xx_plane_id) pipe;
877 plane->id = PLANE_PRIMARY;
878 plane->frontbuffer_bit = INTEL_FRONTBUFFER(pipe, plane->id);
880 intel_fbc_add_plane(i9xx_plane_fbc(dev_priv, plane->i9xx_plane), plane);
882 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
883 formats = vlv_primary_formats;
884 num_formats = ARRAY_SIZE(vlv_primary_formats);
885 } else if (DISPLAY_VER(dev_priv) >= 4) {
887 * WaFP16GammaEnabling:ivb
888 * "Workaround : When using the 64-bit format, the plane
889 * output on each color channel has one quarter amplitude.
890 * It can be brought up to full amplitude by using pipe
891 * gamma correction or pipe color space conversion to
892 * multiply the plane output by four."
894 * There is no dedicated plane gamma for the primary plane,
895 * and using the pipe gamma/csc could conflict with other
896 * planes, so we choose not to expose fp16 on IVB primary
897 * planes. HSW primary planes no longer have this problem.
899 if (IS_IVYBRIDGE(dev_priv)) {
900 formats = ivb_primary_formats;
901 num_formats = ARRAY_SIZE(ivb_primary_formats);
903 formats = i965_primary_formats;
904 num_formats = ARRAY_SIZE(i965_primary_formats);
907 formats = i8xx_primary_formats;
908 num_formats = ARRAY_SIZE(i8xx_primary_formats);
911 if (DISPLAY_VER(dev_priv) >= 4)
912 plane_funcs = &i965_plane_funcs;
914 plane_funcs = &i8xx_plane_funcs;
916 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
917 plane->min_cdclk = vlv_plane_min_cdclk;
918 else if (IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv))
919 plane->min_cdclk = hsw_plane_min_cdclk;
920 else if (IS_IVYBRIDGE(dev_priv))
921 plane->min_cdclk = ivb_plane_min_cdclk;
923 plane->min_cdclk = i9xx_plane_min_cdclk;
925 if (HAS_GMCH(dev_priv)) {
926 if (DISPLAY_VER(dev_priv) >= 4)
927 plane->max_stride = i965_plane_max_stride;
928 else if (DISPLAY_VER(dev_priv) == 3)
929 plane->max_stride = i915_plane_max_stride;
931 plane->max_stride = i8xx_plane_max_stride;
933 if (IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv))
934 plane->max_stride = hsw_primary_max_stride;
936 plane->max_stride = ilk_primary_max_stride;
939 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
940 plane->min_alignment = vlv_primary_min_alignment;
941 else if (DISPLAY_VER(dev_priv) >= 5 || IS_G4X(dev_priv))
942 plane->min_alignment = g4x_primary_min_alignment;
943 else if (DISPLAY_VER(dev_priv) == 4)
944 plane->min_alignment = i965_plane_min_alignment;
946 plane->min_alignment = i9xx_plane_min_alignment;
948 if (IS_I830(dev_priv) || IS_I845G(dev_priv)) {
949 plane->update_arm = i830_plane_update_arm;
951 plane->update_noarm = i9xx_plane_update_noarm;
952 plane->update_arm = i9xx_plane_update_arm;
954 plane->disable_arm = i9xx_plane_disable_arm;
955 plane->get_hw_state = i9xx_plane_get_hw_state;
956 plane->check_plane = i9xx_plane_check;
958 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
959 plane->async_flip = vlv_primary_async_flip;
960 plane->enable_flip_done = vlv_primary_enable_flip_done;
961 plane->disable_flip_done = vlv_primary_disable_flip_done;
962 } else if (IS_BROADWELL(dev_priv)) {
963 plane->need_async_flip_toggle_wa = true;
964 plane->async_flip = g4x_primary_async_flip;
965 plane->enable_flip_done = bdw_primary_enable_flip_done;
966 plane->disable_flip_done = bdw_primary_disable_flip_done;
967 } else if (DISPLAY_VER(dev_priv) >= 7) {
968 plane->async_flip = g4x_primary_async_flip;
969 plane->enable_flip_done = ivb_primary_enable_flip_done;
970 plane->disable_flip_done = ivb_primary_disable_flip_done;
971 } else if (DISPLAY_VER(dev_priv) >= 5) {
972 plane->async_flip = g4x_primary_async_flip;
973 plane->enable_flip_done = ilk_primary_enable_flip_done;
974 plane->disable_flip_done = ilk_primary_disable_flip_done;
977 modifiers = intel_fb_plane_get_modifiers(dev_priv, INTEL_PLANE_CAP_TILING_X);
979 if (DISPLAY_VER(dev_priv) >= 5 || IS_G4X(dev_priv))
980 ret = drm_universal_plane_init(&dev_priv->drm, &plane->base,
982 formats, num_formats,
984 DRM_PLANE_TYPE_PRIMARY,
985 "primary %c", pipe_name(pipe));
987 ret = drm_universal_plane_init(&dev_priv->drm, &plane->base,
989 formats, num_formats,
991 DRM_PLANE_TYPE_PRIMARY,
993 plane_name(plane->i9xx_plane));
1000 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B) {
1001 supported_rotations =
1002 DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180 |
1004 } else if (DISPLAY_VER(dev_priv) >= 4) {
1005 supported_rotations =
1006 DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180;
1008 supported_rotations = DRM_MODE_ROTATE_0;
1011 if (DISPLAY_VER(dev_priv) >= 4)
1012 drm_plane_create_rotation_property(&plane->base,
1014 supported_rotations);
1017 drm_plane_create_zpos_immutable_property(&plane->base, zpos);
1019 intel_plane_helper_add(plane);
1024 intel_plane_free(plane);
1026 return ERR_PTR(ret);
1029 static int i9xx_format_to_fourcc(int format)
1032 case DISP_FORMAT_8BPP:
1033 return DRM_FORMAT_C8;
1034 case DISP_FORMAT_BGRA555:
1035 return DRM_FORMAT_ARGB1555;
1036 case DISP_FORMAT_BGRX555:
1037 return DRM_FORMAT_XRGB1555;
1038 case DISP_FORMAT_BGRX565:
1039 return DRM_FORMAT_RGB565;
1041 case DISP_FORMAT_BGRX888:
1042 return DRM_FORMAT_XRGB8888;
1043 case DISP_FORMAT_RGBX888:
1044 return DRM_FORMAT_XBGR8888;
1045 case DISP_FORMAT_BGRA888:
1046 return DRM_FORMAT_ARGB8888;
1047 case DISP_FORMAT_RGBA888:
1048 return DRM_FORMAT_ABGR8888;
1049 case DISP_FORMAT_BGRX101010:
1050 return DRM_FORMAT_XRGB2101010;
1051 case DISP_FORMAT_RGBX101010:
1052 return DRM_FORMAT_XBGR2101010;
1053 case DISP_FORMAT_BGRA101010:
1054 return DRM_FORMAT_ARGB2101010;
1055 case DISP_FORMAT_RGBA101010:
1056 return DRM_FORMAT_ABGR2101010;
1057 case DISP_FORMAT_RGBX161616:
1058 return DRM_FORMAT_XBGR16161616F;
1063 i9xx_get_initial_plane_config(struct intel_crtc *crtc,
1064 struct intel_initial_plane_config *plane_config)
1066 struct drm_device *dev = crtc->base.dev;
1067 struct drm_i915_private *dev_priv = to_i915(dev);
1068 struct intel_plane *plane = to_intel_plane(crtc->base.primary);
1069 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
1071 u32 val, base, offset;
1072 int fourcc, pixel_format;
1073 unsigned int aligned_height;
1074 struct drm_framebuffer *fb;
1075 struct intel_framebuffer *intel_fb;
1077 if (!plane->get_hw_state(plane, &pipe))
1080 drm_WARN_ON(dev, pipe != crtc->pipe);
1082 intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
1084 drm_dbg_kms(&dev_priv->drm, "failed to alloc fb\n");
1088 fb = &intel_fb->base;
1092 val = intel_de_read(dev_priv, DSPCNTR(dev_priv, i9xx_plane));
1094 if (DISPLAY_VER(dev_priv) >= 4) {
1095 if (val & DISP_TILED) {
1096 plane_config->tiling = I915_TILING_X;
1097 fb->modifier = I915_FORMAT_MOD_X_TILED;
1100 if (val & DISP_ROTATE_180)
1101 plane_config->rotation = DRM_MODE_ROTATE_180;
1104 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B &&
1106 plane_config->rotation |= DRM_MODE_REFLECT_X;
1108 pixel_format = val & DISP_FORMAT_MASK;
1109 fourcc = i9xx_format_to_fourcc(pixel_format);
1110 fb->format = drm_format_info(fourcc);
1112 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
1113 offset = intel_de_read(dev_priv,
1114 DSPOFFSET(dev_priv, i9xx_plane));
1115 base = intel_de_read(dev_priv, DSPSURF(dev_priv, i9xx_plane)) & DISP_ADDR_MASK;
1116 } else if (DISPLAY_VER(dev_priv) >= 4) {
1117 if (plane_config->tiling)
1118 offset = intel_de_read(dev_priv,
1119 DSPTILEOFF(dev_priv, i9xx_plane));
1121 offset = intel_de_read(dev_priv,
1122 DSPLINOFF(dev_priv, i9xx_plane));
1123 base = intel_de_read(dev_priv, DSPSURF(dev_priv, i9xx_plane)) & DISP_ADDR_MASK;
1126 base = intel_de_read(dev_priv, DSPADDR(dev_priv, i9xx_plane));
1128 plane_config->base = base;
1130 drm_WARN_ON(&dev_priv->drm, offset != 0);
1132 val = intel_de_read(dev_priv, PIPESRC(dev_priv, pipe));
1133 fb->width = REG_FIELD_GET(PIPESRC_WIDTH_MASK, val) + 1;
1134 fb->height = REG_FIELD_GET(PIPESRC_HEIGHT_MASK, val) + 1;
1136 val = intel_de_read(dev_priv, DSPSTRIDE(dev_priv, i9xx_plane));
1137 fb->pitches[0] = val & 0xffffffc0;
1139 aligned_height = intel_fb_align_height(fb, 0, fb->height);
1141 plane_config->size = fb->pitches[0] * aligned_height;
1143 drm_dbg_kms(&dev_priv->drm,
1144 "%s/%s with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
1145 crtc->base.name, plane->base.name, fb->width, fb->height,
1146 fb->format->cpp[0] * 8, base, fb->pitches[0],
1147 plane_config->size);
1149 plane_config->fb = intel_fb;
1152 bool i9xx_fixup_initial_plane_config(struct intel_crtc *crtc,
1153 const struct intel_initial_plane_config *plane_config)
1155 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1156 struct intel_plane *plane = to_intel_plane(crtc->base.primary);
1157 const struct intel_plane_state *plane_state =
1158 to_intel_plane_state(plane->base.state);
1159 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
1162 if (!plane_state->uapi.visible)
1165 base = intel_plane_ggtt_offset(plane_state);
1168 * We may have moved the surface to a different
1169 * part of ggtt, make the plane aware of that.
1171 if (plane_config->base == base)
1174 if (DISPLAY_VER(dev_priv) >= 4)
1175 intel_de_write(dev_priv, DSPSURF(dev_priv, i9xx_plane), base);
1177 intel_de_write(dev_priv, DSPADDR(dev_priv, i9xx_plane), base);