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_atomic_uapi.h>
9 #include <drm/drm_blend.h>
10 #include <drm/drm_damage_helper.h>
11 #include <drm/drm_fourcc.h>
14 #include "intel_atomic.h"
15 #include "intel_atomic_plane.h"
16 #include "intel_cursor.h"
18 #include "intel_display.h"
19 #include "intel_display_types.h"
21 #include "intel_fb_pin.h"
22 #include "intel_frontbuffer.h"
23 #include "intel_psr.h"
24 #include "intel_psr_regs.h"
25 #include "intel_vblank.h"
26 #include "skl_watermark.h"
28 #include "gem/i915_gem_object.h"
31 static const u32 intel_cursor_formats[] = {
35 static u32 intel_cursor_base(const struct intel_plane_state *plane_state)
37 struct drm_i915_private *dev_priv =
38 to_i915(plane_state->uapi.plane->dev);
41 if (DISPLAY_INFO(dev_priv)->cursor_needs_physical)
42 base = plane_state->phys_dma_addr;
44 base = intel_plane_ggtt_offset(plane_state);
46 return base + plane_state->view.color_plane[0].offset;
49 static u32 intel_cursor_position(const struct intel_crtc_state *crtc_state,
50 const struct intel_plane_state *plane_state,
53 int x = plane_state->uapi.dst.x1;
54 int y = plane_state->uapi.dst.y1;
59 * MAX(-1 * <Cursor vertical size from CUR_CTL base on cursor mode
60 * select setting> + 1, CUR_POS Y Position - Update region Y position
63 y = max(-1 * drm_rect_height(&plane_state->uapi.dst) + 1,
64 y - crtc_state->psr2_su_area.y1);
67 pos |= CURSOR_POS_X_SIGN;
70 pos |= CURSOR_POS_X(x);
73 pos |= CURSOR_POS_Y_SIGN;
76 pos |= CURSOR_POS_Y(y);
81 static bool intel_cursor_size_ok(const struct intel_plane_state *plane_state)
83 const struct drm_mode_config *config =
84 &plane_state->uapi.plane->dev->mode_config;
85 int width = drm_rect_width(&plane_state->uapi.dst);
86 int height = drm_rect_height(&plane_state->uapi.dst);
88 return width > 0 && width <= config->cursor_width &&
89 height > 0 && height <= config->cursor_height;
92 static int intel_cursor_check_surface(struct intel_plane_state *plane_state)
94 struct drm_i915_private *dev_priv =
95 to_i915(plane_state->uapi.plane->dev);
96 unsigned int rotation = plane_state->hw.rotation;
101 ret = intel_plane_compute_gtt(plane_state);
105 if (!plane_state->uapi.visible)
108 src_x = plane_state->uapi.src.x1 >> 16;
109 src_y = plane_state->uapi.src.y1 >> 16;
111 intel_add_fb_offsets(&src_x, &src_y, plane_state, 0);
112 offset = intel_plane_compute_aligned_offset(&src_x, &src_y,
115 if (src_x != 0 || src_y != 0) {
116 drm_dbg_kms(&dev_priv->drm,
117 "Arbitrary cursor panning not supported\n");
122 * Put the final coordinates back so that the src
123 * coordinate checks will see the right values.
125 drm_rect_translate_to(&plane_state->uapi.src,
126 src_x << 16, src_y << 16);
128 /* ILK+ do this automagically in hardware */
129 if (HAS_GMCH(dev_priv) && rotation & DRM_MODE_ROTATE_180) {
130 const struct drm_framebuffer *fb = plane_state->hw.fb;
131 int src_w = drm_rect_width(&plane_state->uapi.src) >> 16;
132 int src_h = drm_rect_height(&plane_state->uapi.src) >> 16;
134 offset += (src_h * src_w - 1) * fb->format->cpp[0];
137 plane_state->view.color_plane[0].offset = offset;
138 plane_state->view.color_plane[0].x = src_x;
139 plane_state->view.color_plane[0].y = src_y;
144 static int intel_check_cursor(struct intel_crtc_state *crtc_state,
145 struct intel_plane_state *plane_state)
147 const struct drm_framebuffer *fb = plane_state->hw.fb;
148 struct drm_i915_private *i915 = to_i915(plane_state->uapi.plane->dev);
149 const struct drm_rect src = plane_state->uapi.src;
150 const struct drm_rect dst = plane_state->uapi.dst;
153 if (fb && fb->modifier != DRM_FORMAT_MOD_LINEAR) {
154 drm_dbg_kms(&i915->drm, "cursor cannot be tiled\n");
158 ret = intel_atomic_plane_check_clipping(plane_state, crtc_state,
159 DRM_PLANE_NO_SCALING,
160 DRM_PLANE_NO_SCALING,
165 /* Use the unclipped src/dst rectangles, which we program to hw */
166 plane_state->uapi.src = src;
167 plane_state->uapi.dst = dst;
169 /* final plane coordinates will be relative to the plane's pipe */
170 drm_rect_translate(&plane_state->uapi.dst,
171 -crtc_state->pipe_src.x1,
172 -crtc_state->pipe_src.y1);
174 ret = intel_cursor_check_surface(plane_state);
178 if (!plane_state->uapi.visible)
181 ret = intel_plane_check_src_coordinates(plane_state);
189 i845_cursor_max_stride(struct intel_plane *plane,
190 u32 pixel_format, u64 modifier,
191 unsigned int rotation)
196 static u32 i845_cursor_ctl_crtc(const struct intel_crtc_state *crtc_state)
200 if (crtc_state->gamma_enable)
201 cntl |= CURSOR_PIPE_GAMMA_ENABLE;
206 static u32 i845_cursor_ctl(const struct intel_crtc_state *crtc_state,
207 const struct intel_plane_state *plane_state)
209 return CURSOR_ENABLE |
211 CURSOR_STRIDE(plane_state->view.color_plane[0].mapping_stride);
214 static bool i845_cursor_size_ok(const struct intel_plane_state *plane_state)
216 int width = drm_rect_width(&plane_state->uapi.dst);
219 * 845g/865g are only limited by the width of their cursors,
220 * the height is arbitrary up to the precision of the register.
222 return intel_cursor_size_ok(plane_state) && IS_ALIGNED(width, 64);
225 static int i845_check_cursor(struct intel_crtc_state *crtc_state,
226 struct intel_plane_state *plane_state)
228 const struct drm_framebuffer *fb = plane_state->hw.fb;
229 struct drm_i915_private *i915 = to_i915(plane_state->uapi.plane->dev);
232 ret = intel_check_cursor(crtc_state, plane_state);
236 /* if we want to turn off the cursor ignore width and height */
240 /* Check for which cursor types we support */
241 if (!i845_cursor_size_ok(plane_state)) {
242 drm_dbg_kms(&i915->drm,
243 "Cursor dimension %dx%d not supported\n",
244 drm_rect_width(&plane_state->uapi.dst),
245 drm_rect_height(&plane_state->uapi.dst));
249 drm_WARN_ON(&i915->drm, plane_state->uapi.visible &&
250 plane_state->view.color_plane[0].mapping_stride != fb->pitches[0]);
252 switch (fb->pitches[0]) {
259 drm_dbg_kms(&i915->drm, "Invalid cursor stride (%u)\n",
264 plane_state->ctl = i845_cursor_ctl(crtc_state, plane_state);
269 /* TODO: split into noarm+arm pair */
270 static void i845_cursor_update_arm(struct intel_plane *plane,
271 const struct intel_crtc_state *crtc_state,
272 const struct intel_plane_state *plane_state)
274 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
275 u32 cntl = 0, base = 0, pos = 0, size = 0;
277 if (plane_state && plane_state->uapi.visible) {
278 unsigned int width = drm_rect_width(&plane_state->uapi.dst);
279 unsigned int height = drm_rect_height(&plane_state->uapi.dst);
281 cntl = plane_state->ctl |
282 i845_cursor_ctl_crtc(crtc_state);
284 size = CURSOR_HEIGHT(height) | CURSOR_WIDTH(width);
286 base = intel_cursor_base(plane_state);
287 pos = intel_cursor_position(crtc_state, plane_state, false);
290 /* On these chipsets we can only modify the base/size/stride
291 * whilst the cursor is disabled.
293 if (plane->cursor.base != base ||
294 plane->cursor.size != size ||
295 plane->cursor.cntl != cntl) {
296 intel_de_write_fw(dev_priv, CURCNTR(PIPE_A), 0);
297 intel_de_write_fw(dev_priv, CURBASE(PIPE_A), base);
298 intel_de_write_fw(dev_priv, CURSIZE(PIPE_A), size);
299 intel_de_write_fw(dev_priv, CURPOS(PIPE_A), pos);
300 intel_de_write_fw(dev_priv, CURCNTR(PIPE_A), cntl);
302 plane->cursor.base = base;
303 plane->cursor.size = size;
304 plane->cursor.cntl = cntl;
306 intel_de_write_fw(dev_priv, CURPOS(PIPE_A), pos);
310 static void i845_cursor_disable_arm(struct intel_plane *plane,
311 const struct intel_crtc_state *crtc_state)
313 i845_cursor_update_arm(plane, crtc_state, NULL);
316 static bool i845_cursor_get_hw_state(struct intel_plane *plane,
319 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
320 enum intel_display_power_domain power_domain;
321 intel_wakeref_t wakeref;
324 power_domain = POWER_DOMAIN_PIPE(PIPE_A);
325 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
329 ret = intel_de_read(dev_priv, CURCNTR(PIPE_A)) & CURSOR_ENABLE;
333 intel_display_power_put(dev_priv, power_domain, wakeref);
339 i9xx_cursor_max_stride(struct intel_plane *plane,
340 u32 pixel_format, u64 modifier,
341 unsigned int rotation)
343 return plane->base.dev->mode_config.cursor_width * 4;
346 static u32 i9xx_cursor_ctl_crtc(const struct intel_crtc_state *crtc_state)
348 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
349 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
352 if (DISPLAY_VER(dev_priv) >= 11)
355 if (crtc_state->gamma_enable)
356 cntl = MCURSOR_PIPE_GAMMA_ENABLE;
358 if (crtc_state->csc_enable)
359 cntl |= MCURSOR_PIPE_CSC_ENABLE;
361 if (DISPLAY_VER(dev_priv) < 5 && !IS_G4X(dev_priv))
362 cntl |= MCURSOR_PIPE_SEL(crtc->pipe);
367 static u32 i9xx_cursor_ctl(const struct intel_crtc_state *crtc_state,
368 const struct intel_plane_state *plane_state)
370 struct drm_i915_private *dev_priv =
371 to_i915(plane_state->uapi.plane->dev);
374 if (IS_SANDYBRIDGE(dev_priv) || IS_IVYBRIDGE(dev_priv))
375 cntl |= MCURSOR_TRICKLE_FEED_DISABLE;
377 switch (drm_rect_width(&plane_state->uapi.dst)) {
379 cntl |= MCURSOR_MODE_64_ARGB_AX;
382 cntl |= MCURSOR_MODE_128_ARGB_AX;
385 cntl |= MCURSOR_MODE_256_ARGB_AX;
388 MISSING_CASE(drm_rect_width(&plane_state->uapi.dst));
392 if (plane_state->hw.rotation & DRM_MODE_ROTATE_180)
393 cntl |= MCURSOR_ROTATE_180;
395 /* Wa_22012358565:adl-p */
396 if (DISPLAY_VER(dev_priv) == 13)
397 cntl |= MCURSOR_ARB_SLOTS(1);
402 static bool i9xx_cursor_size_ok(const struct intel_plane_state *plane_state)
404 struct drm_i915_private *dev_priv =
405 to_i915(plane_state->uapi.plane->dev);
406 int width = drm_rect_width(&plane_state->uapi.dst);
407 int height = drm_rect_height(&plane_state->uapi.dst);
409 if (!intel_cursor_size_ok(plane_state))
412 /* Cursor width is limited to a few power-of-two sizes */
423 * IVB+ have CUR_FBC_CTL which allows an arbitrary cursor
424 * height from 8 lines up to the cursor width, when the
425 * cursor is not rotated. Everything else requires square
428 if (HAS_CUR_FBC(dev_priv) &&
429 plane_state->hw.rotation & DRM_MODE_ROTATE_0) {
430 if (height < 8 || height > width)
440 static int i9xx_check_cursor(struct intel_crtc_state *crtc_state,
441 struct intel_plane_state *plane_state)
443 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
444 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
445 const struct drm_framebuffer *fb = plane_state->hw.fb;
446 enum pipe pipe = plane->pipe;
449 ret = intel_check_cursor(crtc_state, plane_state);
453 /* if we want to turn off the cursor ignore width and height */
457 /* Check for which cursor types we support */
458 if (!i9xx_cursor_size_ok(plane_state)) {
459 drm_dbg(&dev_priv->drm,
460 "Cursor dimension %dx%d not supported\n",
461 drm_rect_width(&plane_state->uapi.dst),
462 drm_rect_height(&plane_state->uapi.dst));
466 drm_WARN_ON(&dev_priv->drm, plane_state->uapi.visible &&
467 plane_state->view.color_plane[0].mapping_stride != fb->pitches[0]);
469 if (fb->pitches[0] !=
470 drm_rect_width(&plane_state->uapi.dst) * fb->format->cpp[0]) {
471 drm_dbg_kms(&dev_priv->drm,
472 "Invalid cursor stride (%u) (cursor width %d)\n",
474 drm_rect_width(&plane_state->uapi.dst));
479 * There's something wrong with the cursor on CHV pipe C.
480 * If it straddles the left edge of the screen then
481 * moving it away from the edge or disabling it often
482 * results in a pipe underrun, and often that can lead to
483 * dead pipe (constant underrun reported, and it scans
484 * out just a solid color). To recover from that, the
485 * display power well must be turned off and on again.
486 * Refuse the put the cursor into that compromised position.
488 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_C &&
489 plane_state->uapi.visible && plane_state->uapi.dst.x1 < 0) {
490 drm_dbg_kms(&dev_priv->drm,
491 "CHV cursor C not allowed to straddle the left screen edge\n");
495 plane_state->ctl = i9xx_cursor_ctl(crtc_state, plane_state);
500 static void i9xx_cursor_disable_sel_fetch_arm(struct intel_plane *plane,
501 const struct intel_crtc_state *crtc_state)
503 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
504 enum pipe pipe = plane->pipe;
506 if (!crtc_state->enable_psr2_sel_fetch)
509 intel_de_write_fw(dev_priv, PLANE_SEL_FETCH_CTL(pipe, plane->id), 0);
512 static void wa_16021440873(struct intel_plane *plane,
513 const struct intel_crtc_state *crtc_state,
514 const struct intel_plane_state *plane_state)
516 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
517 u32 ctl = plane_state->ctl;
518 int et_y_position = drm_rect_height(&crtc_state->pipe_src) + 1;
519 enum pipe pipe = plane->pipe;
521 ctl &= ~MCURSOR_MODE_MASK;
522 ctl |= MCURSOR_MODE_64_2B;
524 intel_de_write_fw(dev_priv, PLANE_SEL_FETCH_CTL(pipe, plane->id), ctl);
526 intel_de_write(dev_priv, PIPE_SRCSZ_ERLY_TPT(pipe),
527 PIPESRC_HEIGHT(et_y_position));
530 static void i9xx_cursor_update_sel_fetch_arm(struct intel_plane *plane,
531 const struct intel_crtc_state *crtc_state,
532 const struct intel_plane_state *plane_state)
534 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
535 enum pipe pipe = plane->pipe;
537 if (!crtc_state->enable_psr2_sel_fetch)
540 if (drm_rect_height(&plane_state->psr2_sel_fetch_area) > 0) {
541 if (crtc_state->enable_psr2_su_region_et) {
542 u32 val = intel_cursor_position(crtc_state, plane_state,
544 intel_de_write_fw(dev_priv, CURPOS_ERLY_TPT(pipe), val);
547 intel_de_write_fw(dev_priv, PLANE_SEL_FETCH_CTL(pipe, plane->id),
551 if (crtc_state->enable_psr2_su_region_et)
552 wa_16021440873(plane, crtc_state, plane_state);
554 i9xx_cursor_disable_sel_fetch_arm(plane, crtc_state);
558 /* TODO: split into noarm+arm pair */
559 static void i9xx_cursor_update_arm(struct intel_plane *plane,
560 const struct intel_crtc_state *crtc_state,
561 const struct intel_plane_state *plane_state)
563 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
564 enum pipe pipe = plane->pipe;
565 u32 cntl = 0, base = 0, pos = 0, fbc_ctl = 0;
567 if (plane_state && plane_state->uapi.visible) {
568 int width = drm_rect_width(&plane_state->uapi.dst);
569 int height = drm_rect_height(&plane_state->uapi.dst);
571 cntl = plane_state->ctl |
572 i9xx_cursor_ctl_crtc(crtc_state);
575 fbc_ctl = CUR_FBC_EN | CUR_FBC_HEIGHT(height - 1);
577 base = intel_cursor_base(plane_state);
578 pos = intel_cursor_position(crtc_state, plane_state, false);
582 * On some platforms writing CURCNTR first will also
583 * cause CURPOS to be armed by the CURBASE write.
584 * Without the CURCNTR write the CURPOS write would
585 * arm itself. Thus we always update CURCNTR before
588 * On other platforms CURPOS always requires the
589 * CURBASE write to arm the update. Additonally
590 * a write to any of the cursor register will cancel
591 * an already armed cursor update. Thus leaving out
592 * the CURBASE write after CURPOS could lead to a
593 * cursor that doesn't appear to move, or even change
594 * shape. Thus we always write CURBASE.
596 * The other registers are armed by the CURBASE write
597 * except when the plane is getting enabled at which time
598 * the CURCNTR write arms the update.
601 if (DISPLAY_VER(dev_priv) >= 9)
602 skl_write_cursor_wm(plane, crtc_state);
605 i9xx_cursor_update_sel_fetch_arm(plane, crtc_state,
608 i9xx_cursor_disable_sel_fetch_arm(plane, crtc_state);
610 if (plane->cursor.base != base ||
611 plane->cursor.size != fbc_ctl ||
612 plane->cursor.cntl != cntl) {
613 if (HAS_CUR_FBC(dev_priv))
614 intel_de_write_fw(dev_priv, CUR_FBC_CTL(pipe),
616 intel_de_write_fw(dev_priv, CURCNTR(pipe), cntl);
617 intel_de_write_fw(dev_priv, CURPOS(pipe), pos);
618 intel_de_write_fw(dev_priv, CURBASE(pipe), base);
620 plane->cursor.base = base;
621 plane->cursor.size = fbc_ctl;
622 plane->cursor.cntl = cntl;
624 intel_de_write_fw(dev_priv, CURPOS(pipe), pos);
625 intel_de_write_fw(dev_priv, CURBASE(pipe), base);
629 static void i9xx_cursor_disable_arm(struct intel_plane *plane,
630 const struct intel_crtc_state *crtc_state)
632 i9xx_cursor_update_arm(plane, crtc_state, NULL);
635 static bool i9xx_cursor_get_hw_state(struct intel_plane *plane,
638 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
639 enum intel_display_power_domain power_domain;
640 intel_wakeref_t wakeref;
645 * Not 100% correct for planes that can move between pipes,
646 * but that's only the case for gen2-3 which don't have any
647 * display power wells.
649 power_domain = POWER_DOMAIN_PIPE(plane->pipe);
650 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
654 val = intel_de_read(dev_priv, CURCNTR(plane->pipe));
656 ret = val & MCURSOR_MODE_MASK;
658 if (DISPLAY_VER(dev_priv) >= 5 || IS_G4X(dev_priv))
661 *pipe = REG_FIELD_GET(MCURSOR_PIPE_SEL_MASK, val);
663 intel_display_power_put(dev_priv, power_domain, wakeref);
668 static bool intel_cursor_format_mod_supported(struct drm_plane *_plane,
669 u32 format, u64 modifier)
671 if (!intel_fb_plane_supports_modifier(to_intel_plane(_plane), modifier))
674 return format == DRM_FORMAT_ARGB8888;
678 intel_legacy_cursor_update(struct drm_plane *_plane,
679 struct drm_crtc *_crtc,
680 struct drm_framebuffer *fb,
681 int crtc_x, int crtc_y,
682 unsigned int crtc_w, unsigned int crtc_h,
683 u32 src_x, u32 src_y,
684 u32 src_w, u32 src_h,
685 struct drm_modeset_acquire_ctx *ctx)
687 struct intel_plane *plane = to_intel_plane(_plane);
688 struct intel_crtc *crtc = to_intel_crtc(_crtc);
689 struct drm_i915_private *i915 = to_i915(plane->base.dev);
690 struct intel_plane_state *old_plane_state =
691 to_intel_plane_state(plane->base.state);
692 struct intel_plane_state *new_plane_state;
693 struct intel_crtc_state *crtc_state =
694 to_intel_crtc_state(crtc->base.state);
695 struct intel_crtc_state *new_crtc_state;
696 struct intel_vblank_evade_ctx evade;
700 * When crtc is inactive or there is a modeset pending,
701 * wait for it to complete in the slowpath.
702 * PSR2 selective fetch also requires the slow path as
703 * PSR2 plane and transcoder registers can only be updated during
706 * FIXME bigjoiner fastpath would be good
708 if (!crtc_state->hw.active ||
709 intel_crtc_needs_modeset(crtc_state) ||
710 intel_crtc_needs_fastset(crtc_state) ||
711 crtc_state->bigjoiner_pipes)
715 * Don't do an async update if there is an outstanding commit modifying
716 * the plane. This prevents our async update's changes from getting
717 * overridden by a previous synchronous update's state.
719 if (old_plane_state->uapi.commit &&
720 !try_wait_for_completion(&old_plane_state->uapi.commit->hw_done))
724 * If any parameters change that may affect watermarks,
725 * take the slowpath. Only changing fb or position should be
728 if (old_plane_state->uapi.crtc != &crtc->base ||
729 old_plane_state->uapi.src_w != src_w ||
730 old_plane_state->uapi.src_h != src_h ||
731 old_plane_state->uapi.crtc_w != crtc_w ||
732 old_plane_state->uapi.crtc_h != crtc_h ||
733 !old_plane_state->uapi.fb != !fb)
736 new_plane_state = to_intel_plane_state(intel_plane_duplicate_state(&plane->base));
737 if (!new_plane_state)
740 new_crtc_state = to_intel_crtc_state(intel_crtc_duplicate_state(&crtc->base));
741 if (!new_crtc_state) {
746 drm_atomic_set_fb_for_plane(&new_plane_state->uapi, fb);
748 new_plane_state->uapi.src_x = src_x;
749 new_plane_state->uapi.src_y = src_y;
750 new_plane_state->uapi.src_w = src_w;
751 new_plane_state->uapi.src_h = src_h;
752 new_plane_state->uapi.crtc_x = crtc_x;
753 new_plane_state->uapi.crtc_y = crtc_y;
754 new_plane_state->uapi.crtc_w = crtc_w;
755 new_plane_state->uapi.crtc_h = crtc_h;
757 intel_plane_copy_uapi_to_hw_state(new_plane_state, new_plane_state, crtc);
759 ret = intel_plane_atomic_check_with_state(crtc_state, new_crtc_state,
760 old_plane_state, new_plane_state);
764 ret = intel_plane_pin_fb(new_plane_state);
768 intel_frontbuffer_flush(to_intel_frontbuffer(new_plane_state->hw.fb),
769 ORIGIN_CURSOR_UPDATE);
770 intel_frontbuffer_track(to_intel_frontbuffer(old_plane_state->hw.fb),
771 to_intel_frontbuffer(new_plane_state->hw.fb),
772 plane->frontbuffer_bit);
774 /* Swap plane state */
775 plane->base.state = &new_plane_state->uapi;
778 * We cannot swap crtc_state as it may be in use by an atomic commit or
779 * page flip that's running simultaneously. If we swap crtc_state and
780 * destroy the old state, we will cause a use-after-free there.
782 * Only update active_planes, which is needed for our internal
783 * bookkeeping. Either value will do the right thing when updating
784 * planes atomically. If the cursor was part of the atomic update then
785 * we would have taken the slowpath.
787 crtc_state->active_planes = new_crtc_state->active_planes;
789 intel_vblank_evade_init(crtc_state, crtc_state, &evade);
791 intel_psr_lock(crtc_state);
793 if (!drm_WARN_ON(&i915->drm, drm_crtc_vblank_get(&crtc->base))) {
795 * TODO: maybe check if we're still in PSR
796 * and skip the vblank evasion entirely?
798 intel_psr_wait_for_idle_locked(crtc_state);
802 intel_vblank_evade(&evade);
804 drm_crtc_vblank_put(&crtc->base);
809 if (new_plane_state->uapi.visible) {
810 intel_plane_update_noarm(plane, crtc_state, new_plane_state);
811 intel_plane_update_arm(plane, crtc_state, new_plane_state);
813 intel_plane_disable_arm(plane, crtc_state);
818 intel_psr_unlock(crtc_state);
820 intel_plane_unpin_fb(old_plane_state);
824 intel_crtc_destroy_state(&crtc->base, &new_crtc_state->uapi);
826 intel_plane_destroy_state(&plane->base, &new_plane_state->uapi);
828 intel_plane_destroy_state(&plane->base, &old_plane_state->uapi);
832 return drm_atomic_helper_update_plane(&plane->base, &crtc->base, fb,
833 crtc_x, crtc_y, crtc_w, crtc_h,
834 src_x, src_y, src_w, src_h, ctx);
837 static const struct drm_plane_funcs intel_cursor_plane_funcs = {
838 .update_plane = intel_legacy_cursor_update,
839 .disable_plane = drm_atomic_helper_disable_plane,
840 .destroy = intel_plane_destroy,
841 .atomic_duplicate_state = intel_plane_duplicate_state,
842 .atomic_destroy_state = intel_plane_destroy_state,
843 .format_mod_supported = intel_cursor_format_mod_supported,
846 static void intel_cursor_add_size_hints_property(struct intel_plane *plane)
848 struct drm_i915_private *i915 = to_i915(plane->base.dev);
849 const struct drm_mode_config *config = &i915->drm.mode_config;
850 struct drm_plane_size_hint hints[4];
851 int size, max_size, num_hints = 0;
853 max_size = min(config->cursor_width, config->cursor_height);
855 /* for simplicity only enumerate the supported square+POT sizes */
856 for (size = 64; size <= max_size; size *= 2) {
857 if (drm_WARN_ON(&i915->drm, num_hints >= ARRAY_SIZE(hints)))
860 hints[num_hints].width = size;
861 hints[num_hints].height = size;
865 drm_plane_add_size_hints_property(&plane->base, hints, num_hints);
869 intel_cursor_plane_create(struct drm_i915_private *dev_priv,
872 struct intel_plane *cursor;
876 cursor = intel_plane_alloc();
881 cursor->i9xx_plane = (enum i9xx_plane_id) pipe;
882 cursor->id = PLANE_CURSOR;
883 cursor->frontbuffer_bit = INTEL_FRONTBUFFER(pipe, cursor->id);
885 if (IS_I845G(dev_priv) || IS_I865G(dev_priv)) {
886 cursor->max_stride = i845_cursor_max_stride;
887 cursor->update_arm = i845_cursor_update_arm;
888 cursor->disable_arm = i845_cursor_disable_arm;
889 cursor->get_hw_state = i845_cursor_get_hw_state;
890 cursor->check_plane = i845_check_cursor;
892 cursor->max_stride = i9xx_cursor_max_stride;
893 cursor->update_arm = i9xx_cursor_update_arm;
894 cursor->disable_arm = i9xx_cursor_disable_arm;
895 cursor->get_hw_state = i9xx_cursor_get_hw_state;
896 cursor->check_plane = i9xx_check_cursor;
899 cursor->cursor.base = ~0;
900 cursor->cursor.cntl = ~0;
902 if (IS_I845G(dev_priv) || IS_I865G(dev_priv) || HAS_CUR_FBC(dev_priv))
903 cursor->cursor.size = ~0;
905 modifiers = intel_fb_plane_get_modifiers(dev_priv, INTEL_PLANE_CAP_NONE);
907 ret = drm_universal_plane_init(&dev_priv->drm, &cursor->base,
908 0, &intel_cursor_plane_funcs,
909 intel_cursor_formats,
910 ARRAY_SIZE(intel_cursor_formats),
912 DRM_PLANE_TYPE_CURSOR,
913 "cursor %c", pipe_name(pipe));
920 if (DISPLAY_VER(dev_priv) >= 4)
921 drm_plane_create_rotation_property(&cursor->base,
924 DRM_MODE_ROTATE_180);
926 intel_cursor_add_size_hints_property(cursor);
928 zpos = DISPLAY_RUNTIME_INFO(dev_priv)->num_sprites[pipe] + 1;
929 drm_plane_create_zpos_immutable_property(&cursor->base, zpos);
931 if (DISPLAY_VER(dev_priv) >= 12)
932 drm_plane_enable_fb_damage_clips(&cursor->base);
934 intel_plane_helper_add(cursor);
939 intel_plane_free(cursor);